no message

This commit is contained in:
Diamantis Tziotzios 2017-12-18 17:53:17 +02:00
parent 0fdf82728b
commit 1f9d07885f
5 changed files with 68 additions and 36 deletions

View File

@ -2,7 +2,7 @@
<form *ngIf="formGroup" (ngSubmit)="formSubmit()" [formGroup]="formGroup"> <form *ngIf="formGroup" (ngSubmit)="formSubmit()" [formGroup]="formGroup">
<mat-card> <mat-card>
<mat-card-title *ngIf="isNew">{{'PROJECT-EDITOR.TITLE.NEW' | translate}}</mat-card-title> <mat-card-title *ngIf="isNew">{{'PROJECT-EDITOR.TITLE.NEW' | translate}}</mat-card-title>
<mat-card-title *ngIf="!isNew">{{'PROJECT-EDITOR.TITLE.EDIT' | translate}} {{project.label}}</mat-card-title> <mat-card-title *ngIf="!isNew">{{formGroup.get('label').value}}</mat-card-title>
<mat-card-content> <mat-card-content>
<mat-form-field> <mat-form-field>
@ -51,7 +51,8 @@
</table> </table>
<mat-form-field class="full-width"> <mat-form-field class="full-width">
<textarea matInput class="description-area" placeholder="{{'PROJECT-EDITOR.FIELDS.DESCRIPTION' | translate}}" formControlName="description" required></textarea> <textarea matInput class="description-area" placeholder="{{'PROJECT-EDITOR.FIELDS.DESCRIPTION' | translate}}" formControlName="description"
required></textarea>
<mat-error *ngIf="formGroup.get('description').errors?.backendError">{{errorModel.description}}</mat-error> <mat-error *ngIf="formGroup.get('description').errors?.backendError">{{errorModel.description}}</mat-error>
<mat-error *ngIf="formGroup.get('description').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="formGroup.get('description').errors?.required">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
@ -59,7 +60,7 @@
<div layout="row" class="full-width text-right" align="end"> <div layout="row" class="full-width text-right" align="end">
<button mat-raised-button color="primary" (click)="cancel()" type="button">{{'PROJECT-EDITOR.ACTIONS.CANCEL' | translate}}</button> <button mat-raised-button color="primary" (click)="cancel()" type="button">{{'PROJECT-EDITOR.ACTIONS.CANCEL' | translate}}</button>
<button mat-raised-button color="primary" type="submit">{{'PROJECT-EDITOR.ACTIONS.SAVE' | translate}}</button> <button mat-raised-button color="primary" type="submit">{{'PROJECT-EDITOR.ACTIONS.SAVE' | translate}}</button>
<button *ngIf="!isNew" mat-raised-button color="primary" type="submit" (click)="delete()">{{'PROJECT-EDITOR.ACTIONS.DELETE' | translate}}</button> <button *ngIf="!isNew" mat-raised-button color="primary" type="button" (click)="delete()">{{'PROJECT-EDITOR.ACTIONS.DELETE' | translate}}</button>
</div> </div>
</mat-card-content> </mat-card-content>

View File

@ -11,6 +11,7 @@ import { JsonSerializer } from "../../utilities/JsonSerializer";
import { FormGroup } from "@angular/forms"; import { FormGroup } from "@angular/forms";
import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component"; import { SnackBarNotificationComponent } from "../../shared/components/notificaiton/snack-bar-notification.component";
import { BaseErrorModel } from "../../models/error/BaseErrorModel"; import { BaseErrorModel } from "../../models/error/BaseErrorModel";
import { TdDialogService } from "@covalent/core";
@ -32,7 +33,8 @@ export class ProjectEditorComponent implements AfterViewInit {
private route: ActivatedRoute, private route: ActivatedRoute,
public snackBar: MatSnackBar, public snackBar: MatSnackBar,
public router: Router, public router: Router,
public language: TranslateService public language: TranslateService,
private dialogService: TdDialogService
) { ) {
} }
@ -58,43 +60,61 @@ export class ProjectEditorComponent implements AfterViewInit {
} }
formSubmit(): void { formSubmit(): void {
//this.touchAllFormFields(this.formGroup); //this.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) { return; } if (!this.isFormValid()) { return; }
this.onSubmit(); this.onSubmit();
} }
public isFormValid() { public isFormValid() {
return this.formGroup.valid; return this.formGroup.valid;
}
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) { onSubmit(): void {
this.setErrorModel(error.error); this.projectService.createProject(this.formGroup.value).subscribe(
//this.validateAllFormFields(this.formGroup); 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) { public setErrorModel(errorModel: BaseErrorModel) {
Object.keys(errorModel).forEach(item => { Object.keys(errorModel).forEach(item => {
(<any>this.project.errorModel)[item] = (<any>errorModel)[item]; (<any>this.project.errorModel)[item] = (<any>errorModel)[item];
}) })
} }
public cancel(): void { 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)
);
}
});
});
}
} }

View File

@ -37,4 +37,8 @@ export class ProjectService {
createProject(projectModel: ProjectModel): Observable<ProjectModel> { createProject(projectModel: ProjectModel): Observable<ProjectModel> {
return this.http.post<ProjectModel>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers }); return this.http.post<ProjectModel>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers });
} }
inactivate(id: String): Observable<ProjectModel> {
return this.http.delete<ProjectModel>(this.actionUrl + 'inactivate' + id, { headers: this.headers });
}
} }

View File

@ -27,7 +27,7 @@ import {
} from '@angular/material'; } from '@angular/material';
import { CdkTableModule } from '@angular/cdk/table'; import { CdkTableModule } from '@angular/cdk/table';
import { SnackBarNotificationComponent } from '../components/notificaiton/snack-bar-notification.component'; import { SnackBarNotificationComponent } from '../components/notificaiton/snack-bar-notification.component';
import { CovalentLayoutModule, CovalentChipsModule } from '@covalent/core'; import { CovalentLayoutModule, CovalentChipsModule, CovalentDialogsModule } from '@covalent/core';
@NgModule({ @NgModule({
imports: [ imports: [
@ -59,7 +59,8 @@ import { CovalentLayoutModule, CovalentChipsModule } from '@covalent/core';
MatCheckboxModule, MatCheckboxModule,
MatTabsModule, MatTabsModule,
CovalentLayoutModule, CovalentLayoutModule,
CovalentChipsModule CovalentChipsModule,
CovalentDialogsModule
], ],
providers: [ providers: [

View File

@ -2,6 +2,12 @@
"GENERAL": { "GENERAL": {
"VALIDATION": { "VALIDATION": {
"REQUIRED": "Required" "REQUIRED": "Required"
},
"DELETE-CONFIRMATION": {
"TITLE": "Warning",
"MESSAGE": "Are you sure you want to delete this item?",
"POSITIVE": "Yes",
"NEGATIVE": "Cancel"
} }
}, },
"NAV-BAR": { "NAV-BAR": {