Skip to content

Commit

Permalink
Fix automatic actions category bug issue kiswa#130.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiswa committed Feb 12, 2015
1 parent 4d2b213 commit 580924e
Showing 1 changed file with 53 additions and 36 deletions.
89 changes: 53 additions & 36 deletions js/controllers/settingsAutoActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ function ($scope, $interval, BoardService) {
]
};

$scope.updateTriggers = function() {
var foundCategories = false;
$scope.actionOptions.triggers.forEach(function(trigger) {
if (trigger.id === 2) {
foundCategories = true;
}
}, this);

if (!foundCategories) {
$scope.actionOptions.triggers.push({ id: 2, trigger: 'Item set to category' });
}

if ($scope.boardCategories.length === 1) {
$scope.actionOptions.triggers.forEach(function(trigger, index) {
if (trigger.id === 2) {
$scope.actionOptions.triggers.splice(index, 1);
}
});
$scope.actionTypes.forEach(function(type, index) {
if (type.id === 1) {
$scope.actionTypes.splice(index, 1);
}
});
}
};

var getBoardData = function(boardId) {
if (null === boardId || undefined === boardId)
{
Expand All @@ -59,17 +85,6 @@ function ($scope, $interval, BoardService) {
boardData.ownCategory.forEach(function(category) {
categories.push(category);
});
} else {
$scope.actionOptions.triggers.forEach(function(trigger, index) {
if (trigger.id === 2) {
$scope.actionOptions.triggers.splice(index, 1);
}
});
$scope.actionTypes.forEach(function(type, index) {
if (type.id === 1) {
$scope.actionTypes.splice(index, 1);
}
});
}
return categories;
},
Expand Down Expand Up @@ -146,35 +161,35 @@ function ($scope, $interval, BoardService) {
},

updateAutoActions = function(actions) {
if (!actions) {
$scope.actions = [];
return;
}
if (!actions) {
$scope.actions = [];
return;
}

var mappedActions = [];
actions.forEach(function(action) {
var actionTrigger, actionType;
$scope.actionOptions.triggers.forEach(function(trigger) {
if (trigger.id === parseInt(action.trigger_id)) {
actionTrigger = trigger.trigger;
}
});
$scope.actionTypes.forEach(function(type) {
if (type.id === parseInt(action.action_id)) {
actionType = type.action;
}
});
var mappedActions = [];
actions.forEach(function(action) {
var actionTrigger, actionType;
$scope.actionOptions.triggers.forEach(function(trigger) {
if (trigger.id === parseInt(action.trigger_id)) {
actionTrigger = trigger.trigger;
}
});
$scope.actionTypes.forEach(function(type) {
if (type.id === parseInt(action.action_id)) {
actionType = type.action;
}
});

mappedActions.push({
id: action.id,
board: $scope.boardLookup[action.board_id],
trigger: actionTrigger + getSecondaryText(action),
action: actionType + getActionText(action)
mappedActions.push({
id: action.id,
board: $scope.boardLookup[action.board_id],
trigger: actionTrigger + getSecondaryText(action),
action: actionType + getActionText(action)
});
});
});

$scope.actions = mappedActions;
};
$scope.actions = mappedActions;
};

$scope.loadActions = function() {
BoardService.getAutoActions()
Expand Down Expand Up @@ -232,6 +247,7 @@ function ($scope, $interval, BoardService) {

var boardData = getBoardData($scope.actionData.board);
$scope.boardCategories = getCategories(boardData);
$scope.updateTriggers();
$scope.userList = getUsers(boardData);

if (boardData) {
Expand Down Expand Up @@ -284,6 +300,7 @@ function ($scope, $interval, BoardService) {
if (null !== $scope.actionData.board) {
$('#spectrum').spectrum('enable');
$scope.actionData.color = $('#spectrum').spectrum('option', 'color');
$scope.updateSecondary();
return;
}
$('#spectrum').spectrum('disable');
Expand Down

0 comments on commit 580924e

Please sign in to comment.