Commit f87ec85f authored by Aleksandr Ivanov's avatar Aleksandr Ivanov

Merge pull request #27 in RIHA/riha-browser from...

Merge pull request #27 in RIHA/riha-browser from bugfix/RIHAKB-870-riha-kasutajana-soovin-et-avatud-modaalakna-kohal-back-nuppu-vajutades-suletakse to develop

* commit 'ecbba893':
  feedback fixed
  fixed
parents fdadfbfe ecbba893
......@@ -80,6 +80,7 @@ import {LoginLinkComponent} from './components/login-link-component/login-link-c
import {ProducerSearchFilterComponent} from './components/producer-search-filter/producer-search-filter-component';
import {ProducerOrganizationComponent} from './components/producer-organization/producer-organization.component';
import {httpInterceptorProviders} from "./http-interceptors";
import {CanDeactivateModalGuard} from './guards/can-deactivate-modal.guard';
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
......@@ -104,7 +105,7 @@ const routes: Routes = [
{ path: 'Systems', component: BrowserListComponent },
{ path: 'Kirjelda', component: ProducerListComponent },
{ path: 'Describe', component: ProducerListComponent },
{ path: 'Infosüsteemid/Vaata/:reference', component: ProducerDetailsComponent },
{ path: 'Infosüsteemid/Vaata/:reference', component: ProducerDetailsComponent, canDeactivate: [CanDeactivateModalGuard] },
{ path: 'Infosüsteemid/Vaata/:reference/Arutelu/:issue_id', component: ProducerDetailsComponent },
{ path: 'Systems/Vaata/:reference', component: ProducerDetailsComponent },
{ path: 'Kirjelda/Vaata/:reference', component: ProducerDetailsComponent },
......@@ -225,7 +226,8 @@ const routes: Routes = [
{ provide: APP_INITIALIZER, useFactory: onApplicationStart, deps: [EnvironmentService], multi: true },
{ provide: APP_INITIALIZER, useFactory: loadClassifiers, deps: [EnvironmentService], multi: true },
httpInterceptorProviders,
]
CanDeactivateModalGuard,
]
})
export class AppModule {}
......@@ -129,11 +129,11 @@
</div>
<div class="actions-bar">
<div *ngIf="isApprovalRequest && openIssuesMatrix" class="buttons pull-right">
<button (click)="closeModal(approvalRequestForm)" class="btn btn-secondary pull-right">Katkesta</button>
<button (click)="closeModal()" class="btn btn-secondary pull-right">Katkesta</button>
<button (click)="onSubmitApprovalRequest(approvalRequestForm)" class="btn btn-success pull-right">Salvesta</button>
</div>
<div *ngIf="!isApprovalRequest" class="buttons pull-right">
<button (click)="closeModal(newIssueForm)" class="btn btn-secondary pull-right">Katkesta</button>
<button (click)="closeModal()" class="btn btn-secondary pull-right">Katkesta</button>
<button (click)="onSubmitNewIssue(newIssueForm)" class="btn btn-success pull-right">Salvesta</button>
</div>
</div>
......
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../services/systems.service';
import { EnvironmentService, classifiers } from '../../services/environment.service';
import { System } from '../../models/system';
import { ToastrService } from 'ngx-toastr';
import { User } from '../../models/user';
import { ModalHelperService } from '../../services/modal-helper.service';
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {SystemsService} from '../../services/systems.service';
import {classifiers, EnvironmentService} from '../../services/environment.service';
import {System} from '../../models/system';
import {ToastrService} from 'ngx-toastr';
import {User} from '../../models/user';
import {ModalHelperService} from '../../services/modal-helper.service';
import {CanDeactivateModal} from '../../guards/can-deactivate-modal.guard';
import {Observable} from "rxjs";
import {NgForm} from "@angular/forms";
import {CONSTANTS} from '../../utils/constants';
@Component({
selector: 'app-approver-add-comment',
templateUrl: './approver-add-issue.component.html',
styleUrls: ['./approver-add-issue.component.scss']
})
export class ApproverAddIssueComponent implements OnInit {
export class ApproverAddIssueComponent implements OnInit, CanDeactivateModal {
@ViewChild('approvalRequestForm', null) formObjectApprovalRequest: NgForm;
@ViewChild('newIssueForm', null) formObjectNewIssue: NgForm;
@Input() system: System;
activeUser: User;
......@@ -78,20 +85,42 @@ export class ApproverAddIssueComponent implements OnInit {
}
}
closeModal(f){
if (f.form.dirty){
if (confirm('Oled sisestanud väljadesse infot. Kui navigeerid siit ära ilma salvestamata, siis sinu sisestatud info kaob.')){
this.modalService.dismissActiveModal();
} else {
return false;
}
} else {
this.modalService.dismissActiveModal();
canSwitchViews(){
return this.environmentService.getUserMatrix().hasApproverRole && this.activeUser.canEdit(this.system.getOwnerCode());
}
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.closeModal();
}
closeModal() {
if (this.isFormChanged) {
const observer = this.modalService.confirm(CONSTANTS.CLOSE_DIALOG_WARNING);
observer.subscribe(confirmed => {
if (confirmed) {
this.modalService.dismissActiveModal();
}
});
return observer;
}
this.modalService.dismissActiveModal();
return true;
}
canSwitchViews(){
return this.environmentService.getUserMatrix().hasApproverRole && this.activeUser.canEdit(this.system.getOwnerCode());
/**
* Getters
*/
/**
* Is form data changed ?
*/
get isFormChanged(): boolean {
if (this.isApprovalRequest) {
return this.formObjectApprovalRequest.form.dirty;
} else {
return this.formObjectNewIssue.form.dirty;
}
}
constructor(private modalService: ModalHelperService,
......
<div class="fixed-header">
Hindajate tagasiside
<button (click)="closeModal(commentForm)" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
<button (click)="closeModal()" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
</div>
<section class="col card p-3 main-content scrollable-modal-content">
<div class="my-1">
......
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../services/systems.service';
import { EnvironmentService } from '../../services/environment.service';
import { ToastrService } from 'ngx-toastr';
import { User } from '../../models/user';
import { ModalHelperService } from "../../services/modal-helper.service";
import { classifiers } from "../../services/environment.service";
import { System } from '../../models/system';
import { GeneralHelperService } from '../../services/general-helper.service';
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {SystemsService} from '../../services/systems.service';
import {classifiers, EnvironmentService} from '../../services/environment.service';
import {ToastrService} from 'ngx-toastr';
import {User} from '../../models/user';
import {ModalHelperService} from "../../services/modal-helper.service";
import {System} from '../../models/system';
import {GeneralHelperService} from '../../services/general-helper.service';
import {CanDeactivateModal} from '../../guards/can-deactivate-modal.guard';
import {NgForm} from "@angular/forms";
import {Observable} from "rxjs";
import {CONSTANTS} from '../../utils/constants';
@Component({
selector: 'app-approver-feedback-details',
templateUrl: './approver-issue-details.component.html',
styleUrls: ['./approver-issue-details.component.scss']
})
export class ApproverIssueDetailsComponent implements OnInit {
export class ApproverIssueDetailsComponent implements OnInit, CanDeactivateModal {
@ViewChild('commentForm', null) formObject: NgForm;
@Input() feedback: any;
@Input() system: System;
......@@ -127,18 +132,37 @@ export class ApproverIssueDetailsComponent implements OnInit {
return ret;
}
closeModal(f){
if (f.form.dirty){
if (confirm('Oled sisestanud väljadesse infot. Kui navigeerid siit ära ilma salvestamata, siis sinu sisestatud info kaob.')){
this.modalService.closeActiveModal();
} else {
return false;
}
} else {
this.modalService.closeActiveModal();
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.closeModal();
}
closeModal() {
if (this.isFormChanged) {
const observer = this.modalService.confirm(CONSTANTS.CLOSE_DIALOG_WARNING);
observer.subscribe(confirmed => {
if (confirmed) {
this.modalService.dismissActiveModal();
}
});
return observer;
}
this.modalService.dismissActiveModal();
return true;
}
/**
* Getters
*/
/**
* Is form data changed ?
*/
get isFormChanged(): boolean {
return this.formObject.form.dirty
}
constructor(private systemService: SystemsService,
private toastrService: ToastrService,
private modalService: ModalHelperService,
......
......@@ -7,13 +7,15 @@ import {User} from '../../models/user';
import {ToastrService} from 'ngx-toastr';
import {UserMatrix} from '../../models/user-matrix';
import {GeneralHelperService} from '../../services/general-helper.service';
import {CanDeactivateModal} from "../../guards/can-deactivate-modal.guard";
import {ModalHelperService} from "../../services/modal-helper.service";
@Component({
selector: 'app-producer-details',
templateUrl: './producer-details.component.html',
styleUrls: ['./producer-details.component.scss']
})
export class ProducerDetailsComponent implements OnInit, DoCheck {
export class ProducerDetailsComponent implements OnInit, DoCheck, CanDeactivateModal {
private system: System = new System();
private user: User;
public loaded: boolean;
......@@ -22,6 +24,21 @@ export class ProducerDetailsComponent implements OnInit, DoCheck {
public userMatrix: UserMatrix;
private differ: any;
// canDeactivate guard handler
canDeactivate() {
const modal = this.modalService.lastModal;
if (modal) {
const component = modal && modal.componentInstance ? modal.componentInstance : null;
if (component && 'canDeactivate' in component) {
return component.canDeactivate()
}
return true;
}
return true;
}
isEditingAllowed(){
const user = this.environmentService.getActiveUser();
let editable = false;
......@@ -121,7 +138,8 @@ export class ProducerDetailsComponent implements OnInit, DoCheck {
public generalHelperService: GeneralHelperService,
private route: ActivatedRoute,
private router: Router,
private toastrService: ToastrService) {
private toastrService: ToastrService,
private modalService: ModalHelperService) {
this.differ = differs.find({}).create();
this.userMatrix = this.environmentService.getUserMatrix();
}
......
<div class="fixed-header">
Kontaktid
<button (click)="closeModal(addForm)" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
<button (click)="closeModal()" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
</div>
<section class="col card p-3 main-content scrollable-modal-content">
<div class="my-1">
......
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';
import { System } from '../../../models/system';
import { ToastrService } from 'ngx-toastr';
import { ModalHelperService } from '../../../services/modal-helper.service';
import { GeneralHelperService } from '../../../services/general-helper.service';
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {SystemsService} from '../../../services/systems.service';
import {System} from '../../../models/system';
import {ToastrService} from 'ngx-toastr';
import {ModalHelperService} from '../../../services/modal-helper.service';
import {GeneralHelperService} from '../../../services/general-helper.service';
import {Observable} from "rxjs";
import {NgForm} from "@angular/forms";
import {CanDeactivateModal} from '../../../guards/can-deactivate-modal.guard';
import {CONSTANTS} from '../../../utils/constants';
@Component({
selector: 'app-producer-edit-contacts',
templateUrl: './producer-edit-contacts.component.html',
styleUrls: ['./producer-edit-contacts.component.scss']
})
export class ProducerEditContactsComponent implements OnInit {
export class ProducerEditContactsComponent implements OnInit, CanDeactivateModal {
@ViewChild('addForm', null) formObject: NgForm;
@Input() system: System;
contacts: any[] = [];
......@@ -47,18 +53,37 @@ export class ProducerEditContactsComponent implements OnInit {
});
}
closeModal(f){
if (this.isChanged || f.form.dirty){
if (confirm('Oled väljades muudatusi teinud. Kui navigeerid siit ära ilma salvestamata, siis sinu muudatused kaovad.')){
this.modalService.dismissActiveModal();
} else {
return false;
}
} else {
this.modalService.dismissActiveModal();
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.closeModal();
}
closeModal() {
if (this.isFormChanged) {
const observer = this.modalService.confirm(CONSTANTS.CLOSE_DIALOG_WARNING);
observer.subscribe(confirmed => {
if (confirmed) {
this.modalService.dismissActiveModal();
}
});
return observer;
}
this.modalService.dismissActiveModal();
return true;
}
/**
* Getters
*/
/**
* Is form data changed ?
*/
get isFormChanged(): boolean {
return this.isChanged || this.formObject.form.dirty
}
constructor(private modalService: ModalHelperService,
private systemsService: SystemsService,
private toastrService: ToastrService,
......
<div class="fixed-header">
Dokumentatsioon
<button (click)="closeModal(addForm, editForm)" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
<button (click)="closeModal()" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
</div>
<section class="col card p-3 main-content scrollable-modal-content">
<div class="my-1">
......
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';
import { System } from '../../../models/system';
import { ToastrService } from 'ngx-toastr';
import { ModalHelperService } from '../../../services/modal-helper.service';
import { GeneralHelperService } from '../../../services/general-helper.service';
import { classifiers } from '../../../services/environment.service';
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {SystemsService} from '../../../services/systems.service';
import {System} from '../../../models/system';
import {ToastrService} from 'ngx-toastr';
import {ModalHelperService} from '../../../services/modal-helper.service';
import {GeneralHelperService} from '../../../services/general-helper.service';
import {classifiers} from '../../../services/environment.service';
import {NgForm} from "@angular/forms";
import {Observable} from "rxjs";
import {CanDeactivateModal} from '../../../guards/can-deactivate-modal.guard';
import {CONSTANTS} from '../../../utils/constants';
@Component({
selector: 'app-producer-edit-tech-docs',
templateUrl: './producer-edit-documents.component.html',
styleUrls: ['./producer-edit-documents.component.scss']
})
export class ProducerEditDocumentsComponent implements OnInit {
export class ProducerEditDocumentsComponent implements OnInit, CanDeactivateModal {
@ViewChild('addForm', null) formObjectAdd: NgForm;
@ViewChild('editForm', null) formObjectEdit: NgForm;
@Input() system: System;
documents: any[] = [];
......@@ -108,17 +115,6 @@ export class ProducerEditDocumentsComponent implements OnInit {
}
}
closeModal(addForm, editForm){
if (this.isChanged || addForm.form.dirty || editForm.form.dirty){
if (confirm('Oled väljades muudatusi teinud. Kui navigeerid siit ära ilma salvestamata, siis sinu muudatused kaovad.')){
this.modalService.dismissActiveModal();
} else {
return false;
}
} else {
this.modalService.dismissActiveModal();
}
}
isUploaded(doc){
return doc.url.substr(0,7) == 'file://';
......@@ -146,6 +142,36 @@ export class ProducerEditDocumentsComponent implements OnInit {
}
}
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.closeModal();
}
closeModal() {
if (this.isFormChanged) {
const observer = this.modalService.confirm(CONSTANTS.CLOSE_DIALOG_WARNING);
observer.subscribe(confirmed => {
if (confirmed) {
this.modalService.dismissActiveModal();
}
});
return observer;
}
this.modalService.dismissActiveModal();
return true;
}
/**
* Getters
*/
/**
* Is form data changed ?
*/
get isFormChanged(): boolean {
return this.isChanged || this.formObjectAdd.form.dirty || this.formObjectEdit.form.dirty
}
constructor(private modalService: ModalHelperService,
private systemsService: SystemsService,
private toastrService: ToastrService,
......
<div class="fixed-header">
Õigusaktid
<button (click)="closeModal(addForm)" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
<button (click)="closeModal()" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
</div>
<section class="col card p-3 main-content scrollable-modal-content">
<div class="my-1">
......
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';
import { System } from '../../../models/system';
import { ToastrService } from 'ngx-toastr';
import { ModalHelperService } from '../../../services/modal-helper.service';
import { GeneralHelperService } from '../../../services/general-helper.service';
import { classifiers } from "../../../services/environment.service";
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {SystemsService} from '../../../services/systems.service';
import {System} from '../../../models/system';
import {ToastrService} from 'ngx-toastr';
import {ModalHelperService} from '../../../services/modal-helper.service';
import {GeneralHelperService} from '../../../services/general-helper.service';
import {classifiers} from "../../../services/environment.service";
import {Observable} from "rxjs";
import {NgForm} from "@angular/forms";
import {CanDeactivateModal} from '../../../guards/can-deactivate-modal.guard';
import {CONSTANTS} from '../../../utils/constants';
@Component({
selector: 'app-producer-edit-legislations',
templateUrl: './producer-edit-legislations.component.html',
styleUrls: ['./producer-edit-legislations.component.scss']
})
export class ProducerEditLegislationsComponent implements OnInit {
export class ProducerEditLegislationsComponent implements OnInit, CanDeactivateModal {
@ViewChild('addForm', null) formObjectAdd: NgForm;
@Input() system: System;
legislations: any[] = [];
......@@ -36,18 +42,6 @@ export class ProducerEditLegislationsComponent implements OnInit {
this.isChanged = true;
}
closeModal(f){
if (this.isChanged || f.form.dirty){
if (confirm('Oled väljades muudatusi teinud. Kui navigeerid siit ära ilma salvestamata, siis sinu muudatused kaovad.')){
this.modalService.dismissActiveModal();
} else {
return false;
}
} else {
this.modalService.dismissActiveModal();
}
}
saveSystem(){
this.systemsService.getSystem(this.system.details.short_name).subscribe(responseSystem => {
const system = new System(responseSystem);
......@@ -62,6 +56,36 @@ export class ProducerEditLegislationsComponent implements OnInit {
});
}
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.closeModal();
}
closeModal() {
if (this.isFormChanged) {
const observer = this.modalService.confirm(CONSTANTS.CLOSE_DIALOG_WARNING);
observer.subscribe(confirmed => {
if (confirmed) {
this.modalService.dismissActiveModal();
}
});
return observer;
}
this.modalService.dismissActiveModal();
return true;
}
/**
* Getters
*/
/**
* Is form data changed ?
*/
get isFormChanged(): boolean {
return this.isChanged || this.formObjectAdd.form.dirty
}
constructor(private modalService: ModalHelperService,
private systemsService: SystemsService,
private toastrService: ToastrService,
......
<div class="fixed-header">
Andmed
<button (click)="closeModal(dataFilesForm, object)" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
<button (click)="closeModal()" class="btn btn-sm btn-secondary close-modal-btn pull-right"><i class="fa fa-remove" aria-hidden="true"></i></button>
</div>
<section class="col card p-3 main-content scrollable-modal-content">
<div class="my-1">
......
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';
import { GeneralHelperService } from '../../../services/general-helper.service';
import { System } from '../../../models/system';
import { ToastrService } from 'ngx-toastr';
import { ModalHelperService } from '../../../services/modal-helper.service';
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {SystemsService} from '../../../services/systems.service';
import {GeneralHelperService} from '../../../services/general-helper.service';
import {System} from '../../../models/system';
import {ToastrService} from 'ngx-toastr';
import {ModalHelperService} from '../../../services/modal-helper.service';
import {NgForm} from "@angular/forms";
import {Observable} from "rxjs";
import {CanDeactivateModal} from '../../../guards/can-deactivate-modal.guard';
import {CONSTANTS} from '../../../utils/constants';
@Component({
selector: 'app-producer-edit-objects',
templateUrl: './producer-edit-objects.component.html',
styleUrls: ['./producer-edit-objects.component.scss']
})
export class ProducerEditObjectsComponent implements OnInit {
export class ProducerEditObjectsComponent implements OnInit, CanDeactivateModal {
@ViewChild('dataFilesForm', null) formObject: NgForm;
@ViewChild('object', null) inputObject: ElementRef;
@Input() system: System;
stored_data: string[] =[];
......@@ -90,16 +97,34 @@ export class ProducerEditObjectsComponent implements OnInit {
});
}
closeModal(f, i){
if (this.isChanged || f.form.dirty || i.value.length > 0){
if (confirm('Oled väljades muudatusi teinud. Kui navigeerid siit ära ilma salvestamata, siis sinu muudatused kaovad.')){
this.modalService.dismissActiveModal();
} else {
return false;
}
} else {
this.modalService.dismissActiveModal();
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.closeModal();
}
closeModal() {
if (this.isFormChanged) {
const observer = this.modalService.confirm(CONSTANTS.CLOSE_DIALOG_WARNING);
observer.subscribe(confirmed => {
if (confirmed) {
this.modalService.dismissActiveModal();
}
});
return observer;
}
this.modalService.dismissActiveModal();
return true;
}
/**
* Getters
*/
/**
* Is form data changed ?
*/
get isFormChanged(): boolean {
return this.isChanged || this.formObject.form.dirty || this.inputObject.nativeElement.value.length > 0
}
constructor(private modalService: ModalHelperService,
......@@ -113,5 +138,4 @@ export class ProducerEditObjectsComponent implements OnInit {
this.stored_data = system.details.stored_data || [];
this.data_files = system.details.data_files || [];
}
}
import { Component, OnInit, Input } from '@angular/core';
import { SystemsService } from '../../../services/systems.service';