Skip to content

Commit

Permalink
added command-modal service
Browse files Browse the repository at this point in the history
fix issue with command modal showing success command error message
publish new version
  • Loading branch information
Mathias Beaulieu-Duncan committed Mar 1, 2023
1 parent 0bf06fd commit d46e97f
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 26 deletions.
6 changes: 3 additions & 3 deletions projects/poweredsoft/ngx-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -15,4 +15,4 @@
"dependencies": {
"tslib": "^1.10.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ 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: [
CommonModule,
ModalModule.forRoot(),
FormsModule
],
providers: [CommandModalService],
declarations: [CommandModalDirective, CommandModalComponent],
exports: [CommandModalDirective]
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TModel>(options: {
dataSource: IDataSource<TModel>
command: string,
model: TModel,
template: TemplateRef<any>,
commandTitle?: string,
refreshOnSuccess?: boolean,
commandText?: string,
cancelText?: string,
animated?: boolean,
btnClass?: string,
modalSize?: string,
disableValidationSummary?: boolean,
backdrop?: boolean,
ignoreBackdropClick?: boolean,
params?: any,
success?: EventEmitter<any>
}) {
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 => {

});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ <h4 class="modal-title pull-left">{{ title }}</h4>
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="100"
aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
</div>

</div>

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class CommandModalComponent implements OnInit, OnDestroy {
validationMessage:string ;
disableValidationSummary: boolean;
btnClass:string;
successEmitter: EventEmitter<any>;
successEmitter: EventEmitter<any>;
hasError: boolean;
errorMessage: string = '';

Expand All @@ -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');
Expand Down Expand Up @@ -82,7 +82,7 @@ export class CommandModalComponent implements OnInit, OnDestroy {
}

attemptSave() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,16 +30,16 @@ export class CommandModalDirective {
@Output() success: EventEmitter<any> = new EventEmitter<any>();

@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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 { }
3 changes: 2 additions & 1 deletion projects/poweredsoft/ngx-bootstrap/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
export * from './lib/command/directives/command.directive';

0 comments on commit d46e97f

Please sign in to comment.