[ADF-4896] Merging AMA and ADF notifications for a better world

This commit is contained in:
Andras Popovics
2019-09-17 14:33:35 +01:00
committed by Denys Vuika
parent 922a85935e
commit 14800ce399
35 changed files with 276 additions and 217 deletions

View File

@@ -16,7 +16,7 @@
*/ */
import { LogService } from '../services/log.service'; 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 { AppConfigService } from '../app-config/app-config.service';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { ClipboardModule } from './clipboard.module'; import { ClipboardModule } from './clipboard.module';

View File

@@ -18,7 +18,7 @@
import { Injectable, Inject } from '@angular/core'; import { Injectable, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser'; import { DOCUMENT } from '@angular/platform-browser';
import { LogService } from '../services/log.service'; import { LogService } from '../services/log.service';
import { NotificationService } from '../services/notification.service'; import { NotificationService } from '../notifications/services/notification.service';
@Injectable() @Injectable()
export class ClipboardService { export class ClipboardService {

View File

@@ -41,7 +41,7 @@ import { CommentsModule } from './comments/comments.module';
import { ButtonsMenuModule } from './buttons-menu/buttons-menu.module'; import { ButtonsMenuModule } from './buttons-menu/buttons-menu.module';
import { TemplateModule } from './templates/template.module'; import { TemplateModule } from './templates/template.module';
import { ClipboardModule } from './clipboard/clipboard.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 { DirectiveModule } from './directives/directive.module';
import { DialogModule } from './dialogs/dialog.module'; import { DialogModule } from './dialogs/dialog.module';

View File

@@ -5,9 +5,9 @@
"CLAIM": "مطالبة", "CLAIM": "مطالبة",
"UNCLAIM": "تحرير", "UNCLAIM": "تحرير",
"START PROCESS": "بدء العملية", "START PROCESS": "بدء العملية",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "لا توجد رسائل", "NO_MESSAGE": "لا توجد رسائل",
"NOTIFICATIONS": "إعلامات", "TITLE": "إعلامات",
"MARK_AS_READ": "وضع علامة على الكل كغير مقروءة" "MARK_AS_READ": "وضع علامة على الكل كغير مقروءة"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "انقر للنسخ", "CLICK_TO_COPY": "انقر للنسخ",
"SUCCESS_COPY": "تم نسخ النص إلى الحافظة" "SUCCESS_COPY": "تم نسخ النص إلى الحافظة"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Převzít", "CLAIM": "Převzít",
"UNCLAIM": "Vzdát se", "UNCLAIM": "Vzdát se",
"START PROCESS": "Zahájit proces", "START PROCESS": "Zahájit proces",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Žádné zprávy", "NO_MESSAGE": "Žádné zprávy",
"NOTIFICATIONS": "Upozornění", "TITLE": "Upozornění",
"MARK_AS_READ": "Označit všechny jako přečtené" "MARK_AS_READ": "Označit všechny jako přečtené"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Kliknutím zkopírovat", "CLICK_TO_COPY": "Kliknutím zkopírovat",
"SUCCESS_COPY": "Text zkopírovaný do schránky" "SUCCESS_COPY": "Text zkopírovaný do schránky"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Gør krav på", "CLAIM": "Gør krav på",
"UNCLAIM": "Frigiv", "UNCLAIM": "Frigiv",
"START PROCESS": "Start proces", "START PROCESS": "Start proces",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Ingen meddelelser", "NO_MESSAGE": "Ingen meddelelser",
"NOTIFICATIONS": "Meddelelser", "TITLE": "Meddelelser",
"MARK_AS_READ": "Markér alle som læst" "MARK_AS_READ": "Markér alle som læst"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Klik for at kopiere", "CLICK_TO_COPY": "Klik for at kopiere",
"SUCCESS_COPY": "Teksten er kopieret til Udklipsholder" "SUCCESS_COPY": "Teksten er kopieret til Udklipsholder"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Beanspruchen", "CLAIM": "Beanspruchen",
"UNCLAIM": "Anspruch aufheben", "UNCLAIM": "Anspruch aufheben",
"START PROCESS": "Prozess starten", "START PROCESS": "Prozess starten",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Keine Nachrichten", "NO_MESSAGE": "Keine Nachrichten",
"NOTIFICATIONS": "Benachrichtigungen", "TITLE": "Benachrichtigungen",
"MARK_AS_READ": "Alles als gelesen markieren" "MARK_AS_READ": "Alles als gelesen markieren"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Zum Kopieren klicken", "CLICK_TO_COPY": "Zum Kopieren klicken",
"SUCCESS_COPY": "Text in Zwischenablage kopiert" "SUCCESS_COPY": "Text in Zwischenablage kopiert"
} }
} }

