Commit 07ca3dc4 authored by Clement Ho's avatar Clement Ho

[skip ci] refactor to only use id

parent 6da80dbd
...@@ -727,12 +727,6 @@ GitLabDropdown = (function() { ...@@ -727,12 +727,6 @@ GitLabDropdown = (function() {
$input.attr('id', this.options.inputId); $input.attr('id', this.options.inputId);
} }
if (this.options.saveUserDataToInput) {
$input.attr('data-name', selectedObject.name);
$input.attr('data-username', selectedObject.username);
$input.attr('data-avatar-url', selectedObject.avatar_url);
}
return this.dropdown.before($input); return this.dropdown.before($input);
}; };
......
/* global Flash */
import Vue from 'vue'; import Vue from 'vue';
import eventHub from './event_hub'; import eventHub from './event_hub';
...@@ -23,16 +25,11 @@ export default { ...@@ -23,16 +25,11 @@ export default {
const path = element.dataset.path; const path = element.dataset.path;
const field = element.dataset.field; const field = element.dataset.field;
const editable = element.hasAttribute('data-editable'); const editable = element.hasAttribute('data-editable');
const currentUser = { const currentUserId = parseInt(element.dataset.userId, 10);
id: parseInt(element.dataset.userId, 10),
name: element.dataset.userName,
username: element.dataset.userUserName,
avatarUrl: element.dataset.avatar_url,
};
const service = new SidebarAssigneesService(path, field); const service = new SidebarAssigneesService(path, field);
const store = new SidebarAssigneesStore({ const store = new SidebarAssigneesStore({
currentUser, currentUserId,
rootPath, rootPath,
editable, editable,
assignees: gl.sidebarAssigneesData, assignees: gl.sidebarAssigneesData,
...@@ -50,14 +47,14 @@ export default { ...@@ -50,14 +47,14 @@ export default {
}, },
created() { created() {
eventHub.$on('addCurrentUser', this.addCurrentUser); eventHub.$on('addCurrentUser', this.addCurrentUser);
eventHub.$on('addUser', this.store.addUser.bind(this.store)); eventHub.$on('addUser', this.store.addUserId.bind(this.store));
eventHub.$on('removeUser', this.store.removeUser.bind(this.store)); eventHub.$on('removeUser', this.store.removeUserId.bind(this.store));
eventHub.$on('removeAllUsers', this.store.removeAllUsers.bind(this.store)); eventHub.$on('removeAllUsers', this.store.removeAllUserIds.bind(this.store));
eventHub.$on('saveUsers', this.saveUsers); eventHub.$on('saveUsers', this.saveUsers);
}, },
methods: { methods: {
addCurrentUser() { addCurrentUser() {
this.store.addCurrentUser(); this.store.addCurrentUserId();
this.saveUsers(); this.saveUsers();
}, },
saveUsers() { saveUsers() {
...@@ -65,7 +62,7 @@ export default { ...@@ -65,7 +62,7 @@ export default {
this.service.update(this.store.getUserIds()) this.service.update(this.store.getUserIds())
.then((response) => { .then((response) => {
this.store.loading = false; this.store.loading = false;
this.store.saveUsers(response.data.assignees); this.store.setUsers(response.data.assignees);
}).catch(() => { }).catch(() => {
this.store.loading = false; this.store.loading = false;
return new Flash('An error occured while saving assignees', 'alert'); return new Flash('An error occured while saving assignees', 'alert');
...@@ -82,7 +79,7 @@ export default { ...@@ -82,7 +79,7 @@ export default {
template: ` template: `
<div> <div>
<assignee-title <assignee-title
:numberOfAssignees="store.users.length" :numberOfAssignees="store.userIds.length"
:loading="store.loading" :loading="store.loading"
:editable="store.editable" :editable="store.editable"
/> />
......
/* global Flash */
import '~/flash';
export default class SidebarAssigneesStore { export default class SidebarAssigneesStore {
constructor(store) { constructor(store) {
const { currentUser, assignees, rootPath, editable } = store; const { currentUserId, assignees, rootPath, editable } = store;
this.currentUser = currentUser; this.currentUserId = currentUserId;
this.rootPath = rootPath; this.rootPath = rootPath;
this.users = []; this.userIds = [];
this.loading = false; this.loading = false;
this.editable = editable; this.editable = editable;
assignees.forEach(a => this.addUser(this.destructUser(a))); this.setUsers(assignees);
assignees.forEach(a => this.addUserId(a.id));
} }
addUser(user) { addUserId(id) {
const { id, name, username, avatarUrl } = user; this.userIds.push(id);
this.users.push({
id,
name,
username,
avatarUrl,
});
} }
addCurrentUser() { removeUserId(id) {
this.addUser(this.currentUser); this.userIds = this.userIds.filter(uid => uid !== id);
} }
removeUser(id) { removeAllUserIds() {
this.users = this.users.filter(u => u.id !== id); this.userIds = [];
} }
removeAllUsers() { addCurrentUserId() {
this.users = []; this.addUserId(this.currentUserId);
} }
getUserIds() { getUserIds() {
const ids = this.users.map(u => u.id);
// If there are no ids, that means we have to unassign (which is id = 0) // If there are no ids, that means we have to unassign (which is id = 0)
return ids.length > 0 ? ids : [0]; return this.userIds.length > 0 ? this.userIds : [0];
}
destructUser(u) {
return {
id: u.id,
name: u.name,
username: u.username,
avatarUrl: u.avatar_url,
};
} }
saveUsers(assignees) { setUsers(users) {
this.users = []; this.users = [];
assignees.forEach(a => this.addUser(this.destructUser(a))); users.forEach((u) => {
this.users.push({
id: u.id,
name: u.name,
username: u.username,
avatarUrl: u.avatar_url,
});
});
} }
} }
...@@ -264,7 +264,6 @@ import eventHub from './sidebar_assignees/event_hub'; ...@@ -264,7 +264,6 @@ import eventHub from './sidebar_assignees/event_hub';
return $value.css('display', ''); return $value.css('display', '');
}, },
multiSelect: $dropdown.hasClass('js-multiselect'), multiSelect: $dropdown.hasClass('js-multiselect'),
saveUserDataToInput: $dropdown.hasClass('js-save-user-data'),
vue: $dropdown.hasClass('js-issue-board-sidebar'), vue: $dropdown.hasClass('js-issue-board-sidebar'),
clicked: function(user, $el, e, isMarking) { clicked: function(user, $el, e, isMarking) {
if ($dropdown.hasClass('js-multiselect')) { if ($dropdown.hasClass('js-multiselect')) {
...@@ -281,12 +280,7 @@ import eventHub from './sidebar_assignees/event_hub'; ...@@ -281,12 +280,7 @@ import eventHub from './sidebar_assignees/event_hub';
eventHub.$emit('removeAllUsers'); eventHub.$emit('removeAllUsers');
} else if (isActive) { } else if (isActive) {
// user selected // user selected
eventHub.$emit('addUser', { eventHub.$emit('addUser', user.id);
id: user.id,
name: user.name,
username: user.username,
avatarUrl: user.avatar_url
});
// 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')
......
...@@ -103,4 +103,4 @@ ...@@ -103,4 +103,4 @@
font-size: 9px; font-size: 9px;
line-height: 16px; line-height: 16px;
text-align: center; text-align: center;
} }
\ No newline at end of file
...@@ -24,12 +24,7 @@ ...@@ -24,12 +24,7 @@
= form_for [@project.namespace.becomes(Namespace), @project, issuable], remote: true, format: :json, html: { class: 'issuable-context-form inline-update js-issuable-update' } do |f| = form_for [@project.namespace.becomes(Namespace), @project, issuable], remote: true, format: :json, html: { class: 'issuable-context-form inline-update js-issuable-update' } do |f|
.block.assignee .block.assignee
- if issuable.instance_of?(Issue) - if issuable.instance_of?(Issue)
#js-vue-sidebar-assignees{ data: { path: issuable_json_path(issuable), field: "#{issuable.to_ability_name}[assignee_ids]",'editable' => can_edit_issuable ? true : false, user: { id: current_user.id }, name: current_user.name, username: current_user.username, avatar_url: current_user.avatar_url, root: { path: root_path } } } #js-vue-sidebar-assignees{ data: { path: issuable_json_path(issuable), field: "#{issuable.to_ability_name}[assignee_ids]",'editable' => can_edit_issuable ? true : false, user: { id: current_user.id }, root: { path: root_path } } }
.title.hide-collapsed
Assignee
= icon('spinner spin', class: 'block-loading', 'aria-hidden': 'true')
- if can_edit_issuable
= link_to 'Edit', '#', class: 'edit-link pull-right'
- content_for :page_specific_javascripts do - content_for :page_specific_javascripts do
= page_specific_javascript_bundle_tag('sidebar_assignees') = page_specific_javascript_bundle_tag('sidebar_assignees')
:javascript :javascript
......
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