From f4b6f9de1b47aabd7bbe4347b58e7bf0ca6ac29d Mon Sep 17 00:00:00 2001 From: Boris Voropaev Date: Fri, 22 Dec 2023 15:20:30 +0300 Subject: [PATCH] prompt allert --- .../_modules/layout/grid/grid.component.html | 1 + .../sections/menu/page-menu.component.ts | 18 +++++-- .../cms-dialog/cms-dialog.component.html | 30 +++++++++++ .../cms-dialog/cms-dialog.component.scss | 6 +++ .../widjet/cms-dialog/cms-dialog.component.ts | 54 +++++++++++++++++++ src/app/_modules/widjet/widjet.module.ts | 7 ++- src/app/_services/dialog.service.ts | 35 ++++++++++++ 7 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 src/app/_modules/widjet/cms-dialog/cms-dialog.component.html create mode 100644 src/app/_modules/widjet/cms-dialog/cms-dialog.component.scss create mode 100644 src/app/_modules/widjet/cms-dialog/cms-dialog.component.ts create mode 100644 src/app/_services/dialog.service.ts diff --git a/src/app/_modules/layout/grid/grid.component.html b/src/app/_modules/layout/grid/grid.component.html index 58b57be..0db5209 100644 --- a/src/app/_modules/layout/grid/grid.component.html +++ b/src/app/_modules/layout/grid/grid.component.html @@ -16,3 +16,4 @@ + diff --git a/src/app/_modules/pages/sections/menu/page-menu.component.ts b/src/app/_modules/pages/sections/menu/page-menu.component.ts index 8179b7f..137c40d 100644 --- a/src/app/_modules/pages/sections/menu/page-menu.component.ts +++ b/src/app/_modules/pages/sections/menu/page-menu.component.ts @@ -1,5 +1,6 @@ import {Component, Input} from '@angular/core'; import {FormsService, ListsService, ObjectsService} from "@app/_services"; +import { DialogService } from '@app/_services/dialog.service'; @Component({ selector: 'page-menu', @@ -14,7 +15,11 @@ export class PageMenuComponent { @Input() modelId: string; @Input() modelType: string; - constructor(private formsService: FormsService, private objectsService: ObjectsService, private listsService: ListsService) { + constructor( + private formsService: FormsService, + private objectsService: ObjectsService, + private listsService: ListsService, + private dialog: DialogService) { } ngOnInit() { @@ -50,9 +55,12 @@ export class PageMenuComponent { } delete() { - //r u sure? - if (confirm('Удалить этот блок?')) this.objectsService.destroy(this.section.id).subscribe(res => { - this.listsService.refresh(); - }); + this.dialog.prompt('Удалить этот блок?').subscribe( + resp=>{ + if (resp) this.objectsService.destroy(this.section.id).subscribe(res => { + this.listsService.refresh(); + }); + } + ) } } diff --git a/src/app/_modules/widjet/cms-dialog/cms-dialog.component.html b/src/app/_modules/widjet/cms-dialog/cms-dialog.component.html new file mode 100644 index 0000000..9db534c --- /dev/null +++ b/src/app/_modules/widjet/cms-dialog/cms-dialog.component.html @@ -0,0 +1,30 @@ + +
+

Внимание

+
+
+ {{allert}} +
+
+ +
+
+ + +
+

Подтверждение

+
+
+ {{prompt}} +
+
+ + +
+
diff --git a/src/app/_modules/widjet/cms-dialog/cms-dialog.component.scss b/src/app/_modules/widjet/cms-dialog/cms-dialog.component.scss new file mode 100644 index 0000000..a86f021 --- /dev/null +++ b/src/app/_modules/widjet/cms-dialog/cms-dialog.component.scss @@ -0,0 +1,6 @@ +[footer]{ + display: flex; + justify-content: flex-end; + gap: 20px; + margin-bottom: 24px; +} \ No newline at end of file diff --git a/src/app/_modules/widjet/cms-dialog/cms-dialog.component.ts b/src/app/_modules/widjet/cms-dialog/cms-dialog.component.ts new file mode 100644 index 0000000..e92ee26 --- /dev/null +++ b/src/app/_modules/widjet/cms-dialog/cms-dialog.component.ts @@ -0,0 +1,54 @@ +import { Component } from '@angular/core'; +import { DialogService } from '@app/_services/dialog.service'; +import { Subscription, BehaviorSubject } from 'rxjs'; + +@Component({ + selector: 'cms-dialog', + templateUrl: './cms-dialog.component.html', + styleUrls: ['./cms-dialog.component.scss'] +}) +export class CmsDialogComponent { + constructor( + private dialog: DialogService + ){} + + allert: string; + prompt: string; + resp: BehaviorSubject; + showAllert: boolean; + showPrompt: boolean; + + ngOnInit(){ + this.dialog.modalAllertSubject.subscribe( + allert=>{ + if (allert) { + this.allert = allert; + this.showAllert = true; + } + } + ) + this.dialog.modalPromptSubject.subscribe( + prompt=>{ + if (prompt) { + this.prompt = prompt; + this.showPrompt = true; + } + } + ) + } + + respYes(){ + this.dialog.modalRespSubject.next(true); + this.close(); + } + + respNo(){ + this.dialog.modalRespSubject.next(false); + this.close(); + } + + close(){ + this.showPrompt = this.showAllert = false; + } + +} diff --git a/src/app/_modules/widjet/widjet.module.ts b/src/app/_modules/widjet/widjet.module.ts index 6ac36ec..686a167 100644 --- a/src/app/_modules/widjet/widjet.module.ts +++ b/src/app/_modules/widjet/widjet.module.ts @@ -14,6 +14,7 @@ import {SwiperModule} from "swiper/angular"; import { SwiperGalleryComponent } from './swiper-gallery/swiper-gallery.component'; import {FullscreenGalleryComponent} from "@app/_modules/widjet/swiper-gallery/fullscreen/fullscreen-gallery.component"; import { CmsModalComponent } from './cms-modal/cms-modal.component'; +import { CmsDialogComponent } from './cms-dialog/cms-dialog.component'; @NgModule({ @@ -34,7 +35,8 @@ import { CmsModalComponent } from './cms-modal/cms-modal.component'; ModalComponent, SwiperGalleryComponent, FullscreenGalleryComponent, - CmsModalComponent + CmsModalComponent, + CmsDialogComponent ], exports: [ IcoComponent, @@ -47,7 +49,8 @@ import { CmsModalComponent } from './cms-modal/cms-modal.component'; ModalComponent, SwiperGalleryComponent, FullscreenGalleryComponent, - CmsModalComponent + CmsModalComponent, + CmsDialogComponent ] }) export class WidjetModule { diff --git a/src/app/_services/dialog.service.ts b/src/app/_services/dialog.service.ts new file mode 100644 index 0000000..8cc8c13 --- /dev/null +++ b/src/app/_services/dialog.service.ts @@ -0,0 +1,35 @@ +import {Injectable} from '@angular/core'; +import {HttpClient} from '@angular/common/http'; +import {environment} from '@environments/environment'; +import {Observable, BehaviorSubject} from "rxjs"; + +@Injectable({ providedIn: 'root' }) +export class DialogService { + + public modalAllertSubject = new BehaviorSubject(null) + public modalPromptSubject = new BehaviorSubject(null); + public modalRespSubject = new BehaviorSubject(null); + private userResp: BehaviorSubject + + constructor(){ + this.modalRespSubject.subscribe( + resp=>{ + if (resp !== null){ + this.userResp.next(resp); + this.userResp.complete(); + } + } + ) + } + + + alert(txt:string){ + this.modalAllertSubject.next(txt) + } + prompt(txt:string){ + this.modalPromptSubject.next(txt); + this.userResp = new BehaviorSubject(null) + return this.userResp; + } + +} \ No newline at end of file