From 5a35d71131f0eee8519c06fd85c7a186aa82f836 Mon Sep 17 00:00:00 2001 From: kiswa Date: Wed, 1 Feb 2017 22:27:54 +0000 Subject: [PATCH] Auto Actions front-end behaviors complete --- src/api/helpers/ActionTrigger.php | 4 +- src/api/helpers/ActionType.php | 8 +- .../auto-actions/auto-actions.component.html | 40 +++++-- .../auto-actions/auto-actions.component.ts | 108 ++++++++++++++---- src/app/shared/models/auto-actions.model.ts | 10 +- 5 files changed, 129 insertions(+), 41 deletions(-) diff --git a/src/api/helpers/ActionTrigger.php b/src/api/helpers/ActionTrigger.php index 4ba2e53..63f43ed 100644 --- a/src/api/helpers/ActionTrigger.php +++ b/src/api/helpers/ActionTrigger.php @@ -2,9 +2,9 @@ use MyCLabs\Enum\Enum; class ActionTrigger extends Enum { - const MOVE_TO_COLUMN = 1; + const MOVED_TO_COLUMN = 1; const ASSIGNED_TO_USER = 2; - const SET_TO_CATEGORY = 3; + const ADDED_TO_CATEGORY = 3; const POINTS_CHANGED = 4; } diff --git a/src/api/helpers/ActionType.php b/src/api/helpers/ActionType.php index 24556ba..f89b8f1 100644 --- a/src/api/helpers/ActionType.php +++ b/src/api/helpers/ActionType.php @@ -4,8 +4,10 @@ use MyCLabs\Enum\Enum; class ActionType extends Enum { const SET_COLOR = 1; const SET_CATEGORY = 2; - const SET_ASSIGNEE = 3; - const CLEAR_DUE_DATE = 4; - const USE_BASE_COLOR = 5; + const ADD_CATEGORY = 3; + const CLEAR_ALL_CATEGORIES = 4; + const SET_ASSIGNEE = 5; + const CLEAR_DUE_DATE = 6; + const ALTER_COLOR_BY_POINTS= 7; } diff --git a/src/app/settings/auto-actions/auto-actions.component.html b/src/app/settings/auto-actions/auto-actions.component.html index 32c7a95..48532a3 100644 --- a/src/app/settings/auto-actions/auto-actions.component.html +++ b/src/app/settings/auto-actions/auto-actions.component.html @@ -55,25 +55,29 @@ - + - + @@ -82,21 +86,33 @@ - + + - diff --git a/src/app/settings/auto-actions/auto-actions.component.ts b/src/app/settings/auto-actions/auto-actions.component.ts index 895bdc9..40f7f81 100644 --- a/src/app/settings/auto-actions/auto-actions.component.ts +++ b/src/app/settings/auto-actions/auto-actions.component.ts @@ -22,6 +22,7 @@ import { SettingsService } from '../settings.service'; export class AutoActions { private noActionsMessage: string; private MODAL_CONFIRM_ID: string; + private activeUser: User; private actionToRemove: AutoAction; private newAction: AutoAction; @@ -32,9 +33,12 @@ export class AutoActions { private triggers: Array>; private triggerSources: Array>; private types: Array>; + private typesList: Array>; + private actionSources: Array>; private loading = true; private firstRun = true; + private isAddDisabled = true; private saving = false; constructor(private auth: AuthService, @@ -47,19 +51,21 @@ export class AutoActions { this.MODAL_CONFIRM_ID = 'action-remove-confirm'; this.triggers = [ - [ ActionTrigger.MoveToColumn, 'Item moves to column' ], + [ ActionTrigger.MovedToColumn, 'Item moved to column' ], [ ActionTrigger.AssignedToUser, 'Item assigned to user' ], - [ ActionTrigger.SetToCategory, 'Item set to category' ], + [ ActionTrigger.AddedToCategory, 'Item added to category' ], [ ActionTrigger.PointsChanged, 'Item points change' ] ]; this.updateTriggerSources(); - this.types = [ + this.typesList = [ [ ActionType.SetColor, 'Set item color'], [ ActionType.SetCategory, 'Set item category' ], + [ ActionType.AddCategory, 'Add item category' ], + [ ActionType.ClearAllCategories, 'Clear item categories' ], [ ActionType.SetAssignee, 'Set item assignee' ], - [ ActionType.ClearDueDate, 'Clear item due date' ], - [ ActionType.UseBaseColor, 'Dim item color by points' ] + [ ActionType.ClearDueDate, 'Clear item due date' ] ]; + this.types = this.typesList; auth.userChanged .subscribe(activeUser => { @@ -86,29 +92,91 @@ export class AutoActions { updateTriggerSources(): void { this.triggerSources = []; + this.newAction.source_id = null; + + this.types = this.typesList; 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 ]); - }); - } + case ActionTrigger.MovedToColumn: + this.buildSourcesArray('triggerSources', + 'Column', 'columns'); break; case ActionTrigger.AssignedToUser: + this.buildSourcesArray('triggerSources', + 'User', 'users', 'username'); break; - case ActionTrigger.SetToCategory: + case ActionTrigger.AddedToCategory: + this.buildSourcesArray('triggerSources', + 'Category', 'categories'); break; case ActionTrigger.PointsChanged: - // Leave it empty + // Leave triggerSources empty + this.types = [ + [ ActionType.AlterColorByPoints, 'Alter color by points' ] + ]; break; } + + this.newAction.type = this.types ? + this.types[0][0] : ActionType.SetColor; + + this.checkAddDisabled(); + } + + updateActionSources(): void { + this.actionSources = []; + this.newAction.change_to = null; + + switch (this.newAction.type) { + case ActionType.SetCategory: + case ActionType.AddCategory: + this.buildSourcesArray('actionSources', + 'Category', 'categories'); + break; + case ActionType.SetAssignee: + this.buildSourcesArray('actionSources', + 'Assignee', 'users', 'username'); + break; + case ActionType.SetColor: + this.newAction.change_to = '#000000'; + break; + } + + this.checkAddDisabled(); + } + + checkAddDisabled(): void { + this.isAddDisabled = false; + + if (this.newAction.board_id !== null) { + if (this.newAction.source_id === null) { + this.isAddDisabled = + (this.newAction.trigger !== ActionTrigger.PointsChanged); + } + + if (!this.isAddDisabled && this.newAction.change_to === null) { + this.isAddDisabled = + (this.newAction.type !== ActionType.ClearAllCategories && + this.newAction.type !== ActionType.ClearDueDate); + } + } + } + + private buildSourcesArray(sourceArray: string, + name: string, + arrayName: string, + prop: string = 'name'): void { + this[sourceArray] = [ [ null, 'Select ' + name ] ]; + + for (let i = 0; i < this.boards.length; ++i) { + if (this.boards[i].id !== this.newAction.board_id) { + continue; + } + + this.boards[i][arrayName].forEach((item: any) => { + this[sourceArray].push([ item.id, item[prop] ]); + }); + } } private removeAutoAction(): void { @@ -160,7 +228,7 @@ export class AutoActions { this.noActionsMessage = 'There are no current automatic actions. ' + 'Use the Add Action form below to add one.'; - if (+activeUser.security_level === 3) { + if (activeUser.security_level === 3) { this.noActionsMessage = 'There are no automatic actions. ' + 'Contact an admin user to create one.'; } diff --git a/src/app/shared/models/auto-actions.model.ts b/src/app/shared/models/auto-actions.model.ts index c29a0cf..b8794a6 100644 --- a/src/app/shared/models/auto-actions.model.ts +++ b/src/app/shared/models/auto-actions.model.ts @@ -1,20 +1,22 @@ export enum ActionTrigger { - MoveToColumn = 1, + MovedToColumn = 1, AssignedToUser, - SetToCategory, + AddedToCategory, PointsChanged } export enum ActionType { SetColor = 1, SetCategory, + AddCategory, + ClearAllCategories, SetAssignee, ClearDueDate, - UseBaseColor + AlterColorByPoints } export class AutoAction { - constructor(public trigger: ActionTrigger = ActionTrigger.MoveToColumn, + constructor(public trigger: ActionTrigger = ActionTrigger.MovedToColumn, public source_id: number = null, // tslint:disable-line public type: ActionType = ActionType.SetColor, public change_to: string = null, // tslint:disable-line