Commit d4387bd3 authored by Phil Hughes's avatar Phil Hughes

Fixed removing items from list

parent 299cb77c
...@@ -64,8 +64,10 @@ ...@@ -64,8 +64,10 @@
group: 'boards', group: 'boards',
draggable: '.is-draggable', draggable: '.is-draggable',
handle: '.js-board-handle', handle: '.js-board-handle',
onUpdate (e) { onUpdate: (e) => {
gl.issueBoards.BoardsStore.moveList(e.oldIndex, e.newIndex); if (e.oldIndex !== e.newIndex) {
gl.issueBoards.BoardsStore.moveList(e.oldIndex, this.sortable.toArray());
}
} }
}); });
...@@ -76,7 +78,11 @@ ...@@ -76,7 +78,11 @@
this.sortable = Sortable.create(this.$el.parentNode, options); this.sortable = Sortable.create(this.$el.parentNode, options);
}, },
beforeDestroy () { beforeDestroy () {
this.sortable.destroy(); this.list.destroy();
if (gl.issueBoards.BoardsStore.state.lists.length === 0) {
this.sortable.destroy();
}
} }
}); });
})(); })();
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
list: Object, list: Object,
issue: Object, issue: Object,
issueLinkBase: String, issueLinkBase: String,
disabled: Boolean disabled: Boolean,
index: Number
}, },
methods: { methods: {
filterByLabel (label, e) { filterByLabel (label, e) {
......
...@@ -3,16 +3,13 @@ ...@@ -3,16 +3,13 @@
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.list.destroy(); this.$parent.$destroy(true);
} }
} }
} }
......
...@@ -56,16 +56,28 @@ ...@@ -56,16 +56,28 @@
group: 'issues', group: 'issues',
sort: false, sort: false,
disabled: this.disabled, disabled: this.disabled,
onAdd (e) { onStart: (e) => {
const card = this.$refs.issue[e.oldIndex];
gl.issueBoards.BoardsStore.moving.issue = card.issue;
gl.issueBoards.BoardsStore.moving.list = card.list;
},
onAdd: (e) => {
const card = e.item,
fromList = gl.issueBoards.BoardsStore.moving.list,
issue = gl.issueBoards.BoardsStore.moving.issue;
gl.issueBoards.BoardsStore.moveIssueToList(fromList, this.list, issue);
},
onRemove (e) {
const card = e.item, const card = e.item,
fromListId = parseInt(e.from.getAttribute('data-board')), list = gl.issueBoards.BoardsStore.moving.list,
toListId = parseInt(e.to.getAttribute('data-board')), issue = gl.issueBoards.BoardsStore.moving.issue;
issueId = parseInt(card.getAttribute('data-issue'));
// Remove the new dom element & let vue add the element // Remove the new dom element & let vue add the element
card.parentNode.removeChild(card); card.parentNode.removeChild(card);
gl.issueBoards.BoardsStore.moveCardToList(fromListId, toListId, issueId); list.removeIssue(issue);
} }
}); });
......
...@@ -38,7 +38,7 @@ $(() => { ...@@ -38,7 +38,7 @@ $(() => {
if (!gl.issueBoards.BoardsStore.findList('title', label.title)) { if (!gl.issueBoards.BoardsStore.findList('title', label.title)) {
gl.issueBoards.BoardsStore.new({ gl.issueBoards.BoardsStore.new({
title: label.title, title: label.title,
position: gl.issueBoards.BoardsStore.state.lists.length - 1, position: gl.issueBoards.BoardsStore.state.lists.length - 2,
list_type: 'label', list_type: 'label',
label: { label: {
id: label.id, id: label.id,
......
...@@ -34,9 +34,7 @@ class List { ...@@ -34,9 +34,7 @@ class List {
destroy () { destroy () {
if (this.type !== 'blank') { if (this.type !== 'blank') {
gl.issueBoards.BoardsStore.state.lists = gl.issueBoards.BoardsStore.state.lists.filter((list) => { gl.issueBoards.BoardsStore.state.lists.$remove(this);
return list.id !== this.id;
});
gl.issueBoards.BoardsStore.updateNewListDropdown(this.id); gl.issueBoards.BoardsStore.updateNewListDropdown(this.id);
gl.boardService.destroyList(this.id); gl.boardService.destroyList(this.id);
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
gl.issueBoards.BoardsStore = { gl.issueBoards.BoardsStore = {
disabled: false, disabled: false,
state: {}, state: {},
moving: {
issue: {},
list: {}
},
create () { create () {
this.state.lists = []; this.state.lists = [];
this.state.filters = { this.state.filters = {
...@@ -76,31 +80,21 @@ ...@@ -76,31 +80,21 @@
return list.id !== id; return list.id !== id;
}); });
}, },
moveList (oldIndex, newIndex) { moveList (oldIndex, orderLists) {
if (oldIndex === newIndex) return; const listFrom = this.findList('position', oldIndex);
const listFrom = this.findList('position', oldIndex), for (let i = 0, orderLength = orderLists.length; i < orderLength; i++) {
listTo = this.findList('position', newIndex); const id = parseInt(orderLists[i]),
list = this.findList('id', id);
listFrom.position = newIndex; list.position = i;
if (newIndex === listTo.position) {
listTo.position = oldIndex;
} else if (newIndex > listTo.position) {
listTo.position--;
} else {
listTo.position++;
} }
listFrom.update();
}, },
moveCardToList (listFromId, listToId, issueId) { moveIssueToList (listFrom, listTo, issue) {
const listFrom = this.findList('id', listFromId, false), const issueTo = listTo.findIssue(issue.id),
listTo = this.findList('id', listToId, false),
issueTo = listTo.findIssue(issueId),
issue = listFrom.findIssue(issueId),
issueLists = issue.getLists(), issueLists = issue.getLists(),
listLabels = issueLists.map((issue) => { listLabels = issueLists.map((listIssue) => {
return issue.label; return listIssue.label;
}); });
// Add to new lists issues if it doesn't already exist // Add to new lists issues if it doesn't already exist
...@@ -114,8 +108,6 @@ ...@@ -114,8 +108,6 @@
list.removeIssue(issue); list.removeIssue(issue);
} }
issue.removeLabels(listLabels); issue.removeLabels(listLabels);
} else {
listFrom.removeIssue(issue);
} }
}, },
findList (key, val, type = 'label') { findList (key, val, type = 'label') {
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
":list" => "list", ":list" => "list",
":disabled" => "disabled", ":disabled" => "disabled",
":issue-link-base" => "issueLinkBase" } ":issue-link-base" => "issueLinkBase" }
.board{ ":class" => "{ 'is-draggable': !isPreset }" } .board{ ":class" => "{ 'is-draggable': !isPreset }",
":data-id" => "list.id" }
.board-inner .board-inner
%header.board-header{ ":class" => "{ 'has-border': list.label }", ":style" => "{ borderTopColor: (list.label ? list.label.color : null) }" } %header.board-header{ ":class" => "{ 'has-border': list.label }", ":style" => "{ borderTopColor: (list.label ? list.label.color : null) }" }
%h3.board-title.js-board-handle{ ":class" => "{ 'user-can-drag': (!disabled && !isPreset) }" } %h3.board-title.js-board-handle{ ":class" => "{ 'user-can-drag': (!disabled && !isPreset) }" }
...@@ -14,8 +15,7 @@ ...@@ -14,8 +15,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,
"v-if" => "!isPreset", "v-if" => "!isPreset && list.id" }
":list" => "list" }
%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")
= icon("spinner spin", class: "board-header-loading-spinner pull-right", "v-show" => "list.loadingMore") = icon("spinner spin", class: "board-header-loading-spinner pull-right", "v-show" => "list.loadingMore")
......
%board-card{ "inline-template" => true, %board-card{ "inline-template" => true,
"v-for" => "issue in issues | orderBy 'priority'", "v-for" => "issue in issues | orderBy 'priority'",
"v-ref:issue" => true,
":index" => "$index",
":list" => "list", ":list" => "list",
":issue" => "issue", ":issue" => "issue",
":issue-link-base" => "issueLinkBase", ":issue-link-base" => "issueLinkBase",
":disabled" => "disabled", ":disabled" => "disabled",
"track-by" => "id" } "track-by" => "id" }
%li.card{ ":data-issue" => "issue.id", %li.card{ ":class" => "{ 'user-can-drag': !disabled }",
":class" => "{ 'user-can-drag': !disabled }" } ":index" => "index" }
= icon("align-justify", class: "board-mobile-handle js-card-drag-handle", "v-if" => "!disabled") = icon("align-justify", class: "board-mobile-handle js-card-drag-handle", "v-if" => "!disabled")
%h4.card-title %h4.card-title
= icon("eye-slash", class: "confidential-icon", "v-if" => "issue.confidential") = icon("eye-slash", class: "confidential-icon", "v-if" => "issue.confidential")
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
- if show_boards_content - if show_boards_content
.issue-board-dropdown-content .issue-board-dropdown-content
%p %p
Add a list to issue boards by selecting a label below. The list will automatically be populated with issues that have that label. To create a list for a label that doesn't exist yet, simply create the label below. Each label that exists in your issue tracker can have its own dedicated list. Select a label below to add a list to your Board and it will automatically be populated with issues that have that label. To create a list for a label that doesn't exist yet, simply create the label below.
= dropdown_filter(filter_placeholder) = dropdown_filter(filter_placeholder)
= dropdown_content = dropdown_content
- if @project && show_footer - if @project && show_footer
......
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
expect(list.issues.length).toBe(1); expect(list.issues.length).toBe(1);
expect(listTwo.issues.length).toBe(1); expect(listTwo.issues.length).toBe(1);
gl.issueBoards.BoardsStore.moveCardToList(1, 2, 1); gl.issueBoards.BoardsStore.moveIssueToList(1, 2, 1);
expect(list.issues.length).toBe(0); expect(list.issues.length).toBe(0);
expect(listTwo.issues.length).toBe(1); expect(listTwo.issues.length).toBe(1);
......
This diff is collapsed.
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