View File

@@ -5,10 +5,11 @@
"CLAIM": "CLAIM", "CLAIM": "CLAIM",
"UNCLAIM": "RELEASE", "UNCLAIM": "RELEASE",
"START PROCESS": "START PROCESS", "START PROCESS": "START PROCESS",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "No messages", "NO_MESSAGE": "No messages",
"NOTIFICATIONS": "Notifications", "TITLE": "Notifications",
"MARK_AS_READ": "Mark all as read" "MARK_AS_READ": "Mark all as read",
"SYSTEM": "System"
}, },
"FORM": { "FORM": {
"START_FORM": { "START_FORM": {

View File

@@ -5,9 +5,9 @@
"CLAIM": "Pedir", "CLAIM": "Pedir",
"UNCLAIM": "Liberar", "UNCLAIM": "Liberar",
"START PROCESS": "Iniciar proceso", "START PROCESS": "Iniciar proceso",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "No hay mensajes", "NO_MESSAGE": "No hay mensajes",
"NOTIFICATIONS": "Notificaciones", "TITLE": "Notificaciones",
"MARK_AS_READ": "Marcar todo como leído" "MARK_AS_READ": "Marcar todo como leído"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Haga clic para copiar", "CLICK_TO_COPY": "Haga clic para copiar",
"SUCCESS_COPY": "Texto copiado al portapapeles" "SUCCESS_COPY": "Texto copiado al portapapeles"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Varaa", "CLAIM": "Varaa",
"UNCLAIM": "Vapauta", "UNCLAIM": "Vapauta",
"START PROCESS": "Käynnistä prosessi", "START PROCESS": "Käynnistä prosessi",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Ei viestejä", "NO_MESSAGE": "Ei viestejä",
"NOTIFICATIONS": "Ilmoitukset", "TITLE": "Ilmoitukset",
"MARK_AS_READ": "Merkitse kaikki luetuiksi" "MARK_AS_READ": "Merkitse kaikki luetuiksi"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Kopioi napsauttamalla", "CLICK_TO_COPY": "Kopioi napsauttamalla",
"SUCCESS_COPY": "Teksti kopioitiin leikepöydälle" "SUCCESS_COPY": "Teksti kopioitiin leikepöydälle"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "S'attribuer", "CLAIM": "S'attribuer",
"UNCLAIM": "Libérer", "UNCLAIM": "Libérer",
"START PROCESS": "Démarrer le processus", "START PROCESS": "Démarrer le processus",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Aucun message", "NO_MESSAGE": "Aucun message",
"NOTIFICATIONS": "Notifications", "TITLE": "Notifications",
"MARK_AS_READ": "Marquer tout comme lu" "MARK_AS_READ": "Marquer tout comme lu"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Cliquer pour copier", "CLICK_TO_COPY": "Cliquer pour copier",
"SUCCESS_COPY": "Texte copié dans le presse-papiers" "SUCCESS_COPY": "Texte copié dans le presse-papiers"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Richiedi", "CLAIM": "Richiedi",
"UNCLAIM": "Restituisci", "UNCLAIM": "Restituisci",
"START PROCESS": "Avvia processo", "START PROCESS": "Avvia processo",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Nessun messaggio", "NO_MESSAGE": "Nessun messaggio",
"NOTIFICATIONS": "Notifiche", "TITLE": "Notifiche",
"MARK_AS_READ": "Seleziona tutti come già letti" "MARK_AS_READ": "Seleziona tutti come già letti"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Fare clic per copiare", "CLICK_TO_COPY": "Fare clic per copiare",
"SUCCESS_COPY": "Testo copiato negli appunti" "SUCCESS_COPY": "Testo copiato negli appunti"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "担当する", "CLAIM": "担当する",
"UNCLAIM": "担当解除", "UNCLAIM": "担当解除",
"START PROCESS": "プロセスの開始", "START PROCESS": "プロセスの開始",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "メッセージなし", "NO_MESSAGE": "メッセージなし",
"NOTIFICATIONS": "通知", "TITLE": "通知",
"MARK_AS_READ": "すべて既読にする" "MARK_AS_READ": "すべて既読にする"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "コピーするにはクリックします", "CLICK_TO_COPY": "コピーするにはクリックします",
"SUCCESS_COPY": "テキストがクリップボードにコピーされました" "SUCCESS_COPY": "テキストがクリップボードにコピーされました"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Krev", "CLAIM": "Krev",
"UNCLAIM": "Frigi", "UNCLAIM": "Frigi",
"START PROCESS": "Start prosess", "START PROCESS": "Start prosess",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Ingen meldinger", "NO_MESSAGE": "Ingen meldinger",
"NOTIFICATIONS": "Varsler", "TITLE": "Varsler",
"MARK_AS_READ": "Merk alle som lest" "MARK_AS_READ": "Merk alle som lest"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Klikk for å kopiere", "CLICK_TO_COPY": "Klikk for å kopiere",
"SUCCESS_COPY": "Tekst kopiert til utklippstavle" "SUCCESS_COPY": "Tekst kopiert til utklippstavle"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Claimen", "CLAIM": "Claimen",
"UNCLAIM": "Vrijgeven", "UNCLAIM": "Vrijgeven",
"START PROCESS": "Proces starten", "START PROCESS": "Proces starten",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Geen berichten", "NO_MESSAGE": "Geen berichten",
"NOTIFICATIONS": "Meldingen", "TITLE": "Meldingen",
"MARK_AS_READ": "Alles markeren als gelezen" "MARK_AS_READ": "Alles markeren als gelezen"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Klik om te kopiëren", "CLICK_TO_COPY": "Klik om te kopiëren",
"SUCCESS_COPY": "Tekst gekopieerd naar Klembord" "SUCCESS_COPY": "Tekst gekopieerd naar Klembord"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Przejmij", "CLAIM": "Przejmij",
"UNCLAIM": "Zwolnij", "UNCLAIM": "Zwolnij",
"START PROCESS": "Rozpocznij proces", "START PROCESS": "Rozpocznij proces",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Brak komunikatów", "NO_MESSAGE": "Brak komunikatów",
"NOTIFICATIONS": "Powiadomienia", "TITLE": "Powiadomienia",
"MARK_AS_READ": "Oznacz wszystkie jako przeczytane" "MARK_AS_READ": "Oznacz wszystkie jako przeczytane"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Kliknij, aby skopiować", "CLICK_TO_COPY": "Kliknij, aby skopiować",
"SUCCESS_COPY": "Tekst skopiowano do schowka" "SUCCESS_COPY": "Tekst skopiowano do schowka"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Reivindicar", "CLAIM": "Reivindicar",
"UNCLAIM": "Liberar", "UNCLAIM": "Liberar",
"START PROCESS": "Iniciar processo", "START PROCESS": "Iniciar processo",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Não há mensagens", "NO_MESSAGE": "Não há mensagens",
"NOTIFICATIONS": "Notificações", "TITLE": "Notificações",
"MARK_AS_READ": "Marcar todas como lidas" "MARK_AS_READ": "Marcar todas como lidas"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Clique para copiar", "CLICK_TO_COPY": "Clique para copiar",
"SUCCESS_COPY": "Texto copiado para a área de transferência" "SUCCESS_COPY": "Texto copiado para a área de transferência"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Принять", "CLAIM": "Принять",
"UNCLAIM": "Освободить", "UNCLAIM": "Освободить",
"START PROCESS": "Начать процесс", "START PROCESS": "Начать процесс",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Нет сообщений", "NO_MESSAGE": "Нет сообщений",
"NOTIFICATIONS": "Оповещения", "TITLE": "Оповещения",
"MARK_AS_READ": "Отметить все как прочитанное" "MARK_AS_READ": "Отметить все как прочитанное"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Нажмите, чтобы скопировать", "CLICK_TO_COPY": "Нажмите, чтобы скопировать",
"SUCCESS_COPY": "Текст скопирован в буфер обмена" "SUCCESS_COPY": "Текст скопирован в буфер обмена"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "Anta", "CLAIM": "Anta",
"UNCLAIM": "Avsäga", "UNCLAIM": "Avsäga",
"START PROCESS": "Starta process", "START PROCESS": "Starta process",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "Inga meddelanden", "NO_MESSAGE": "Inga meddelanden",
"NOTIFICATIONS": "Aviseringar", "TITLE": "Aviseringar",
"MARK_AS_READ": "Markera allt som läst" "MARK_AS_READ": "Markera allt som läst"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "Klicka för att kopiera", "CLICK_TO_COPY": "Klicka för att kopiera",
"SUCCESS_COPY": "Texten har kopierats till urklipp" "SUCCESS_COPY": "Texten har kopierats till urklipp"
} }
} }

