Fixes #128. Setting to have tasks appear at top of column.
This commit is contained in:
parent
ee0e38e5c7
commit
f989b2acb3
@ -386,22 +386,40 @@ function createInitialUser() {
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the position for a new item in a lane.
|
||||
function getNextItemPosition($laneId) {
|
||||
// Gets the position for a new item in a column.
|
||||
function getNextItemPosition($columnId) {
|
||||
$retVal = 0;
|
||||
$column = R::load('lane', $columnId);
|
||||
|
||||
$lane = R::load('lane', $laneId);
|
||||
if ($lane->id) {
|
||||
try {
|
||||
$retVal = $lane->countOwn('item');
|
||||
} catch (Exception $e) {
|
||||
// Ignore, just means there are no items.
|
||||
if ($column->id) {
|
||||
$options = R::exportAll(getUser()->ownOption);
|
||||
|
||||
if ($options[0]['tasks_order'] == 1) {
|
||||
// Tasks at top of column.
|
||||
renumberItems($columnId, 0, false);
|
||||
} else {
|
||||
try {
|
||||
$retVal = $column->countOwn('item');
|
||||
} catch (Exception $e) {
|
||||
// Ignore, just means there are no items.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
$lane = R::load('lane', $item->laneId);
|
||||
$board = R::load('board', $lane->boardId);
|
||||
|
@ -348,6 +348,8 @@ $app->post('/items/remove', function() use ($app, $jsonResponse) {
|
||||
$before = $item->export();
|
||||
R::trash($item);
|
||||
|
||||
renumberItems($item->lane_id, $item->position);
|
||||
|
||||
$actor = getUser();
|
||||
logAction($actor->username . ' removed item ' . $item->title, $before, null, $data->itemId);
|
||||
$jsonResponse->addAlert('success', $item->title . ' was deleted.');
|
||||
|
Reference in New Issue
Block a user