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/clipboard/clipboard.service.spec.ts b/lib/core/clipboard/clipboard.service.spec.ts index 3760b5f7c9..6d07a4d6fd 100644 --- a/lib/core/clipboard/clipboard.service.spec.ts +++ b/lib/core/clipboard/clipboard.service.spec.ts @@ -16,7 +16,7 @@ */ import { LogService } from '../services/log.service'; -import { NotificationService } from '../services/notification.service'; +import { NotificationService } from '../notifications/services/notification.service'; import { AppConfigService } from '../app-config/app-config.service'; import { TestBed } from '@angular/core/testing'; import { ClipboardModule } from './clipboard.module'; diff --git a/lib/core/clipboard/clipboard.service.ts b/lib/core/clipboard/clipboard.service.ts index a265340e70..32eb064a19 100644 --- a/lib/core/clipboard/clipboard.service.ts +++ b/lib/core/clipboard/clipboard.service.ts @@ -18,7 +18,7 @@ import { Injectable, Inject } from '@angular/core'; import { DOCUMENT } from '@angular/platform-browser'; import { LogService } from '../services/log.service'; -import { NotificationService } from '../services/notification.service'; +import { NotificationService } from '../notifications/services/notification.service'; @Injectable() export class ClipboardService { diff --git a/lib/core/core.module.ts b/lib/core/core.module.ts index d724a1bf14..042b8a247f 100644 --- a/lib/core/core.module.ts +++ b/lib/core/core.module.ts @@ -41,7 +41,7 @@ import { CommentsModule } from './comments/comments.module'; import { ButtonsMenuModule } from './buttons-menu/buttons-menu.module'; import { TemplateModule } from './templates/template.module'; import { ClipboardModule } from './clipboard/clipboard.module'; -import { NotificationHistoryModule } from './notification-history/notification-history.module'; +import { NotificationHistoryModule } from './notifications/notification-history.module'; import { DirectiveModule } from './directives/directive.module'; import { DialogModule } from './dialogs/dialog.module'; diff --git a/lib/core/i18n/ar.json b/lib/core/i18n/ar.json index 3f8909a883..a128a7e963 100755 --- a/lib/core/i18n/ar.json +++ b/lib/core/i18n/ar.json @@ -5,9 +5,9 @@ "CLAIM": "مطالبة", "UNCLAIM": "تحرير", "START PROCESS": "بدء العملية", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "لا توجد رسائل", - "NOTIFICATIONS": "إعلامات", + "TITLE": "إعلامات", "MARK_AS_READ": "وضع علامة على الكل كغير مقروءة" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "انقر للنسخ", "SUCCESS_COPY": "تم نسخ النص إلى الحافظة" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/cs.json b/lib/core/i18n/cs.json index 302e800c03..b13639a4b0 100755 --- a/lib/core/i18n/cs.json +++ b/lib/core/i18n/cs.json @@ -5,9 +5,9 @@ "CLAIM": "Převzít", "UNCLAIM": "Vzdát se", "START PROCESS": "Zahájit proces", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Žádné zprávy", - "NOTIFICATIONS": "Upozornění", + "TITLE": "Upozornění", "MARK_AS_READ": "Označit všechny jako přečtené" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Kliknutím zkopírovat", "SUCCESS_COPY": "Text zkopírovaný do schránky" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/da.json b/lib/core/i18n/da.json index 8184745722..7d208db223 100755 --- a/lib/core/i18n/da.json +++ b/lib/core/i18n/da.json @@ -5,9 +5,9 @@ "CLAIM": "Gør krav på", "UNCLAIM": "Frigiv", "START PROCESS": "Start proces", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Ingen meddelelser", - "NOTIFICATIONS": "Meddelelser", + "TITLE": "Meddelelser", "MARK_AS_READ": "Markér alle som læst" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Klik for at kopiere", "SUCCESS_COPY": "Teksten er kopieret til Udklipsholder" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/de.json b/lib/core/i18n/de.json index ac2ec706cd..87932609d6 100755 --- a/lib/core/i18n/de.json +++ b/lib/core/i18n/de.json @@ -5,9 +5,9 @@ "CLAIM": "Beanspruchen", "UNCLAIM": "Anspruch aufheben", "START PROCESS": "Prozess starten", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Keine Nachrichten", - "NOTIFICATIONS": "Benachrichtigungen", + "TITLE": "Benachrichtigungen", "MARK_AS_READ": "Alles als gelesen markieren" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Zum Kopieren klicken", "SUCCESS_COPY": "Text in Zwischenablage kopiert" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/en.json b/lib/core/i18n/en.json index ced58feafb..f92a469376 100644 --- a/lib/core/i18n/en.json +++ b/lib/core/i18n/en.json @@ -5,10 +5,11 @@ "CLAIM": "CLAIM", "UNCLAIM": "RELEASE", "START PROCESS": "START PROCESS", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "No messages", - "NOTIFICATIONS": "Notifications", - "MARK_AS_READ": "Mark all as read" + "TITLE": "Notifications", + "MARK_AS_READ": "Mark all as read", + "SYSTEM": "System" }, "FORM": { "START_FORM": { diff --git a/lib/core/i18n/es.json b/lib/core/i18n/es.json index 1458e5fd84..315b1da060 100755 --- a/lib/core/i18n/es.json +++ b/lib/core/i18n/es.json @@ -5,9 +5,9 @@ "CLAIM": "Pedir", "UNCLAIM": "Liberar", "START PROCESS": "Iniciar proceso", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "No hay mensajes", - "NOTIFICATIONS": "Notificaciones", + "TITLE": "Notificaciones", "MARK_AS_READ": "Marcar todo como leído" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Haga clic para copiar", "SUCCESS_COPY": "Texto copiado al portapapeles" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/fi.json b/lib/core/i18n/fi.json index 7c1d983dae..64f9d2d4eb 100755 --- a/lib/core/i18n/fi.json +++ b/lib/core/i18n/fi.json @@ -5,9 +5,9 @@ "CLAIM": "Varaa", "UNCLAIM": "Vapauta", "START PROCESS": "Käynnistä prosessi", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Ei viestejä", - "NOTIFICATIONS": "Ilmoitukset", + "TITLE": "Ilmoitukset", "MARK_AS_READ": "Merkitse kaikki luetuiksi" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Kopioi napsauttamalla", "SUCCESS_COPY": "Teksti kopioitiin leikepöydälle" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/fr.json b/lib/core/i18n/fr.json index cdf88042a3..f8a92a454e 100755 --- a/lib/core/i18n/fr.json +++ b/lib/core/i18n/fr.json @@ -5,9 +5,9 @@ "CLAIM": "S'attribuer", "UNCLAIM": "Libérer", "START PROCESS": "Démarrer le processus", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Aucun message", - "NOTIFICATIONS": "Notifications", + "TITLE": "Notifications", "MARK_AS_READ": "Marquer tout comme lu" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Cliquer pour copier", "SUCCESS_COPY": "Texte copié dans le presse-papiers" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/it.json b/lib/core/i18n/it.json index 0c17625989..4de2c71fa4 100755 --- a/lib/core/i18n/it.json +++ b/lib/core/i18n/it.json @@ -5,9 +5,9 @@ "CLAIM": "Richiedi", "UNCLAIM": "Restituisci", "START PROCESS": "Avvia processo", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Nessun messaggio", - "NOTIFICATIONS": "Notifiche", + "TITLE": "Notifiche", "MARK_AS_READ": "Seleziona tutti come già letti" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Fare clic per copiare", "SUCCESS_COPY": "Testo copiato negli appunti" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/ja.json b/lib/core/i18n/ja.json index b78fc097ba..47910cc16d 100755 --- a/lib/core/i18n/ja.json +++ b/lib/core/i18n/ja.json @@ -5,9 +5,9 @@ "CLAIM": "担当する", "UNCLAIM": "担当解除", "START PROCESS": "プロセスの開始", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "メッセージなし", - "NOTIFICATIONS": "通知", + "TITLE": "通知", "MARK_AS_READ": "すべて既読にする" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "コピーするにはクリックします", "SUCCESS_COPY": "テキストがクリップボードにコピーされました" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/nb.json b/lib/core/i18n/nb.json index 54d5650066..6784e02dc4 100755 --- a/lib/core/i18n/nb.json +++ b/lib/core/i18n/nb.json @@ -5,9 +5,9 @@ "CLAIM": "Krev", "UNCLAIM": "Frigi", "START PROCESS": "Start prosess", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Ingen meldinger", - "NOTIFICATIONS": "Varsler", + "TITLE": "Varsler", "MARK_AS_READ": "Merk alle som lest" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Klikk for å kopiere", "SUCCESS_COPY": "Tekst kopiert til utklippstavle" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/nl.json b/lib/core/i18n/nl.json index f998496a4e..66733cc60b 100755 --- a/lib/core/i18n/nl.json +++ b/lib/core/i18n/nl.json @@ -5,9 +5,9 @@ "CLAIM": "Claimen", "UNCLAIM": "Vrijgeven", "START PROCESS": "Proces starten", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Geen berichten", - "NOTIFICATIONS": "Meldingen", + "TITLE": "Meldingen", "MARK_AS_READ": "Alles markeren als gelezen" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Klik om te kopiëren", "SUCCESS_COPY": "Tekst gekopieerd naar Klembord" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/pl.json b/lib/core/i18n/pl.json index 2a79cc7f25..4325f5ec83 100755 --- a/lib/core/i18n/pl.json +++ b/lib/core/i18n/pl.json @@ -5,9 +5,9 @@ "CLAIM": "Przejmij", "UNCLAIM": "Zwolnij", "START PROCESS": "Rozpocznij proces", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Brak komunikatów", - "NOTIFICATIONS": "Powiadomienia", + "TITLE": "Powiadomienia", "MARK_AS_READ": "Oznacz wszystkie jako przeczytane" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Kliknij, aby skopiować", "SUCCESS_COPY": "Tekst skopiowano do schowka" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/pt-BR.json b/lib/core/i18n/pt-BR.json index ed807b1303..3300d44847 100755 --- a/lib/core/i18n/pt-BR.json +++ b/lib/core/i18n/pt-BR.json @@ -5,9 +5,9 @@ "CLAIM": "Reivindicar", "UNCLAIM": "Liberar", "START PROCESS": "Iniciar processo", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Não há mensagens", - "NOTIFICATIONS": "Notificações", + "TITLE": "Notificações", "MARK_AS_READ": "Marcar todas como lidas" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Clique para copiar", "SUCCESS_COPY": "Texto copiado para a área de transferência" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/ru.json b/lib/core/i18n/ru.json index b81fc63b92..71844f2c92 100755 --- a/lib/core/i18n/ru.json +++ b/lib/core/i18n/ru.json @@ -5,9 +5,9 @@ "CLAIM": "Принять", "UNCLAIM": "Освободить", "START PROCESS": "Начать процесс", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Нет сообщений", - "NOTIFICATIONS": "Оповещения", + "TITLE": "Оповещения", "MARK_AS_READ": "Отметить все как прочитанное" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Нажмите, чтобы скопировать", "SUCCESS_COPY": "Текст скопирован в буфер обмена" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/sv.json b/lib/core/i18n/sv.json index f03ef0233f..4aa6b22e55 100755 --- a/lib/core/i18n/sv.json +++ b/lib/core/i18n/sv.json @@ -5,9 +5,9 @@ "CLAIM": "Anta", "UNCLAIM": "Avsäga", "START PROCESS": "Starta process", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "Inga meddelanden", - "NOTIFICATIONS": "Aviseringar", + "TITLE": "Aviseringar", "MARK_AS_READ": "Markera allt som läst" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "Klicka för att kopiera", "SUCCESS_COPY": "Texten har kopierats till urklipp" } -} \ No newline at end of file +} diff --git a/lib/core/i18n/zh-CN.json b/lib/core/i18n/zh-CN.json index 772b801965..fc0d9cffe7 100755 --- a/lib/core/i18n/zh-CN.json +++ b/lib/core/i18n/zh-CN.json @@ -5,9 +5,9 @@ "CLAIM": "申领", "UNCLAIM": "释放", "START PROCESS": "启动流程", - "NOTIFICATION_HISTORY": { + "NOTIFICATIONS": { "NO_MESSAGE": "无消息", - "NOTIFICATIONS": "通知", + "TITLE": "通知", "MARK_AS_READ": "全部标记为已读" }, "FORM": { @@ -480,4 +480,4 @@ "CLICK_TO_COPY": "单击以复制", "SUCCESS_COPY": "复制到剪贴板上的文本" } -} \ No newline at end of file +} diff --git a/lib/core/index.ts b/lib/core/index.ts index 7411e7597f..a78bb5c00b 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -41,7 +41,7 @@ export * from './directives/index'; export * from './clipboard/index'; export * from './dialogs/index'; export * from './icon/index'; -export * from './notification-history/index'; +export * from './notifications/index'; export * from './utils/index'; export * from './interface/index'; diff --git a/lib/core/models/public-api.ts b/lib/core/models/public-api.ts index 8df9e6af25..e79a97fa5d 100644 --- a/lib/core/models/public-api.ts +++ b/lib/core/models/public-api.ts @@ -26,5 +26,4 @@ export * from './redirection.model'; export * from './pagination.model'; export * from './oauth-config.model'; export * from './request-pagination.model'; -export * from './notification.model'; export * from './decimal-number.model'; diff --git a/lib/core/notification-history/notification-history.component.html b/lib/core/notifications/components/notification-history.component.html similarity index 68% rename from lib/core/notification-history/notification-history.component.html rename to lib/core/notifications/components/notification-history.component.html index 00fe54a17c..b8388b66dd 100644 --- a/lib/core/notification-history/notification-history.component.html +++ b/lib/core/notifications/components/notification-history.component.html @@ -9,22 +9,23 @@
-
{{ 'NOTIFICATION_HISTORY.NOTIFICATIONS' | translate }}
+
{{ 'NOTIFICATIONS.TITLE' | translate }}
- {{notification.info? notification.info: 'info'}} -

{{notification.message}}

-

{{notification.dateTime | date}}

+ {{ notification | noticicationIcon }} +

{{ message }}

+

{{notification.datetime | date}}

+

{{notification.initiator.displayName | translate}}

-

{{ 'NOTIFICATION_HISTORY.NO_MESSAGE' | translate }}

+

{{ 'NOTIFICATIONS.NO_MESSAGE' | translate }}

-
diff --git a/lib/core/notification-history/notification-history.component.scss b/lib/core/notifications/components/notification-history.component.scss similarity index 100% rename from lib/core/notification-history/notification-history.component.scss rename to lib/core/notifications/components/notification-history.component.scss diff --git a/lib/core/notification-history/notification-history.component.spec.ts b/lib/core/notifications/components/notification-history.component.spec.ts similarity index 93% rename from lib/core/notification-history/notification-history.component.spec.ts rename to lib/core/notifications/components/notification-history.component.spec.ts index 18e3e8b534..33d27dc046 100644 --- a/lib/core/notification-history/notification-history.component.spec.ts +++ b/lib/core/notifications/components/notification-history.component.spec.ts @@ -16,11 +16,11 @@ */ import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing'; -import { NotificationService } from '../services'; -import { setupTestBed } from '../testing/setupTestBed'; -import { CoreTestingModule } from '../testing/core.testing.module'; +import { setupTestBed } from '../../testing/setupTestBed'; +import { CoreTestingModule } from '../../testing/core.testing.module'; import { NotificationHistoryComponent } from './notification-history.component'; import { OverlayContainer } from '@angular/cdk/overlay'; +import { NotificationService } from '../services/notification.service'; describe('Notification History Component', () => { diff --git a/lib/core/notification-history/notification-history.component.ts b/lib/core/notifications/components/notification-history.component.ts similarity index 97% rename from lib/core/notification-history/notification-history.component.ts rename to lib/core/notifications/components/notification-history.component.ts index 120337a8ff..a8ba17cacd 100644 --- a/lib/core/notification-history/notification-history.component.ts +++ b/lib/core/notifications/components/notification-history.component.ts @@ -46,7 +46,7 @@ export class NotificationHistoryComponent implements OnDestroy { constructor( private notificationService: NotificationService) { - this.notificationService.messages + this.notificationService.notifications$ .pipe(takeUntil(this.onDestroy$)) .subscribe((message) => { this.notifications.push(message); diff --git a/lib/core/notifications/helpers/notification.factory.ts b/lib/core/notifications/helpers/notification.factory.ts new file mode 100644 index 0000000000..b8b08bd7a6 --- /dev/null +++ b/lib/core/notifications/helpers/notification.factory.ts @@ -0,0 +1,54 @@ +/*! + * @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 { + NotificationInitiator, + NOTIFICATION_TYPE, + NotificationModel +} from '../models/notification.model'; + +export const rootInitiator: NotificationInitiator = { + key: '*', + displayName: 'NOTIFICATIONS.SYSTEM' +}; + +export function info(messages: string | string[], initiator: NotificationInitiator = rootInitiator): NotificationModel { + return { + type: NOTIFICATION_TYPE.INFO, + datetime: new Date(), + initiator, + messages: [].concat(messages) + }; +} + +export function warning(messages: string | string[], initiator: NotificationInitiator = rootInitiator): NotificationModel { + return { + type: NOTIFICATION_TYPE.WARN, + datetime: new Date(), + initiator, + messages: [].concat(messages) + }; +} + +export function error(messages: string | string[], initiator: NotificationInitiator = rootInitiator): NotificationModel { + return { + type: NOTIFICATION_TYPE.ERROR, + datetime: new Date(), + initiator, + messages: [].concat(messages) + }; +} diff --git a/lib/core/notification-history/index.ts b/lib/core/notifications/index.ts similarity index 100% rename from lib/core/notification-history/index.ts rename to lib/core/notifications/index.ts diff --git a/lib/core/models/notification.model.ts b/lib/core/notifications/models/notification.model.ts similarity index 67% rename from lib/core/models/notification.model.ts rename to lib/core/notifications/models/notification.model.ts index 973d71e9ba..012c495196 100644 --- a/lib/core/models/notification.model.ts +++ b/lib/core/notifications/models/notification.model.ts @@ -15,7 +15,21 @@ * limitations under the License. */ -export interface NotificationModel { - dateTime: Date; - message: string; +export enum NOTIFICATION_TYPE { + INFO = 'info', + WARN = 'warning', + ERROR = 'error' +} + +export interface NotificationInitiator { + key: string | Symbol; + displayName: string; + extra?: any; +} + +export interface NotificationModel { + type: NOTIFICATION_TYPE; + initiator: NotificationInitiator; + datetime: Date; + messages: string[]; } diff --git a/lib/core/notification-history/notification-history.module.ts b/lib/core/notifications/notification-history.module.ts similarity index 82% rename from lib/core/notification-history/notification-history.module.ts rename to lib/core/notifications/notification-history.module.ts index 7ff6a537e6..7aa3fb61f6 100644 --- a/lib/core/notification-history/notification-history.module.ts +++ b/lib/core/notifications/notification-history.module.ts @@ -19,8 +19,9 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { MaterialModule } from '../material.module'; -import { NotificationHistoryComponent } from './notification-history.component'; +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/notification-history/public-api.ts b/lib/core/notifications/public-api.ts similarity index 76% rename from lib/core/notification-history/public-api.ts rename to lib/core/notifications/public-api.ts index 887fe4b1c6..4270a04134 100644 --- a/lib/core/notification-history/public-api.ts +++ b/lib/core/notifications/public-api.ts @@ -15,5 +15,8 @@ * limitations under the License. */ -export * from './notification-history.component'; +export * from './components/notification-history.component'; +export * from './helpers/notification.factory'; +export * from './models/notification.model'; +export * from './services/notification.service'; export * from './notification-history.module'; diff --git a/lib/core/services/notification.service.spec.ts b/lib/core/notifications/services/notification.service.spec.ts similarity index 96% rename from lib/core/services/notification.service.spec.ts rename to lib/core/notifications/services/notification.service.spec.ts index f26646baa1..d9664c47ed 100644 --- a/lib/core/services/notification.service.spec.ts +++ b/lib/core/notifications/services/notification.service.spec.ts @@ -23,10 +23,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MatSnackBar, MatSnackBarModule, MatSnackBarConfig } from '@angular/material'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NotificationService } from './notification.service'; -import { TranslationMock } from '../mock/translation.service.mock'; -import { TranslationService } from './translation.service'; +import { TranslationMock } from '../../mock/translation.service.mock'; +import { TranslationService } from '../../services/translation.service'; import { HttpClientModule } from '@angular/common/http'; -import { setupTestBed } from '../testing/setupTestBed'; +import { setupTestBed } from '../../testing/setupTestBed'; @Component({ template: '', diff --git a/lib/core/services/notification.service.ts b/lib/core/notifications/services/notification.service.ts similarity index 50% rename from lib/core/services/notification.service.ts rename to lib/core/notifications/services/notification.service.ts index a8ba26d12c..77be38b91e 100644 --- a/lib/core/services/notification.service.ts +++ b/lib/core/notifications/services/notification.service.ts @@ -17,10 +17,15 @@ import { Injectable } from '@angular/core'; import { MatSnackBar, MatSnackBarRef, MatSnackBarConfig } from '@angular/material'; -import { TranslationService } from './translation.service'; -import { AppConfigService, AppConfigValues } from '../app-config/app-config.service'; +import { TranslationService } from '../../services/translation.service'; +import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service'; import { Subject } from 'rxjs'; import { NotificationModel } from '../models/notification.model'; +import { info, warning, error } from '../helpers/notification.factory'; + +const INFO_SNACK_CLASS = 'adf-info-snackbar'; +const WARN_SNACK_CLASS = 'adf-warning-snackbar'; +const ERROR_SNACK_CLASS = 'adf-error-snackbar'; @Injectable({ providedIn: 'root' @@ -29,40 +34,23 @@ export class NotificationService { DEFAULT_DURATION_MESSAGE: number = 5000; - messages: Subject = new Subject(); + notifications$: Subject = new Subject(); constructor(private snackBar: MatSnackBar, private translationService: TranslationService, private appConfigService: AppConfigService) { this.DEFAULT_DURATION_MESSAGE = this.appConfigService.get(AppConfigValues.NOTIFY_DURATION) || this.DEFAULT_DURATION_MESSAGE; - } /** * 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 + * @param interpolateArgs The interpolation parameters to add for the translation * @returns Information/control object for the SnackBar */ - openSnackMessage(message: string, config?: number | MatSnackBarConfig, translationArgs?: any): MatSnackBarRef { - const translatedMessage = this.translationService.instant(message, translationArgs); - return this.performOpening(translatedMessage, config); - } - - private performOpening(translatedMessage: string, config?: number | MatSnackBarConfig): MatSnackBarRef { - if (!config) { - config = this.DEFAULT_DURATION_MESSAGE; - } - - if (typeof config === 'number') { - config = { - duration: config - }; - } - this.messages.next({ message: translatedMessage, dateTime: new Date }); - - return this.snackBar.open(translatedMessage, null, config); + openSnackMessage(message: string, config?: number | MatSnackBarConfig, interpolateArgs?: any): MatSnackBarRef { + return this.dispatchNotification(message, null, config, interpolateArgs); } /** @@ -70,24 +58,41 @@ export class NotificationService { * @param message The message (or resource key) to show. * @param action Caption for the response button * @param config Time before notification disappears after being shown or MatSnackBarConfig object + * @param interpolateArgs The interpolation parameters to add for the translation * @returns Information/control object for the SnackBar */ - openSnackMessageAction(message: string, action: string, config?: number | MatSnackBarConfig): MatSnackBarRef { - if (!config) { - config = this.DEFAULT_DURATION_MESSAGE; - } + openSnackMessageAction(message: string, action: string, config?: number | MatSnackBarConfig, interpolateArgs?: any): MatSnackBarRef { + return this.dispatchNotification(message, action, config, interpolateArgs); + } - const translatedMessage = this.translationService.instant(message); + /** + * Rase error message + * @param message Text message or translation key for the message. + * @param action Action name + * @param interpolateArgs The interpolation parameters to add for the translation + */ + showError(message: string, action?: string, interpolateArgs?: any): MatSnackBarRef { + return this.dispatchNotification(message, action, { panelClass: ERROR_SNACK_CLASS }, interpolateArgs); + } - if (typeof config === 'number') { - config = { - duration: config - }; - } + /** + * Rase info message + * @param message Text message or translation key for the message. + * @param action Action name + * @param interpolateArgs The interpolation parameters to add for the translation + */ + showInfo(message: string, action?: string, interpolateArgs?: any): MatSnackBarRef { + return this.dispatchNotification(message, action, { panelClass: INFO_SNACK_CLASS }, interpolateArgs); + } - this.messages.next({ message: translatedMessage, dateTime: new Date }); - - return this.snackBar.open(translatedMessage, action, config); + /** + * Rase warning message + * @param message Text message or translation key for the message. + * @param action Action name + * @param interpolateArgs The interpolation parameters to add for the translation + */ + showWarning(message: string, action?: string, interpolateArgs?: any): MatSnackBarRef { + return this.dispatchNotification(message, action, { panelClass: WARN_SNACK_CLASS }, interpolateArgs); } /** @@ -97,44 +102,31 @@ export class NotificationService { return this.snackBar.dismiss(); } - protected showMessage(message: string, panelClass: string, action?: string, interpolateArgs?: any): MatSnackBarRef { - message = this.translationService.instant(message, interpolateArgs); - return this.openMessageBar(message, panelClass, action); + private dispatchNotification(message: string, action?: string, config?: number | MatSnackBarConfig, interpolateArgs?: any): MatSnackBarRef { + const translatedMessage: string = this.translationService.instant(message, interpolateArgs); + const createNotification = this.getNotificationCreator(config); + this.notifications$.next(createNotification(translatedMessage)); + + return this.snackBar.open(translatedMessage, action, { + duration: (typeof config === 'number') ? config : this.DEFAULT_DURATION_MESSAGE, + panelClass: INFO_SNACK_CLASS, + ...( (typeof config === 'object') ? config : {} ) + }); } - private openMessageBar(message: string, panelClass: string, action?: string): MatSnackBarRef { - this.messages.next({ message: message, dateTime: new Date }); + private getNotificationCreator(config?: number | MatSnackBarConfig) { + let panelClass: string = null; + if (typeof config === 'object') { + panelClass = Array.isArray(config.panelClass) ? config.panelClass[0] : config.panelClass; + } - return this.snackBar.open(message, action, { - duration: this.DEFAULT_DURATION_MESSAGE, - panelClass - }); - } - - /** - * Rase error message - * @param message Text message or translation key for the message. - * @param action Action name - */ - showError(message: string, action?: string): MatSnackBarRef { - return this.showMessage(message, 'adf-error-snackbar', action); - } - - /** - * Rase info message - * @param message Text message or translation key for the message. - * @param action Action name - */ - showInfo(message: string, action?: string, interpolateArgs?: any): MatSnackBarRef { - return this.showMessage(message, 'adf-info-snackbar', action, interpolateArgs); - } - - /** - * Rase warning message - * @param message Text message or translation key for the message. - * @param action Action name - */ - showWarning(message: string, action?: string): MatSnackBarRef { - return this.showMessage(message, 'adf-warning-snackbar', action); + switch (panelClass) { + case ERROR_SNACK_CLASS: + return error; + case WARN_SNACK_CLASS: + return warning; + default: + return info; + } } } diff --git a/lib/core/services/public-api.ts b/lib/core/services/public-api.ts index a336846312..423bee6f94 100644 --- a/lib/core/services/public-api.ts +++ b/lib/core/services/public-api.ts @@ -28,7 +28,6 @@ export * from './page-title.service'; export * from './storage.service'; export * from './cookie.service'; export * from './renditions.service'; -export * from './notification.service'; export * from './log.service'; export * from './translation.service'; export * from './translate-loader.service'; diff --git a/package-lock.json b/package-lock.json index 9aa7d8b119..72be33b630 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "alfresco-ng2-components", - "version": "3.4.0", + "version": "3.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@alfresco/adf-cli": { - "version": "3.5.0-7ebd28772876fa4144c347fd4fca956a27bce493", - "resolved": "https://registry.npmjs.org/@alfresco/adf-cli/-/adf-cli-3.5.0-7ebd28772876fa4144c347fd4fca956a27bce493.tgz", - "integrity": "sha512-FdIvMKQ9DleFXV1g+w6dKgWg6h4mB1a44bJtxL0l/fJy4Cdsf/1IQQ2BRDl3X3dPmTOVV26Q1pAlhF08KySzKQ==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-cli/-/adf-cli-3.5.0.tgz", + "integrity": "sha512-qHkuhb2WRzhdU7fsRfTuhWwjl0yRoaXV0XEzcBzQ+8FDIcUzkUc/cT5TzJQrkhKkJtfpV4MQEYhhXWCoXqGlVA==", "requires": { "@angular-devkit/core": "^7.2.15", "commander": "^2.15.1", @@ -20,65 +20,65 @@ } }, "@alfresco/adf-content-services": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-content-services/-/adf-content-services-3.4.0.tgz", - "integrity": "sha512-4VdB2GkWwKahOGr1jDQ3n3kaA3RFMYrIWRIdv+MU3Mx9XUPCrj/f6X0Um8qf1Wp110hDxhbSXd4PZtCqwBd1dQ==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-content-services/-/adf-content-services-3.5.0.tgz", + "integrity": "sha512-fdw6AJyujOP/XHzVeLRnH09IMfGRFiCKFfAPxt71jhq0fj4eywlIq/OwibvXNQ2jQfWBom7tt8WHKx5uq3nHZQ==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/adf-core": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-core/-/adf-core-3.4.0.tgz", - "integrity": "sha512-1TwJ9ELFTBxOKU8rKy1MDMviAHDmtexV2Q1Eo9f5JmEPRGwps2aO0R5JrdvBAf8HGpNcOp3NvJlBnVI5gjGA9Q==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-core/-/adf-core-3.5.0.tgz", + "integrity": "sha512-uUD4hwTo2H7PTVSgo8bsp6X49dKQY5EPOh0B79bW4bTma6naoKoAGJ6wlpDBmxcG9CJNzBmmKu1pIwWhdmO71Q==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/adf-extensions": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-extensions/-/adf-extensions-3.4.0.tgz", - "integrity": "sha512-nxSgwOYBn7Q3c+4Tt7J8lAw32tTWUjUOO/suYJDdaPFRG7GB2G7Ulv2gb2105gPnGDDWPUCx3qvfGRbPWjPB/A==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-extensions/-/adf-extensions-3.5.0.tgz", + "integrity": "sha512-SbQ3+bXLZ1J+KJafcdttenJ/fe4EuqTzsb24C1Tkt4vDyHp48f0PdQL0Lq0FnMxQyErsrLijCIIlRsiWOIy24A==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/adf-insights": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-insights/-/adf-insights-3.4.0.tgz", - "integrity": "sha512-skCVL80nC1uyTsjIWNwHktj0zHNLKcM1rPiqWfygW6zZwTjVpI5/XGPR7Yespr96v0qq19p1KOSwLWQ86NfL0g==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-insights/-/adf-insights-3.5.0.tgz", + "integrity": "sha512-u1XtaFxcaC4GBR9sJ/Tt3g/Zy6Hmg3mlq4uabqYMmHe13hmtnyQ0EZZkafpn7MD7yJ+uHejUNPuFD7brRuVxVg==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/adf-process-services": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-process-services/-/adf-process-services-3.4.0.tgz", - "integrity": "sha512-KD9/55QuVdoa7jZZuMPaPfQVPRFKb+3X5QAjkEb1j0+7+1tT1TNJzMxMbdCz4Z4GiFscMNUN3v8GzG4pToSxCA==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-process-services/-/adf-process-services-3.5.0.tgz", + "integrity": "sha512-7QpVUlIDhOrX7/mTeMPNQmkUBOUSvtcKouvyVw8d9R4Huuxr7Kg7xTzdfvfNW3zRN+LYPTzDW9cBepf1Z4ywyA==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/adf-process-services-cloud": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-process-services-cloud/-/adf-process-services-cloud-3.4.0.tgz", - "integrity": "sha512-pIEVNnr0muHIHPUxoP5TMgbOhojR6BaY/uA0t5hSB8tAkh6s7nM3/WUTVQCUcJWalb6xmSS1XYTrMgOvDVDH6g==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-process-services-cloud/-/adf-process-services-cloud-3.5.0.tgz", + "integrity": "sha512-+2uSBkOip12vROQBe6KXQLxB2dgJzSi5mkvVf5z9Ubn3adFwYa8JI2Bdr5EUz0cQU9t+kjdqjEe7u6+Oo4g4YQ==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/adf-testing": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/@alfresco/adf-testing/-/adf-testing-3.4.0.tgz", - "integrity": "sha512-JKKq/yo2zA7x+KjcW+4tL91WLrvizvvywPyA8AyVu93SiWbuR9LUfg6DfrIhcI7ijM60SKx60PQT9gTA+ypETw==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/adf-testing/-/adf-testing-3.5.0.tgz", + "integrity": "sha512-eYGtcalnWCzxpv98kVN9rkQUWAB0Iglux43AwQXSiHRJnA4yWeuIS3UuaXL/grSuRyj+6H+1M8fMJZfKyXjDhQ==", "requires": { "tslib": "^1.9.0" } }, "@alfresco/js-api": { - "version": "3.5.0-00a7b1b556070818a4c689ae63aa21e0b6e26f9f", - "resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-3.5.0-00a7b1b556070818a4c689ae63aa21e0b6e26f9f.tgz", - "integrity": "sha512-JIWAMO+mmJkMjdtL4w5wqvsMNGSyJlMCJuDdR7fBH6tQJqMEmYeHwU7OQZxsM0Ev4IrnlefNx/Hxf6P7I1JsAQ==", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@alfresco/js-api/-/js-api-3.5.0.tgz", + "integrity": "sha512-LdbVDAR9AA5vwHHLHsp+v00D0XR82+myLR4JxRHIe/+KaP2DSIcZbmgqzIn0LH+tQgq3KSVcxSOZkVivB0TxOQ==", "requires": { "event-emitter": "0.3.4", "minimatch": "3.0.4",