View File

@@ -5,9 +5,9 @@
"CLAIM": "申领", "CLAIM": "申领",
"UNCLAIM": "释放", "UNCLAIM": "释放",
"START PROCESS": "启动流程", "START PROCESS": "启动流程",
"NOTIFICATION_HISTORY": { "NOTIFICATIONS": {
"NO_MESSAGE": "无消息", "NO_MESSAGE": "无消息",
"NOTIFICATIONS": "通知", "TITLE": "通知",
"MARK_AS_READ": "全部标记为已读" "MARK_AS_READ": "全部标记为已读"
}, },
"FORM": { "FORM": {
@@ -480,4 +480,4 @@
"CLICK_TO_COPY": "单击以复制", "CLICK_TO_COPY": "单击以复制",
"SUCCESS_COPY": "复制到剪贴板上的文本" "SUCCESS_COPY": "复制到剪贴板上的文本"
} }
} }

View File

@@ -41,7 +41,7 @@ export * from './directives/index';
export * from './clipboard/index'; export * from './clipboard/index';
export * from './dialogs/index'; export * from './dialogs/index';
export * from './icon/index'; export * from './icon/index';
export * from './notification-history/index'; export * from './notifications/index';
export * from './utils/index'; export * from './utils/index';
export * from './interface/index'; export * from './interface/index';

