Commit 10d74f0a authored by Clement Ho's avatar Clement Ho

[skip ci] refactor store to use one ssot for assignees

parent bde67068
...@@ -73,14 +73,14 @@ require('./sidebar/remove_issue'); ...@@ -73,14 +73,14 @@ require('./sidebar/remove_issue');
this.addUser(this.currentUser.id); this.addUser(this.currentUser.id);
this.saveUsers(); this.saveUsers();
}, },
removeUser (id) { removeUser (u) {
gl.issueBoards.BoardsStore.detail.issue.removeUserId(id); gl.issueBoards.BoardsStore.detail.issue.removeUser(u);
}, },
addUser (id) { addUser (u) {
gl.issueBoards.BoardsStore.detail.issue.addUserId(id); gl.issueBoards.BoardsStore.detail.issue.addUser(u);
}, },
removeAllUsers () { removeAllUsers () {
gl.issueBoards.BoardsStore.detail.issue.removeAllUserIds(); gl.issueBoards.BoardsStore.detail.issue.removeAllUsers();
}, },
saveUsers () { saveUsers () {
this.loadingAssignees = true; this.loadingAssignees = true;
......
...@@ -15,7 +15,6 @@ class ListIssue { ...@@ -15,7 +15,6 @@ class ListIssue {
this.subscribed = obj.subscribed; this.subscribed = obj.subscribed;
this.labels = []; this.labels = [];
this.assignees = []; this.assignees = [];
this.selectedAssigneeIds = [];
this.selected = false; this.selected = false;
this.position = obj.relative_position || Infinity; this.position = obj.relative_position || Infinity;
this.milestone_id = obj.milestone_id; this.milestone_id = obj.milestone_id;
...@@ -33,7 +32,6 @@ class ListIssue { ...@@ -33,7 +32,6 @@ class ListIssue {
processAssignees(assignees) { processAssignees(assignees) {
this.assignees = assignees.map(a => new ListUser(a)); this.assignees = assignees.map(a => new ListUser(a));
this.selectedAssigneeIds = this.assignees.map(a => a.id);
} }
addLabel (label) { addLabel (label) {
...@@ -56,18 +54,24 @@ class ListIssue { ...@@ -56,18 +54,24 @@ class ListIssue {
labels.forEach(this.removeLabel.bind(this)); labels.forEach(this.removeLabel.bind(this));
} }
addUserId (id) { addUser (user) {
if (this.selectedAssigneeIds.indexOf(id) === -1) { if (!this.findUser(user)) {
this.selectedAssigneeIds.push(id); this.assignees.push(new ListUser(user));
} }
} }
removeUserId (id) { findUser (user) {
this.selectedAssigneeIds = this.selectedAssigneeIds.filter(uid => uid !== id); return this.assignees.filter(assignee => assignee.id === user.id)[0];
} }
removeAllUserIds () { removeUser (user) {
this.selectedAssigneeIds = []; if (user) {
this.assignees = this.assignees.filter(assignee => assignee.id !== user.id);
}
}
removeAllUsers () {
this.assignees = [];
} }
getLists () { getLists () {
...@@ -79,7 +83,7 @@ class ListIssue { ...@@ -79,7 +83,7 @@ class ListIssue {
issue: { issue: {
milestone_id: this.milestone ? this.milestone.id : null, milestone_id: this.milestone ? this.milestone.id : null,
due_date: this.dueDate, due_date: this.dueDate,
assignee_ids: this.selectedAssigneeIds.length > 0 ? this.selectedAssigneeIds : [0], assignee_ids: this.assignees.length > 0 ? this.assignees.map((u) => u.id) : [0],
label_ids: this.labels.map((label) => label.id) label_ids: this.labels.map((label) => label.id)
} }
}; };
......
...@@ -290,7 +290,9 @@ import eventHub from './sidebar/event_hub'; ...@@ -290,7 +290,9 @@ import eventHub from './sidebar/event_hub';
.find(`input[name='${$dropdown.data('field-name')}'][value=${firstSelectedId}]`); .find(`input[name='${$dropdown.data('field-name')}'][value=${firstSelectedId}]`);
firstSelected.remove(); firstSelected.remove();
eventHub.$emit('sidebar.removeUser', firstSelectedId); eventHub.$emit('sidebar.removeUser', {
id: firstSelectedId,
});
} }
} }
...@@ -303,7 +305,7 @@ import eventHub from './sidebar/event_hub'; ...@@ -303,7 +305,7 @@ import eventHub from './sidebar/event_hub';
eventHub.$emit('sidebar.removeAllUsers'); eventHub.$emit('sidebar.removeAllUsers');
} else if (isActive) { } else if (isActive) {
// user selected // user selected
eventHub.$emit('sidebar.addUser', user.id); eventHub.$emit('sidebar.addUser', user);
// Remove unassigned selection (if it was previously selected) // Remove unassigned selection (if it was previously selected)
const unassignedSelected = $dropdown.closest('.selectbox') const unassignedSelected = $dropdown.closest('.selectbox')
...@@ -319,7 +321,7 @@ import eventHub from './sidebar/event_hub'; ...@@ -319,7 +321,7 @@ import eventHub from './sidebar/event_hub';
} }
// User unselected // User unselected
eventHub.$emit('sidebar.removeUser', user.id); eventHub.$emit('sidebar.removeUser', user);
} }
} }
......
.block.assignee{ ref: "assigneeBlock" } .block.assignee{ ref: "assigneeBlock" }
%template{ "v-if" => "issue.assignees"} %template{ "v-if" => "issue.assignees"}
%assignee-title{ ":number-of-assignees" => "issue.selectedAssigneeIds.length", %assignee-title{ ":number-of-assignees" => "issue.assignees.length",
":loading" => "loadingAssignees", ":loading" => "loadingAssignees",
":editable" => can?(current_user, :admin_issue, @project) } ":editable" => can?(current_user, :admin_issue, @project) }
%assignees{ class: "value", "root-path" => "#{root_url}", %assignees{ class: "value", "root-path" => "#{root_url}",
......
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