From 21498a7ecfd897f27121b6a5434f2aba58bc7a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Barbeau?= Date: Wed, 7 Jun 2017 13:48:49 -0400 Subject: [PATCH] fix(message-center): fix message center (#69) --- package.json | 2 +- src/lib/context/shared/context.service.ts | 18 ++++++++++++++---- .../message-center.component.styl | 9 +++++++++ .../message-center/message-center.component.ts | 4 ++-- src/lib/core/message/shared/message.service.ts | 5 ++--- src/lib/core/request/request.service.ts | 7 +++++-- src/lib/language.extract.ts | 3 +++ src/locale/en.json | 5 +++++ src/locale/fr.json | 5 +++++ 9 files changed, 46 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index d61a983be1..49b3b98c87 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@angular/platform-browser": "^4.0.0", "@ngx-translate/core": "^6.0.1", "@types/jspdf": "^1.1.31", - "angular2-notifications": "^0.4.46", + "angular2-notifications": "^0.7.4", "core-js": "^2.4.1", "hammerjs": "^2.0.8", "jspdf": "^1.3.3", diff --git a/src/lib/context/shared/context.service.ts b/src/lib/context/shared/context.service.ts index 80e92eb05a..8a097a57b9 100644 --- a/src/lib/context/shared/context.service.ts +++ b/src/lib/context/shared/context.service.ts @@ -2,7 +2,8 @@ import { Injectable, Optional } from '@angular/core'; import { Http } from '@angular/http'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; -import { RequestService, ConfigService, Message, RouteService } from '../../core'; +import { RequestService, ConfigService, RouteService, + Message, LanguageService } from '../../core'; // Import from shared to avoid circular dependencies import { ToolService } from '../../tool/shared'; @@ -20,6 +21,7 @@ export class ContextService { constructor(private http: Http, private requestService: RequestService, + private languageService: LanguageService, private toolService: ToolService, private config: ConfigService, @Optional() private route: RouteService) { @@ -62,7 +64,7 @@ export class ContextService { this.requestService.register( this.http.get(this.getPath(`${uri}.json`)) .map(res => res.json()) - .catch(res => this.handleError(res)) + .catch(res => this.handleError(res, uri)) , 'Context') .subscribe((_context: DetailedContext) => { this.setContext(_context); @@ -117,8 +119,16 @@ export class ContextService { return `${basePath}/${file}`; } - private handleError(res: Response): Message[] { - throw [{text: 'Invalid context'}]; + private handleError(res: Response, uri: string): Message[] { + const context = this.contexts$.value.find((obj) => obj.uri === uri); + const titleContext = context ? context.title : uri; + const titleError = this.languageService.translate + .instant('igo.contextInvalid.title'); + + const textError = this.languageService.translate + .instant('igo.contextInvalid.text', {value: titleContext}); + + throw [{title: titleError, text: textError}]; } } diff --git a/src/lib/core/message/message-center/message-center.component.styl b/src/lib/core/message/message-center/message-center.component.styl index f04f669b89..3fe7edc40d 100644 --- a/src/lib/core/message/message-center/message-center.component.styl +++ b/src/lib/core/message/message-center/message-center.component.styl @@ -2,6 +2,15 @@ :host >>> simple-notifications { + div.simple-notification-wrapper { + bottom: 0; + right: calc(50% - 150px); + +media(mobile) { + right: 0; + width: 100%; + } + } + div.simple-notification { min-height: 50px; margin-bottom: 5px; diff --git a/src/lib/core/message/message-center/message-center.component.ts b/src/lib/core/message/message-center/message-center.component.ts index 51e804988c..55f7a4a957 100644 --- a/src/lib/core/message/message-center/message-center.component.ts +++ b/src/lib/core/message/message-center/message-center.component.ts @@ -1,6 +1,6 @@ import { Component, Input } from '@angular/core'; -import { Options } from 'angular2-notifications/src/options.type'; +import { Options } from 'angular2-notifications/src/simple-notifications.module'; @Component({ @@ -12,7 +12,7 @@ import { Options } from 'angular2-notifications/src/options.type'; export class MessageCenterComponent { static defaultOptions = { - timeOut: 500000, + timeOut: 5000, showProgressBar: true, pauseOnHover: true, clickToClose: true, diff --git a/src/lib/core/message/shared/message.service.ts b/src/lib/core/message/shared/message.service.ts index a58cbd9212..ba6210d610 100644 --- a/src/lib/core/message/shared/message.service.ts +++ b/src/lib/core/message/shared/message.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; -import { NotificationsService } from 'angular2-notifications'; -import { Notification } from 'angular2-notifications/src/notification.type'; +import { Notification, NotificationsService } from 'angular2-notifications'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { Message } from './message.interface'; @@ -12,7 +11,7 @@ export class MessageService { public messages$ = new BehaviorSubject([]); - constructor(private notificationService: NotificationsService) { } + constructor(private notificationService: NotificationsService) {} message(message: Message) { this.messages$.next(this.messages$.value.concat([message])); diff --git a/src/lib/core/request/request.service.ts b/src/lib/core/request/request.service.ts index f888fe0a6c..a70b9e2631 100644 --- a/src/lib/core/request/request.service.ts +++ b/src/lib/core/request/request.service.ts @@ -3,7 +3,7 @@ import { Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; -import { Message, MessageService } from '../message'; +import { Message, MessageService, MessageType } from '../message'; import { ActivityService } from '../activity'; @Injectable() @@ -74,7 +74,10 @@ export class RequestService { private pushMessages(messages, title?: string) { messages.forEach((message: Message) => - this.messageService.message(Object.assign({title: title}, message))); + this.messageService.message(Object.assign({ + title: title, + type: MessageType.ERROR + }, message))); } } diff --git a/src/lib/language.extract.ts b/src/lib/language.extract.ts index f85a24bc54..a35b6119df 100644 --- a/src/lib/language.extract.ts +++ b/src/lib/language.extract.ts @@ -2,8 +2,11 @@ import { _ } from '@biesbjerg/ngx-translate-extract'; _('igo.map'); _('igo.searchResults'); +_('igo.context'); _('igo.contexts'); _('igo.timeAnalysis'); _('igo.landscape'); _('igo.portrait'); _('igo.orientation'); +_('igo.contextInvalid.title'); +_('igo.contextInvalid.text'); diff --git a/src/locale/en.json b/src/locale/en.json index 806e36beab..26c97a16d6 100644 --- a/src/locale/en.json +++ b/src/locale/en.json @@ -1,5 +1,10 @@ { "igo": { + "context": "Context", + "contextInvalid": { + "text": "Context '{{value}}' is invalid", + "title": "Invalid context" + }, "contexts": "Contexts", "endDate": "End Date", "format": "Format", diff --git a/src/locale/fr.json b/src/locale/fr.json index 74b1f709f1..85dee5dab5 100644 --- a/src/locale/fr.json +++ b/src/locale/fr.json @@ -1,5 +1,10 @@ { "igo": { + "context": "Contexte", + "contextInvalid": { + "text": "Le contexte \"{{value}}\" est invalide", + "title": "Contexte invalide" + }, "contexts": "Contextes", "endDate": "Date de fin", "format": "Format",