mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Second part
This commit is contained in:
committed by
Denys Vuika
parent
14800ce399
commit
ca79190880
@@ -16,9 +16,10 @@
|
||||
|
||||
<mat-list>
|
||||
<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 | noticicationIcon }}</mat-icon>
|
||||
<h4 *ngFor="let message of notification.messages" mat-line>{{ message }}</h4>
|
||||
<p mat-line> {{notification.datetime | date}} </p>
|
||||
<p mat-line> {{notification.initiator.displayName | translate}} </p>
|
||||
</mat-list-item>
|
||||
<mat-list-item *ngIf="isEmptyNotification()" id="adf-notification-history-component-no-message">
|
||||
<h4 mat-line>{{ 'NOTIFICATIONS.NO_MESSAGE' | translate }}</h4>
|
||||
|
@@ -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<boolean>();
|
||||
|
||||
notifications: Notification[] = [];
|
||||
notifications: NotificationModel[] = [];
|
||||
|
||||
@ViewChild(MatMenuTrigger)
|
||||
trigger: MatMenuTrigger;
|
||||
|
@@ -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(),
|
||||
|
@@ -27,7 +27,7 @@ export interface NotificationInitiator {
|
||||
extra?: any;
|
||||
}
|
||||
|
||||
export interface Notification {
|
||||
export interface NotificationModel {
|
||||
type: NOTIFICATION_TYPE;
|
||||
initiator: NotificationInitiator;
|
||||
datetime: Date;
|
||||
|
@@ -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
|
||||
|
36
lib/core/notifications/pipes/notification-icon.pipe.ts
Normal file
36
lib/core/notifications/pipes/notification-icon.pipe.ts
Normal file
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
@@ -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<Notification> = new Subject();
|
||||
notifications$: Subject<NotificationModel> = 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 && (<MatSnackBarConfig> config).panelClass && (<MatSnackBarConfig> 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:
|
||||
|
Reference in New Issue
Block a user