Fixes #128. Setting to have tasks appear at top of column.

This commit is contained in:
Matthew Ross 2015-06-05 18:01:37 -04:00
parent ee0e38e5c7
commit f989b2acb3
2 changed files with 28 additions and 8 deletions

View File

@ -386,22 +386,40 @@ function createInitialUser() {
} }
} }
// Gets the position for a new item in a lane. // Gets the position for a new item in a column.
function getNextItemPosition($laneId) { function getNextItemPosition($columnId) {
$retVal = 0; $retVal = 0;
$column = R::load('lane', $columnId);
$lane = R::load('lane', $laneId); if ($column->id) {
if ($lane->id) { $options = R::exportAll(getUser()->ownOption);
if ($options[0]['tasks_order'] == 1) {
// Tasks at top of column.
renumberItems($columnId, 0, false);
} else {
try { try {
$retVal = $lane->countOwn('item'); $retVal = $column->countOwn('item');
} catch (Exception $e) { } catch (Exception $e) {
// Ignore, just means there are no items. // Ignore, just means there are no items.
} }
} }
}
return $retVal; return $retVal;
} }
function renumberItems($columnId, $itemPosition, $isRemoved = true) {
$items = R::find('item', 'lane_id = ' . $columnId);
foreach ($items as $item) {
if ($item->position >= $itemPosition) {
$item->position += $isRemoved ? -1 : 1;
R::store($item);
}
}
}
function runAutoActions(&$item) { function runAutoActions(&$item) {
$lane = R::load('lane', $item->laneId); $lane = R::load('lane', $item->laneId);
$board = R::load('board', $lane->boardId); $board = R::load('board', $lane->boardId);

View File

@ -348,6 +348,8 @@ $app->post('/items/remove', function() use ($app, $jsonResponse) {
$before = $item->export(); $before = $item->export();
R::trash($item); R::trash($item);
renumberItems($item->lane_id, $item->position);
$actor = getUser(); $actor = getUser();
logAction($actor->username . ' removed item ' . $item->title, $before, null, $data->itemId); logAction($actor->username . ' removed item ' . $item->title, $before, null, $data->itemId);
$jsonResponse->addAlert('success', $item->title . ' was deleted.'); $jsonResponse->addAlert('success', $item->title . ' was deleted.');