Commit 84f53f64 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch '38869-milestone-select' into 'master'

Resolve "Webpack Roadmap"

Closes #38869

See merge request gitlab-org/gitlab-ce!16076
parents eb400b5e bcd00c85
/* eslint-disable comma-dangle, space-before-function-paren, no-new */ /* eslint-disable comma-dangle, space-before-function-paren, no-new */
/* global MilestoneSelect */
import Vue from 'vue'; import Vue from 'vue';
import Flash from '../../flash'; import Flash from '../../flash';
...@@ -12,6 +11,7 @@ import './sidebar/remove_issue'; ...@@ -12,6 +11,7 @@ import './sidebar/remove_issue';
import IssuableContext from '../../issuable_context'; import IssuableContext from '../../issuable_context';
import LabelsSelect from '../../labels_select'; import LabelsSelect from '../../labels_select';
import subscriptions from '../../sidebar/components/subscriptions/subscriptions.vue'; import subscriptions from '../../sidebar/components/subscriptions/subscriptions.vue';
import MilestoneSelect from '../../milestone_select';
const Store = gl.issueBoards.BoardsStore; const Store = gl.issueBoards.BoardsStore;
......
...@@ -5,7 +5,7 @@ import IssuableIndex from './issuable_index'; ...@@ -5,7 +5,7 @@ import IssuableIndex from './issuable_index';
import Milestone from './milestone'; import Milestone from './milestone';
import IssuableForm from './issuable_form'; import IssuableForm from './issuable_form';
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
/* global MilestoneSelect */ import MilestoneSelect from './milestone_select';
import NewBranchForm from './new_branch_form'; import NewBranchForm from './new_branch_form';
import NotificationsForm from './notifications_form'; import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown'; import notificationsDropdown from './notifications_dropdown';
......
/* eslint-disable no-new */ /* eslint-disable no-new */
/* global MilestoneSelect */
import MilestoneSelect from './milestone_select';
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
import IssuableContext from './issuable_context'; import IssuableContext from './issuable_context';
import Sidebar from './right_sidebar'; import Sidebar from './right_sidebar';
......
/* eslint-disable no-new */ /* eslint-disable no-new */
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
/* global MilestoneSelect */
import subscriptionSelect from './subscription_select'; import subscriptionSelect from './subscription_select';
import UsersSelect from './users_select'; import UsersSelect from './users_select';
import issueStatusSelect from './issue_status_select'; import issueStatusSelect from './issue_status_select';
import MilestoneSelect from './milestone_select';
export default () => { export default () => {
new UsersSelect(); new UsersSelect();
......
/* eslint-disable class-methods-use-this, no-new */ /* eslint-disable class-methods-use-this, no-new */
/* global MilestoneSelect */
import IssuableBulkUpdateActions from './issuable_bulk_update_actions'; import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
import './milestone_select'; import MilestoneSelect from './milestone_select';
import issueStatusSelect from './issue_status_select'; import issueStatusSelect from './issue_status_select';
import subscriptionSelect from './subscription_select'; import subscriptionSelect from './subscription_select';
import LabelsSelect from './labels_select'; import LabelsSelect from './labels_select';
......
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, no-underscore-dangle, prefer-arrow-callback, max-len, one-var, one-var-declaration-per-line, no-unused-vars, object-shorthand, comma-dangle, no-else-return, no-self-compare, consistent-return, no-param-reassign, no-shadow */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-underscore-dangle, prefer-arrow-callback, max-len, one-var, one-var-declaration-per-line, no-unused-vars, object-shorthand, comma-dangle, no-else-return, no-self-compare, consistent-return, no-param-reassign, no-shadow */
/* global Issuable */ /* global Issuable */
/* global ListMilestone */ /* global ListMilestone */
import _ from 'underscore'; import _ from 'underscore';
import { timeFor } from './lib/utils/datetime_utility'; import { timeFor } from './lib/utils/datetime_utility';
(function() { export default class MilestoneSelect {
this.MilestoneSelect = (function() { constructor(currentProject, els, options = {}) {
function MilestoneSelect(currentProject, els, options = {}) { if (currentProject !== null) {
var _this, $els; this.currentProject = typeof currentProject === 'string' ? JSON.parse(currentProject) : currentProject;
if (currentProject != null) { }
_this = this;
this.currentProject = typeof currentProject === 'string' ? JSON.parse(currentProject) : currentProject;
}
$els = $(els); this.init(els, options);
}
if (!els) { init(els, options) {
$els = $('.js-milestone-select'); let $els = $(els);
}
$els.each(function(i, dropdown) { if (!els) {
var $block, $dropdown, $loading, $selectbox, $sidebarCollapsedValue, $value, abilityName, collapsedSidebarLabelTemplate, defaultLabel, defaultNo, issuableId, issueUpdateURL, milestoneLinkNoneTemplate, milestoneLinkTemplate, milestonesUrl, projectId, selectedMilestone, selectedMilestoneDefault, showAny, showNo, showUpcoming, showStarted, useId, showMenuAbove; $els = $('.js-milestone-select');
$dropdown = $(dropdown); }
projectId = $dropdown.data('project-id');
milestonesUrl = $dropdown.data('milestones');
issueUpdateURL = $dropdown.data('issueUpdate');
showNo = $dropdown.data('show-no');
showAny = $dropdown.data('show-any');
showMenuAbove = $dropdown.data('showMenuAbove');
showUpcoming = $dropdown.data('show-upcoming');
showStarted = $dropdown.data('show-started');
useId = $dropdown.data('use-id');
defaultLabel = $dropdown.data('default-label');
defaultNo = $dropdown.data('default-no');
issuableId = $dropdown.data('issuable-id');
abilityName = $dropdown.data('ability-name');
$selectbox = $dropdown.closest('.selectbox');
$block = $selectbox.closest('.block');
$sidebarCollapsedValue = $block.find('.sidebar-collapsed-icon');
$value = $block.find('.value');
$loading = $block.find('.block-loading').fadeOut();
selectedMilestoneDefault = (showAny ? '' : null);
selectedMilestoneDefault = (showNo && defaultNo ? 'No Milestone' : selectedMilestoneDefault);
selectedMilestone = $dropdown.data('selected') || selectedMilestoneDefault;
if (issueUpdateURL) {
milestoneLinkTemplate = _.template('<a href="/<%- full_path %>/milestones/<%- iid %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>');
milestoneLinkNoneTemplate = '<span class="no-value">None</span>';
collapsedSidebarLabelTemplate = _.template('<span class="has-tooltip" data-container="body" title="<%- name %><br /><%- remaining %>" data-placement="left" data-html="true"> <%- title %> </span>');
}
return $dropdown.glDropdown({
showMenuAbove: showMenuAbove,
data: function(term, callback) {
return $.ajax({
url: milestonesUrl
}).done(function(data) {
var extraOptions = [];
if (showAny) {
extraOptions.push({
id: 0,
name: '',
title: 'Any Milestone'
});
}
if (showNo) {
extraOptions.push({
id: -1,
name: 'No Milestone',
title: 'No Milestone'
});
}
if (showUpcoming) {
extraOptions.push({
id: -2,
name: '#upcoming',
title: 'Upcoming'
});
}
if (showStarted) {
extraOptions.push({
id: -3,
name: '#started',
title: 'Started'
});
}
if (extraOptions.length) {
extraOptions.push('divider');
}
callback(extraOptions.concat(data)); $els.each((i, dropdown) => {
if (showMenuAbove) { let collapsedSidebarLabelTemplate, milestoneLinkNoneTemplate, milestoneLinkTemplate, selectedMilestone, selectedMilestoneDefault;
$dropdown.data('glDropdown').positionMenuAbove(); const $dropdown = $(dropdown);
} const projectId = $dropdown.data('project-id');
$(`[data-milestone-id="${selectedMilestone}"] > a`).addClass('is-active'); const milestonesUrl = $dropdown.data('milestones');
}); const issueUpdateURL = $dropdown.data('issueUpdate');
}, const showNo = $dropdown.data('show-no');
renderRow: function(milestone) { const showAny = $dropdown.data('show-any');
return ` const showMenuAbove = $dropdown.data('showMenuAbove');
<li data-milestone-id="${milestone.name}"> const showUpcoming = $dropdown.data('show-upcoming');
<a href='#' class='dropdown-menu-milestone-link'> const showStarted = $dropdown.data('show-started');
${_.escape(milestone.title)} const useId = $dropdown.data('use-id');
</a> const defaultLabel = $dropdown.data('default-label');
</li> const defaultNo = $dropdown.data('default-no');
`; const issuableId = $dropdown.data('issuable-id');
}, const abilityName = $dropdown.data('ability-name');
filterable: true, const $selectBox = $dropdown.closest('.selectbox');
search: { const $block = $selectBox.closest('.block');
fields: ['title'] const $sidebarCollapsedValue = $block.find('.sidebar-collapsed-icon');
}, const $value = $block.find('.value');
selectable: true, const $loading = $block.find('.block-loading').fadeOut();
toggleLabel: function(selected, el, e) { selectedMilestoneDefault = (showAny ? '' : null);
if (selected && 'id' in selected && $(el).hasClass('is-active')) { selectedMilestoneDefault = (showNo && defaultNo ? 'No Milestone' : selectedMilestoneDefault);
return selected.title; selectedMilestone = $dropdown.data('selected') || selectedMilestoneDefault;
} else {
return defaultLabel;
}
},
defaultLabel: defaultLabel,
fieldName: $dropdown.data('field-name'),
text: function(milestone) {
return _.escape(milestone.title);
},
id: function(milestone) {
if (!useId && !$dropdown.is('.js-issuable-form-dropdown')) {
return milestone.name;
} else {
return milestone.id;
}
},
isSelected: function(milestone) {
return milestone.name === selectedMilestone;
},
hidden: function() {
$selectbox.hide();
// display:block overrides the hide-collapse rule
return $value.css('display', '');
},
opened: function(e) {
const $el = $(e.currentTarget);
if ($dropdown.hasClass('js-issue-board-sidebar') || options.handleClick) {
selectedMilestone = $dropdown[0].dataset.selected || selectedMilestoneDefault;
}
$('a.is-active', $el).removeClass('is-active');
$(`[data-milestone-id="${selectedMilestone}"] > a`, $el).addClass('is-active');
},
vue: $dropdown.hasClass('js-issue-board-sidebar'),
clicked: function(clickEvent) {
const { $el, e } = clickEvent;
let selected = clickEvent.selectedObj;
var data, isIssueIndex, isMRIndex, isSelecting, page, boardsStore; if (issueUpdateURL) {
if (!selected) return; milestoneLinkTemplate = _.template('<a href="/<%- full_path %>/milestones/<%- iid %>" class="bold has-tooltip" data-container="body" title="<%- remaining %>"><%- title %></a>');
milestoneLinkNoneTemplate = '<span class="no-value">None</span>';
collapsedSidebarLabelTemplate = _.template('<span class="has-tooltip" data-container="body" title="<%- name %><br /><%- remaining %>" data-placement="left" data-html="true"> <%- title %> </span>');
}
return $dropdown.glDropdown({
showMenuAbove: showMenuAbove,
data: (term, callback) => $.ajax({
url: milestonesUrl
}).done((data) => {
const extraOptions = [];
if (showAny) {
extraOptions.push({
id: 0,
name: '',
title: 'Any Milestone'
});
}
if (showNo) {
extraOptions.push({
id: -1,
name: 'No Milestone',
title: 'No Milestone'
});
}
if (showUpcoming) {
extraOptions.push({
id: -2,
name: '#upcoming',
title: 'Upcoming'
});
}
if (showStarted) {
extraOptions.push({
id: -3,
name: '#started',
title: 'Started'
});
}
if (extraOptions.length) {
extraOptions.push('divider');
}
if (options.handleClick) { callback(extraOptions.concat(data));
e.preventDefault(); if (showMenuAbove) {
options.handleClick(selected); $dropdown.data('glDropdown').positionMenuAbove();
return; }
} $(`[data-milestone-id="${selectedMilestone}"] > a`).addClass('is-active');
}),
renderRow: milestone => `
<li data-milestone-id="${milestone.name}">
<a href='#' class='dropdown-menu-milestone-link'>
${_.escape(milestone.title)}
</a>
</li>
`,
filterable: true,
search: {
fields: ['title']
},
selectable: true,
toggleLabel: (selected, el, e) => {
if (selected && 'id' in selected && $(el).hasClass('is-active')) {
return selected.title;
} else {
return defaultLabel;
}
},
defaultLabel: defaultLabel,
fieldName: $dropdown.data('field-name'),
text: milestone => _.escape(milestone.title),
id: (milestone) => {
if (!useId && !$dropdown.is('.js-issuable-form-dropdown')) {
return milestone.name;
} else {
return milestone.id;
}
},
isSelected: milestone => milestone.name === selectedMilestone,
hidden: () => {
$selectBox.hide();
// display:block overrides the hide-collapse rule
return $value.css('display', '');
},
opened: (e) => {
const $el = $(e.currentTarget);
if ($dropdown.hasClass('js-issue-board-sidebar') || options.handleClick) {
selectedMilestone = $dropdown[0].dataset.selected || selectedMilestoneDefault;
}
$('a.is-active', $el).removeClass('is-active');
$(`[data-milestone-id="${selectedMilestone}"] > a`, $el).addClass('is-active');
},
vue: $dropdown.hasClass('js-issue-board-sidebar'),
clicked: (clickEvent) => {
const { $el, e } = clickEvent;
let selected = clickEvent.selectedObj;
page = $('body').attr('data-page'); let data, boardsStore;
isIssueIndex = page === 'projects:issues:index'; if (!selected) return;
isMRIndex = (page === page && page === 'projects:merge_requests:index');
isSelecting = (selected.name !== selectedMilestone);
selectedMilestone = isSelecting ? selected.name : selectedMilestoneDefault;
if ($dropdown.hasClass('js-filter-bulk-update') || $dropdown.hasClass('js-issuable-form-dropdown')) {
e.preventDefault();
return;
}
if ($dropdown.closest('.add-issues-modal').length) { if (options.handleClick) {
boardsStore = gl.issueBoards.ModalStore.store.filter; e.preventDefault();
} options.handleClick(selected);
return;
}
if (boardsStore) { const page = $('body').attr('data-page');
boardsStore[$dropdown.data('field-name')] = selected.name; const isIssueIndex = page === 'projects:issues:index';
e.preventDefault(); const isMRIndex = (page === page && page === 'projects:merge_requests:index');
} else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) { const isSelecting = (selected.name !== selectedMilestone);
return Issuable.filterResults($dropdown.closest('form')); selectedMilestone = isSelecting ? selected.name : selectedMilestoneDefault;
} else if ($dropdown.hasClass('js-filter-submit')) { if ($dropdown.hasClass('js-filter-bulk-update') || $dropdown.hasClass('js-issuable-form-dropdown')) {
return $dropdown.closest('form').submit(); e.preventDefault();
} else if ($dropdown.hasClass('js-issue-board-sidebar')) { return;
if (selected.id !== -1 && isSelecting) { }
gl.issueBoards.boardStoreIssueSet('milestone', new ListMilestone({
id: selected.id,
title: selected.name
}));
} else {
gl.issueBoards.boardStoreIssueDelete('milestone');
}
$dropdown.trigger('loading.gl.dropdown'); if ($dropdown.closest('.add-issues-modal').length) {
$loading.removeClass('hidden').fadeIn(); boardsStore = gl.issueBoards.ModalStore.store.filter;
}
gl.issueBoards.BoardsStore.detail.issue.update($dropdown.attr('data-issue-update')) if (boardsStore) {
.then(function () { boardsStore[$dropdown.data('field-name')] = selected.name;
$dropdown.trigger('loaded.gl.dropdown'); e.preventDefault();
$loading.fadeOut(); } else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
}) return Issuable.filterResults($dropdown.closest('form'));
.catch(() => { } else if ($dropdown.hasClass('js-filter-submit')) {
$loading.fadeOut(); return $dropdown.closest('form').submit();
}); } else if ($dropdown.hasClass('js-issue-board-sidebar')) {
if (selected.id !== -1 && isSelecting) {
gl.issueBoards.boardStoreIssueSet('milestone', new ListMilestone({
id: selected.id,
title: selected.name
}));
} else { } else {
selected = $selectbox.find('input[type="hidden"]').val(); gl.issueBoards.boardStoreIssueDelete('milestone');
data = {}; }
data[abilityName] = {};
data[abilityName].milestone_id = selected != null ? selected : null; $dropdown.trigger('loading.gl.dropdown');
$loading.removeClass('hidden').fadeIn(); $loading.removeClass('hidden').fadeIn();
$dropdown.trigger('loading.gl.dropdown');
return $.ajax({ gl.issueBoards.BoardsStore.detail.issue.update($dropdown.attr('data-issue-update'))
type: 'PUT', .then(() => {
url: issueUpdateURL,
data: data
}).done(function(data) {
$dropdown.trigger('loaded.gl.dropdown'); $dropdown.trigger('loaded.gl.dropdown');
$loading.fadeOut(); $loading.fadeOut();
$selectbox.hide(); })
$value.css('display', ''); .catch(() => {
if (data.milestone != null) { $loading.fadeOut();
data.milestone.full_path = _this.currentProject.full_path;
data.milestone.remaining = timeFor(data.milestone.due_date);
data.milestone.name = data.milestone.title;
$value.html(milestoneLinkTemplate(data.milestone));
return $sidebarCollapsedValue.find('span').html(collapsedSidebarLabelTemplate(data.milestone));
} else {
$value.html(milestoneLinkNoneTemplate);
return $sidebarCollapsedValue.find('span').text('No');
}
}); });
} } else {
selected = $selectBox.find('input[type="hidden"]').val();
data = {};
data[abilityName] = {};
data[abilityName].milestone_id = selected != null ? selected : null;
$loading.removeClass('hidden').fadeIn();
$dropdown.trigger('loading.gl.dropdown');
return $.ajax({
type: 'PUT',
url: issueUpdateURL,
data: data
}).done((data) => {
$dropdown.trigger('loaded.gl.dropdown');
$loading.fadeOut();
$selectBox.hide();
$value.css('display', '');
if (data.milestone != null) {
data.milestone.full_path = this.currentProject.full_path;
data.milestone.remaining = timeFor(data.milestone.due_date);
data.milestone.name = data.milestone.title;
$value.html(milestoneLinkTemplate(data.milestone));
return $sidebarCollapsedValue.find('span').html(collapsedSidebarLabelTemplate(data.milestone));
} else {
$value.html(milestoneLinkNoneTemplate);
return $sidebarCollapsedValue.find('span').text('No');
}
});
} }
}); }
}); });
} });
}
return MilestoneSelect; }
})();
}).call(window);
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