Adjusted CSS and added default notification options in the environment config files

This commit is contained in:
Giuseppe Digilio
2018-05-07 15:49:03 +02:00
parent e0deb52ed7
commit bafa46bb24
9 changed files with 82 additions and 76 deletions

View File

@@ -25,7 +25,12 @@ module.exports = {
notifications: { notifications: {
rtl: false, rtl: false,
position: ['top', 'right'], position: ['top', 'right'],
maxStack: 8 maxStack: 8,
// NOTE: after how many seconds notification is closed automatically. If set to zero notifications are not closed automatically
timeOut: 5000, // 5 second
clickToClose: true,
// NOTE: 'fade' | 'fromTop' | 'fromRight' | 'fromBottom' | 'fromLeft' | 'rotate' | 'scale'
animate: 'scale'
}, },
// Angular Universal settings // Angular Universal settings
universal: { universal: {

View File

@@ -28,7 +28,6 @@ import { HeaderComponent } from './header/header.component';
import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component'; import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
import { DSpaceRouterStateSerializer } from './shared/ngrx/dspace-router-state-serializer'; import { DSpaceRouterStateSerializer } from './shared/ngrx/dspace-router-state-serializer';
import { NotificationsService } from './shared/notifications/notifications.service';
import { NotificationsBoardComponent } from './shared/notifications/notifications-board/notifications-board.component'; import { NotificationsBoardComponent } from './shared/notifications/notifications-board/notifications-board.component';
import { NotificationComponent } from './shared/notifications/notification/notification.component'; import { NotificationComponent } from './shared/notifications/notification/notification.component';

View File

@@ -1,22 +1,20 @@
<div class="alert {{item.type}} alert-dismissible" role="alert" <div class="alert {{item.type}} alert-dismissible p-3" role="alert"
[@enterLeave]="animate"> [@enterLeave]="animate">
<div class="sn-progress-loader" *ngIf="showProgressBar"> <div class="notification-progress-loader position-absolute w-100" *ngIf="showProgressBar">
<span [ngStyle]="{'width': progressWidth + '%'}"></span> <span [ngStyle]="{'width': progressWidth + '%'}" class="h-100 float-left"></span>
</div> </div>
<button *ngIf="item.options.clickToClose" <button *ngIf="item.options.clickToClose"
(click)="remove()" (click)="remove()"
type="button" class="notificationClose close" data-dismiss="alert" aria-label="Close"> type="button" class="close pt-0 pr-1 pl-0 pb-0" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<div class="d-flex flex-row"> <div class="d-flex flex-row">
<div class="d-flex flex-column justify-content-center"> <div class="d-flex flex-column justify-content-center align-items-center">
<div class="p-2"> <div class="notification-icon d-flex justify-content-center"><i
<div class="icon"><i
[ngClass]="{'fa fa-2x': true, [ngClass]="{'fa fa-2x': true,
'fa-check': item.type == 'alert-success', 'fa-check': item.type == 'alert-success',
'fa-times-circle': item.type == 'alert-danger', 'fa-times-circle': item.type == 'alert-danger',
@@ -24,34 +22,33 @@
'fa-info': item.type == 'alert-info' 'fa-info': item.type == 'alert-info'
}"></i></div> }"></i></div>
</div> </div>
</div>
<div class="d-flex flex-column justify-content-center align-content-stretch"> <div class="d-flex flex-column justify-content-center align-content-stretch">
<div class="p-2 mr-3" *ngIf="title"> <div class="p-2 mr-3" *ngIf="title">
<strong> <strong>
<div class="sn-title" *ngIf="titleIsTemplate; else regularTitle"> <div class="pl-1" *ngIf="titleIsTemplate; else regularTitle">
<ng-container *ngTemplateOutlet="title"></ng-container> <ng-container *ngTemplateOutlet="title"></ng-container>
</div> </div>
<ng-template #regularTitle> <ng-template #regularTitle>
<div class="sn-title" [innerHTML]="(title | async)"></div> <div class="pl-1" [innerHTML]="(title | async)"></div>
</ng-template> </ng-template>
</strong> </strong>
</div> </div>
<div class="p-2 mr-3" *ngIf="content"> <div class="p-2 mr-3" *ngIf="content">
<div class="sn-content" *ngIf="contentIsTemplate; else regularContent"> <div class="pl-1" *ngIf="contentIsTemplate; else regularContent">
<ng-container *ngTemplateOutlet="content"></ng-container> <ng-container *ngTemplateOutlet="content"></ng-container>
</div> </div>
<ng-template #regularContent> <ng-template #regularContent>
<div class="sn-content" [innerHTML]="(content | async)"></div> <div class="pl-1" [innerHTML]="(content | async)"></div>
</ng-template> </ng-template>
</div> </div>
<div class="p-2 mr-3" *ngIf="item.html"> <div class="p-2 mr-3" *ngIf="item.html">
<div class="sn-html" *ngIf="htmlIsTemplate; else regularHtml"> <div class="pl-1" *ngIf="htmlIsTemplate; else regularHtml">
<ng-container *ngTemplateOutlet="html"></ng-container> <ng-container *ngTemplateOutlet="html"></ng-container>
</div> </div>
<ng-template #regularHtml> <ng-template #regularHtml>
<div class="sn-content" [innerHTML]="html"></div> <div class="pl-1" [innerHTML]="html"></div>
</ng-template> </ng-template>
</div> </div>
</div> </div>

View File

@@ -1,40 +1,28 @@
.alert-dismissible .close { @import '../../../../styles/variables.scss';
top: -13px;
right: -15px; .close {
outline: none !important
} }
.notificationClose:focus { .notification-icon {
outline: none !important; min-width: 3rem;
} }
.icon { .notification-progress-loader {
//float: left; top: -1px;
//padding: 5px; left: 0;
}
.alert-dismissible {
padding: 10px;
}
.sn-title, .sn-content, .sn-html {
position: relative;
left: 20px;
}
.sn-progress-loader {
position: absolute;
top: 0;
left: 1px;
width: 99%;
height: 1px; height: 1px;
} }
.sn-progress-loader span { .alert-success .notification-progress-loader span {
float: left; background: darken(adjust-hue(map-get($theme-colors, success), -10), 10%);
height: 100%; }
.alert-danger .notification-progress-loader span {
background: darken(adjust-hue(map-get($theme-colors, danger), -10), 10%);
}
.alert-info .notification-progress-loader span {
background: darken(adjust-hue(map-get($theme-colors, info), -10), 10%);
}
.alert-warning .notification-progress-loader span {
background: darken(adjust-hue(map-get($theme-colors, warning), -10), 10%);
} }
.alert-success .sn-progress-loader span { background: #CBC1AD; }
.alert-danger .sn-progress-loader span { background: #D5BABA; }
.alert-info .sn-progress-loader span { background: #B4C9CF; }
.alert-warning .sn-progress-loader span { background: #DBD1BD; }

View File

@@ -1,4 +1,4 @@
<div class="simple-notification-wrapper" [ngClass]="position"> <div class="notifications-wrapper position-fixed" [ngClass]="position">
<ds-notification <ds-notification
*ngFor="let a of notifications; let i = index" *ngFor="let a of notifications; let i = index"
[item]="a"> [item]="a">

View File

@@ -1,41 +1,43 @@
.simple-notification-wrapper { @import '../../../../styles/variables';
position: fixed; @import '../../../../styles/mixins';
.notifications-wrapper {
width: 300px; width: 300px;
z-index: 1051; z-index: 1051;
} }
.simple-notification-wrapper.left { .notifications-wrapper.left {
left: 20px; left: 20px;
} }
.simple-notification-wrapper.top { .notifications-wrapper.top {
top: 20px; top: 20px;
} }
.simple-notification-wrapper.right { .notifications-wrapper.right {
right: 20px; right: 20px;
} }
.simple-notification-wrapper.bottom { .notifications-wrapper.bottom {
bottom: 20px; bottom: 20px;
} }
.simple-notification-wrapper.center { .notifications-wrapper.center {
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
} }
.simple-notification-wrapper.middle { .notifications-wrapper.middle {
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
} }
.simple-notification-wrapper.middle.center { .notifications-wrapper.middle.center {
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
@media (max-width: 340px) { @media screen and (max-width: map-get($grid-breakpoints, sm)) {
.simple-notification-wrapper { .notifications-wrapper {
width: auto; width: auto;
left: 20px; left: 20px;
right: 20px; right: 20px;

View File

@@ -7,14 +7,16 @@ import {
OnInit, OnInit,
ViewEncapsulation ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import { NotificationsService } from '../notifications.service';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Subscription } from 'rxjs/Subscription';
import { difference } from 'lodash';
import { NotificationsService } from '../notifications.service';
import { AppState } from '../../../app.reducer'; import { AppState } from '../../../app.reducer';
import { notificationsStateSelector } from '../selectors'; import { notificationsStateSelector } from '../selectors';
import { difference } from 'lodash';
import { INotification } from '../models/notification.model'; import { INotification } from '../models/notification.model';
import { NotificationsState } from '../notifications.reducers'; import { NotificationsState } from '../notifications.reducers';
import { Subscription } from 'rxjs/Subscription';
import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces'; import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces';
@Component({ @Component({

View File

@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'; import { Inject, Injectable } from '@angular/core';
import { INotification, Notification } from './models/notification.model'; import { INotification, Notification } from './models/notification.model';
import { NotificationType } from './models/notification-type'; import { NotificationType } from './models/notification-type';
import { NotificationOptions } from './models/notification-options.model'; import { NotificationOptions } from './models/notification-options.model';
@@ -6,11 +6,13 @@ import { uniqueId } from 'lodash';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { NewNotificationAction, RemoveAllNotificationsAction, RemoveNotificationAction } from './notifications.actions'; import { NewNotificationAction, RemoveAllNotificationsAction, RemoveNotificationAction } from './notifications.actions';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { GLOBAL_CONFIG, GlobalConfig } from '../../../config';
@Injectable() @Injectable()
export class NotificationsService { export class NotificationsService {
constructor(private store: Store<Notification>) { constructor(@Inject(GLOBAL_CONFIG) public config: GlobalConfig,
private store: Store<Notification>) {
} }
private add(notification: Notification) { private add(notification: Notification) {
@@ -21,7 +23,7 @@ export class NotificationsService {
success(title: any = Observable.of(''), success(title: any = Observable.of(''),
content: any = Observable.of(''), content: any = Observable.of(''),
options = new NotificationOptions(), options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification { html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Success, title, content, options, html); const notification = new Notification(uniqueId(), NotificationType.Success, title, content, options, html);
this.add(notification); this.add(notification);
@@ -30,7 +32,7 @@ export class NotificationsService {
error(title: any = Observable.of(''), error(title: any = Observable.of(''),
content: any = Observable.of(''), content: any = Observable.of(''),
options = new NotificationOptions(), options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification { html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Error, title, content, options, html); const notification = new Notification(uniqueId(), NotificationType.Error, title, content, options, html);
this.add(notification); this.add(notification);
@@ -39,7 +41,7 @@ export class NotificationsService {
info(title: any = Observable.of(''), info(title: any = Observable.of(''),
content: any = Observable.of(''), content: any = Observable.of(''),
options = new NotificationOptions(), options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification { html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Info, title, content, options, html); const notification = new Notification(uniqueId(), NotificationType.Info, title, content, options, html);
this.add(notification); this.add(notification);
@@ -48,7 +50,7 @@ export class NotificationsService {
warning(title: any = Observable.of(''), warning(title: any = Observable.of(''),
content: any = Observable.of(''), content: any = Observable.of(''),
options = new NotificationOptions(), options: NotificationOptions = this.getDefaultOptions(),
html?: any): INotification { html?: any): INotification {
const notification = new Notification(uniqueId(), NotificationType.Warning, title, content, options, html); const notification = new Notification(uniqueId(), NotificationType.Warning, title, content, options, html);
this.add(notification); this.add(notification);
@@ -65,4 +67,11 @@ export class NotificationsService {
this.store.dispatch(actionRemoveAll); this.store.dispatch(actionRemoveAll);
} }
private getDefaultOptions(): NotificationOptions {
return new NotificationOptions(
this.config.notifications.timeOut,
this.config.notifications.clickToClose,
this.config.notifications.animate
);
}
} }

View File

@@ -1,7 +1,11 @@
import { Config } from './config.interface'; import { Config } from './config.interface';
import { NotificationAnimationsType } from '../app/shared/notifications/models/notification-animations-type';
export interface INotificationBoardOptions extends Config { export interface INotificationBoardOptions extends Config {
rtl: boolean; rtl: boolean;
position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center']; position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center'];
maxStack: number; maxStack: number;
timeOut: number;
clickToClose: boolean;
animate: NotificationAnimationsType;
} }