Skip to content

Commit

Permalink
Merge pull request #606 from 4Science/#603_mydspace_fixes
Browse files Browse the repository at this point in the history
#603 mydspace fixes
  • Loading branch information
tdonohue authored Mar 3, 2020
2 parents 000bfb8 + 98d44fd commit 01231ef
Show file tree
Hide file tree
Showing 25 changed files with 193 additions and 161 deletions.
2 changes: 1 addition & 1 deletion src/app/+my-dspace-page/my-dspace-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ds-search-labels [inPlaceSearch]="inPlaceSearch"></ds-search-labels>
<div class="row">
<div id="search-body"
class="row-offcanvas row-offcanvas-left"
class="row-offcanvas row-offcanvas-left w-100"
[@pushInOut]="(isSidebarCollapsed() | async) ? 'collapsed' : 'expanded'">
<ds-search-sidebar *ngIf="(isXsOrSm$ | async)" class="col-12"
id="search-sidebar-sm"
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/data/bitstream-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/internal/Observable';
import { map, switchMap } from 'rxjs/operators';
import { hasValue } from '../../shared/empty.util';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { dataService } from '../cache/builders/build-decorators';
Expand Down Expand Up @@ -72,7 +72,7 @@ export class BitstreamDataService extends DataService<Bitstream> {
public getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
switchMap((bundleRD: RemoteData<Bundle>) => {
if (hasValue(bundleRD.payload)) {
if (isNotEmpty(bundleRD.payload)) {
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: 1 }).pipe(
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {
Expand Down Expand Up @@ -108,7 +108,7 @@ export class BitstreamDataService extends DataService<Bitstream> {
public getMatchingThumbnail(item: Item, bitstreamInOriginal: Bitstream): Observable<RemoteData<Bitstream>> {
return this.bundleService.findByItemAndName(item, 'THUMBNAIL').pipe(
switchMap((bundleRD: RemoteData<Bundle>) => {
if (hasValue(bundleRD.payload)) {
if (isNotEmpty(bundleRD.payload)) {
return this.findAllByBundle(bundleRD.payload, { elementsPerPage: Number.MAX_SAFE_INTEGER }).pipe(
map((bitstreamRD: RemoteData<PaginatedList<Bitstream>>) => {
if (hasValue(bitstreamRD.payload) && hasValue(bitstreamRD.payload.page)) {
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/eperson/group-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import { RemoteData } from '../data/remote-data';
import { PaginatedList } from '../data/paginated-list';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service';
import { dataService } from '../cache/builders/build-decorators';
import { GROUP } from './models/group.resource-type';

/**
* Provides methods to retrieve eperson group resources.
*/
@Injectable({
providedIn: 'root'
})
@dataService(GROUP)
export class GroupDataService extends DataService<Group> {
protected linkPath = 'groups';
protected browseEndpoint = '';
Expand Down
12 changes: 7 additions & 5 deletions src/app/core/shared/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { combineLatest as observableCombineLatest, Observable, of as observableO
import { Injectable, OnDestroy } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';
import { first, map, switchMap, tap } from 'rxjs/operators';
import { followLink } from '../../../shared/utils/follow-link-config.model';
import { followLink, FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
import { LinkService } from '../../cache/builders/link.service';
import { FacetConfigSuccessResponse, FacetValueSuccessResponse, SearchSuccessResponse } from '../../cache/response.models';
import { PaginatedList } from '../../data/paginated-list';
Expand Down Expand Up @@ -107,10 +107,11 @@ export class SearchService implements OnDestroy {
* Method to retrieve a paginated list of search results from the server
* @param {PaginatedSearchOptions} searchOptions The configuration necessary to perform this search
* @param responseMsToLive The amount of milliseconds for the response to live in cache
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
* @returns {Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>} Emits a paginated list with all search results found
*/
search(searchOptions?: PaginatedSearchOptions, responseMsToLive?: number): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
return this.getPaginatedResults(this.searchEntries(searchOptions));
search<T extends DSpaceObject>(searchOptions?: PaginatedSearchOptions, responseMsToLive?: number, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
return this.getPaginatedResults<T>(this.searchEntries(searchOptions), ...linksToFollow);
}

/**
Expand Down Expand Up @@ -151,9 +152,10 @@ export class SearchService implements OnDestroy {
/**
* Method to convert the parsed responses into a paginated list of search results
* @param searchEntries: The request entries from the search method
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
* @returns {Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>} Emits a paginated list with all search results found
*/
getPaginatedResults(searchEntries: Observable<{ searchOptions: PaginatedSearchOptions, requestEntry: RequestEntry }>): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
getPaginatedResults<T extends DSpaceObject>(searchEntries: Observable<{ searchOptions: PaginatedSearchOptions, requestEntry: RequestEntry }>, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
const requestEntryObs: Observable<RequestEntry> = searchEntries.pipe(
map((entry) => entry.requestEntry),
);
Expand All @@ -174,7 +176,7 @@ export class SearchService implements OnDestroy {
}),
// Send a request for each item to ensure fresh cache
tap((reqs: RestRequest[]) => reqs.forEach((req: RestRequest) => this.requestService.configure(req))),
map((reqs: RestRequest[]) => reqs.map((req: RestRequest) => this.rdb.buildSingle(req.href))),
map((reqs: RestRequest[]) => reqs.map((req: RestRequest) => this.rdb.buildSingle(req.href, ...linksToFollow))),
switchMap((input: Array<Observable<RemoteData<DSpaceObject>>>) => this.rdb.aggregate(input)),
);

Expand Down
6 changes: 3 additions & 3 deletions src/app/core/tasks/models/claimed-task-object.model.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { inheritSerialization } from 'cerialize';
import { typedObject } from '../../cache/builders/build-decorators';
import { DSpaceObject } from '../../shared/dspace-object.model';
import { inheritLinkAnnotations, typedObject } from '../../cache/builders/build-decorators';
import { CLAIMED_TASK } from './claimed-task-object.resource-type';
import { TaskObject } from './task-object.model';

/**
* A model class for a ClaimedTask.
*/
@typedObject
@inheritSerialization(DSpaceObject)
@inheritSerialization(TaskObject)
@inheritLinkAnnotations(TaskObject)
export class ClaimedTask extends TaskObject {
static type = CLAIMED_TASK;
}
3 changes: 2 additions & 1 deletion src/app/core/tasks/models/pool-task-object.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inheritSerialization } from 'cerialize';
import { typedObject } from '../../cache/builders/build-decorators';
import { inheritLinkAnnotations, typedObject } from '../../cache/builders/build-decorators';
import { POOL_TASK } from './pool-task-object.resource-type';
import { TaskObject } from './task-object.model';

Expand All @@ -8,6 +8,7 @@ import { TaskObject } from './task-object.model';
*/
@typedObject
@inheritSerialization(TaskObject)
@inheritLinkAnnotations(TaskObject)
export class PoolTask extends TaskObject {
static type = POOL_TASK;
}
7 changes: 4 additions & 3 deletions src/app/core/tasks/models/task-object.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DSpaceObject } from '../../shared/dspace-object.model';
import { HALLink } from '../../shared/hal-link.model';
import { WorkflowItem } from '../../submission/models/workflowitem.model';
import { TASK_OBJECT } from './task-object.resource-type';
import { WORKFLOWITEM } from '../../eperson/models/workflowitem.resource-type';

/**
* An abstract model class for a TaskObject.
Expand Down Expand Up @@ -45,7 +46,7 @@ export class TaskObject extends DSpaceObject implements CacheableObject {
@deserialize
_links: {
self: HALLink;
eperson: HALLink;
owner: HALLink;
group: HALLink;
workflowitem: HALLink;
};
Expand All @@ -54,7 +55,7 @@ export class TaskObject extends DSpaceObject implements CacheableObject {
* The EPerson for this task
* Will be undefined unless the eperson {@link HALLink} has been resolved.
*/
@link(EPERSON)
@link(EPERSON, false, 'owner')
eperson?: Observable<RemoteData<EPerson>>;

/**
Expand All @@ -68,7 +69,7 @@ export class TaskObject extends DSpaceObject implements CacheableObject {
* The WorkflowItem for this task
* Will be undefined unless the workflowitem {@link HALLink} has been resolved.
*/
@link(WorkflowItem.type)
@link(WORKFLOWITEM)
workflowitem?: Observable<RemoteData<WorkflowItem>> | WorkflowItem;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a [class.disabled]="!(object.workflowitem | async)?.hasSucceeded"
class="btn btn-primary mt-1 mb-3"
ngbTooltip="{{'submission.workflow.tasks.claimed.edit_help' | translate}}"
[routerLink]="['/workflowitems/' + (object.workflowitem | async)?.payload.id + '/edit']"
[routerLink]="['/workflowitems/' + (object?.workflowitem | async)?.payload?.id + '/edit']"
role="button">
<i class="fa fa-edit"></i> {{'submission.workflow.tasks.claimed.edit' | translate}}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<ds-item-detail-preview *ngIf="workflowitem"
[item]="(workflowitem.item | async)?.payload"
[object]="object"
[showSubmitter]="showSubmitter"
[status]="status">
</ds-item-detail-preview>
<ng-container *ngVar="(workflowitemRD$ | async)?.payload as workflowitem">
<ds-item-detail-preview *ngIf="workflowitem"
[item]="(workflowitem.item | async)?.payload"
[object]="object"
[showSubmitter]="showSubmitter"
[status]="status">
</ds-item-detail-preview>

<ds-claimed-task-actions *ngIf="workflowitem" [object]="dso"></ds-claimed-task-actions>
<ds-claimed-task-actions *ngIf="workflowitem" [object]="dso"></ds-claimed-task-actions>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspa
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { createSuccessfulRemoteDataObject } from '../../../testing/utils';
import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model';
import { VarDirective } from '../../../utils/var.directive';
import { getMockLinkService } from '../../../mocks/mock-link-service';
import { LinkService } from '../../../../core/cache/builders/link.service';

let component: ClaimedTaskSearchResultDetailElementComponent;
let fixture: ComponentFixture<ClaimedTaskSearchResultDetailElementComponent>;
Expand Down Expand Up @@ -53,12 +56,16 @@ const rdItem = createSuccessfulRemoteDataObject(item);
const workflowitem = Object.assign(new WorkflowItem(), { item: observableOf(rdItem) });
const rdWorkflowitem = createSuccessfulRemoteDataObject(workflowitem);
mockResultObject.indexableObject = Object.assign(new ClaimedTask(), { workflowitem: observableOf(rdWorkflowitem) });
const linkService = getMockLinkService();

describe('ClaimedTaskSearchResultDetailElementComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [ClaimedTaskSearchResultDetailElementComponent],
declarations: [ClaimedTaskSearchResultDetailElementComponent, VarDirective],
providers: [
{ provide: LinkService, useValue: linkService }
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(ClaimedTaskSearchResultDetailElementComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
Expand All @@ -75,8 +82,12 @@ describe('ClaimedTaskSearchResultDetailElementComponent', () => {
fixture.detectChanges();
});

it('should init item properly', () => {
expect(component.workflowitem).toEqual(workflowitem);
it('should init workflowitem properly', (done) => {
component.workflowitemRD$.subscribe((workflowitemRD) => {
expect(linkService.resolveLink).toHaveBeenCalled();
expect(workflowitemRD.payload).toEqual(workflowitem);
done();
});
});

it('should have properly status', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Component } from '@angular/core';

import { Observable } from 'rxjs';
import { find } from 'rxjs/operators';

import { RemoteData } from '../../../../core/data/remote-data';
import { ViewMode } from '../../../../core/shared/view-mode.model';
import { isNotUndefined } from '../../../empty.util';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
import { SearchResultDetailElementComponent } from '../search-result-detail-element.component';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
import { listableObjectComponent } from '../../../object-collection/shared/listable-object/listable-object.decorator';
import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model';
import { followLink } from '../../../utils/follow-link-config.model';
import { LinkService } from '../../../../core/cache/builders/link.service';

/**
* This component renders claimed task object for the search result in the detail view.
Expand All @@ -38,25 +38,24 @@ export class ClaimedTaskSearchResultDetailElementComponent extends SearchResultD
/**
* The workflowitem object that belonging to the result object
*/
public workflowitem: WorkflowItem;
public workflowitemRD$: Observable<RemoteData<WorkflowItem>>;

constructor(protected linkService: LinkService) {
super();
}

/**
* Initialize all instance variables
*/
ngOnInit() {
super.ngOnInit();
this.initWorkflowItem(this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>);
}

/**
* Retrieve workflow item from result object
*/
initWorkflowItem(wfi$: Observable<RemoteData<WorkflowItem>>) {
wfi$.pipe(
find((rd: RemoteData<WorkflowItem>) => (rd.hasSucceeded && isNotUndefined(rd.payload)))
).subscribe((rd: RemoteData<WorkflowItem>) => {
this.workflowitem = rd.payload;
});
this.linkService.resolveLink(this.dso, followLink(
'workflowitem',
null,
followLink('item', null, followLink('bundles')),
followLink('submitter')
));
this.workflowitemRD$ = this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ <h2 class="item-page-title-field">
<div class="row mb-1">
<div class="col-xs-12 col-md-4">
<ds-metadata-field-wrapper>
<ds-thumbnail [thumbnail]="thumbnail$ | async"></ds-thumbnail>
<ds-thumbnail [thumbnail]="getThumbnail() | async"></ds-thumbnail>
</ds-metadata-field-wrapper>
<ng-container *ngVar="(bitstreams$ | async) as bitstreams">
<ng-container *ngVar="(getFiles() | async) as bitstreams">
<ds-metadata-field-wrapper [label]="('item.page.files' | translate)">
<div *ngIf="bitstreams?.length > 0" class="file-section">
<button class="btn btn-link" *ngFor="let file of bitstreams; let last=last;" (click)="downloadBitstreamFile(file?.uuid)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Store } from '@ngrx/store';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';

import { of as observableOf } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
import { Observable, of as observableOf } from 'rxjs';

import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
import { BitstreamDataService } from '../../../../core/data/bitstream-data.service';
Expand All @@ -28,7 +28,6 @@ import { HALEndpointServiceStub } from '../../../testing/hal-endpoint-service-st
import { createSuccessfulRemoteDataObject$ } from '../../../testing/utils';
import { FileSizePipe } from '../../../utils/file-size-pipe';
import { FollowLinkConfig } from '../../../utils/follow-link-config.model';

import { TruncatePipe } from '../../../utils/truncate.pipe';
import { VarDirective } from '../../../utils/var.directive';
import { ItemDetailPreviewFieldComponent } from './item-detail-preview-field/item-detail-preview-field.component';
Expand Down Expand Up @@ -127,8 +126,17 @@ describe('ItemDetailPreviewComponent', () => {

}));

it('should init thumbnail and bitstreams on init', () => {
expect(component.thumbnail$).toBeDefined();
expect(component.bitstreams$).toBeDefined();
it('should get item thumbnail', (done) => {
component.getThumbnail().subscribe((thumbnail) => {
expect(thumbnail).toBeDefined();
done();
});
});

it('should get item bitstreams', (done) => {
component.getFiles().subscribe((bitstreams) => {
expect(bitstreams).toBeDefined();
done();
})
});
});
Loading

0 comments on commit 01231ef

Please sign in to comment.