Merge pull request #191 from taigaio/bug/1714/ordering-tasks
fix #1714 - bulk resort tasks in the taskboardstable
commit
7f4b66f9eb
|
@ -42,6 +42,7 @@ urls = {
|
||||||
"userstories-restore": "/userstories/%s/restore"
|
"userstories-restore": "/userstories/%s/restore"
|
||||||
"tasks": "/tasks"
|
"tasks": "/tasks"
|
||||||
"bulk-create-tasks": "/tasks/bulk_create"
|
"bulk-create-tasks": "/tasks/bulk_create"
|
||||||
|
"bulk-update-task-taskboard-order": "/tasks/bulk_update_taskboard_order"
|
||||||
"tasks-restore": "/tasks/%s/restore"
|
"tasks-restore": "/tasks/%s/restore"
|
||||||
"issues": "/issues"
|
"issues": "/issues"
|
||||||
"bulk-create-issues": "/issues/bulk_create"
|
"bulk-create-issues": "/issues/bulk_create"
|
||||||
|
|
|
@ -46,6 +46,11 @@ resourceProvider = ($repo, $http, $urls, $storage) ->
|
||||||
return $http.post(url, params).then (result) ->
|
return $http.post(url, params).then (result) ->
|
||||||
return result.data
|
return result.data
|
||||||
|
|
||||||
|
service.bulkUpdateTaskTaskboardOrder = (projectId, data) ->
|
||||||
|
url = $urls.resolve("bulk-update-task-taskboard-order")
|
||||||
|
params = {project_id: projectId, bulk_tasks: data}
|
||||||
|
return $http.post(url, params)
|
||||||
|
|
||||||
service.listValues = (projectId, type) ->
|
service.listValues = (projectId, type) ->
|
||||||
params = {"project": projectId}
|
params = {"project": projectId}
|
||||||
return $repo.queryMany(type, params)
|
return $repo.queryMany(type, params)
|
||||||
|
|
|
@ -184,21 +184,44 @@ class TaskboardController extends mixOf(taiga.Controller, taiga.PageMixin)
|
||||||
.then(=> @.loadUsersAndRoles())
|
.then(=> @.loadUsersAndRoles())
|
||||||
.then(=> @.loadTaskboard())
|
.then(=> @.loadTaskboard())
|
||||||
|
|
||||||
|
refreshTasksOrder: (tasks) ->
|
||||||
|
items = @.resortTasks(tasks)
|
||||||
|
data = @.prepareBulkUpdateData(items)
|
||||||
|
|
||||||
|
return @rs.tasks.bulkUpdateTaskTaskboardOrder(@scope.project.id, data)
|
||||||
|
|
||||||
|
resortTasks: (tasks) ->
|
||||||
|
items = []
|
||||||
|
|
||||||
|
for item, index in tasks
|
||||||
|
item["taskboard_order"] = index
|
||||||
|
if item.isModified()
|
||||||
|
items.push(item)
|
||||||
|
|
||||||
|
return items
|
||||||
|
|
||||||
|
prepareBulkUpdateData: (uses) ->
|
||||||
|
return _.map(uses, (x) -> {"task_id": x.id, "order": x["taskboard_order"]})
|
||||||
|
|
||||||
taskMove: (ctx, task, usId, statusId, order) ->
|
taskMove: (ctx, task, usId, statusId, order) ->
|
||||||
# Remove task from old position
|
# Remove task from old position
|
||||||
r = @scope.usTasks[task.user_story][task.status].indexOf(task)
|
r = @scope.usTasks[task.user_story][task.status].indexOf(task)
|
||||||
@scope.usTasks[task.user_story][task.status].splice(r, 1)
|
@scope.usTasks[task.user_story][task.status].splice(r, 1)
|
||||||
|
|
||||||
# Add task to new position
|
# Add task to new position
|
||||||
@scope.usTasks[usId][statusId].splice(order, 0, task)
|
tasks = @scope.usTasks[usId][statusId]
|
||||||
|
tasks.splice(order, 0, task)
|
||||||
|
|
||||||
task.user_story = usId
|
task.user_story = usId
|
||||||
task.status = statusId
|
task.status = statusId
|
||||||
task.taskboard_order = order
|
task.taskboard_order = order
|
||||||
|
|
||||||
promise = @repo.save(task)
|
promise = @repo.save(task)
|
||||||
|
|
||||||
promise.then =>
|
promise.then =>
|
||||||
|
@.refreshTasksOrder(tasks)
|
||||||
@.loadSprintStats()
|
@.loadSprintStats()
|
||||||
|
|
||||||
promise.then null, =>
|
promise.then null, =>
|
||||||
console.log "FAIL TASK SAVE"
|
console.log "FAIL TASK SAVE"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue