Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(message-center): fix message center #69

Merged
merged 2 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 14 additions & 4 deletions src/lib/context/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/core/message/shared/message.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,7 +11,7 @@ export class MessageService {

public messages$ = new BehaviorSubject<Message[]>([]);

constructor(private notificationService: NotificationsService) { }
constructor(private notificationService: NotificationsService) {}

message(message: Message) {
this.messages$.next(this.messages$.value.concat([message]));
Expand Down
7 changes: 5 additions & 2 deletions src/lib/core/request/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)));
}

}
3 changes: 3 additions & 0 deletions src/lib/language.extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
5 changes: 5 additions & 0 deletions src/locale/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"igo": {
"context": "Context",
"contextInvalid": {
"text": "Context '{{value}}' is invalid",
"title": "Context invalid"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "Invalid Context" or something like "This context is invalid".

},
"contexts": "Contexts",
"endDate": "End Date",
"format": "Format",
Expand Down
5 changes: 5 additions & 0 deletions src/locale/fr.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down