Skip to content

Commit

Permalink
fix(build): fix builds to work with the new tool module from the comm…
Browse files Browse the repository at this point in the history
…on package
  • Loading branch information
cbourget committed Feb 22, 2019
1 parent dae039b commit e06c58b
Show file tree
Hide file tree
Showing 65 changed files with 251 additions and 859 deletions.
1 change: 1 addition & 0 deletions demo/src/app/common/tool/tool.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class AppToolComponent implements OnInit, OnDestroy {
constructor(private toolService: ToolService) {}

ngOnInit() {
this.toolbox.setToolbar(['salutation', 'about']);
this.toolbox.setTools(this.toolService.getTools());
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/lib/action/shared/action.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export interface Action {
args?: any[];
}

export type ActionHandler = (...any) => void;
export type ActionHandler = (...args: any[]) => void;
5 changes: 5 additions & 0 deletions packages/common/src/lib/entity/shared/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export class EntityStore<E extends object, S extends EntityState = EntityState>
get index(): Map<EntityKey, E> { return this._index; }
private _index: Map<EntityKey, E>;

/**
* Whether there are entities in the store
*/
get empty(): boolean { return this.entities$.value.length === 0; }

constructor(entities: E[], options: EntityStoreOptions = {}) {
this.getKey = options.getKey ? options.getKey : getEntityId;
this.getProperty = options.getProperty ? options.getProperty : getEntityProperty;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/lib/entity/shared/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class EntityView<E extends object, V extends object = E> {
private values$$: Subscription;

/**
* Whether there are pending operations
* Whether there are entities in the view
*/
get empty(): boolean { return this.values$.value.length === 0; }

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/lib/tool/shared/tool-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Tool } from './tool.interface';
import { ToolService } from './tool.service';

export function ToolComponent(tool: Partial<Tool>): (cls: any) => any {
return function (compType: any) {
return (compType: any) => {
ToolService.register(Object.assign({}, tool, {
component: compType
} as Tool));
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/lib/tool/shared/tool.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export interface Tool {
tooltip?: string;
options?: { [key: string]: any };
}

export interface ToolboxOptions {
toolbar?: string[];
}
64 changes: 57 additions & 7 deletions packages/common/src/lib/tool/shared/toolbox.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
import { EntityRecord, EntityStore } from '../../entity';
import { Tool } from './tool.interface';
import { Tool, ToolboxOptions } from './tool.interface';
import { BehaviorSubject, Subscription } from 'rxjs';

/**
* Service where all available tools and their component are registered.
*/
export class Toolbox {

/**
* Observable of the active tool
*/
activeTool$: BehaviorSubject<Tool> = new BehaviorSubject(undefined);

activeToolHistory: string[] = [];
/**
* Ordered list of tool names to display in a toolbar
*/
toolbar: string[];

/**
* Observable of the active tool
*/
private activeTool$$: Subscription;

/**
* Active tool history. Useful for activating the previous tool.
*/
private activeToolHistory: string[] = [];

/**
* Tool store
*/
private store = new EntityStore<Tool>([], {
getKey: (tool: Tool) => tool.name
});

constructor() {
constructor(private options: ToolboxOptions = {}) {
this.toolbar = options.toolbar ? options.toolbar : [];
this.initStore();
}

/**
* Destroy the toolbox
*/
destroy() {
this.activeTool$$.unsubscribe();
this.store.destroy();
Expand All @@ -43,10 +64,6 @@ export class Toolbox {
return this.store.all();
}

addTool(tool: Tool) {
this.store.update(tool);
}

/**
* Set tool configurations
* @param tools Tools
Expand All @@ -55,11 +72,31 @@ export class Toolbox {
this.store.load(tools);
}

/**
* Set toolbar
* @param toolbar A list of tool names
*/
setToolbar(toolbar: string[]) {
this.toolbar = toolbar || [];
}

/**
* Activate a tool (and deactivate other tools)
* @param name Tool name
* @param options Tool options
*/
activateTool(name: string, options: {[key: string]: any} = {}) {
const tool = this.getTool(name);
if (tool === undefined) {
return;
}

this.store.state.update(tool, {active: true, options}, true);
}

/**
* Activate the previous tool, if any
*/
activatePreviousTool() {
if (this.activeToolHistory.length <= 1) {
this.deactivateTool();
Expand All @@ -69,11 +106,17 @@ export class Toolbox {
this.activateTool(previous);
}

/**
* Deactivate the active tool
*/
deactivateTool() {
this.clearActiveToolHistory();
this.store.state.updateAll({active: false});
}

/**
* Initialize the tool store and start observing the active tool
*/
private initStore() {
this.store = new EntityStore<Tool>([], {
getKey: (entity: Tool) => entity.name
Expand All @@ -97,6 +140,10 @@ export class Toolbox {
});
}

/**
* Set the active tool and update the tool history
* @param tool Tool
*/
private setActiveTool(tool: Tool | undefined) {
this.activeTool$.next(tool);
if (tool === undefined) {
Expand All @@ -108,6 +155,9 @@ export class Toolbox {
}
}

/**
* Clear the tool history
*/
private clearActiveToolHistory() {
this.activeToolHistory = [];
}
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/lib/tool/toolbox/toolbox.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<igo-actionbar
*ngIf="!actionStore.empty"
[store]="actionStore"
[withIcon]="true"
[withTitle]="actionbarWithTitle"
[withTitle]="toolbarWithTitle"
[horizontal]="false">
</igo-actionbar>

<div
*ngIf="activeTool$ | async as tool"
class="igo-tool-container"
[ngClass]="{'igo-tool-container-with-toolbar': !actionStore.empty}"
[@toolSlideInOut]="animation$ | async"
(@toolSlideInOut.start)="onAnimationStart()"
(@toolSlideInOut.done)="onAnimationComplete()">
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/lib/tool/toolbox/toolbox.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
position: absolute;
top: 0;
bottom: 0;
left: 51px;
left: 0;
right: 0;
transform: translate3d(100%, 0, 0);
}

.igo-tool-container-empty {
width: 0;
.igo-tool-container-with-toolbar {
left: 51px;
}

igo-actionbar {
Expand Down
32 changes: 19 additions & 13 deletions packages/common/src/lib/tool/toolbox/toolbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ export class ToolboxComponent implements OnInit, OnDestroy {
this.actionStore.state.updateAll({active: false});
} else {
const action = this.actionStore.get(tool.name);
this.actionStore.state.update(action, {active: true}, true);
if (action !== undefined) {
this.actionStore.state.update(action, {active: true}, true);
}
}

this.activeTool$.next(tool);
Expand All @@ -150,18 +152,22 @@ export class ToolboxComponent implements OnInit, OnDestroy {
* Initialize the toolbar
*/
private initToolbar() {
const actions = this.toolbox.getTools().map((tool: Tool) => {
return {
id: tool.name,
title: tool.title,
icon: tool.icon,
iconImage: tool.iconImage,
tooltip: tool.tooltip,
args: [tool, this.toolbox],
handler: (_tool: Tool, _toolbox: Toolbox) => {
_toolbox.activateTool(_tool.name);
}
};
const actions = [];
this.toolbox.toolbar.forEach((toolName: string) => {
const tool = this.toolbox.getTool(toolName);
if (tool !== undefined) {
actions.push({
id: tool.name,
title: tool.title,
icon: tool.icon,
iconImage: tool.iconImage,
tooltip: tool.tooltip,
args: [tool, this.toolbox],
handler: (_tool: Tool, _toolbox: Toolbox) => {
_toolbox.activateTool(_tool.name);
}
});
}
});
this.actionStore.load(actions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {

import { MapContextDirective } from './shared/map-context.directive';
import { LayerContextDirective } from './shared/layer-context.directive';
import { ToolContextDirective } from './shared/tool-context.directive';
import { ContextListComponent } from './context-list/context-list.component';
import { ContextListBindingDirective } from './context-list/context-list-binding.directive';
import { ContextItemComponent } from './context-item/context-item.component';
Expand All @@ -35,8 +34,7 @@ import { ContextPermissionsBindingDirective } from './context-permissions/contex

const CONTEXT_DIRECTIVES = [
MapContextDirective,
LayerContextDirective,
ToolContextDirective
LayerContextDirective
];

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MapViewOptions, LayerOptions } from '@igo2/geo';

import { Tool } from '../../tool/shared/tool.interface';
import { Tool } from '@igo2/common';
import { TypePermission } from './context.enum';

export interface Context {
Expand Down
27 changes: 13 additions & 14 deletions packages/context/src/lib/context-manager/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
import { AuthService } from '@igo2/auth';
import { IgoMap } from '@igo2/geo';

import { ToolService } from '../../tool/shared/tool.service';

import { TypePermission } from './context.enum';
import {
ContextsList,
Expand All @@ -45,7 +43,6 @@ export class ContextService {
private http: HttpClient,
private authService: AuthService,
private languageService: LanguageService,
private toolService: ToolService,
private config: ConfigService,
@Optional() private route: RouteService
) {
Expand Down Expand Up @@ -307,9 +304,10 @@ export class ContextService {
}

// Update the tools options with those found in the context
if (context.tools !== undefined) {
this.toolService.setTools(context.tools);
}
// TODO
// if (context.tools !== undefined) {
// this.toolService.setTools(context.tools);
// }

if (!context.map) {
context.map = { view: {} };
Expand Down Expand Up @@ -371,14 +369,15 @@ export class ContextService {
context.layers.push(opts);
}

const tools = this.toolService.tools$.value;
for (const key in tools) {
if (tools.hasOwnProperty(key)) {
context.tools.push({
id: String(tools[key].id)
});
}
}
// TODO
// const tools = this.toolService.tools$.value;
// for (const key in tools) {
// if (tools.hasOwnProperty(key)) {
// context.tools.push({
// id: String(tools[key].id)
// });
// }
// }

return context;
}
Expand Down
1 change: 0 additions & 1 deletion packages/context/src/lib/context-manager/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './context.enum';
export * from './context.interface';
export * from './layer-context.directive';
export * from './map-context.directive';
export * from './tool-context.directive';

This file was deleted.

Loading

0 comments on commit e06c58b

Please sign in to comment.