workflow delete/sendback

This commit is contained in:
lotte
2020-04-03 18:13:22 +02:00
parent 2eb3d11cd2
commit de1b57d8d9
24 changed files with 271 additions and 127 deletions

View File

@@ -0,0 +1,6 @@
<div class="container" *ngVar="item$ | async as item">
<h2>{{'workflow-item.' + type + '.header' | translate}}</h2>
<ds-modify-item-overview *ngIf="item" [item]="item"></ds-modify-item-overview>
<button class="btn btn-default" (click)="previousPage()">{{'workflow-item.' + type + '.button.cancel' | translate}}</button>
<button class="btn btn-danger" (click)="performAction()">{{'workflow-item.' + type + '.button.confirm' | translate}}</button>
</div>

View File

@@ -0,0 +1,65 @@
import { OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
import { WorkflowItem } from '../core/submission/models/workflowitem.model';
import { Item } from '../core/shared/item.model';
import { ActivatedRoute, Data, Router } from '@angular/router';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
import { RouteService } from '../core/services/route.service';
import { NotificationsService } from '../shared/notifications/notifications.service';
import { RemoteData } from '../core/data/remote-data';
import { getAllSucceededRemoteData, getRemoteDataPayload } from '../core/shared/operators';
import { isEmpty } from '../shared/empty.util';
export abstract class WorkflowItemActionPageComponent implements OnInit {
public type;
public wfi$: Observable<WorkflowItem>;
public item$: Observable<Item>;
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService) {
}
ngOnInit() {
this.type = this.getType();
this.wfi$ = this.route.data.pipe(map((data: Data) => data.wfi as RemoteData<WorkflowItem>), getRemoteDataPayload());
this.item$ = this.wfi$.pipe(switchMap((wfi: WorkflowItem) => (wfi.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
}
performAction() {
this.wfi$.pipe(
take(1),
switchMap((wfi: WorkflowItem) => this.sendRequest(wfi.id))
).subscribe((successful: boolean) => {
if (successful) {
const title = this.translationService.get('workflow-item.' + this.type + '.notification.success.title');
const content = this.translationService.get('workflow-item.' + this.type + '.notification.success.content');
this.notificationsService.success(title, content)
} else {
const title = this.translationService.get('workflow-item.' + this.type + '.notification.error.title');
const content = this.translationService.get('workflow-item.' + this.type + '.notification.error.content');
this.notificationsService.error(title, content)
}
this.previousPage();
})
}
previousPage() {
this.routeService.getPreviousUrl().pipe(take(1))
.subscribe((url) => {
if (isEmpty(url)) {
url = '/mydspace';
}
this.router.navigateByUrl(url);
}
);
}
abstract sendRequest(id: string): Observable<boolean>;
abstract getType(): string;
}

View File

@@ -1,6 +0,0 @@
<div class="container" *ngVar="item$ | async as item">
<ds-modify-item-overview *ngIf="item" [item]="item"></ds-modify-item-overview>
<button class="btn btn-default" (click)="previousPage()">Cancel</button>
<button class="btn btn-danger" (click)="delete()">Delete</button>
</div>

View File

@@ -1,58 +1,31 @@
import { Component, OnInit } from '@angular/core';
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
import { Item } from '../../core/shared/item.model';
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { getAllSucceededRemoteData, getRemoteDataPayload } from '../../core/shared/operators';
import { RemoteData } from '../../core/data/remote-data';
import { ActivatedRoute, Data, Router } from '@angular/router';
import { map, switchMap, take } from 'rxjs/operators';
import { WorkflowItemActionPageComponent } from '../workflow-item-action-page.component';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { TranslateService } from '@ngx-translate/core';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'ds-workflow-item-delete',
templateUrl: './workflow-item-delete.component.html',
styleUrls: ['./workflow-item-delete.component.scss']
templateUrl: '../workflow-item-action-page.component.html'
})
export class WorkflowItemDeleteComponent implements OnInit {
public wfi$: Observable<WorkflowItem>;
public item$: Observable<Item>;
constructor(private route: ActivatedRoute,
private workflowItemService: WorkflowItemDataService,
private router: Router,
private routeService: RouteService,
private notificationsService: NotificationsService,
private translationService: TranslateService) {
export class WorkflowItemDeleteComponent extends WorkflowItemActionPageComponent {
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService);
}
ngOnInit() {
this.route.data.subscribe((t) => console.log(t));
this.wfi$ = this.route.data.pipe(map((data: Data) => data.wfi as RemoteData<WorkflowItem>), getRemoteDataPayload());
this.item$ = this.wfi$.pipe(switchMap((wfi: WorkflowItem) => (wfi.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
getType(): string {
return 'delete';
}
delete() {
this.wfi$.pipe(
take(1),
switchMap((wfi: WorkflowItem) => this.workflowItemService.delete(wfi.id))
).subscribe((successful: boolean) => {
if (successful) {
const title = this.translationService.get('workflowitem.delete.notification.success.title');
const content = this.translationService.get('workflowitem.delete.notification.success.content');
this.notificationsService.success(title, content)
} else {
const title = this.translationService.get('workflowitem.delete.notification.error.title');
const content = this.translationService.get('workflowitem.delete.notification.error.content');
this.notificationsService.error(title, content)
}
this.previousPage();
})
}
previousPage() {
this.routeService.getPreviousUrl();
sendRequest(id: string): Observable<boolean> {
return this.workflowItemService.delete(id);
}
}

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { WorkflowItemDeleteComponent } from './workflow-item-send-back.component';
describe('WorkflowItemDeleteComponent', () => {
let component: WorkflowItemDeleteComponent;
let fixture: ComponentFixture<WorkflowItemDeleteComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WorkflowItemDeleteComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WorkflowItemDeleteComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,31 @@
import { Component } from '@angular/core';
import { WorkflowItemActionPageComponent } from '../workflow-item-action-page.component';
import { Observable } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'ds-workflow-item-send-back',
templateUrl: '../workflow-item-action-page.component.html'
})
export class WorkflowItemSendBackComponent extends WorkflowItemActionPageComponent {
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
protected router: Router,
protected routeService: RouteService,
protected notificationsService: NotificationsService,
protected translationService: TranslateService) {
super(route, workflowItemService, router, routeService, notificationsService, translationService);
}
getType(): string {
return 'send-back';
}
sendRequest(id: string): Observable<boolean> {
return this.workflowItemService.sendBack(id);
}
}

View File

@@ -7,6 +7,7 @@ import { URLCombiner } from '../core/url-combiner/url-combiner';
import { getWorkflowItemModulePath } from '../app-routing.module';
import { WorkflowItemDeleteComponent } from './workflow-item-delete/workflow-item-delete.component';
import { WorkflowItemPageResolver } from './workflow-item-page.resolver';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back/workflow-item-send-back.component';
export function getWorkflowItemPageRoute(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId).toString();
@@ -50,8 +51,8 @@ const WORKFLOW_ITEM_SEND_BACK_PATH = 'sendback';
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_SEND_BACK_PATH,
component: WorkflowItemDeleteComponent,
data: { title: 'workflow-item.sendback.title' }
component: WorkflowItemSendBackComponent,
data: { title: 'workflow-item.send-back.title' }
}
]
}]

View File

@@ -4,6 +4,7 @@ import { SharedModule } from '../shared/shared.module';
import { WorkflowItemsEditPageRoutingModule } from './workflowitems-edit-page-routing.module';
import { SubmissionModule } from '../submission/submission.module';
import { WorkflowItemDeleteComponent } from './workflow-item-delete/workflow-item-delete.component';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back/workflow-item-send-back.component';
@NgModule({
imports: [
@@ -12,7 +13,7 @@ import { WorkflowItemDeleteComponent } from './workflow-item-delete/workflow-ite
SharedModule,
SubmissionModule,
],
declarations: [WorkflowItemDeleteComponent]
declarations: [WorkflowItemDeleteComponent, WorkflowItemSendBackComponent]
})
/**
* This module handles all modules that need to access the workflowitems edit page.