2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-10-31 09:20:27 +00:00
RTL/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.ts

76 lines
2.9 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { faInfoCircle, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
import { LoggerService } from '../../../services/logger.service';
import { InputData, ConfirmationData } from '../../../models/alertData';
import { AlertTypeEnum, DataTypeEnum } from '../../../services/consts-enums-functions';
2021-12-29 23:08:41 +00:00
import { RTLState } from '../../../../store/rtl.state';
import { closeConfirmation } from '../../../../store/rtl.actions';
@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
public faInfoCircle = faInfoCircle;
public faExclamationTriangle = faExclamationTriangle;
public informationMessage = '';
public warningMessage = '';
public noBtnText = 'No';
public yesBtnText = 'Yes';
public messageObjs = [];
public flgShowInput = false;
public hasAdvanced = false;
public alertTypeEnum = AlertTypeEnum;
public dataTypeEnum = DataTypeEnum;
public getInputs: Array<InputData> = [{ placeholder: '', inputType: 'text', inputValue: '', hintText: '', hintFunction: null, advancedField: false }];
private showAdvanced = false;
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
) { }
ngOnInit() {
2022-08-20 18:44:58 +00:00
this.informationMessage = this.data.informationMessage || '';
this.warningMessage = this.data.warningMessage || '';
this.flgShowInput = !!this.data.flgShowInput;
this.getInputs = this.data.getInputs || [];
this.noBtnText = (this.data.noBtnText) ? this.data.noBtnText : 'No';
this.yesBtnText = (this.data.yesBtnText) ? this.data.yesBtnText : 'Yes';
this.hasAdvanced = (this.data.hasAdvanced) ? this.data.hasAdvanced : false;
this.messageObjs = this.data.message;
if (this.data.type === AlertTypeEnum.ERROR) {
if (!this.data.message && !this.data.titleMessage && this.messageObjs.length <= 0) {
this.data.titleMessage = 'Please Check Server Connection';
}
}
}
onShowAdvanced() {
this.showAdvanced = !this.showAdvanced;
}
onClose(dialogRes: any): boolean | any[] | void {
if (dialogRes && this.getInputs && this.getInputs.some((input) => typeof input.inputValue === 'undefined')) {
2021-08-28 21:03:18 +00:00
return true;
}
if (!this.showAdvanced && dialogRes.length) {
dialogRes = dialogRes?.reduce((accumulator, current) => {
if (!current.advancedField) {
accumulator.push(current);
}
return accumulator;
}, []);
}
2021-12-29 23:08:41 +00:00
this.store.dispatch(closeConfirmation({ payload: dialogRes }));
}
2021-08-28 21:03:18 +00:00
}