Skip to content

Commit

Permalink
[DURACOM-191] Fix issue with admin workflow page
Browse files Browse the repository at this point in the history
  • Loading branch information
atarix83 committed Mar 18, 2024
1 parent ddd0131 commit dfad3f3
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { SearchResult } from '../../../shared/search/models/search-result.model';
import { searchResultFor } from '../../../shared/search/search-result-element-decorator';
import { AdminNotifyMessage } from './admin-notify-message.model';

@searchResultFor(AdminNotifyMessage)
export class AdminNotifySearchResult extends SearchResult<AdminNotifyMessage> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
OnInit,
} from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import {
BehaviorSubject,
Observable,
} from 'rxjs';

import {
APP_CONFIG,
Expand All @@ -20,7 +23,7 @@ import { RemoteData } from '../../../../../core/data/remote-data';
import { Context } from '../../../../../core/shared/context.model';
import { Item } from '../../../../../core/shared/item.model';
import {
getAllSucceededRemoteData,
getFirstCompletedRemoteData,
getRemoteDataPayload,
} from '../../../../../core/shared/operators';
import { ViewMode } from '../../../../../core/shared/view-mode.model';
Expand Down Expand Up @@ -49,7 +52,7 @@ export class WorkflowItemSearchResultAdminWorkflowListElementComponent extends S
/**
* The item linked to the workflow item
*/
public item$: Observable<Item>;
public item$: BehaviorSubject<Item> = new BehaviorSubject<Item>(undefined);

constructor(private linkService: LinkService,
protected truncatableService: TruncatableService,
Expand All @@ -65,6 +68,11 @@ export class WorkflowItemSearchResultAdminWorkflowListElementComponent extends S
ngOnInit(): void {
super.ngOnInit();
this.dso = this.linkService.resolveLink(this.dso, followLink('item'));
this.item$ = (this.dso.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload());
(this.dso.item as Observable<RemoteData<Item>>).pipe(
getFirstCompletedRemoteData(),
getRemoteDataPayload())
.subscribe((item: Item) => {
this.item$.next(item);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { Context } from '../../../../../core/shared/context.model';
import { DSpaceObject } from '../../../../../core/shared/dspace-object.model';
import { Item } from '../../../../../core/shared/item.model';
import {
getAllSucceededRemoteData,
getFirstCompletedRemoteData,
getRemoteDataPayload,
} from '../../../../../core/shared/operators';
Expand Down Expand Up @@ -63,7 +62,7 @@ export class WorkspaceItemSearchResultAdminWorkflowListElementComponent extends
/**
* The item linked to the workflow item
*/
public item$: Observable<Item>;
public item$: BehaviorSubject<Item> = new BehaviorSubject<Item>(undefined);

/**
* The id of the item linked to the workflow item
Expand All @@ -90,11 +89,14 @@ export class WorkspaceItemSearchResultAdminWorkflowListElementComponent extends
ngOnInit(): void {
super.ngOnInit();
this.dso = this.linkService.resolveLink(this.dso, followLink('item'));
this.item$ = (this.dso.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload());
const item$ = (this.dso.item as Observable<RemoteData<Item>>).pipe(getFirstCompletedRemoteData(), getRemoteDataPayload());

this.item$.pipe(
item$.pipe(
take(1),
tap((item: Item) => this.itemId = item.id),
tap((item: Item) => {
this.item$.next(item);
this.itemId = item.id;
}),
mergeMap((item: Item) => this.retrieveSupervisorOrders(item.id)),
).subscribe((supervisionOrderList: SupervisionOrder[]) => {
this.supervisionOrder$.next(supervisionOrderList);
Expand Down
3 changes: 2 additions & 1 deletion src/app/app-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { COMMUNITY_MODULE_PATH } from './community-page/community-page-routing-p
import { AuthBlockingGuard } from './core/auth/auth-blocking.guard';
import { AuthenticatedGuard } from './core/auth/authenticated.guard';
import { GroupAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/group-administrator.guard';
import { SiteAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/site-administrator.guard';
import { SiteRegisterGuard } from './core/data/feature-authorization/feature-authorization-guard/site-register.guard';
import { EndUserAgreementCurrentUserGuard } from './core/end-user-agreement/end-user-agreement-current-user.guard';
import { ReloadGuard } from './core/reload/reload.guard';
Expand Down Expand Up @@ -155,7 +156,7 @@ export const APP_ROUTES: Route[] = [
path: ADMIN_MODULE_PATH,
loadChildren: () => import('./admin/admin-routes')
.then((m) => m.ROUTES),
canActivate: [EndUserAgreementCurrentUserGuard],
canActivate: [SiteAdministratorGuard, EndUserAgreementCurrentUserGuard],
},
{
path: NOTIFICATIONS_MODULE_PATH,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ClaimedTask } from '../../../core/tasks/models/claimed-task-object.model';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';

/**
* Represents a search result object of a ClaimedTask object
*/
@searchResultFor(ClaimedTask)
export class ClaimedTaskSearchResult extends SearchResult<ClaimedTask> {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Collection } from '../../../core/shared/collection.model';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';

@searchResultFor(Collection)
export class CollectionSearchResult extends SearchResult<Collection> {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Community } from '../../../core/shared/community.model';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';

@searchResultFor(Community)
export class CommunitySearchResult extends SearchResult<Community> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { GenericConstructor } from '../../../core/shared/generic-constructor';
import { Item } from '../../../core/shared/item.model';
import { inheritEquatable } from '../../../core/utilities/equals.decorators';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';
import { ListableObject } from './listable-object.model';

@searchResultFor(Item)
@inheritEquatable(SearchResult)
export class ItemSearchResult extends SearchResult<Item> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { PoolTask } from '../../../core/tasks/models/pool-task-object.model';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';

/**
* Represents a search result object of a PoolTask object
*/
@searchResultFor(PoolTask)
export class PoolTaskSearchResult extends SearchResult<PoolTask> {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { WorkflowItem } from '../../../core/submission/models/workflowitem.model';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';

/**
* Represents a search result object of a WorkflowItem object
*/
@searchResultFor(WorkflowItem)
export class WorkflowItemSearchResult extends SearchResult<WorkflowItem> {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
import { SearchResult } from '../../search/models/search-result.model';
import { searchResultFor } from '../../search/search-result-element-decorator';

/**
* Represents a search result object of a WorkspaceItem object
*/
@searchResultFor(WorkspaceItem)
export class WorkspaceItemSearchResult extends SearchResult<WorkspaceItem> {
}
42 changes: 27 additions & 15 deletions src/app/shared/search/search-result-element-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { AdminNotifyMessage } from '../../admin/admin-notify-dashboard/models/admin-notify-message.model';
import { AdminNotifySearchResult } from '../../admin/admin-notify-dashboard/models/admin-notify-message-search-result.model';
import { Collection } from '../../core/shared/collection.model';
import { Community } from '../../core/shared/community.model';
import { GenericConstructor } from '../../core/shared/generic-constructor';
import { Item } from '../../core/shared/item.model';
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model';
import { ClaimedTask } from '../../core/tasks/models/claimed-task-object.model';
import { PoolTask } from '../../core/tasks/models/pool-task-object.model';
import { ClaimedTaskSearchResult } from '../object-collection/shared/claimed-task-search-result.model';
import { CollectionSearchResult } from '../object-collection/shared/collection-search-result.model';
import { CommunitySearchResult } from '../object-collection/shared/community-search-result.model';
import { ItemSearchResult } from '../object-collection/shared/item-search-result.model';
import { ListableObject } from '../object-collection/shared/listable-object.model';
import { PoolTaskSearchResult } from '../object-collection/shared/pool-task-search-result.model';
import { WorkflowItemSearchResult } from '../object-collection/shared/workflow-item-search-result.model';
import { WorkspaceItemSearchResult } from '../object-collection/shared/workspace-item-search-result.model';

/**
* Contains the mapping between a search result component and a DSpaceObject
*/
const searchResultMap = new Map();
export const SEARCH_RESULT_MAP = new Map<string| GenericConstructor<ListableObject>, GenericConstructor<ListableObject>>([
[AdminNotifyMessage, AdminNotifySearchResult],
[ClaimedTask, ClaimedTaskSearchResult],
[PoolTask, PoolTaskSearchResult],
[Collection, CollectionSearchResult],
[Community, CommunitySearchResult],
[Item, ItemSearchResult],
[WorkflowItem, WorkflowItemSearchResult],
[WorkspaceItem, WorkspaceItemSearchResult],
]);

/**
* Used to map Search Result components to their matching DSpaceObject
* @param {GenericConstructor<ListableObject>} domainConstructor The constructor of the DSpaceObject
* @returns Decorator function that performs the actual mapping on initialization of the component
*/
export function searchResultFor(domainConstructor: GenericConstructor<ListableObject>) {
return function decorator(searchResult: any) {
if (!searchResult) {
return;
}
searchResultMap.set(domainConstructor, searchResult);
};
}

/**
* Requests the matching component based on a given DSpaceObject's constructor
* @param {GenericConstructor<ListableObject>} domainConstructor The DSpaceObject's constructor for which the search result component is requested
* @returns The component's constructor that matches the given DSpaceObject
*/
export function getSearchResultFor(domainConstructor: GenericConstructor<ListableObject>) {
return searchResultMap.get(domainConstructor);
return SEARCH_RESULT_MAP.get(domainConstructor);
}

0 comments on commit dfad3f3

Please sign in to comment.