mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4811] - added extra method to open snackbar with interpolate arg… (#4989)
* [ADF-4811] - added extra method to open snackbar with interpolate args for translated messages * [ADF-4811] - added extra parameter to show info * [ADF-4811] - added extra parameter to show info * [ADF-4811] added review changes
This commit is contained in:
@@ -21,6 +21,7 @@ Shows a notification message with optional feedback.
|
||||
Opens a SnackBar notification to show a message.
|
||||
- _message:_ `string` - The message (or resource key) to show.
|
||||
- _config:_ `number|MatSnackBarConfig` - (Optional) Time before notification disappears after being shown or MatSnackBarConfig object
|
||||
- translationArgs: `any` - The object with the keys for the interpolation of your translation string
|
||||
- **Returns** [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>` - Information/control object for the SnackBar
|
||||
- **openSnackMessageAction**(message: `string`, action: `string`, config?: `number|MatSnackBarConfig`): [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>`<br/>
|
||||
Opens a SnackBar notification with a message and a response button.
|
||||
|
@@ -45,6 +45,10 @@ class ProvidesNotificationServiceComponent {
|
||||
return this.notificationService.openSnackMessage('Test notification', 1000);
|
||||
}
|
||||
|
||||
sendMessageWithArgs() {
|
||||
return this.notificationService.openSnackMessage('Test notification {{ arg }}', 1000, {arg: 'arg'});
|
||||
}
|
||||
|
||||
sendCustomMessage() {
|
||||
const matSnackBarConfig = new MatSnackBarConfig();
|
||||
matSnackBarConfig.duration = 1000;
|
||||
@@ -108,6 +112,18 @@ describe('NotificationService', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should translate messages with args', (done) => {
|
||||
spyOn(translationService, 'instant').and.callThrough();
|
||||
|
||||
const promise = fixture.componentInstance.sendMessageWithArgs();
|
||||
promise.afterDismissed().subscribe(() => {
|
||||
expect(translationService.instant).toHaveBeenCalledWith('Test notification {{ arg }}', {arg: 'arg'});
|
||||
done();
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should open a message notification bar', (done) => {
|
||||
const promise = fixture.componentInstance.sendMessage();
|
||||
promise.afterDismissed().subscribe(() => {
|
||||
|
@@ -41,22 +41,25 @@ export class NotificationService {
|
||||
/**
|
||||
* Opens a SnackBar notification to show a message.
|
||||
* @param message The message (or resource key) to show.
|
||||
* @param translationArgs The interpolation parameters to add for the translation
|
||||
* @param config Time before notification disappears after being shown or MatSnackBarConfig object
|
||||
* @returns Information/control object for the SnackBar
|
||||
*/
|
||||
openSnackMessage(message: string, config?: number | MatSnackBarConfig): MatSnackBarRef<any> {
|
||||
openSnackMessage(message: string, config?: number | MatSnackBarConfig, translationArgs?: any): MatSnackBarRef<any> {
|
||||
const translatedMessage = this.translationService.instant(message, translationArgs);
|
||||
return this.performOpening(translatedMessage, config);
|
||||
}
|
||||
|
||||
private performOpening(translatedMessage: string, config?: number | MatSnackBarConfig): MatSnackBarRef<any> {
|
||||
if (!config) {
|
||||
config = this.DEFAULT_DURATION_MESSAGE;
|
||||
}
|
||||
|
||||
const translatedMessage = this.translationService.instant(message);
|
||||
|
||||
if (typeof config === 'number') {
|
||||
config = {
|
||||
duration: config
|
||||
};
|
||||
}
|
||||
|
||||
this.messages.next({ message: translatedMessage, dateTime: new Date });
|
||||
|
||||
return this.snackBar.open(translatedMessage, null, config);
|
||||
@@ -94,9 +97,12 @@ export class NotificationService {
|
||||
return this.snackBar.dismiss();
|
||||
}
|
||||
|
||||
protected showMessage(message: string, panelClass: string, action?: string): MatSnackBarRef<any> {
|
||||
message = this.translationService.instant(message);
|
||||
protected showMessage(message: string, panelClass: string, action?: string, interpolateArgs?: any): MatSnackBarRef<any> {
|
||||
message = this.translationService.instant(message, interpolateArgs);
|
||||
return this.openMessageBar(message, panelClass, action);
|
||||
}
|
||||
|
||||
private openMessageBar(message: string, panelClass: string, action?: string): MatSnackBarRef<any> {
|
||||
this.messages.next({ message: message, dateTime: new Date });
|
||||
|
||||
return this.snackBar.open(message, action, {
|
||||
@@ -119,8 +125,8 @@ export class NotificationService {
|
||||
* @param message Text message or translation key for the message.
|
||||
* @param action Action name
|
||||
*/
|
||||
showInfo(message: string, action?: string): MatSnackBarRef<any> {
|
||||
return this.showMessage(message, 'adf-info-snackbar', action);
|
||||
showInfo(message: string, action?: string, interpolateArgs?: any): MatSnackBarRef<any> {
|
||||
return this.showMessage(message, 'adf-info-snackbar', action, interpolateArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user