Skip to content

Commit

Permalink
Merge e1f9406 into a6f1a6d
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmire-Kristof committed Feb 27, 2020
2 parents a6f1a6d + e1f9406 commit 1a37842
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 38 deletions.
7 changes: 6 additions & 1 deletion src/app/+my-dspace-page/my-dspace-page.component.ts
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/eperson/group-data.service.ts
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
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
@@ -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;
}
7 changes: 4 additions & 3 deletions src/app/core/tasks/models/task-object.model.ts
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;

}
Expand Up @@ -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;
Expand Down
@@ -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>
Expand Up @@ -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>;
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('ClaimedSearchResultListElementComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule],
declarations: [ClaimedSearchResultListElementComponent],
declarations: [ClaimedSearchResultListElementComponent, VarDirective],
providers: [
{ provide: TruncatableService, useValue: {} },
],
Expand All @@ -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', () => {
Expand Down
Expand Up @@ -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';
Expand Down Expand Up @@ -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>>;
}
}

0 comments on commit 1a37842

Please sign in to comment.