Skip to content

Commit 98a2706

Browse files
committed
Small fixes and improvements
1 parent 0bb7ae9 commit 98a2706

File tree

20 files changed

+139
-21
lines changed

20 files changed

+139
-21
lines changed

eform-client/src/app/app.declarations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {DatePipe, LocationStrategy, PathLocationStrategy} from '@angular/common';
22
import {ToastrService} from 'ngx-toastr';
3-
import {AdminGuard, AuthGuard} from 'src/app/common/guards';
3+
import {AdminGuard, AuthGuard, CanDeactivateGuard} from 'src/app/common/guards';
44
import {EventBrokerService} from 'src/app/common/helpers';
55
import {
66
EntitySearchService,
@@ -21,6 +21,7 @@ export let providers = [
2121
// Guards
2222
AuthGuard,
2323
AdminGuard,
24+
CanDeactivateGuard,
2425
// Libs services
2526
ToastrService,
2627
// Services
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Injectable } from '@angular/core';
2+
import {CanDeactivate} from '@angular/router';
3+
import { Observable } from 'rxjs';
4+
5+
export interface CanComponentDeactivate {
6+
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
7+
}
8+
9+
@Injectable()
10+
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
11+
12+
canDeactivate(component: CanComponentDeactivate) {
13+
return component.canDeactivate ? component.canDeactivate() : true;
14+
}
15+
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './auth.guard';
22
export * from './admin.guard';
3+
export * from './can-deactivate.guard';

eform-client/src/app/modules/cases/cases.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
CaseEditElementComponent,
1616
CaseEditSwitchComponent,
1717
CasesTableComponent,
18+
CaseEditConfirmationComponent,
1819
ElementAudioComponent,
1920
ElementCheckboxComponent,
2021
ElementCommentComponent, ElementContainerComponent,
@@ -49,6 +50,7 @@ import {
4950
CaseEditComponent,
5051
CaseEditSwitchComponent,
5152
CaseEditElementComponent,
53+
CaseEditConfirmationComponent,
5254
ElementTextComponent,
5355
ElementNumberComponent,
5456
ElementCheckboxComponent,

eform-client/src/app/modules/cases/cases.routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {NgModule} from '@angular/core';
22
import {RouterModule, Routes} from '@angular/router';
3+
import {CanDeactivateGuard} from 'src/app/common/guards';
34
import {CaseEditComponent, CasesTableComponent} from 'src/app/modules/cases/components';
45

56
const routes: Routes = [
@@ -11,6 +12,7 @@ const routes: Routes = [
1112
{
1213
path: 'edit/:id/:templateId',
1314
component: CaseEditComponent,
15+
canDeactivate: [CanDeactivateGuard]
1416
}
1517
];
1618

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div mdbModal class="modal fade" #frame="mdbModal">
2+
<div class="modal-dialog modal-md">
3+
<div class="modal-content">
4+
<div class="modal-header">
5+
<h3>{{ 'Do you want to leave this page' | translate }}?</h3>
6+
</div>
7+
<div class="modal-body">
8+
<h4>{{'If you leave before saving your changes will be lost'}}.</h4>
9+
</div>
10+
<div class="modal-footer d-flex justify-content-center">
11+
<button class="btn btn-success" (click)="confirmationClicked(true)">
12+
{{ 'Save & Leave' | translate }}
13+
</button>
14+
<button class="btn btn-danger" (click)="confirmationClicked(false)">
15+
{{ 'Leave' | translate }}
16+
</button>
17+
<button class="btn btn-accent text-black-50" (click)="frame.hide()">{{'Cancel' | translate}}</button>
18+
</div>
19+
</div>
20+
</div>
21+
</div>

eform-client/src/app/modules/cases/components/case-edit-confirmation/case-edit-confirmation.component.scss

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-case-edit-confirmation',
5+
templateUrl: './case-edit-confirmation.component.html',
6+
styleUrls: ['./case-edit-confirmation.component.scss']
7+
})
8+
export class CaseEditConfirmationComponent implements OnInit {
9+
@ViewChild('frame') frame;
10+
@Output() onConfirmationPressed: EventEmitter<boolean> = new EventEmitter<boolean>();
11+
12+
constructor() { }
13+
14+
ngOnInit() {
15+
}
16+
17+
show() {
18+
this.frame.show();
19+
}
20+
21+
confirmationClicked(keepData: boolean) {
22+
this.onConfirmationPressed.emit(keepData);
23+
this.frame.hide();
24+
}
25+
26+
}

eform-client/src/app/modules/cases/components/case-edit/case-edit.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@
3636
</div>
3737

3838
<eform-spinner [spinnerVisibility]="spinnerStatus"></eform-spinner>
39+
40+
<app-case-edit-confirmation (onConfirmationPressed)="confirmExit($event)" #caseConfirmation></app-case-edit-confirmation>

eform-client/src/app/modules/cases/components/case-edit/case-edit.component.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {Component, OnInit, QueryList, ViewChildren} from '@angular/core';
2-
import {ActivatedRoute, Router} from '@angular/router';
1+
import {Component, OnDestroy, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core';
2+
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
3+
import {RouteConfigLoadEnd} from '@angular/router';
4+
import {Subscription} from 'rxjs';
35
import {CaseEditRequest, ReplyElement, ReplyRequest} from 'src/app/common/models/cases';
46
import {TemplateDto} from 'src/app/common/models/dto';
57
import {CasesService} from 'src/app/common/services/cases';
@@ -11,8 +13,10 @@ import {CaseEditElementComponent} from '../case-edit-element/case-edit-element.c
1113
templateUrl: './case-edit.component.html',
1214
styleUrls: ['./case-edit.component.scss']
1315
})
14-
export class CaseEditComponent implements OnInit {
16+
export class CaseEditComponent implements OnInit, OnDestroy {
1517
@ViewChildren(CaseEditElementComponent) editElements: QueryList<CaseEditElementComponent>;
18+
@ViewChild('caseConfirmation') caseConfirmation;
19+
activatedRouteSub: Subscription;
1620
id: number;
1721
templateId: number;
1822
currentTemplate: TemplateDto = new TemplateDto;
@@ -21,13 +25,15 @@ export class CaseEditComponent implements OnInit {
2125
requestModels: Array<CaseEditRequest> = [];
2226
replyRequest: ReplyRequest = new ReplyRequest();
2327

28+
isNoSaveExitAllowed = false;
29+
2430
spinnerStatus = false;
2531

2632
constructor(private activateRoute: ActivatedRoute,
2733
private casesService: CasesService,
2834
private eFormService: EFormService,
2935
private router: Router) {
30-
this.activateRoute.params.subscribe(params => {
36+
const activatedRouteSub = this.activateRoute.params.subscribe(params => {
3137
this.id = +params['id'];
3238
this.templateId = +params['templateId'];
3339
});
@@ -38,6 +44,10 @@ export class CaseEditComponent implements OnInit {
3844
this.loadTemplateInfo();
3945
}
4046

47+
ngOnDestroy() {
48+
49+
}
50+
4151
loadCase() {
4252
if (!this.id || this.id == 0) {
4353
return;
@@ -63,6 +73,7 @@ export class CaseEditComponent implements OnInit {
6373
if (operation && operation.success) {
6474
this.replyElement = new ReplyElement();
6575
this.spinnerStatus = false;
76+
this.isNoSaveExitAllowed = true;
6677
this.router.navigate(['/cases/', this.currentTemplate.id]).then();
6778
} this.spinnerStatus = false;
6879
});
@@ -85,4 +96,19 @@ export class CaseEditComponent implements OnInit {
8596
});
8697
}
8798

99+
confirmExit(keepData: boolean) {
100+
if (keepData) {
101+
this.saveCase();
102+
} else {
103+
this.isNoSaveExitAllowed = true;
104+
this.router.navigate(['/cases/', this.currentTemplate.id]).then();
105+
}
106+
}
107+
108+
canDeactivate() {
109+
if (!this.isNoSaveExitAllowed) {
110+
return this.caseConfirmation.show();
111+
}
112+
return true;
113+
}
88114
}

0 commit comments

Comments
 (0)