Merge pull request #151 from nextcloud/sort-stacks

Add stack sorting functionality
This commit is contained in:
Julius Härtl
2017-05-23 23:07:04 +02:00
committed by GitHub
9 changed files with 141 additions and 9 deletions

View File

@@ -80,6 +80,16 @@ class StackController extends Controller {
return $this->stackService->update($id, $title, $boardId, $order);
}
/**
* @NoAdminRequired
* @param $stackId
* @param $order
* @return array
*/
public function reorder($stackId, $order) {
return $this->stackService->reorder($stackId, $order);
}
/**
* @NoAdminRequired
* @param $stackId

View File

@@ -102,4 +102,29 @@ class StackService {
$stack->setOrder($order);
return $this->stackMapper->update($stack);
}
public function reorder($id, $order) {
$this->permissionService->checkPermission($this->stackMapper, $id, Acl::PERMISSION_EDIT);
$stackToSort = $this->stackMapper->find($id);
$stacks = $this->stackMapper->findAll($stackToSort->getBoardId());
$result = [];
$i = 0;
foreach ($stacks as $stack) {
if ($stack->id === $id) {
$stack->setOrder($order);
}
if ($i === $order) {
$i++;
}
if ($stack->id !== $id) {
$stack->setOrder($i++);
}
$this->stackMapper->update($stack);
$result[$stack->getOrder()] = $stack;
}
return $result;
}
}