From 1f9d07885f0a73d6ef3bdd48a49f1e42053a088f Mon Sep 17 00:00:00 2001 From: Diamadis Tziotzios Date: Mon, 18 Dec 2017 17:53:17 +0200 Subject: [PATCH] no message --- .../editor/project-editor.component.html | 7 +- .../editor/project-editor.component.ts | 82 ++++++++++++------- .../app/services/project/project.service.ts | 4 + .../app/shared/material/material.module.ts | 5 +- dmp-frontend/src/assets/lang/en.json | 6 ++ 5 files changed, 68 insertions(+), 36 deletions(-) diff --git a/dmp-frontend/src/app/projects/editor/project-editor.component.html b/dmp-frontend/src/app/projects/editor/project-editor.component.html index e78eb51e2..b0cd9d48a 100644 --- a/dmp-frontend/src/app/projects/editor/project-editor.component.html +++ b/dmp-frontend/src/app/projects/editor/project-editor.component.html @@ -2,7 +2,7 @@
{{'PROJECT-EDITOR.TITLE.NEW' | translate}} - {{'PROJECT-EDITOR.TITLE.EDIT' | translate}} {{project.label}} + {{formGroup.get('label').value}} @@ -51,7 +51,8 @@ - + {{errorModel.description}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -59,7 +60,7 @@
- +
diff --git a/dmp-frontend/src/app/projects/editor/project-editor.component.ts b/dmp-frontend/src/app/projects/editor/project-editor.component.ts index ae0c2db6e..5d8f5e405 100644 --- a/dmp-frontend/src/app/projects/editor/project-editor.component.ts +++ b/dmp-frontend/src/app/projects/editor/project-editor.component.ts @@ -11,6 +11,7 @@ import { JsonSerializer } from "../../utilities/JsonSerializer"; import { FormGroup } from "@angular/forms"; import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component"; import { BaseErrorModel } from "../../models/error/BaseErrorModel"; +import { TdDialogService } from "@covalent/core"; @@ -32,7 +33,8 @@ export class ProjectEditorComponent implements AfterViewInit { private route: ActivatedRoute, public snackBar: MatSnackBar, public router: Router, - public language: TranslateService + public language: TranslateService, + private dialogService: TdDialogService ) { } @@ -58,43 +60,61 @@ export class ProjectEditorComponent implements AfterViewInit { } formSubmit(): void { - //this.touchAllFormFields(this.formGroup); - if (!this.isFormValid()) { return; } - this.onSubmit(); + //this.touchAllFormFields(this.formGroup); + if (!this.isFormValid()) { return; } + this.onSubmit(); } public isFormValid() { - return this.formGroup.valid; - } - - onSubmit(): void { - this.projectService.createProject(this.formGroup.value).subscribe( - complete => this.onCallbackSuccess(), - error => this.onCallbackError(error) - ); + return this.formGroup.valid; } - - onCallbackSuccess(): void { - this.snackBar.openFromComponent(SnackBarNotificationComponent, { - data: { message: this.isNew ? 'GENERAL.SNACK-BAR.SUCCESSFUL-CREATION' : 'GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE', language: this.language }, - duration: 3000, - extraClasses: ['snackbar-success'] - }) - this.router.navigate(['/projects']); - } - onCallbackError(error: any) { - this.setErrorModel(error.error); - //this.validateAllFormFields(this.formGroup); + onSubmit(): void { + this.projectService.createProject(this.formGroup.value).subscribe( + complete => this.onCallbackSuccess(), + error => this.onCallbackError(error) + ); } - + + onCallbackSuccess(): void { + this.snackBar.openFromComponent(SnackBarNotificationComponent, { + data: { message: this.isNew ? 'GENERAL.SNACK-BAR.SUCCESSFUL-CREATION' : 'GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE', language: this.language }, + duration: 3000, + extraClasses: ['snackbar-success'] + }) + this.router.navigate(['/projects']); + } + + onCallbackError(error: any) { + this.setErrorModel(error.error); + //this.validateAllFormFields(this.formGroup); + } + public setErrorModel(errorModel: BaseErrorModel) { - Object.keys(errorModel).forEach(item => { - (this.project.errorModel)[item] = (errorModel)[item]; - }) + Object.keys(errorModel).forEach(item => { + (this.project.errorModel)[item] = (errorModel)[item]; + }) } - + public cancel(): void { - this.router.navigate(['/projects']); - } + this.router.navigate(['/projects']); + } + + public delete(): void { + this.language.get('GENERAL.DELETE-CONFIRMATION').subscribe((messages: any) => { + this.dialogService.openConfirm({ + message: messages.MESSAGE, + title: messages.TITLE, + cancelButton: messages.NEGATIVE, + acceptButton: messages.POSITIVE + }).afterClosed().subscribe((accept: boolean) => { + if (accept) { + this.projectService.inactivate(this.project.id).subscribe( + complete => { this.router.navigate(['/projects']); }, + error => this.onCallbackError(error) + ); + } + }); + }); + } } \ No newline at end of file diff --git a/dmp-frontend/src/app/services/project/project.service.ts b/dmp-frontend/src/app/services/project/project.service.ts index 9056f4455..f3c6627a4 100644 --- a/dmp-frontend/src/app/services/project/project.service.ts +++ b/dmp-frontend/src/app/services/project/project.service.ts @@ -37,4 +37,8 @@ export class ProjectService { createProject(projectModel: ProjectModel): Observable { return this.http.post(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers }); } + + inactivate(id: String): Observable { + return this.http.delete(this.actionUrl + 'inactivate' + id, { headers: this.headers }); + } } diff --git a/dmp-frontend/src/app/shared/material/material.module.ts b/dmp-frontend/src/app/shared/material/material.module.ts index 4370b685f..b31568832 100644 --- a/dmp-frontend/src/app/shared/material/material.module.ts +++ b/dmp-frontend/src/app/shared/material/material.module.ts @@ -27,7 +27,7 @@ import { } from '@angular/material'; import { CdkTableModule } from '@angular/cdk/table'; import { SnackBarNotificationComponent } from '../components/notificaiton/snack-bar-notification.component'; -import { CovalentLayoutModule, CovalentChipsModule } from '@covalent/core'; +import { CovalentLayoutModule, CovalentChipsModule, CovalentDialogsModule } from '@covalent/core'; @NgModule({ imports: [ @@ -59,7 +59,8 @@ import { CovalentLayoutModule, CovalentChipsModule } from '@covalent/core'; MatCheckboxModule, MatTabsModule, CovalentLayoutModule, - CovalentChipsModule + CovalentChipsModule, + CovalentDialogsModule ], providers: [ diff --git a/dmp-frontend/src/assets/lang/en.json b/dmp-frontend/src/assets/lang/en.json index a005cd6ec..2876089f3 100644 --- a/dmp-frontend/src/assets/lang/en.json +++ b/dmp-frontend/src/assets/lang/en.json @@ -2,6 +2,12 @@ "GENERAL": { "VALIDATION": { "REQUIRED": "Required" + }, + "DELETE-CONFIRMATION": { + "TITLE": "Warning", + "MESSAGE": "Are you sure you want to delete this item?", + "POSITIVE": "Yes", + "NEGATIVE": "Cancel" } }, "NAV-BAR": {