Skip to content

Commit

Permalink
Use named parameters in messagebox.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarn committed Nov 8, 2022
1 parent 7d7d1c7 commit 07f37c1
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ export class WidgetContainerComponent implements OnInit {
const title = this.translateService.instant('Settings');
const acceptButtonLabel = this.translateService.instant('Save');
const cancelButtonLabel = this.translateService.instant('Cancel');
const messageBox = this.messageBoxService.show(undefined, title,
undefined,
undefined,
acceptButtonLabel, cancelButtonLabel,
false, false, false,
this.widgetConfigComponent, this.widget.config);
const messageBox = this.messageBoxService.show({
title:title,
acceptButtonLabel:acceptButtonLabel,
cancelButtonLabel:cancelButtonLabel,
visible:false,
injectedComponentType:this.widgetConfigComponent,
injectComponentData:this.widget.config,
});

messageBox.accepted = () => {
this.dashboardConfigService.changeWidgetConfig(this.widget.id, messageBox.injectedComponentInstance?.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ export class TabService {
const acceptButtonLabel = this.translateService.instant('OK');
const cancelButtonLabel = this.translateService.instant('Cancel');

const messageBox = this.messageBoxService.show(undefined, undefined, messageBoxTitle,
'', acceptButtonLabel, cancelButtonLabel);
const messageBox = this.messageBoxService.show({
promptText:messageBoxTitle,
acceptButtonLabel:acceptButtonLabel,
cancelButtonLabel:cancelButtonLabel
});

messageBox.accepted = () => {
if (messageBox.value) {
Expand All @@ -63,8 +66,12 @@ export class TabService {
const acceptButtonLabel = this.translateService.instant('OK');
const cancelButtonLabel = this.translateService.instant('Cancel');

const messageBox = this.messageBoxService.show(undefined, undefined, promptTitle,
promptInitialValue, acceptButtonLabel, cancelButtonLabel);
const messageBox = this.messageBoxService.show({
promptText:promptTitle,
promptInitialValue:promptInitialValue,
acceptButtonLabel:acceptButtonLabel,
cancelButtonLabel:cancelButtonLabel,
});

messageBox.accepted = () => {
if (messageBox.value) {
Expand All @@ -82,7 +89,11 @@ export class TabService {
const messageboxTitle = this.translateService.instant('Remove the \'' + this.activeTabName + '\' tab?');
const positiveButtonTitle = this.translateService.instant('Remove');
const negativeButtonTitle = this.translateService.instant('Cancel');
const messageBox = this.messageBoxService.show(messageboxTitle, undefined, undefined, undefined, positiveButtonTitle, negativeButtonTitle);
const messageBox = this.messageBoxService.show({
title:messageboxTitle,
acceptButtonLabel:positiveButtonTitle,
cancelButtonLabel:negativeButtonTitle
});
messageBox.accepted = () => {
this.setActiveTab(this._tabs[0].name);
this.dashboardConfigService.removeTab(indexTabToDelete);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Type } from '@angular/core';

export interface MessageBoxParams {
text: string;
title: string;
promptText: string;
promptInitialValue: string;
acceptButtonLabel: string;
cancelButtonLabel: string;
visible: boolean;
scrollable: boolean;
progress: boolean;
injectedComponentType: Type<any>;
injectComponentData: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { BehaviorSubject, Observable } from 'rxjs';
import { MessageBox } from './message-box.model';
import { Injectable, Type } from '@angular/core';
import { MessageBoxParams } from './message-box-params.interface';

@Injectable({
providedIn: 'platform',
Expand Down Expand Up @@ -40,14 +41,34 @@ export class MessageBoxService {
*
* @returns The shown message box object.
*/
public show(
text: string = '', title: string = '', promptText: string = '', promptInitialValue: string = '',
acceptButtonLabel: string = '', cancelButtonLabel: string = '', visible: boolean = false,
scrollable: boolean = false, progress: boolean = false, injectedComponentType?: Type<any>, injectComponentData?: any,
): MessageBox {
public show(params: Partial<MessageBoxParams> ): MessageBox {
const defaultValues = {
text: '',
title: '',
promptText: '',
promptInitialValue: '',
acceptButtonLabel: '',
cancelButtonLabel: '',
visible: true,
scrollable: false,
progress: false,
injectedComponentType: undefined,
injectComponentData: '',
};
const options = {...defaultValues, ...params};
const messageBox = new MessageBox(
this.close, text, promptText, promptInitialValue, acceptButtonLabel,
cancelButtonLabel, true, scrollable, progress, title, injectedComponentType, injectComponentData,
this.close,
options.text,
options.promptText,
options.promptInitialValue,
options.acceptButtonLabel,
options.cancelButtonLabel,
options.visible,
options.scrollable,
options.progress,
options.title,
options.injectedComponentType,
options.injectComponentData,
);

const messageBoxes = this._messageBoxes.value;
Expand All @@ -66,7 +87,7 @@ export class MessageBoxService {
* @returns The shown message box object.
*/
public prompt(label: string, initialValue: string = ''): MessageBox {
return this.show('', label, initialValue, 'OK', 'Cancel');
return this.show({title: label, promptInitialValue:initialValue, acceptButtonLabel: 'OK', cancelButtonLabel: 'Cancel'});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ export class RestartService {
};

public restart(): void {
const messageBox = this.mbs.show("Restart the panel ?", "Restart ?", undefined,undefined, "Yes", "No");
const messageBox = this.mbs.show({text:"Restart the panel ?", title:"Restart ?", acceptButtonLabel: "Yes", cancelButtonLabel: "No"});

messageBox.accepted = () => {
this.forceRestart();
};
};

private async forceRestart(): Promise<void> {
let msg = this.mbs.show('', "Restarting...", '', '', '', '', false, false, true);
let msg = this.mbs.show({title:"Restarting...", visible: false, progress: true});
await this.httpClient.post('/api/core/restart-master', '').subscribe((value) => {
setTimeout(() => {
msg.close()
this.mbs.show('', "Restarted !");
this.mbs.show({title:"Restarted !"});
this.pageReload();
setTimeout(() => {
this.pageReload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export class UnauthenticatedInterceptor implements HttpInterceptor {
const closeButtonText = this.translateService.instant('Close');
const injectedComponentData = error;

this.messageBoxService.show('', messageBoxTitle,
undefined,
undefined,
undefined, closeButtonText,
false, false, false,
ServerErrorMessageComponent, injectedComponentData);
this.messageBoxService.show({
title:messageBoxTitle,
cancelButtonLabel: closeButtonText,
visible:false,
injectedComponentType:ServerErrorMessageComponent,
injectComponentData:injectedComponentData});
}

private handleExpiredSession(error: any): void {
Expand Down

0 comments on commit 07f37c1

Please sign in to comment.