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() {
$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);
};
......
/* global Flash */
import Vue from 'vue';
import eventHub from './event_hub';
......@@ -23,16 +25,11 @@ export default {
const path = element.dataset.path;
const field = element.dataset.field;
const editable = element.hasAttribute('data-editable');
const currentUser = {
id: parseInt(element.dataset.userId, 10),
name: element.dataset.userName,
username: element.dataset.userUserName,
avatarUrl: element.dataset.avatar_url,
};
const currentUserId = parseInt(element.dataset.userId, 10);
const service = new SidebarAssigneesService(path, field);
const store = new SidebarAssigneesStore({
currentUser,
currentUserId,
rootPath,
editable,
assignees: gl.sidebarAssigneesData,
......@@ -50,14 +47,14 @@ export default {
},
created() {
eventHub.$on('addCurrentUser', this.addCurrentUser);
eventHub.$on('addUser', this.store.addUser.bind(this.store));
eventHub.$on('removeUser', this.store.removeUser.bind(this.store));
eventHub.$on('removeAllUsers', this.store.removeAllUsers.bind(this.store));
eventHub.$on('addUser', this.store.addUserId.bind(this.store));
eventHub.$on('removeUser', this.store.removeUserId.bind(this.store));
eventHub.$on('removeAllUsers', this.store.removeAllUserIds.bind(this.store));
eventHub.$on('saveUsers', this.saveUsers);
},
methods: {
addCurrentUser() {
this.store.addCurrentUser();
this.store.addCurrentUserId();
this.saveUsers();
},
saveUsers() {
......@@ -65,7 +62,7 @@ export default {
this.service.update(this.store.getUserIds())
.then((response) => {
this.store.loading = false;
this.store.saveUsers(response.data.assignees);
this.store.setUsers(response.data.assignees);
}).catch(() => {
this.store.loading = false;
return new Flash('An error occured while saving assignees', 'alert');
......@@ -82,7 +79,7 @@ export default {
template: `
<div>
<assignee-title
:numberOfAssignees="store.users.length"
:numberOfAssignees="store.userIds.length"
:loading="store.loading"
:editable="store.editable"
/>
......
/* global Flash */
import '~/flash';
export default class SidebarAssigneesStore {
constructor(store) {
const { currentUser, assignees, rootPath, editable } = store;
const { currentUserId, assignees, rootPath, editable } = store;
this.currentUser = currentUser;
this.currentUserId = currentUserId;
this.rootPath = rootPath;
this.users = [];
this.userIds = [];
this.loading = false;
this.editable = editable;
assignees.forEach(a => this.addUser(this.destructUser(a)));
this.setUsers(assignees);
assignees.forEach(a => this.addUserId(a.id));
}
addUser(user) {
const { id, name, username, avatarUrl } = user;
this.users.push({
id,
name,
username,
avatarUrl,
});
addUserId(id) {
this.userIds.push(id);
}
addCurrentUser() {
this.addUser(this.currentUser);
removeUserId(id) {
this.userIds = this.userIds.filter(uid => uid !== id);
}
removeUser(id) {
this.users = this.users.filter(u => u.id !== id);
removeAllUserIds() {
this.userIds = [];
}
removeAllUsers() {
this.users = [];
addCurrentUserId() {
this.addUserId(this.currentUserId);
}
getUserIds() {
const ids = this.users.map(u => u.id);
// If there are no ids, that means we have to unassign (which is id = 0)
return ids.length > 0 ? ids : [0];
}
destructUser(u) {
return {
id: u.id,
name: u.name,
username: u.username,
avatarUrl: u.avatar_url,
};
return this.userIds.length > 0 ? this.userIds : [0];
}
saveUsers(assignees) {
setUsers(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';
return $value.css('display', '');
},
multiSelect: $dropdown.hasClass('js-multiselect'),
saveUserDataToInput: $dropdown.hasClass('js-save-user-data'),
vue: $dropdown.hasClass('js-issue-board-sidebar'),
clicked: function(user, $el, e, isMarking) {
if ($dropdown.hasClass('js-multiselect')) {
......@@ -281,12 +280,7 @@ import eventHub from './sidebar_assignees/event_hub';
eventHub.$emit('removeAllUsers');
} else if (isActive) {
// user selected
eventHub.$emit('addUser', {
id: user.id,
name: user.name,
username: user.username,
avatarUrl: user.avatar_url
});
eventHub.$emit('addUser', user.id);
// Remove unassigned selection (if it was previously selected)
const unassignedSelected = $dropdown.closest('.selectbox')
......
......@@ -103,4 +103,4 @@
font-size: 9px;
line-height: 16px;
text-align: center;
}
\ No newline at end of file
}
......@@ -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|
.block.assignee
- 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 } } }
.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'
#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 } } }
- content_for :page_specific_javascripts do
= page_specific_javascript_bundle_tag('sidebar_assignees')
: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