Commit 7e7673d5 authored by Phil Hughes's avatar Phil Hughes

Fixed bug when moving lists around & then deleting

parent d4387bd3
...@@ -64,9 +64,20 @@ ...@@ -64,9 +64,20 @@
group: 'boards', group: 'boards',
draggable: '.is-draggable', draggable: '.is-draggable',
handle: '.js-board-handle', handle: '.js-board-handle',
onUpdate: (e) => { onEnd: (e) => {
if (e.oldIndex !== e.newIndex) { document.body.classList.remove('is-dragging');
gl.issueBoards.BoardsStore.moveList(e.oldIndex, this.sortable.toArray());
if (e.newIndex !== undefined && e.oldIndex !== e.newIndex) {
const order = this.sortable.toArray(),
$board = this.$parent.$refs.board[e.oldIndex + 1],
list = $board.list;
$board.$destroy(true);
this.$nextTick(() => {
gl.issueBoards.BoardsStore.state.lists.splice(e.newIndex, 0, list);
gl.issueBoards.BoardsStore.moveList(list, order);
});
} }
} }
}); });
...@@ -78,11 +89,7 @@ ...@@ -78,11 +89,7 @@
this.sortable = Sortable.create(this.$el.parentNode, options); this.sortable = Sortable.create(this.$el.parentNode, options);
}, },
beforeDestroy () { beforeDestroy () {
this.list.destroy(); gl.issueBoards.BoardsStore.state.lists.$remove(this.list);
if (gl.issueBoards.BoardsStore.state.lists.length === 0) {
this.sortable.destroy();
}
} }
}); });
})(); })();
...@@ -3,13 +3,16 @@ ...@@ -3,13 +3,16 @@
window.gl.issueBoards = window.gl.issueBoards || {}; window.gl.issueBoards = window.gl.issueBoards || {};
gl.issueBoards.BoardDelete = Vue.extend({ gl.issueBoards.BoardDelete = Vue.extend({
props: {
list: Object
},
methods: { methods: {
deleteBoard (e) { deleteBoard (e) {
e.stopImmediatePropagation(); e.stopImmediatePropagation();
$(this.$el).tooltip('hide'); $(this.$el).tooltip('hide');
if (confirm('Are you sure you want to delete this list?')) { if (confirm('Are you sure you want to delete this list?')) {
this.$parent.$destroy(true); this.list.destroy();
} }
} }
} }
......
class List { class List {
constructor (obj) { constructor (obj) {
this.id = obj.id; this.id = obj.id;
this._uid = Math.ceil(Math.random() * 1000);
this.position = obj.position; this.position = obj.position;
this.title = obj.title; this.title = obj.title;
this.type = obj.list_type; this.type = obj.list_type;
......
...@@ -80,15 +80,14 @@ ...@@ -80,15 +80,14 @@
return list.id !== id; return list.id !== id;
}); });
}, },
moveList (oldIndex, orderLists) { moveList (listFrom, orderLists) {
const listFrom = this.findList('position', oldIndex);
for (let i = 0, orderLength = orderLists.length; i < orderLength; i++) { for (let i = 0, orderLength = orderLists.length; i < orderLength; i++) {
const id = parseInt(orderLists[i]), const id = parseInt(orderLists[i]),
list = this.findList('id', id); list = this.findList('id', id);
list.position = i; list.position = i;
} }
listFrom.update();
}, },
moveIssueToList (listFrom, listTo, issue) { moveIssueToList (listFrom, listTo, issue) {
const issueTo = listTo.findIssue(issue.id), const issueTo = listTo.findIssue(issue.id),
......
%board{ "inline-template" => true, %board{ "inline-template" => true,
"v-cloak" => true, "v-cloak" => true,
"v-for" => "list in state.lists | orderBy 'position'", "v-for" => "list in state.lists | orderBy 'position'",
"v-ref:board" => true,
":list" => "list", ":list" => "list",
":disabled" => "disabled", ":disabled" => "disabled",
":issue-link-base" => "issueLinkBase" } ":issue-link-base" => "issueLinkBase",
"track-by" => "_uid" }
.board{ ":class" => "{ 'is-draggable': !isPreset }", .board{ ":class" => "{ 'is-draggable': !isPreset }",
":data-id" => "list.id" } ":data-id" => "list.id" }
.board-inner .board-inner
...@@ -15,6 +17,7 @@ ...@@ -15,6 +17,7 @@
{{ list.issues.length }} {{ list.issues.length }}
- if can?(current_user, :admin_list, @project) - if can?(current_user, :admin_list, @project)
%board-delete{ "inline-template" => true, %board-delete{ "inline-template" => true,
":list" => "list",
"v-if" => "!isPreset && list.id" } "v-if" => "!isPreset && list.id" }
%button.board-delete.has-tooltip.pull-right{ type: "button", title: "Delete list", "aria-label" => "Delete list", data: { placement: "bottom" }, "@click.stop" => "deleteBoard" } %button.board-delete.has-tooltip.pull-right{ type: "button", title: "Delete list", "aria-label" => "Delete list", data: { placement: "bottom" }, "@click.stop" => "deleteBoard" }
= icon("trash") = icon("trash")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment