69115: MyDSpace ClaimedTask proper link resolving

This commit is contained in:
Kristof De Langhe
2020-02-26 17:50:44 +01:00
parent a6f1a6d1ec
commit e1f940668a
9 changed files with 42 additions and 38 deletions

View File

@@ -29,6 +29,8 @@ import { ViewMode } from '../core/shared/view-mode.model';
import { MyDSpaceRequest } from '../core/data/request.models';
import { SearchResult } from '../shared/search/search-result.model';
import { Context } from '../core/shared/context.model';
import { followLink } from '../shared/utils/follow-link-config.model';
import { ClaimedTask } from '../core/tasks/models/claimed-task-object.model';
export const MYDSPACE_ROUTE = '/mydspace';
export const SEARCH_CONFIG_SERVICE: InjectionToken<SearchConfigurationService> = new InjectionToken<SearchConfigurationService>('searchConfigurationService');
@@ -126,7 +128,10 @@ export class MyDSpacePageComponent implements OnInit {
this.searchOptions$ = this.searchConfigService.paginatedSearchOptions;
this.sub = this.searchOptions$.pipe(
tap(() => this.resultsRD$.next(null)),
switchMap((options: PaginatedSearchOptions) => this.service.search(options).pipe(getSucceededRemoteData())))
switchMap((options: PaginatedSearchOptions) =>
this.service.search<ClaimedTask>(options, undefined,
followLink('workflowitem', undefined, followLink('item'), followLink('submitter')),
followLink('owner')).pipe(getSucceededRemoteData())))
.subscribe((results) => {
this.resultsRD$.next(results);
});

View File

@@ -18,6 +18,8 @@ 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.
@@ -25,6 +27,7 @@ import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service';
@Injectable({
providedIn: 'root'
})
@dataService(GROUP)
export class GroupDataService extends DataService<Group> {
protected linkPath = 'groups';
protected browseEndpoint = '';

View File

@@ -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';
@@ -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);
}
/**
@@ -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),
);
@@ -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)),
);

View File

@@ -1,6 +1,5 @@
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';
@@ -8,7 +7,8 @@ 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;
}

View File

@@ -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.
@@ -45,7 +46,7 @@ export class TaskObject extends DSpaceObject implements CacheableObject {
@deserialize
_links: {
self: HALLink;
eperson: HALLink;
owner: HALLink;
group: HALLink;
workflowitem: HALLink;
};
@@ -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>>;
/**
@@ -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;
}

View File

@@ -27,12 +27,12 @@ describe('OrgUnitItemMetadataListElementComponent', () => {
}).compileComponents();
}));
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(OrgUnitItemMetadataListElementComponent);
comp = fixture.componentInstance;
comp.metadataRepresentation = mockItemMetadataRepresentation;
fixture.detectChanges();
}));
});
it('should show the name of the organisation as a link', () => {
const linkText = fixture.debugElement.query(By.css('a')).nativeElement.textContent;

View File

@@ -1,7 +1,9 @@
<ds-item-list-preview *ngIf="workflowitem"
[item]="(workflowitem.item | async)?.payload"
[object]="object"
[showSubmitter]="showSubmitter"
[status]="status"></ds-item-list-preview>
<ng-container *ngVar="(workflowitemRD$ | async)?.payload as workflowitem">
<ds-item-list-preview *ngIf="workflowitem"
[item]="(workflowitem?.item | async)?.payload"
[object]="object"
[showSubmitter]="showSubmitter"
[status]="status"></ds-item-list-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>

View File

@@ -12,6 +12,7 @@ import { WorkflowItem } from '../../../../core/submission/models/workflowitem.mo
import { createSuccessfulRemoteDataObject } from '../../../testing/utils';
import { ClaimedTaskSearchResult } from '../../../object-collection/shared/claimed-task-search-result.model';
import { TruncatableService } from '../../../truncatable/truncatable.service';
import { VarDirective } from '../../../utils/var.directive';
let component: ClaimedSearchResultListElementComponent;
let fixture: ComponentFixture<ClaimedSearchResultListElementComponent>;
@@ -59,7 +60,7 @@ describe('ClaimedSearchResultListElementComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [ClaimedSearchResultListElementComponent],
declarations: [ClaimedSearchResultListElementComponent, VarDirective],
providers: [
{ provide: TruncatableService, useValue: {} },
],
@@ -79,8 +80,11 @@ describe('ClaimedSearchResultListElementComponent', () => {
fixture.detectChanges();
});
it('should init item properly', () => {
expect(component.workflowitem).toEqual(workflowitem);
it('should init item properly', (done) => {
component.workflowitemRD$.subscribe((workflowitemRD) => {
expect(workflowitemRD.payload).toEqual(workflowitem);
done();
});
});
it('should have properly status', () => {

View File

@@ -2,11 +2,9 @@ import { Component } from '@angular/core';
import { Location, LocationStrategy, PathLocationStrategy } from '@angular/common';
import { Observable } from 'rxjs';
import { find } from 'rxjs/operators';
import { ViewMode } from '../../../../core/shared/view-mode.model';
import { RemoteData } from '../../../../core/data/remote-data';
import { isNotUndefined } from '../../../empty.util';
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
import { MyDspaceItemStatusType } from '../../../object-collection/shared/mydspace-item-status/my-dspace-item-status-type';
@@ -40,24 +38,13 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
/**
* The workflowitem object that belonging to the result object
*/
public workflowitem: WorkflowItem;
public workflowitemRD$: Observable<RemoteData<WorkflowItem>>;
/**
* Initialize all instance variables
*/
ngOnInit() {
super.ngOnInit();
this.initWorkflowItem(this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>);
}
/**
* Retrieve workflowitem 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.workflowitemRD$ = this.dso.workflowitem as Observable<RemoteData<WorkflowItem>>;
}
}