WIP Automatic Actions updates
This commit is contained in:
parent
79ffd00074
commit
b3ddb51619
@ -1,11 +1,9 @@
|
||||
<section *ngIf="showActions">
|
||||
<section>
|
||||
<h2>Automatic Actions</h2>
|
||||
|
||||
<div class="row">
|
||||
<h3>Current Actions</h3>
|
||||
|
||||
<pre>{{ autoActions | json }}</pre>
|
||||
|
||||
<table class="alternating no-bottom-margin">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -15,32 +13,35 @@
|
||||
<th>Remove</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Example Board</td>
|
||||
<td>Item assigned to user: admin</td>
|
||||
<td>Set item color: #debee8</td>
|
||||
<td>
|
||||
<a href="#" title="Remove Automatic Action">
|
||||
<i class="icon icon-trash-empty color-secondary"></i>
|
||||
</a>
|
||||
</td>
|
||||
<tbody *ngIf="!loading">
|
||||
<tr *ngIf="autoActions.length === 0">
|
||||
<td colspan="4" class="center"
|
||||
[innerHTML]="noActionsMessage"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Example Board</td>
|
||||
<td>Item moved to column: Col3</td>
|
||||
<td>Set item color: #debee8</td>
|
||||
<tr *ngFor="let action of autoActions">
|
||||
<td>{{ getBoardName(action.board_id) }}</td>
|
||||
<td>{{ getTriggerDescription(action) }}</td>
|
||||
<td>{{ getTypeDescription(action) }}</td>
|
||||
<td>
|
||||
<a href="#" title="Remove Automatic Action">
|
||||
<i class="icon icon-trash-empty color-secondary"></i>
|
||||
</a>
|
||||
<span *ngIf="activeUser && activeUser.security_level < 3">
|
||||
<a href="javascript:"
|
||||
title="Remove Automatic Action"
|
||||
(click)="showConfirmModal(action)">
|
||||
<i class="icon icon-trash-empty
|
||||
color-secondary"></i>
|
||||
</a>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div *ngIf="loading" class="center">
|
||||
<div class="spinner"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row" *ngIf="activeUser && activeUser.security_level < 3">
|
||||
<h3>Add Action</h3>
|
||||
|
||||
<table>
|
||||
@ -54,17 +55,24 @@
|
||||
<tbody>
|
||||
<tr class="borderless">
|
||||
<td>
|
||||
<select>
|
||||
<option>Select Board...</option>
|
||||
<select [(ngModel)]="newAction.board_id">
|
||||
<option value="null">Select Board...</option>
|
||||
<option *ngFor="let board of boards"
|
||||
[value]="board.id">
|
||||
{{ board.name }}
|
||||
</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select>
|
||||
<option>Item moves to column</option>
|
||||
<select [disabled]="newAction.board_id === null"
|
||||
[ngModel]="newAction.trigger"
|
||||
(change)="updateTriggerSources()">
|
||||
<option *ngFor="let trigger of triggers"
|
||||
[value]="trigger[0]">{{ trigger[1] }}</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select>
|
||||
<select [disabled]="newAction.board_id === null">
|
||||
<option>Set item color</option>
|
||||
</select>
|
||||
</td>
|
||||
@ -72,12 +80,15 @@
|
||||
<tr class="borderless">
|
||||
<td></td>
|
||||
<td>
|
||||
<select>
|
||||
<option>Select Column</option>
|
||||
<select [disabled]="newAction.board_id === null"
|
||||
*ngIf="triggerSources.length"
|
||||
[(ngModel)]="newAction.source_id">
|
||||
<option *ngFor="let source of triggerSources"
|
||||
[value]="source[0]">{{ source[1] }}</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select>
|
||||
<select [disabled]="newAction.board_id === null">
|
||||
<option>Select Color</option>
|
||||
</select>
|
||||
</td>
|
||||
@ -85,10 +96,27 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button class="right" disabled>
|
||||
<button class="right">
|
||||
<i class="icon icon-plus"></i>
|
||||
Add Action
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<tb-modal modal-title="Confirm Automatic Action Removal" blocking="true"
|
||||
modal-id="{{ MODAL_CONFIRM_ID }}">
|
||||
|
||||
<div class="center">
|
||||
Removing an automatic action cannot be undone.<br>Continue?
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button class="flat"
|
||||
(click)="removeAutoAction()"
|
||||
[disabled]="saving">Yes</button>
|
||||
<button #defaultAction
|
||||
(click)="modal.close(MODAL_CONFIRM_ID)"
|
||||
[disabled]="saving">No</button>
|
||||
</div>
|
||||
</tb-modal>
|
||||
|
||||
|
@ -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<Board>;
|
||||
private autoActions: Array<AutoAction>;
|
||||
|
||||
private triggers: Array<Array<any>>;
|
||||
private triggerSources: Array<Array<any>>;
|
||||
private types: Array<Array<any>>;
|
||||
|
||||
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<Board>) => {
|
||||
this.boards = boards;
|
||||
});
|
||||
|
||||
actions.getActions()
|
||||
.subscribe((response: ApiResponse) => {
|
||||
this.autoActions = response.data[1];
|
||||
settings.boardsChanged
|
||||
.subscribe((boards: Array<Board>) => {
|
||||
this.boards = boards;
|
||||
});
|
||||
|
||||
settings.actionsChanged
|
||||
.subscribe((actions: Array<AutoAction>) => {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<ApiResponse> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<Array<User>>([]);
|
||||
private boards = new BehaviorSubject<Array<Board>>([]);
|
||||
private actions = new BehaviorSubject<Array<AutoAction>>([]);
|
||||
|
||||
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<AutoAction>): void {
|
||||
this.actions.next(actions);
|
||||
}
|
||||
|
||||
getActions(): Observable<ApiResponse> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user