View File

@@ -26,5 +26,4 @@ export * from './redirection.model';
export * from './pagination.model'; export * from './pagination.model';
export * from './oauth-config.model'; export * from './oauth-config.model';
export * from './request-pagination.model'; export * from './request-pagination.model';
export * from './notification.model';
export * from './decimal-number.model'; export * from './decimal-number.model';

View File

@@ -9,22 +9,22 @@
<div id="adf-notification-history-list"> <div id="adf-notification-history-list">
<mat-list> <mat-list>
<mat-list-item> <mat-list-item>
<h6 mat-line>{{ 'NOTIFICATION_HISTORY.NOTIFICATIONS' | translate }}</h6> <h6 mat-line>{{ 'NOTIFICATIONS.TITLE' | translate }}</h6>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<mat-list> <mat-list>
<mat-list-item *ngFor="let notification of notifications"> <mat-list-item *ngFor="let notification of notifications">
<mat-icon mat-list-icon>{{notification.info? notification.info: 'info'}}</mat-icon> <mat-icon mat-list-icon>{{notification.info ? notification.info: 'info'}}</mat-icon>
<h4 mat-line>{{notification.message}}</h4> <h4 *ngFor="let message of notification.messages" mat-line>{{ message }}</h4>
<p mat-line> {{notification.dateTime | date}} </p> <p mat-line> {{notification.datetime | date}} </p>
</mat-list-item> </mat-list-item>
<mat-list-item *ngIf="isEmptyNotification()" id="adf-notification-history-component-no-message"> <mat-list-item *ngIf="isEmptyNotification()" id="adf-notification-history-component-no-message">
<h4 mat-line>{{ 'NOTIFICATION_HISTORY.NO_MESSAGE' | translate }}</h4> <h4 mat-line>{{ 'NOTIFICATIONS.NO_MESSAGE' | translate }}</h4>
</mat-list-item> </mat-list-item>
<mat-action-list *ngIf="!isEmptyNotification()" id="adf-notification-history-mark-as-read"> <mat-action-list *ngIf="!isEmptyNotification()" id="adf-notification-history-mark-as-read">
<button mat-list-item (click)="markAsRead()">{{ 'NOTIFICATION_HISTORY.MARK_AS_READ' | translate }} <button mat-list-item (click)="markAsRead()">{{ 'NOTIFICATIONS.MARK_AS_READ' | translate }}
</button> </button>
</mat-action-list> </mat-action-list>
</mat-list> </mat-list>

