Adds: actions on each row of last edited dmp (Dashboard)

This commit is contained in:
apapachristou 2019-06-04 14:34:30 +03:00
parent e35ae42eeb
commit 73bc31ed7c
5 changed files with 153 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import { DmpStatus } from "../../common/enum/dmp-status"; import { DmpStatus } from "../../common/enum/dmp-status";
export interface DmpListingModel { export interface DmpListingModel {
id: String; id: string;
label: String; label: String;
description: String; description: String;
status: DmpStatus; status: DmpStatus;

View File

@ -12,12 +12,14 @@ import { RecentVisitedActivityComponent } from './recent-visited-activity/recent
import { WizardComponent } from './wizard/wizard.component'; import { WizardComponent } from './wizard/wizard.component';
import { DmpInfoCounterComponent } from './dmp-info-counter/dmp-info-counter.component'; import { DmpInfoCounterComponent } from './dmp-info-counter/dmp-info-counter.component';
import { DatasetInfoCounterComponent } from './dataset-info-counter/dataset-info-counter.component'; import { DatasetInfoCounterComponent } from './dataset-info-counter/dataset-info-counter.component';
import { ExportMethodDialogModule } from '../../library/export-method-dialog/export-method-dialog.module';
@NgModule({ @NgModule({
imports: [ imports: [
CommonUiModule, CommonUiModule,
DashboardRoutingModule DashboardRoutingModule,
ExportMethodDialogModule
], ],
declarations: [ declarations: [
DashboardComponent, DashboardComponent,

View File

@ -41,3 +41,7 @@ th {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.mat-icon-button :hover {
color: rgb(120, 173, 220);
}

View File

@ -44,7 +44,27 @@
{{ enumUtils.toDmpStatusString(activity.status) }} {{ enumUtils.toDmpStatusString(activity.status) }}
</td> </td>
<td style="padding-left: 12px">{{ activity.modifiedTime | date: "shortDate" }}</td> <td style="padding-left: 12px">{{ activity.modifiedTime | date: "shortDate" }}</td>
<td><i class="material-icons more-icon">more_horiz</i></td> <td>
<!-- <i class="material-icons more-icon">more_horiz</i> -->
<button mat-icon-button [matMenuTriggerFor]="actionsMenu" class="ml-auto more-icon"
(click)="$event.stopImmediatePropagation();">
<mat-icon class="more-horiz">more_horiz</mat-icon>
</button>
<mat-menu #actionsMenu="matMenu">
<button mat-menu-item (click)="editClicked(activity)" class="menu-item">
<mat-icon>edit</mat-icon>{{ 'DMP-LISTING.ACTIONS.EDIT' | translate }}
</button>
<button mat-menu-item (click)="cloneClicked(activity)" class="menu-item">
<mat-icon>add</mat-icon>{{ 'DMP-LISTING.ACTIONS.CLONE' | translate }}
</button>
<button mat-menu-item (click)="deleteClicked(activity)" class="menu-item">
<mat-icon>delete</mat-icon>{{ 'DMP-LISTING.ACTIONS.DELETE' | translate }}
</button>
<button mat-menu-item (click)="advancedClicked(activity)" class="menu-item">
<mat-icon>save_alt</mat-icon>{{ 'DMP-LISTING.ACTIONS.ADV-EXP' | translate }}
</button>
</mat-menu>
</td>
</tr> </tr>
</tbody> </tbody>
<tbody *ngIf="dmpActivities == null"> <tbody *ngIf="dmpActivities == null">

View File

@ -9,13 +9,20 @@ import { RecentActivityType } from '../../../core/common/enum/recent-activity-ty
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Principal } from '../../../core/model/auth/Principal'; import { Principal } from '../../../core/model/auth/Principal';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ConfirmationDialogComponent } from '../../../library/confirmation-dialog/confirmation-dialog.component';
import { MatDialog } from '@angular/material';
import { ExportMethodDialogComponent } from '../../../library/export-method-dialog/export-method-dialog.component';
import { BaseComponent } from '../../../core/common/base/base.component';
import { UiNotificationService, SnackBarNotificationLevel } from '../../../core/services/notification/ui-notification-service';
import * as FileSaver from 'file-saver';
import { takeUntil } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-recent-edited-activity', selector: 'app-recent-edited-activity',
templateUrl: './recent-edited-activity.component.html', templateUrl: './recent-edited-activity.component.html',
styleUrls: ['./recent-edited-activity.component.css'] styleUrls: ['./recent-edited-activity.component.css']
}) })
export class RecentEditedActivityComponent implements OnInit { export class RecentEditedActivityComponent extends BaseComponent implements OnInit {
dmpActivities: DmpListingModel[]; dmpActivities: DmpListingModel[];
recentActivityTypeEnum = RecentActivityType; recentActivityTypeEnum = RecentActivityType;
@ -24,8 +31,12 @@ export class RecentEditedActivityComponent implements OnInit {
public enumUtils: EnumUtils, public enumUtils: EnumUtils,
private authentication: AuthService, private authentication: AuthService,
private dmpService: DmpService, private dmpService: DmpService,
private language: TranslateService private language: TranslateService,
) { } private dialog: MatDialog,
private uiNotificationService: UiNotificationService
) {
super();
}
ngOnInit() { ngOnInit() {
if (this.isAuthenticated()) { if (this.isAuthenticated()) {
@ -45,6 +56,65 @@ export class RecentEditedActivityComponent implements OnInit {
return !!this.authentication.current(); return !!this.authentication.current();
} }
editClicked(dmp: DmpListingModel) {
this.router.navigate(['/plans/edit/' + dmp.id]);
}
cloneClicked(dmp: DmpListingModel) {
this.router.navigate(['/plans/clone/' + dmp.id]);
}
deleteClicked(dmp: DmpListingModel) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxWidth: '300px',
data: {
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.dmpService.delete(dmp.id)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => { this.onCallbackSuccess() },
error => this.onDeleteCallbackError(error)
);
}
});
}
advancedClicked(dmp: DmpListingModel) {
const dialogRef = this.dialog.open(ExportMethodDialogComponent, {
maxWidth: '400px',
data: {
message: "Download as:",
XMLButton: "XML",
documentButton: "Document",
pdfButton: "PDF"
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result == "pdf") {
this.downloadPDF(dmp.id);
} else if (result == "xml") {
this.downloadXml(dmp.id);
} else if (result == "doc") {
this.downloadDocx(dmp.id);
}
});
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/plans']);
}
onDeleteCallbackError(error) {
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
}
redirect(id: string, type: RecentActivityType) { redirect(id: string, type: RecentActivityType) {
switch (type) { switch (type) {
case RecentActivityType.Project: { case RecentActivityType.Project: {
@ -95,4 +165,55 @@ export class RecentEditedActivityComponent implements OnInit {
return "--"; return "--";
} }
} }
downloadXml(id: string) {
this.dmpService.downloadXML(id)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/xml' });
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
});
}
downloadDocx(id: string) {
this.dmpService.downloadDocx(id)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/msword' });
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
});
}
downloadPDF(id: string) {
this.dmpService.downloadPDF(id)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'application/pdf' });
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
FileSaver.saveAs(blob, filename);
});
}
getFilenameFromContentDispositionHeader(header: string): string {
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
const matches = header.match(regex);
let filename: string;
for (let i = 0; i < matches.length; i++) {
const match = matches[i];
if (match.includes('filename="')) {
filename = match.substring(10, match.length - 1);
break;
} else if (match.includes('filename=')) {
filename = match.substring(9);
break;
}
}
return filename;
}
} }