Skip to content

Commit

Permalink
feat(message-context): add message in context config
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Nov 6, 2019
1 parent 66dc8cb commit 52337f2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -26,6 +27,7 @@ export interface DetailedContext extends Context {
layers?: LayerOptions[];
tools?: Tool[];
toolbar?: string[];
message?: Message;
removeLayersOnContextChange?: boolean;
}

Expand Down
44 changes: 34 additions & 10 deletions packages/context/src/lib/context-manager/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ConfigService,
RouteService,
Message,
MessageService,
Notification,
LanguageService
} from '@igo2/core';

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -197,9 +201,7 @@ export class ContextService {
contextId: string,
permissionId: string
): Observable<void> {
const url = `${
this.baseUrl
}/contexts/${contextId}/permissions/${permissionId}`;
const url = `${this.baseUrl}/contexts/${contextId}/permissions/${permissionId}`;
return this.http.delete<void>(url);
}

Expand All @@ -217,7 +219,7 @@ export class ContextService {
getLocalContext(uri: string): Observable<DetailedContext> {
const url = this.getPath(`${uri}.json`);
return this.http.get<DetailedContext>(url).pipe(
flatMap((res) => {
flatMap(res => {
if (!res.base) {
return of(res);
}
Expand All @@ -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 => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<DetailedContext> {
if (this.baseUrl) {
let contextToLoad;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/message/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './message.enum';
export * from './message.interface';
export * from './message.service';
export { Notification } from 'angular2-notifications';

0 comments on commit 52337f2

Please sign in to comment.