diff --git a/packages/context/src/lib/context-manager/shared/context.interface.ts b/packages/context/src/lib/context-manager/shared/context.interface.ts index 0f977a9335..27c14f199c 100644 --- a/packages/context/src/lib/context-manager/shared/context.interface.ts +++ b/packages/context/src/lib/context-manager/shared/context.interface.ts @@ -1,6 +1,7 @@ +import { Message } from '@igo2/core'; +import { Tool } from '@igo2/common'; import { MapViewOptions, LayerOptions } from '@igo2/geo'; -import { Tool } from '@igo2/common'; import { TypePermission } from './context.enum'; export interface Context { @@ -26,6 +27,7 @@ export interface DetailedContext extends Context { layers?: LayerOptions[]; tools?: Tool[]; toolbar?: string[]; + message?: Message; removeLayersOnContextChange?: boolean; } diff --git a/packages/context/src/lib/context-manager/shared/context.service.ts b/packages/context/src/lib/context-manager/shared/context.service.ts index 780483e341..07efbb35bb 100644 --- a/packages/context/src/lib/context-manager/shared/context.service.ts +++ b/packages/context/src/lib/context-manager/shared/context.service.ts @@ -12,6 +12,8 @@ import { ConfigService, RouteService, Message, + MessageService, + Notification, LanguageService } from '@igo2/core'; @@ -39,6 +41,7 @@ export class ContextService { private mapViewFromRoute: ContextMapView = {}; private options: ContextServiceOptions; private baseUrl: string; + private contextMessage: Notification; // Until the ContextService is completely refactored, this is needed // to track the current tools @@ -49,6 +52,7 @@ export class ContextService { private authService: AuthService, private languageService: LanguageService, private config: ConfigService, + private messageService: MessageService, @Optional() private route: RouteService ) { this.options = Object.assign( @@ -197,9 +201,7 @@ export class ContextService { contextId: string, permissionId: string ): Observable { - const url = `${ - this.baseUrl - }/contexts/${contextId}/permissions/${permissionId}`; + const url = `${this.baseUrl}/contexts/${contextId}/permissions/${permissionId}`; return this.http.delete(url); } @@ -217,7 +219,7 @@ export class ContextService { getLocalContext(uri: string): Observable { const url = this.getPath(`${uri}.json`); return this.http.get(url).pipe( - flatMap((res) => { + flatMap(res => { if (!res.base) { return of(res); } @@ -226,14 +228,25 @@ export class ContextService { map((resBase: DetailedContext) => { const resMerge = res; resMerge.map = ObjectUtils.mergeDeep(resBase.map, res.map); - resMerge.layers = (resBase.layers || []).concat((res.layers || [])).reverse() - .filter((l, index, self) => !l.id || self.findIndex((l2) => l2.id === l.id) === index) + resMerge.layers = (resBase.layers || []) + .concat(res.layers || []) + .reverse() + .filter( + (l, index, self) => + !l.id || self.findIndex(l2 => l2.id === l.id) === index + ) .reverse(); - resMerge.toolbar = [...new Set( - (resBase.toolbar || []).concat((res.toolbar || [])).reverse()) as any + resMerge.toolbar = [ + ...(new Set( + (resBase.toolbar || []).concat(res.toolbar || []).reverse() + ) as any) ].reverse(); - resMerge.tools = (res.tools || []).concat((resBase.tools || [])) - .filter((t, index, self) => self.findIndex((t2) => t2.name === t.name) === index); + resMerge.tools = (res.tools || []) + .concat(resBase.tools || []) + .filter( + (t, index, self) => + self.findIndex(t2 => t2.name === t.name) === index + ); return resMerge; }), catchError(err => { @@ -312,6 +325,7 @@ export class ContextService { } setContext(context: DetailedContext) { + this.handleContextMessage(context); const currentContext = this.context$.value; if (currentContext && context && context.id === currentContext.id) { if (context.map.view.keepCurrentView === undefined) { @@ -394,6 +408,16 @@ export class ContextService { this.tools = tools; } + private handleContextMessage(context: DetailedContext) { + if (this.contextMessage) { + this.messageService.remove(this.contextMessage.id); + } + const message = context.message; + if (message) { + this.contextMessage = this.messageService.message(message as Message); + } + } + private getContextByUri(uri: string): Observable { if (this.baseUrl) { let contextToLoad; diff --git a/packages/core/src/lib/message/shared/index.ts b/packages/core/src/lib/message/shared/index.ts index 9d580e874f..5aadda9cd5 100644 --- a/packages/core/src/lib/message/shared/index.ts +++ b/packages/core/src/lib/message/shared/index.ts @@ -1,3 +1,4 @@ export * from './message.enum'; export * from './message.interface'; export * from './message.service'; +export { Notification } from 'angular2-notifications';