diff --git a/src/app/settings/auto-actions/auto-actions.component.html b/src/app/settings/auto-actions/auto-actions.component.html index fd652bb..32c7a95 100644 --- a/src/app/settings/auto-actions/auto-actions.component.html +++ b/src/app/settings/auto-actions/auto-actions.component.html @@ -1,11 +1,9 @@ -
+

Automatic Actions

Current Actions

-
{{ autoActions | json }}
- @@ -15,32 +13,35 @@ - - - - - - + + + - - - - + + + +
Remove
Example BoardItem assigned to user: adminSet item color: #debee8 - - - -
Example BoardItem moved to column: Col3Set item color: #debee8
{{ getBoardName(action.board_id) }}{{ getTriggerDescription(action) }}{{ getTypeDescription(action) }} - - - + + + + +
+ +
+
+
-
+

Add Action

@@ -54,17 +55,24 @@ @@ -72,12 +80,15 @@ @@ -85,10 +96,27 @@
- + + - + -
- + -
-
+ + +
+ Removing an automatic action cannot be undone.
Continue? +
+ +
+ + +
+
+ diff --git a/src/app/settings/auto-actions/auto-actions.component.ts b/src/app/settings/auto-actions/auto-actions.component.ts index ea27693..895bdc9 100644 --- a/src/app/settings/auto-actions/auto-actions.component.ts +++ b/src/app/settings/auto-actions/auto-actions.component.ts @@ -1,10 +1,10 @@ import { Component } from '@angular/core'; -import { AutoActionsService } from './auto-actions.service'; - import { ApiResponse, AutoAction, + ActionTrigger, + ActionType, User, Board, Modal, @@ -17,37 +17,135 @@ import { SettingsService } from '../settings.service'; @Component({ selector: 'tb-auto-actions', - templateUrl: 'app/settings/auto-actions/auto-actions.component.html', - providers: [ AutoActionsService ] + templateUrl: 'app/settings/auto-actions/auto-actions.component.html' }) export class AutoActions { + private noActionsMessage: string; + private MODAL_CONFIRM_ID: string; private activeUser: User; - private showActions: boolean; + private actionToRemove: AutoAction; + private newAction: AutoAction; + private boards: Array; private autoActions: Array; + private triggers: Array>; + private triggerSources: Array>; + private types: Array>; + + private loading = true; + private firstRun = true; + private saving = false; + constructor(private auth: AuthService, private modal: ModalService, private settings: SettingsService, - private notes: NotificationsService, - private actions: AutoActionsService) { - this.showActions = false; + private notes: NotificationsService) { + this.newAction = new AutoAction(); this.boards = []; this.autoActions = []; + this.MODAL_CONFIRM_ID = 'action-remove-confirm'; + + this.triggers = [ + [ ActionTrigger.MoveToColumn, 'Item moves to column' ], + [ ActionTrigger.AssignedToUser, 'Item assigned to user' ], + [ ActionTrigger.SetToCategory, 'Item set to category' ], + [ ActionTrigger.PointsChanged, 'Item points change' ] + ]; + this.updateTriggerSources(); + this.types = [ + [ ActionType.SetColor, 'Set item color'], + [ ActionType.SetCategory, 'Set item category' ], + [ ActionType.SetAssignee, 'Set item assignee' ], + [ ActionType.ClearDueDate, 'Clear item due date' ], + [ ActionType.UseBaseColor, 'Dim item color by points' ] + ]; auth.userChanged .subscribe(activeUser => { this.updateActiveUser(activeUser); }); - settings.boardsChanged.subscribe((boards: Array) => { - this.boards = boards; - }); - - actions.getActions() - .subscribe((response: ApiResponse) => { - this.autoActions = response.data[1]; + settings.boardsChanged + .subscribe((boards: Array) => { + this.boards = boards; }); + + settings.actionsChanged + .subscribe((actions: Array) => { + this.autoActions = actions; + + if (this.firstRun) { + this.firstRun = false; + return; + } + + this.loading = false; + }); + } + + updateTriggerSources(): void { + this.triggerSources = []; + + switch (this.newAction.trigger) { + case ActionTrigger.MoveToColumn: + this.triggerSources = [ [ null, 'Select Column' ] ]; + + for (let i = 0; i < this.boards.length; ++i) { + if (this.boards[i].id !== +this.newAction.board_id) { + continue; + } + + this.boards[i].columns.forEach(column => { + this.triggerSources.push([ column.id, column.name ]); + }); + } + break; + case ActionTrigger.AssignedToUser: + break; + case ActionTrigger.SetToCategory: + break; + case ActionTrigger.PointsChanged: + // Leave it empty + break; + } + } + + private removeAutoAction(): void { + this.saving = true; + // TODO remove this.actionToRemove + this.saving = false; + } + + private getBoardName(id: number): string { + let board = this.getBoard(id); + + return board ? board.name : ''; + } + + private getTriggerDescription(action: AutoAction): string { + let desc = ''; + + return desc; + } + + private getTypeDescription(action: AutoAction): string { + let desc = ''; + + return desc; + } + + private getBoard(id: number): Board { + let board: Board = null; + + for (let i = 0; i < this.boards.length; ++i) { + if (this.boards[i].id === id) { + board = this.boards[i]; + break; + } + } + + return board; } private updateActiveUser(activeUser: User) { @@ -59,10 +157,18 @@ export class AutoActions { +activeUser.user_option_id, activeUser.username, activeUser.board_access); + this.noActionsMessage = 'There are no current automatic actions. ' + + 'Use the Add Action form below to add one.'; - if (+activeUser.security_level < 3) { - this.showActions = true; + if (+activeUser.security_level === 3) { + this.noActionsMessage = 'There are no automatic actions. ' + + 'Contact an admin user to create one.'; } } + + private showConfirmModal(action: AutoAction): void { + this.actionToRemove = action; + this.modal.open(this.MODAL_CONFIRM_ID); + } } diff --git a/src/app/settings/auto-actions/auto-actions.service.ts b/src/app/settings/auto-actions/auto-actions.service.ts deleted file mode 100644 index 825dfef..0000000 --- a/src/app/settings/auto-actions/auto-actions.service.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Http } from '@angular/http'; - -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/map'; -import 'rxjs/add/operator/catch'; - -import { - ApiResponse -} from '../../shared/index'; - -@Injectable() -export class AutoActionsService { - constructor(private http: Http) { - } - - getActions(): Observable { - return this.http.get('api/autoactions') - .map(res => { - let response: ApiResponse = res.json(); - return Observable.of(response); - }) - .catch((res, caught) => { - let response: ApiResponse = res.json(); - return Observable.of(response); - }); - } -} - diff --git a/src/app/settings/board-admin/board-admin.component.ts b/src/app/settings/board-admin/board-admin.component.ts index fa01f46..4ef176b 100644 --- a/src/app/settings/board-admin/board-admin.component.ts +++ b/src/app/settings/board-admin/board-admin.component.ts @@ -43,6 +43,7 @@ export class BoardAdmin { private hasBAUsers = false; private loading = true; + private firstRun = true; private saving = false; private MODAL_ID: string; @@ -350,6 +351,12 @@ export class BoardAdmin { this.displayBoards = this.deepCopy(this.boards); this.filterBoards(); + + if (this.firstRun) { + this.firstRun = false; + return; + } + this.loading = false; } diff --git a/src/app/settings/settings.service.ts b/src/app/settings/settings.service.ts index c822912..3c20dd9 100644 --- a/src/app/settings/settings.service.ts +++ b/src/app/settings/settings.service.ts @@ -7,15 +7,22 @@ import 'rxjs/add/observable/of'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; -import { ApiResponse, User, Board } from '../shared/index'; +import { + ApiResponse, + User, + Board, + AutoAction +} from '../shared/index'; @Injectable() export class SettingsService { private users = new BehaviorSubject>([]); private boards = new BehaviorSubject>([]); + private actions = new BehaviorSubject>([]); public usersChanged = this.users.asObservable(); public boardsChanged = this.boards.asObservable(); + public actionsChanged = this.actions.asObservable(); constructor(private http: Http) { } @@ -51,5 +58,21 @@ export class SettingsService { return Observable.of(response); }); } + + updateActions(actions: Array): void { + this.actions.next(actions); + } + + getActions(): Observable { + return this.http.get('api/autoactions') + .map(res => { + let response: ApiResponse = res.json(); + return response; + }) + .catch((res, caught) => { + let response: ApiResponse = res.json(); + return Observable.of(response); + }); + } } diff --git a/src/app/settings/user-admin/user-admin.component.ts b/src/app/settings/user-admin/user-admin.component.ts index c860fe0..7bdb1e1 100644 --- a/src/app/settings/user-admin/user-admin.component.ts +++ b/src/app/settings/user-admin/user-admin.component.ts @@ -147,6 +147,16 @@ export class UserAdmin { this.settings.updateBoards(this.boards); this.updateUserList(); + this.getActions(); + }); + } + + private getActions(): void { + this.settings.getActions() + .subscribe((response: ApiResponse) => { + this.settings.updateActions(response.status === 'success' + ? response.data[1] + : []); this.loading = false; }); } diff --git a/src/app/shared/models/auto-actions.model.ts b/src/app/shared/models/auto-actions.model.ts index 11203eb..c29a0cf 100644 --- a/src/app/shared/models/auto-actions.model.ts +++ b/src/app/shared/models/auto-actions.model.ts @@ -14,11 +14,11 @@ export enum ActionType { } export class AutoAction { - constructor(public trigger: ActionTrigger, - public source_id: number, // tslint:disable-line - public type: ActionType, - public change_to: string, // tslint:disable-line - public board_id: number) { // tslint:disable-line + constructor(public trigger: ActionTrigger = ActionTrigger.MoveToColumn, + public source_id: number = null, // tslint:disable-line + public type: ActionType = ActionType.SetColor, + public change_to: string = null, // tslint:disable-line + public board_id: number = null) { // tslint:disable-line } }