import { Injectable } from '@angular/core'; import { BsModalService, BsModalRef, ModalOptions } from 'ngx-bootstrap/modal'; import { TableModalComponent, ChartModalComponent, AnomalyModalComponent, CommentsModalComponent, FormModalComponent, ConfirmModalComponent, ViewOnlyComponent, EventConsoleModalComponent, ShareModalComponent, GraphQLService, Utils } from '@esp/esp-common'; import { Subject, BehaviorSubject, Observable } from 'rxjs'; import {CommentQueryArgs} from "./utils/comments.query.variables"; import {CommentsQuery} from "./utils/comments.query"; import {SimpleFormModalComponent} from '@esp/esp-common'; @Injectable({ providedIn: 'root' }) export class ModalService { private modalInputs; private event = new Subject(); disksUpdatedSub = new BehaviorSubject(false); disksUpdated$ = this.disksUpdatedSub.asObservable(); checkDataChangeSub = new BehaviorSubject(false); checkDataChange$ = this.checkDataChangeSub.asObservable(); comments: any[] = []; castComments = new Subject(); bsModalRef: BsModalRef; constructor( private modalService: BsModalService, private graphQL: GraphQLService, // private toolBarService: ToolbarPredictiveService ) {} setModalInputs(inputs) { this.modalInputs = inputs; } getModalInputs() { return this.modalInputs; } openTableModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(TableModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openConfirmModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(ConfirmModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openSimpleFormModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(SimpleFormModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openFeatureImportanceModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(ChartModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openAnomalyModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(AnomalyModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openCommentsModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show( CommentsModalComponent, Object.assign({ ignoreBackdropClick: true }, config) ); } openFormModal(initialState) { this.bsModalRef = this.modalService.show(FormModalComponent, { initialState }); } openPlannerModal(initialState) { // const config: ModalOptions = initialState; // this.bsModalRef = this.modalService.show(PlannerModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openPromoModal(initialState) { // const config: ModalOptions = initialState; // this.bsModalRef = this.modalService.show(PromoModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openRunAsScenarioModal(initialState) { // const config: ModalOptions = initialState; // this.bsModalRef = this.modalService.show( // RunAsScenarioComponent, // Object.assign({ ignoreBackdropClick: true }, config) // ); } openShareModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(ShareModalComponent, Object.assign({ ignoreBackdropClick: true }, config)); } openViewOnlyModal(initialState) { const config: ModalOptions = initialState; this.bsModalRef = this.modalService.show(ViewOnlyComponent, Object.assign({ ignoreBackdropClick: true }, config)); } // openAssignmentModal(initialState) { // const config: ModalOptions = initialState; // this.bsModalRef = this.modalService.show(AssignmentModalComponent, Object.assign({}, config)); // this.bsModalRef.content.onClose = new Subject(); // } openEventModal(initialState) { const config: ModalOptions = initialState; this.modalService.show(EventConsoleModalComponent, config); } deleteComment(comment, commentData) { const id = comment.id; const args = CommentQueryArgs.deleteCommentArgs(id); this.graphQL.mutate(CommentsQuery.deleteComment(), args).subscribe( response => { if (response?.data) { this.comments = this.comments.filter(c => c.id !== id); this.triggerComments(this.comments); this.triggerEvent({ type: 'delete', data: { success: true } }); // this.toolBarService.updateGridWithDeletedComments(comment, commentData); } }, error => { this.triggerEvent({ type: 'delete', data: { success: false } }); Utils.showError('ModalService.deleteComment(id)', error); } ); } getComments() { return this.comments.slice(); } exposeComments() { return this.castComments.asObservable(); } triggerComments(comments) { this.castComments.next(comments); } exposeEvent = (): Observable => { return this.event.asObservable(); }; triggerEvent = (eventData: any) => { this.event.next(eventData); }; }