View File

@@ -16,11 +16,11 @@
*/ */
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { NotificationService } from '../services'; import { setupTestBed } from '../../testing/setupTestBed';
import { setupTestBed } from '../testing/setupTestBed'; import { CoreTestingModule } from '../../testing/core.testing.module';
import { CoreTestingModule } from '../testing/core.testing.module';
import { NotificationHistoryComponent } from './notification-history.component'; import { NotificationHistoryComponent } from './notification-history.component';
import { OverlayContainer } from '@angular/cdk/overlay'; import { OverlayContainer } from '@angular/cdk/overlay';
import { NotificationService } from '../services/notification.service';
describe('Notification History Component', () => { describe('Notification History Component', () => {

View File

@@ -17,7 +17,7 @@
import { Component, Input, ViewChild, OnDestroy } from '@angular/core'; import { Component, Input, ViewChild, OnDestroy } from '@angular/core';
import { NotificationService } from '../services/notification.service'; import { NotificationService } from '../services/notification.service';
import { NotificationModel } from '../models/notification.model'; import { Notification } from '../models/notification.model';
import { MatMenuTrigger } from '@angular/material'; import { MatMenuTrigger } from '@angular/material';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
@@ -31,7 +31,7 @@ export class NotificationHistoryComponent implements OnDestroy {
onDestroy$ = new Subject<boolean>(); onDestroy$ = new Subject<boolean>();
notifications: NotificationModel[] = []; notifications: Notification[] = [];
@ViewChild(MatMenuTrigger) @ViewChild(MatMenuTrigger)
trigger: MatMenuTrigger; trigger: MatMenuTrigger;
@@ -46,7 +46,7 @@ export class NotificationHistoryComponent implements OnDestroy {
constructor( constructor(
private notificationService: NotificationService) { private notificationService: NotificationService) {
this.notificationService.messages this.notificationService.notifications$
.pipe(takeUntil(this.onDestroy$)) .pipe(takeUntil(this.onDestroy$))
.subscribe((message) => { .subscribe((message) => {
this.notifications.push(message); this.notifications.push(message);

View File

@@ -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,
Notification
} from '../models/notification.model';
export const rootInitiator: NotificationInitiator = {
key: '*',
displayName: 'NOTIFICATIONS.SYSTEM'
};
export function info(messages: string | string[], initiator: NotificationInitiator = rootInitiator): Notification {
return {
type: NOTIFICATION_TYPE.INFO,
datetime: new Date(),
initiator,
messages: [].concat(messages)
};
}
export function warning(messages: string | string[], initiator: NotificationInitiator = rootInitiator): Notification {
return {
type: NOTIFICATION_TYPE.WARN,
datetime: new Date(),
initiator,
messages: [].concat(messages)
};
}
export function error(messages: string | string[], initiator: NotificationInitiator = rootInitiator): Notification {
return {
type: NOTIFICATION_TYPE.ERROR,
datetime: new Date(),
initiator,
messages: [].concat(messages)
};
}

View File

@@ -15,7 +15,21 @@
* limitations under the License. * limitations under the License.
*/ */
export interface NotificationModel { export enum NOTIFICATION_TYPE {
dateTime: Date; INFO = 'info',
message: string; WARN = 'warning',
ERROR = 'error'
}
export interface NotificationInitiator {
key: string | Symbol;
displayName: string;
extra?: any;
}
export interface Notification {
type: NOTIFICATION_TYPE;
initiator: NotificationInitiator;
datetime: Date;
messages: string[];
} }

View File

@@ -19,7 +19,7 @@ import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { MaterialModule } from '../material.module'; 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 { TranslateModule } from '@ngx-translate/core';
@NgModule({ @NgModule({

View File

@@ -15,5 +15,8 @@
* limitations under the License. * 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'; export * from './notification-history.module';

View File

@@ -23,10 +23,10 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatSnackBar, MatSnackBarModule, MatSnackBarConfig } from '@angular/material'; import { MatSnackBar, MatSnackBarModule, MatSnackBarConfig } from '@angular/material';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NotificationService } from './notification.service'; import { NotificationService } from './notification.service';
import { TranslationMock } from '../mock/translation.service.mock'; import { TranslationMock } from '../../mock/translation.service.mock';
import { TranslationService } from './translation.service'; import { TranslationService } from '../../services/translation.service';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { setupTestBed } from '../testing/setupTestBed'; import { setupTestBed } from '../../testing/setupTestBed';
@Component({ @Component({
template: '', template: '',

View File

@@ -0,0 +1,129 @@
/*!
* @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 { Injectable } from '@angular/core';
import { MatSnackBar, MatSnackBarRef, MatSnackBarConfig } from '@angular/material';
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 { 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'
})
export class NotificationService {
DEFAULT_DURATION_MESSAGE: number = 5000;
notifications$: Subject<Notification> = new Subject();
constructor(private snackBar: MatSnackBar,
private translationService: TranslationService,
private appConfigService: AppConfigService) {
this.DEFAULT_DURATION_MESSAGE = this.appConfigService.get<number>(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 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, interpolateArgs?: any): MatSnackBarRef<any> {
return this.dispatchNotification(message, null, config, interpolateArgs);
}
/**
* Opens a SnackBar notification with a message and a response button.
* @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, interpolateArgs?: any): MatSnackBarRef<any> {
return this.dispatchNotification(message, action, config, interpolateArgs);
}
/**
* 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<any> {
return this.dispatchNotification(message, action, { panelClass: ERROR_SNACK_CLASS }, interpolateArgs);
}
/**
* 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<any> {
return this.dispatchNotification(message, action, { panelClass: INFO_SNACK_CLASS }, interpolateArgs);
}
/**
* 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<any> {
return this.dispatchNotification(message, action, { panelClass: WARN_SNACK_CLASS }, interpolateArgs);
}
/**
* dismiss the notification snackbar
*/
dismissSnackMessageAction() {
return this.snackBar.dismiss();
}
private dispatchNotification(message: string, action?: string, config?: number | MatSnackBarConfig, interpolateArgs?: any): MatSnackBarRef<any> {
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 getNotificationCreator(config?: number | MatSnackBarConfig) {
const panelClass: string = config && (<MatSnackBarConfig> config).panelClass && (<MatSnackBarConfig> config).panelClass[0] || '';
switch (panelClass) {
case ERROR_SNACK_CLASS:
return error;
case WARN_SNACK_CLASS:
return warning;
default:
return info;
}
}
}

View File

@@ -1,140 +0,0 @@
/*!
* @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 { 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 { Subject } from 'rxjs';
import { NotificationModel } from '../models/notification.model';
@Injectable({
providedIn: 'root'
})
export class NotificationService {
DEFAULT_DURATION_MESSAGE: number = 5000;
messages: Subject<NotificationModel> = new Subject();
constructor(private snackBar: MatSnackBar,
private translationService: TranslationService,
private appConfigService: AppConfigService) {
this.DEFAULT_DURATION_MESSAGE = this.appConfigService.get<number>(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
* @returns Information/control object for the SnackBar
*/
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;
}
if (typeof config === 'number') {
config = {
duration: config
};
}
this.messages.next({ message: translatedMessage, dateTime: new Date });
return this.snackBar.open(translatedMessage, null, config);
}
/**
* Opens a SnackBar notification with a message and a response button.
* @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
* @returns Information/control object for the SnackBar
*/
openSnackMessageAction(message: string, action: 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, action, config);
}
/**
* dismiss the notification snackbar
*/
dismissSnackMessageAction() {
return this.snackBar.dismiss();
}
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, {
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<any> {
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<any> {
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<any> {
return this.showMessage(message, 'adf-warning-snackbar', action);
}
}

View File

@@ -28,7 +28,6 @@ export * from './page-title.service';
export * from './storage.service'; export * from './storage.service';
export * from './cookie.service'; export * from './cookie.service';
export * from './renditions.service'; export * from './renditions.service';
export * from './notification.service';
export * from './log.service'; export * from './log.service';
export * from './translation.service'; export * from './translation.service';
export * from './translate-loader.service'; export * from './translate-loader.service';