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