debugging issue commit

This commit is contained in:
lotte
2020-04-03 16:00:52 +02:00
parent 258b1228f3
commit 2eb3d11cd2
15 changed files with 233 additions and 32 deletions

View File

@@ -1 +1,6 @@
<ds-modify-item-overview [item]="wfi.item"></ds-modify-item-overview>
<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,5 +1,15 @@
import { Component, OnInit } from '@angular/core';
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
import { Item } from '../../core/shared/item.model';
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 { 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';
@Component({
selector: 'ds-workflow-item-delete',
@@ -7,10 +17,42 @@ import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
styleUrls: ['./workflow-item-delete.component.scss']
})
export class WorkflowItemDeleteComponent implements OnInit {
wfi: WorkflowItem;
constructor() { }
public wfi$: Observable<WorkflowItem>;
public item$: Observable<Item>;
ngOnInit() {
constructor(private route: ActivatedRoute,
private workflowItemService: WorkflowItemDataService,
private router: Router,
private routeService: RouteService,
private notificationsService: NotificationsService,
private translationService: TranslateService) {
}
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())));
}
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();
}
}

View File

@@ -0,0 +1,35 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { RemoteData } from '../core/data/remote-data';
import { ItemDataService } from '../core/data/item-data.service';
import { Item } from '../core/shared/item.model';
import { hasValue } from '../shared/empty.util';
import { find } from 'rxjs/operators';
import { followLink } from '../shared/utils/follow-link-config.model';
import { WorkflowItemDataService } from '../core/submission/workflowitem-data.service';
import { WorkflowItem } from '../core/submission/models/workflowitem.model';
/**
* This class represents a resolver that requests a specific item before the route is activated
*/
@Injectable()
export class WorkflowItemPageResolver implements Resolve<RemoteData<WorkflowItem>> {
constructor(private workflowItemService: WorkflowItemDataService) {
}
/**
* Method for resolving an item based on the parameters in the current route
* @param {ActivatedRouteSnapshot} route The current ActivatedRouteSnapshot
* @param {RouterStateSnapshot} state The current RouterStateSnapshot
* @returns Observable<<RemoteData<Item>> Emits the found item based on the parameters in the current route,
* or an error if something went wrong
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<WorkflowItem>> {
return this.workflowItemService.findById(route.params.id,
followLink('item'),
).pipe(
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
);
}
}

View File

@@ -3,21 +3,64 @@ import { RouterModule } from '@angular/router';
import { AuthenticatedGuard } from '../core/auth/authenticated.guard';
import { SubmissionEditComponent } from '../submission/edit/submission-edit.component';
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';
export function getWorkflowItemPageRoute(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId).toString();
}
export function getWorkflowItemEditPath(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId, WORKFLOW_ITEM_EDIT_PATH).toString()
}
export function getWorkflowItemDeletePath(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId, WORKFLOW_ITEM_DELETE_PATH).toString()
}
export function getWorkflowItemSendBackPath(wfiId: string) {
return new URLCombiner(getWorkflowItemModulePath(), wfiId, WORKFLOW_ITEM_SEND_BACK_PATH).toString()
}
const WORKFLOW_ITEM_EDIT_PATH = 'edit';
const WORKFLOW_ITEM_DELETE_PATH = 'delete';
const WORKFLOW_ITEM_SEND_BACK_PATH = 'sendback';
@NgModule({
imports: [
RouterModule.forChild([
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{
canActivate: [AuthenticatedGuard],
path: ':id/edit',
component: SubmissionEditComponent,
data: { title: 'submission.edit.title' }
}
])
]
path: ':id',
resolve: { wfi: WorkflowItemPageResolver },
children: [
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_EDIT_PATH,
component: SubmissionEditComponent,
data: { title: 'submission.edit.title' }
},
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_DELETE_PATH,
component: WorkflowItemDeleteComponent,
data: { title: 'workflow-item.delete.title' }
},
{
canActivate: [AuthenticatedGuard],
path: WORKFLOW_ITEM_SEND_BACK_PATH,
component: WorkflowItemDeleteComponent,
data: { title: 'workflow-item.sendback.title' }
}
]
}]
)
],
providers: [WorkflowItemPageResolver]
})
/**
* This module defines the default component to load when navigating to the workflowitems edit page path.
*/
export class WorkflowItemsEditPageRoutingModule { }
export class WorkflowItemsEditPageRoutingModule {
}