diff --git a/.gitignore b/.gitignore index a0c75b4c49..0866aee1de 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ bundles workspace.xml .idea/ .env.* +.env dist/ e2e/.env.cloud tmp diff --git a/lib/core/notifications/components/notification-history.component.html b/lib/core/notifications/components/notification-history.component.html index 3ba9cbda4d..b8388b66dd 100644 --- a/lib/core/notifications/components/notification-history.component.html +++ b/lib/core/notifications/components/notification-history.component.html @@ -16,9 +16,10 @@ - {{notification.info ? notification.info: 'info'}} + {{ notification | noticicationIcon }}

{{ message }}

{{notification.datetime | date}}

+

{{notification.initiator.displayName | translate}}

{{ 'NOTIFICATIONS.NO_MESSAGE' | translate }}

diff --git a/lib/core/notifications/components/notification-history.component.ts b/lib/core/notifications/components/notification-history.component.ts index e41b7ffb12..a8ba17cacd 100644 --- a/lib/core/notifications/components/notification-history.component.ts +++ b/lib/core/notifications/components/notification-history.component.ts @@ -17,7 +17,7 @@ import { Component, Input, ViewChild, OnDestroy } from '@angular/core'; import { NotificationService } from '../services/notification.service'; -import { Notification } from '../models/notification.model'; +import { NotificationModel } from '../models/notification.model'; import { MatMenuTrigger } from '@angular/material'; import { takeUntil } from 'rxjs/operators'; import { Subject } from 'rxjs'; @@ -31,7 +31,7 @@ export class NotificationHistoryComponent implements OnDestroy { onDestroy$ = new Subject(); - notifications: Notification[] = []; + notifications: NotificationModel[] = []; @ViewChild(MatMenuTrigger) trigger: MatMenuTrigger; diff --git a/lib/core/notifications/helpers/notification.factory.ts b/lib/core/notifications/helpers/notification.factory.ts index 39545cec9a..b8b08bd7a6 100644 --- a/lib/core/notifications/helpers/notification.factory.ts +++ b/lib/core/notifications/helpers/notification.factory.ts @@ -18,7 +18,7 @@ import { NotificationInitiator, NOTIFICATION_TYPE, - Notification + NotificationModel } from '../models/notification.model'; export const rootInitiator: NotificationInitiator = { @@ -26,7 +26,7 @@ export const rootInitiator: NotificationInitiator = { displayName: 'NOTIFICATIONS.SYSTEM' }; -export function info(messages: string | string[], initiator: NotificationInitiator = rootInitiator): Notification { +export function info(messages: string | string[], initiator: NotificationInitiator = rootInitiator): NotificationModel { return { type: NOTIFICATION_TYPE.INFO, datetime: new Date(), @@ -35,7 +35,7 @@ export function info(messages: string | string[], initiator: NotificationInitiat }; } -export function warning(messages: string | string[], initiator: NotificationInitiator = rootInitiator): Notification { +export function warning(messages: string | string[], initiator: NotificationInitiator = rootInitiator): NotificationModel { return { type: NOTIFICATION_TYPE.WARN, datetime: new Date(), @@ -44,7 +44,7 @@ export function warning(messages: string | string[], initiator: NotificationInit }; } -export function error(messages: string | string[], initiator: NotificationInitiator = rootInitiator): Notification { +export function error(messages: string | string[], initiator: NotificationInitiator = rootInitiator): NotificationModel { return { type: NOTIFICATION_TYPE.ERROR, datetime: new Date(), diff --git a/lib/core/notifications/models/notification.model.ts b/lib/core/notifications/models/notification.model.ts index b7cb44dcf6..012c495196 100644 --- a/lib/core/notifications/models/notification.model.ts +++ b/lib/core/notifications/models/notification.model.ts @@ -27,7 +27,7 @@ export interface NotificationInitiator { extra?: any; } -export interface Notification { +export interface NotificationModel { type: NOTIFICATION_TYPE; initiator: NotificationInitiator; datetime: Date; diff --git a/lib/core/notifications/notification-history.module.ts b/lib/core/notifications/notification-history.module.ts index 1cefa36c47..7aa3fb61f6 100644 --- a/lib/core/notifications/notification-history.module.ts +++ b/lib/core/notifications/notification-history.module.ts @@ -21,6 +21,7 @@ import { MaterialModule } from '../material.module'; import { NotificationHistoryComponent } from './components/notification-history.component'; import { TranslateModule } from '@ngx-translate/core'; +import { NotificationIconPipe } from './pipes/notification-icon.pipe'; @NgModule({ imports: [ @@ -29,7 +30,8 @@ import { TranslateModule } from '@ngx-translate/core'; TranslateModule.forChild() ], declarations: [ - NotificationHistoryComponent + NotificationHistoryComponent, + NotificationIconPipe ], exports: [ NotificationHistoryComponent diff --git a/lib/core/notifications/pipes/notification-icon.pipe.ts b/lib/core/notifications/pipes/notification-icon.pipe.ts new file mode 100644 index 0000000000..005c755f0f --- /dev/null +++ b/lib/core/notifications/pipes/notification-icon.pipe.ts @@ -0,0 +1,36 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Pipe, PipeTransform } from '@angular/core'; +import { NotificationModel, NOTIFICATION_TYPE } from '../models/notification.model'; + +@Pipe({ + name: 'noticicationIcon' +}) +export class NotificationIconPipe implements PipeTransform { + + transform(notification: NotificationModel): string { + switch (notification.type) { + case NOTIFICATION_TYPE.ERROR: + return 'error'; + case NOTIFICATION_TYPE.WARN: + return 'warning'; + default: + return 'info'; + } + } +} diff --git a/lib/core/notifications/services/notification.service.ts b/lib/core/notifications/services/notification.service.ts index bbfd7a8731..77be38b91e 100644 --- a/lib/core/notifications/services/notification.service.ts +++ b/lib/core/notifications/services/notification.service.ts @@ -20,7 +20,7 @@ import { MatSnackBar, MatSnackBarRef, MatSnackBarConfig } from '@angular/materia import { TranslationService } from '../../services/translation.service'; import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service'; import { Subject } from 'rxjs'; -import { Notification } from '../models/notification.model'; +import { NotificationModel } from '../models/notification.model'; import { info, warning, error } from '../helpers/notification.factory'; const INFO_SNACK_CLASS = 'adf-info-snackbar'; @@ -34,7 +34,7 @@ export class NotificationService { DEFAULT_DURATION_MESSAGE: number = 5000; - notifications$: Subject = new Subject(); + notifications$: Subject = new Subject(); constructor(private snackBar: MatSnackBar, private translationService: TranslationService, @@ -115,7 +115,10 @@ export class NotificationService { } private getNotificationCreator(config?: number | MatSnackBarConfig) { - const panelClass: string = config && ( config).panelClass && ( config).panelClass[0] || ''; + let panelClass: string = null; + if (typeof config === 'object') { + panelClass = Array.isArray(config.panelClass) ? config.panelClass[0] : config.panelClass; + } switch (panelClass) { case ERROR_SNACK_CLASS: diff --git a/package-lock.json b/package-lock.json index 9aa7d8b119..b98d878b56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6504,7 +6504,7 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -6526,13 +6526,13 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "optional": true, + "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6548,19 +6548,19 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -6678,7 +6678,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -6690,7 +6690,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "optional": true, + "dev": true, "requires": { "number-is-nan": "^1.0.0" } @@ -6705,7 +6705,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "optional": true, + "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -6714,13 +6714,13 @@ "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", - "optional": true, + "dev": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -6739,7 +6739,7 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "optional": true, + "dev": true, "requires": { "minimist": "0.0.8" } @@ -6821,7 +6821,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -6833,7 +6833,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "optional": true, + "dev": true, "requires": { "wrappy": "1" } @@ -6920,7 +6920,7 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -6956,7 +6956,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "optional": true, + "dev": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6976,7 +6976,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "optional": true, + "dev": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7021,13 +7021,13 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "optional": true + "dev": true } } },