Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return to pool functionality in Administer Workflow #3054

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,15 @@
<a [ngClass]="{'btn-sm': small}" class="btn btn-light my-1 send-back-link" [routerLink]="[getSendBackRoute()]" [title]="'admin.workflow.item.send-back' | translate">
<i class="fa fa-hand-point-left"></i><span *ngIf="!small" class="d-none d-sm-inline"> {{"admin.workflow.item.send-back" | translate}}</span>
</a>
<ng-container *ngIf="showButton">
<a [ngClass]="{'btn-sm': small}" class="btn btn-light my-1" (click)="returnTaskToPool()" [title]="'submission.workflow.tasks.claimed.return' | translate">
<ng-container *ngIf="!isLoading">
<i class="fa fa-undo"></i><span *ngIf="!small" class="d-none d-sm-inline"> {{"submission.workflow.tasks.claimed.return" | translate}}</span>
</ng-container>
<ng-container *ngIf="isLoading" class="loader-container">
<i class="fas fa-circle-notch fa-spin"></i>
<span class="loading-text">{{'submission.workflow.tasks.generic.processing' | translate}}</span>
</ng-container>
</a>
</ng-container>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
.loader-container {
display: inline-flex;
align-items: center;
gap: 0.5rem;
}

.loading-text {
font-size: 14px;
color: #555;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,32 @@ import {
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { StoreModule } from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';
import {
Angulartics2,
RouterlessTracking,
} from 'angulartics2';
import { of } from 'rxjs';

import {
APP_CONFIG,
APP_DATA_SERVICES_MAP,
} from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { LinkService } from '../../../../../core/cache/builders/link.service';
import { ObjectCacheService } from '../../../../../core/cache/object-cache.service';
import { RemoteData } from '../../../../../core/data/remote-data';
import { RequestService } from '../../../../../core/data/request.service';
import { RequestEntryState } from '../../../../../core/data/request-entry-state.model';
import { Item } from '../../../../../core/shared/item.model';
import { SearchService } from '../../../../../core/shared/search/search.service';
import { SearchConfigurationService } from '../../../../../core/shared/search/search-configuration.service';
import { WorkflowItem } from '../../../../../core/submission/models/workflowitem.model';
import { ClaimedTaskDataService } from '../../../../../core/tasks/claimed-task-data.service';
import { PoolTaskDataService } from '../../../../../core/tasks/pool-task-data.service';
import { URLCombiner } from '../../../../../core/url-combiner/url-combiner';
import { NotificationsService } from '../../../../../shared/notifications/notifications.service';
import {
getWorkflowItemDeleteRoute,
getWorkflowItemSendBackRoute,
Expand All @@ -23,14 +41,16 @@ import { WorkflowItemAdminWorkflowActionsComponent } from './workflow-item-admin
describe('WorkflowItemAdminWorkflowActionsComponent', () => {
let component: WorkflowItemAdminWorkflowActionsComponent;
let fixture: ComponentFixture<WorkflowItemAdminWorkflowActionsComponent>;
let id;
let wfi;
let item = new Item();
item.uuid = 'itemUUID1111';
const rd = new RemoteData(undefined, undefined, undefined, RequestEntryState.Success, undefined, item, 200);
let id: string;
let wfi: WorkflowItem;
let item: Item;
let rd: RemoteData<Item>;

function init() {
id = '780b2588-bda5-4112-a1cd-0b15000a5339';
item = new Item();
item.uuid = 'itemUUID1111';
rd = new RemoteData(undefined, undefined, undefined, RequestEntryState.Success, undefined, item, 200);
wfi = new WorkflowItem();
wfi.id = id;
wfi.item = of(rd);
Expand All @@ -42,11 +62,25 @@ describe('WorkflowItemAdminWorkflowActionsComponent', () => {
imports: [
TranslateModule.forRoot(),
RouterTestingModule.withRoutes([]),
StoreModule.forRoot({}),
WorkflowItemAdminWorkflowActionsComponent,
],
providers: [
{ provide: APP_DATA_SERVICES_MAP, useValue: {} },
{ provide: APP_CONFIG, useValue: environment },
{ provide: RouterlessTracking, useValue: { trackLocation: () => {} } },
{ provide: Angulartics2, useValue: { startTracking: () => {} } },
NotificationsService,
LinkService,
RequestService,
ObjectCacheService,
SearchService,
SearchConfigurationService,
ClaimedTaskDataService,
PoolTaskDataService,
],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents();
}).compileComponents();
}));

beforeEach(() => {
Expand All @@ -71,5 +105,4 @@ describe('WorkflowItemAdminWorkflowActionsComponent', () => {
const link = a.nativeElement.href;
expect(link).toContain(new URLCombiner(getWorkflowItemSendBackRoute(wfi.id)).toString());
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,43 @@
} from '@angular/common';
import {
Component,
Injector,
Input,
OnInit,
} from '@angular/core';
import { RouterLink } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import {
Router,
RouterLink,
} from '@angular/router';
import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import {
map,
Observable,
of,
} from 'rxjs';
import {
catchError,
switchMap,
} from 'rxjs/operators';

import { RemoteData } from '../../../../../core/data/remote-data';
import { RequestService } from '../../../../../core/data/request.service';
import { DSpaceObject } from '../../../../../core/shared/dspace-object.model';
import { Item } from '../../../../../core/shared/item.model';
import { getFirstSucceededRemoteData } from '../../../../../core/shared/operators';
import { SearchService } from '../../../../../core/shared/search/search.service';
import { WorkflowItem } from '../../../../../core/submission/models/workflowitem.model';
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
import { ClaimedTaskDataService } from '../../../../../core/tasks/claimed-task-data.service';
import { ClaimedTask } from '../../../../../core/tasks/models/claimed-task-object.model';
import { CLAIMED_TASK } from '../../../../../core/tasks/models/claimed-task-object.resource-type';
import { PoolTaskDataService } from '../../../../../core/tasks/pool-task-data.service';
import { ITEM_EDIT_AUTHORIZATIONS_PATH } from '../../../../../item-page/edit-item-page/edit-item-page.routing-paths';
import { MyDSpaceReloadableActionsComponent } from '../../../../../shared/mydspace-actions/mydspace-reloadable-actions';
import { NotificationsService } from '../../../../../shared/notifications/notifications.service';
import {
getWorkflowItemDeleteRoute,
getWorkflowItemSendBackRoute,
Expand All @@ -25,18 +56,53 @@
/**
* The component for displaying the actions for a list element for a workflow-item on the admin workflow search page
*/
export class WorkflowItemAdminWorkflowActionsComponent {
export class WorkflowItemAdminWorkflowActionsComponent extends MyDSpaceReloadableActionsComponent<ClaimedTask, ClaimedTaskDataService> implements OnInit{

/**
* The workflow item to perform the actions on
*/
@Input() public wfi: WorkflowItem;

@Input() public wsi: WorkspaceItem;

object: ClaimedTask;

/**
* The item object that belonging to the ClaimedTask object
*/
@Input() public item: Item;

option: string;

/**
* Anchor used to reload the pool task.
*/
@Input() itemUuid: string;

resourcePoliciesPageRoute: string[];

subs = [];

showButton = false;

isLoading = false;

/**
* Whether to use small buttons or not
*/
@Input() public small: boolean;

constructor(protected injector: Injector,
protected router: Router,
protected notificationsService: NotificationsService,
protected translate: TranslateService,
protected searchService: SearchService,
protected requestService: RequestService,
protected poolTaskDataService: PoolTaskDataService,
protected claimedTaskDataService: ClaimedTaskDataService) {
super(CLAIMED_TASK, injector, router, notificationsService, translate, searchService, requestService);
}

/**
* Returns the path to the delete page of this workflow item
*/
Expand All @@ -51,4 +117,66 @@
return getWorkflowItemSendBackRoute(this.wfi.id);
}

returnTaskToPool(): void {
this.isLoading = true;
this.wfi.item.pipe(

Check warning on line 122 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L121-L122

Added lines #L121 - L122 were not covered by tests
getFirstSucceededRemoteData(),
switchMap((item: any) => this.claimedTaskDataService.findByItem(item.payload.id)),

Check warning on line 124 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L124

Added line #L124 was not covered by tests
getFirstSucceededRemoteData(),
switchMap((poolTask: any) => this.objectDataService.returnToPoolTask(poolTask.payload.id)),

Check warning on line 126 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L126

Added line #L126 was not covered by tests
).subscribe({
next: response => {
this.isLoading = false;
this.checkItemStatus();
this.reload();

Check warning on line 131 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L129-L131

Added lines #L129 - L131 were not covered by tests
},
error: error => {
this.isLoading = false;
this.checkItemStatus();
this.reload();

Check warning on line 136 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L134-L136

Added lines #L134 - L136 were not covered by tests
},
});
}

createbody(): any {
return {

Check warning on line 142 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L142

Added line #L142 was not covered by tests
[this.option]: 'true',
};
}

reloadObjectExecution(): Observable<RemoteData<DSpaceObject> | DSpaceObject> {
return this.objectDataService.findByItem(this.itemUuid as string);

Check warning on line 148 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L148

Added line #L148 was not covered by tests
}

actionExecution(): Observable<any> {
return this.objectDataService.submitTask(this.object.id, this.createbody());

Check warning on line 152 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L152

Added line #L152 was not covered by tests
}

initObjects(object: ClaimedTask) {
this.object = object;

Check warning on line 156 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L156

Added line #L156 was not covered by tests
}

ngOnInit(): void {
this.checkItemStatus();
}

checkItemStatus(): void {
this.wfi.item.pipe(
getFirstSucceededRemoteData(),
switchMap((item: any) => this.claimedTaskDataService.checkIfClaimedTaskExistForItem(item.payload.id).pipe(
map((response: RemoteData<ClaimedTask>) => response.hasSucceeded && response.statusCode !== 204),
catchError(() => of(false)),
)),
).subscribe({
next: (show: boolean) => {
this.showButton = show;
},
error: error => console.error('Error checking item status', error),

Check warning on line 174 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L174

Added line #L174 was not covered by tests
});
}

getPoliciesRoute(item: Item): string[] {
return ['/items', item.uuid, 'edit', ITEM_EDIT_AUTHORIZATIONS_PATH];

Check warning on line 179 in src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/admin/admin-workflow-page/admin-workflow-search-results/actions/workflow-item/workflow-item-admin-workflow-actions.component.ts#L179

Added line #L179 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,33 @@ import {
} from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import {
Store,
StoreModule,
} from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';
import { of as observableOf } from 'rxjs';
import {
Angulartics2,
RouterlessTracking,
} from 'angulartics2';

import { APP_CONFIG } from '../../../../../../config/app-config.interface';
import { environment } from '../../../../../../environments/environment';
import { AuthService } from '../../../../../core/auth/auth.service';
import { LinkService } from '../../../../../core/cache/builders/link.service';
import { BitstreamDataService } from '../../../../../core/data/bitstream-data.service';
import { AuthorizationDataService } from '../../../../../core/data/feature-authorization/authorization-data.service';
import { Item } from '../../../../../core/shared/item.model';
import { ListableModule } from '../../../../../core/shared/listable.module';
import { ViewMode } from '../../../../../core/shared/view-mode.model';
import { WorkflowItem } from '../../../../../core/submission/models/workflowitem.model';
import { DynamicComponentLoaderDirective } from '../../../../../shared/abstract-component-loader/dynamic-component-loader.directive';
import { XSRFService } from '../../../../../core/xsrf/xsrf.service';
import { AuthServiceMock } from '../../../../../shared/mocks/auth.service.mock';
import { getMockLinkService } from '../../../../../shared/mocks/link-service.mock';
import { mockTruncatableService } from '../../../../../shared/mocks/mock-trucatable.service';
import { getMockThemeService } from '../../../../../shared/mocks/theme-service.mock';
import { CollectionElementLinkType } from '../../../../../shared/object-collection/collection-element-link.type';
import { WorkflowItemSearchResult } from '../../../../../shared/object-collection/shared/workflow-item-search-result.model';
import { ItemGridElementComponent } from '../../../../../shared/object-grid/item-grid-element/item-types/item/item-grid-element.component';
import { createSuccessfulRemoteDataObject$ } from '../../../../../shared/remote-data.utils';
import { AuthorizationDataServiceStub } from '../../../../../shared/testing/authorization-service.stub';
import { ThemeService } from '../../../../../shared/theme-support/theme.service';
import { TruncatableService } from '../../../../../shared/truncatable/truncatable.service';
import { followLink } from '../../../../../shared/utils/follow-link-config.model';
Expand All @@ -39,7 +46,6 @@ describe('WorkflowItemSearchResultAdminWorkflowGridElementComponent', () => {
let itemRD$;
let linkService;
let object;
let themeService: ThemeService;

function init() {
itemRD$ = createSuccessfulRemoteDataObject$(new Item());
Expand All @@ -49,38 +55,33 @@ describe('WorkflowItemSearchResultAdminWorkflowGridElementComponent', () => {
wfi.item = itemRD$;
object.indexableObject = wfi;
linkService = getMockLinkService();
themeService = getMockThemeService();
}

beforeEach(waitForAsync(() => {
init();
TestBed.configureTestingModule(
{
imports: [
WorkflowItemSearchResultAdminWorkflowGridElementComponent,
ItemGridElementComponent,
DynamicComponentLoaderDirective,
NoopAnimationsModule,
TranslateModule.forRoot(),
RouterTestingModule.withRoutes([]),
ListableModule,
WorkflowItemSearchResultAdminWorkflowGridElementComponent,
],
providers: [
{ provide: LinkService, useValue: linkService },
{ provide: ThemeService, useValue: themeService },
{
provide: TruncatableService, useValue: {
isCollapsed: () => observableOf(true),
},
},
{ provide: BitstreamDataService, useValue: {} },
{ provide: AuthService, useValue: new AuthServiceMock() },
{ provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub },
],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents();
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
TranslateModule.forRoot(),
RouterTestingModule.withRoutes([]),
StoreModule.forRoot({}),
WorkflowItemSearchResultAdminWorkflowGridElementComponent,
],
providers: [
{ provide: TruncatableService, useValue: mockTruncatableService },
{ provide: LinkService, useValue: linkService },
{ provide: APP_CONFIG, useValue: environment },
{ provide: ThemeService, useValue: getMockThemeService() },
{ provide: AuthService, useValue: new AuthServiceMock() },
{ provide: AuthorizationDataService, useValue: {} },
{ provide: XSRFService, useValue: {} },
BitstreamDataService,
Store,
{ provide: Angulartics2, useValue: { startTracking: () => {} } },
{ provide: RouterlessTracking, useValue: { trackLocation: () => {} } },
],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
}));

beforeEach(() => {
Expand Down
Loading
Loading