From d46e97f0dfb47c555f5eabe05c015d7a533192f4 Mon Sep 17 00:00:00 2001 From: Mathias Beaulieu-Duncan Date: Tue, 28 Feb 2023 19:23:10 -0500 Subject: [PATCH] added command-modal service fix issue with command modal showing success command error message publish new version --- .../poweredsoft/ngx-bootstrap/package.json | 6 +- .../lib/command-modal/command-modal.module.ts | 3 +- .../command-modal/command-modal.service.ts | 58 +++++++++++++++++++ .../command-modal.component.html | 1 - .../command-modal/command-modal.component.ts | 8 +-- .../directives/command-modal.directive.ts | 8 +-- .../lib/confirm-modal/confirm-modal.module.ts | 18 ++---- .../ngx-bootstrap/src/public-api.ts | 3 +- 8 files changed, 79 insertions(+), 26 deletions(-) create mode 100644 projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.service.ts diff --git a/projects/poweredsoft/ngx-bootstrap/package.json b/projects/poweredsoft/ngx-bootstrap/package.json index 4453816..c5d9c31 100644 --- a/projects/poweredsoft/ngx-bootstrap/package.json +++ b/projects/poweredsoft/ngx-bootstrap/package.json @@ -1,7 +1,7 @@ { "name": "@poweredsoft/ngx-bootstrap", - "version": "0.0.13", - "description": "an internal use libary for handling data souces grid filtering sorting, add commands etc", + "version": "0.0.15", + "description": "an internal use library for handling data sources grid filtering sorting, add commands etc", "keywords": [ "angular", "ngx-bootstrap" @@ -15,4 +15,4 @@ "dependencies": { "tslib": "^1.10.0" } -} \ No newline at end of file +} diff --git a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.module.ts b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.module.ts index c80c5da..e26ead3 100644 --- a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.module.ts +++ b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.module.ts @@ -3,8 +3,8 @@ import { CommonModule } from '@angular/common'; import { ModalModule } from 'ngx-bootstrap/modal'; import { CommandModalDirective } from './directives/command-modal.directive'; import { CommandModalComponent } from './command-modal/command-modal.component'; - import { FormsModule } from '@angular/forms'; +import {CommandModalService} from './command-modal.service'; @NgModule({ imports: [ @@ -12,6 +12,7 @@ import { FormsModule } from '@angular/forms'; ModalModule.forRoot(), FormsModule ], + providers: [CommandModalService], declarations: [CommandModalDirective, CommandModalComponent], exports: [CommandModalDirective] }) diff --git a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.service.ts b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.service.ts new file mode 100644 index 0000000..6d82172 --- /dev/null +++ b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal.service.ts @@ -0,0 +1,58 @@ +import {CommandModalComponent} from './command-modal/command-modal.component'; +import {EventEmitter, Injectable, TemplateRef} from '@angular/core'; +import {IDataSource} from '@poweredsoft/data'; +import {BsModalService} from 'ngx-bootstrap/modal'; + +@Injectable() +export class CommandModalService { + constructor(private modalService: BsModalService) { + } + + spawn(options: { + dataSource: IDataSource + command: string, + model: TModel, + template: TemplateRef, + commandTitle?: string, + refreshOnSuccess?: boolean, + commandText?: string, + cancelText?: string, + animated?: boolean, + btnClass?: string, + modalSize?: string, + disableValidationSummary?: boolean, + backdrop?: boolean, + ignoreBackdropClick?: boolean, + params?: any, + success?: EventEmitter + }) { + options.dataSource.resolveCommandModelByName({ + command: options.command, + model: options.model, + params: options.params + }).subscribe(commandModel => { + const initialState = { + dataSource: options.dataSource, + command: options.command, + commandModel, + template: options.template, + title: options.commandTitle, + disableValidationSummary: options.disableValidationSummary === undefined ? false : options.disableValidationSummary, + refreshOnSuccess: options.refreshOnSuccess === undefined ? true : options.refreshOnSuccess, + commandText: options.commandText || 'OK', + cancelText: options.cancelText || 'Cancel', + successEmitter: options.success, + btnClass: options.btnClass || 'primary' + }; + this.modalService.show(CommandModalComponent, { + animated: options.animated === undefined ? true : options.animated, + class: options.modalSize, + initialState, + backdrop: options.backdrop === undefined ? true : options.backdrop, + ignoreBackdropClick: options.ignoreBackdropClick === undefined ? false : options.ignoreBackdropClick + }); + }, error => { + + }); + } +} diff --git a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.html b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.html index 733fe7f..89ea356 100644 --- a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.html +++ b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.html @@ -20,6 +20,5 @@
- diff --git a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.ts b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.ts index 6afa6e4..ad53ceb 100644 --- a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.ts +++ b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/command-modal/command-modal.component.ts @@ -25,7 +25,7 @@ export class CommandModalComponent implements OnInit, OnDestroy { validationMessage:string ; disableValidationSummary: boolean; btnClass:string; - successEmitter: EventEmitter; + successEmitter: EventEmitter; hasError: boolean; errorMessage: string = ''; @@ -45,11 +45,11 @@ export class CommandModalComponent implements OnInit, OnDestroy { ngOnInit(): void { this._notifyMessage = this.dataSource.notifyMessage$.subscribe(message => { - if (message.type != 'info') + if (message.type !== 'info' && message.type !== 'success') this.errorMessage = message.message; }); - this._validationError = this.dataSource.validationError$.subscribe(validatorErrors => { + this._validationError = this.dataSource.validationError$.subscribe(validatorErrors => { let validationSummary = ''; Object.getOwnPropertyNames(validatorErrors.errors).forEach(property => { const errors = validatorErrors.errors[property].join('\n'); @@ -82,7 +82,7 @@ export class CommandModalComponent implements OnInit, OnDestroy { } attemptSave() { - + } } diff --git a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/directives/command-modal.directive.ts b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/directives/command-modal.directive.ts index aa4b6ad..cd125b6 100644 --- a/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/directives/command-modal.directive.ts +++ b/projects/poweredsoft/ngx-bootstrap/src/lib/command-modal/directives/command-modal.directive.ts @@ -20,7 +20,7 @@ export class CommandModalDirective { @Input() commandText: string; @Input() cancelText: string; @Input() animated: boolean; - @Input() btnClass:string; + @Input() btnClass: string; @Input() modalSize: string; @Input() disableValidationSummary: boolean; @Input() backdrop: boolean; @@ -30,16 +30,16 @@ export class CommandModalDirective { @Output() success: EventEmitter = new EventEmitter(); @HostListener('click') - wasClicked() { + wasClicked() { this.dataSource.resolveCommandModelByName({ command: this.command, model: this.model, params: this.params - }).subscribe(commandModel => { + }).subscribe(commandModel => { const initialState = { dataSource: this.dataSource, command: this.command, - commandModel: commandModel, + commandModel, template: this.template, title: this.commandTitle, disableValidationSummary: this.disableValidationSummary === undefined ? false : this.disableValidationSummary, diff --git a/projects/poweredsoft/ngx-bootstrap/src/lib/confirm-modal/confirm-modal.module.ts b/projects/poweredsoft/ngx-bootstrap/src/lib/confirm-modal/confirm-modal.module.ts index 94314af..f941469 100644 --- a/projects/poweredsoft/ngx-bootstrap/src/lib/confirm-modal/confirm-modal.module.ts +++ b/projects/poweredsoft/ngx-bootstrap/src/lib/confirm-modal/confirm-modal.module.ts @@ -1,22 +1,16 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { ConfirmModalComponent } from './confirm-modal-components/confirm-modal/confirm-modal.component'; -import { ModalModule } from 'ngx-bootstrap/modal'; -import { ConfirmModalService } from './confirm-modal.service'; -import { CommandModule } from '../command/command.module'; - - - +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {ConfirmModalComponent} from './confirm-modal-components/confirm-modal/confirm-modal.component'; +import {ModalModule} from 'ngx-bootstrap/modal'; +import {ConfirmModalService} from './confirm-modal.service'; @NgModule({ declarations: [ConfirmModalComponent], imports: [ CommonModule, - //CommandModule, ModalModule.forRoot(), - ], - exports:[], + exports: [], providers: [ConfirmModalService] }) export class ConfirmModalModule { } diff --git a/projects/poweredsoft/ngx-bootstrap/src/public-api.ts b/projects/poweredsoft/ngx-bootstrap/src/public-api.ts index 1a78a1d..e06ebc7 100644 --- a/projects/poweredsoft/ngx-bootstrap/src/public-api.ts +++ b/projects/poweredsoft/ngx-bootstrap/src/public-api.ts @@ -3,6 +3,7 @@ */ export * from './lib/command-modal/command-modal.module'; +export * from './lib/command-modal/command-modal.service'; export * from './lib/command-modal/directives/command-modal.directive'; export * from './lib/form-group-command-modal/form-group-command-modal.module'; export * from './lib/form-group-command-modal/directives/form-group-command-modal.directive'; @@ -19,4 +20,4 @@ export * from './lib/data-source-filter/datetime-filter/data-source-datetime-fil export * from './lib/data-source-sorting/data-source-sorting.module'; export * from './lib/data-source-sorting/ds-sorting/data-source-sorting.component'; export * from './lib/command/command.module'; -export * from './lib/command/directives/command.directive'; \ No newline at end of file +export * from './lib/command/directives/command.directive';