2019-03-19 00:13:01 +00:00
|
|
|
import { Component, OnInit, Inject } from '@angular/core';
|
2020-07-07 17:57:15 +00:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
2019-03-19 00:13:01 +00:00
|
|
|
import { Store } from '@ngrx/store';
|
2021-02-21 19:02:31 +00:00
|
|
|
import { faInfoCircle, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
|
2019-03-19 00:13:01 +00:00
|
|
|
|
2019-11-21 00:14:37 +00:00
|
|
|
import { LoggerService } from '../../../services/logger.service';
|
2019-12-02 00:22:25 +00:00
|
|
|
import { InputData, ConfirmationData } from '../../../models/alertData';
|
|
|
|
import { AlertTypeEnum, DataTypeEnum } from '../../../services/consts-enums-functions';
|
2019-03-19 00:13:01 +00:00
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
import { RTLState } from '../../../../store/rtl.state';
|
|
|
|
import { closeConfirmation } from '../../../../store/rtl.actions';
|
2019-03-19 00:13:01 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'rtl-confirmation-message',
|
|
|
|
templateUrl: './confirmation-message.component.html',
|
|
|
|
styleUrls: ['./confirmation-message.component.scss']
|
|
|
|
})
|
|
|
|
export class ConfirmationMessageComponent implements OnInit {
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2021-02-21 19:02:31 +00:00
|
|
|
public faInfoCircle = faInfoCircle;
|
|
|
|
public faExclamationTriangle = faExclamationTriangle;
|
|
|
|
public informationMessage = '';
|
|
|
|
public warningMessage = '';
|
2019-03-19 00:13:01 +00:00
|
|
|
public noBtnText = 'No';
|
|
|
|
public yesBtnText = 'Yes';
|
2019-12-02 00:22:25 +00:00
|
|
|
public messageObjs = [];
|
2019-03-19 00:13:01 +00:00
|
|
|
public flgShowInput = false;
|
2022-06-07 11:50:13 +00:00
|
|
|
public hasAdvanced = false;
|
2019-11-27 00:49:44 +00:00
|
|
|
public alertTypeEnum = AlertTypeEnum;
|
2019-12-02 00:22:25 +00:00
|
|
|
public dataTypeEnum = DataTypeEnum;
|
2022-06-07 11:50:13 +00:00
|
|
|
public getInputs: Array<InputData> = [{ placeholder: '', inputType: 'text', inputValue: '', hintText: '', hintFunction: null, advancedField: false }];
|
2022-08-14 05:19:31 +00:00
|
|
|
|
2022-06-07 11:50:13 +00:00
|
|
|
private showAdvanced = false;
|
2019-03-19 00:13:01 +00:00
|
|
|
|
2021-08-28 21:03:18 +00:00
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<ConfirmationMessageComponent>, @Inject(MAT_DIALOG_DATA) public data: ConfirmationData, private logger: LoggerService,
|
2021-12-29 23:08:41 +00:00
|
|
|
private store: Store<RTLState>
|
2021-08-28 21:03:18 +00:00
|
|
|
) { }
|
2019-03-19 00:13:01 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2022-08-20 18:44:58 +00:00
|
|
|
this.informationMessage = this.data.informationMessage || '';
|
|
|
|
this.warningMessage = this.data.warningMessage || '';
|
2022-08-19 04:41:59 +00:00
|
|
|
this.flgShowInput = !!this.data.flgShowInput;
|
|
|
|
this.getInputs = this.data.getInputs || [];
|
2020-02-07 16:36:46 +00:00
|
|
|
this.noBtnText = (this.data.noBtnText) ? this.data.noBtnText : 'No';
|
|
|
|
this.yesBtnText = (this.data.yesBtnText) ? this.data.yesBtnText : 'Yes';
|
2022-06-07 11:50:13 +00:00
|
|
|
this.hasAdvanced = (this.data.hasAdvanced) ? this.data.hasAdvanced : false;
|
2019-12-02 00:22:25 +00:00
|
|
|
this.messageObjs = this.data.message;
|
|
|
|
if (this.data.type === AlertTypeEnum.ERROR) {
|
2020-02-07 16:36:46 +00:00
|
|
|
if (!this.data.message && !this.data.titleMessage && this.messageObjs.length <= 0) {
|
2019-12-02 00:22:25 +00:00
|
|
|
this.data.titleMessage = 'Please Check Server Connection';
|
2019-03-19 00:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-14 05:19:31 +00:00
|
|
|
|
2022-06-07 11:50:13 +00:00
|
|
|
onShowAdvanced() {
|
|
|
|
this.showAdvanced = !this.showAdvanced;
|
|
|
|
}
|
2019-03-19 00:13:01 +00:00
|
|
|
|
2022-08-14 05:19:31 +00:00
|
|
|
onClose(dialogRes: any): boolean | any[] | void {
|
2022-05-01 17:35:20 +00:00
|
|
|
if (dialogRes && this.getInputs && this.getInputs.some((input) => typeof input.inputValue === 'undefined')) {
|
2021-08-28 21:03:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-08-14 05:19:31 +00:00
|
|
|
if (!this.showAdvanced && dialogRes.length) {
|
2022-08-17 22:48:04 +00:00
|
|
|
dialogRes = dialogRes?.reduce((accumulator, current) => {
|
2022-08-14 05:19:31 +00:00
|
|
|
if (!current.advancedField) {
|
|
|
|
accumulator.push(current);
|
|
|
|
}
|
|
|
|
return accumulator;
|
|
|
|
}, []);
|
|
|
|
}
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(closeConfirmation({ payload: dialogRes }));
|
2019-03-19 00:13:01 +00:00
|
|
|
}
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2019-03-19 00:13:01 +00:00
|
|
|
}
|