debian-mirror-gitlab/app/assets/javascripts/sidebar/mount_sidebar.js

291 lines
7.5 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2020-05-24 23:13:21 +05:30
import VueApollo from 'vue-apollo';
2018-10-15 14:42:47 +05:30
import SidebarTimeTracking from './components/time_tracking/sidebar_time_tracking.vue';
2018-03-27 19:54:05 +05:30
import SidebarAssignees from './components/assignees/sidebar_assignees.vue';
2020-11-24 15:15:51 +05:30
import SidebarLabels from './components/labels/sidebar_labels.vue';
2021-01-03 14:25:43 +05:30
import SidebarReviewers from './components/reviewers/sidebar_reviewers.vue';
2018-03-17 18:26:18 +05:30
import ConfidentialIssueSidebar from './components/confidential/confidential_issue_sidebar.vue';
import SidebarMoveIssue from './lib/sidebar_move_issue';
2020-10-24 23:57:45 +05:30
import IssuableLockForm from './components/lock/issuable_lock_form.vue';
2018-03-17 18:26:18 +05:30
import sidebarParticipants from './components/participants/sidebar_participants.vue';
import sidebarSubscriptions from './components/subscriptions/sidebar_subscriptions.vue';
2020-11-24 15:15:51 +05:30
import SidebarSeverity from './components/severity/sidebar_severity.vue';
2018-03-17 18:26:18 +05:30
import Translate from '../vue_shared/translate';
2020-05-24 23:13:21 +05:30
import createDefaultClient from '~/lib/graphql';
2021-01-03 14:25:43 +05:30
import { isInIssuePage, isInIncidentPage, parseBoolean } from '~/lib/utils/common_utils';
import createFlash from '~/flash';
import { __ } from '~/locale';
2018-03-17 18:26:18 +05:30
Vue.use(Translate);
2020-05-24 23:13:21 +05:30
Vue.use(VueApollo);
2021-01-03 14:25:43 +05:30
function getSidebarOptions(sidebarOptEl = document.querySelector('.js-sidebar-options')) {
return JSON.parse(sidebarOptEl.innerHTML);
2020-05-24 23:13:21 +05:30
}
2018-03-17 18:26:18 +05:30
function mountAssigneesComponent(mediator) {
const el = document.getElementById('js-vue-sidebar-assignees');
2020-05-24 23:13:21 +05:30
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
2018-03-17 18:26:18 +05:30
if (!el) return;
2020-05-24 23:13:21 +05:30
const { iid, fullPath } = getSidebarOptions();
2018-03-17 18:26:18 +05:30
// eslint-disable-next-line no-new
new Vue({
el,
2020-05-24 23:13:21 +05:30
apolloProvider,
2018-03-17 18:26:18 +05:30
components: {
SidebarAssignees,
},
2018-12-13 13:39:08 +05:30
render: createElement =>
createElement('sidebar-assignees', {
2021-01-03 14:25:43 +05:30
props: {
mediator,
issuableIid: String(iid),
projectPath: fullPath,
field: el.dataset.field,
signedIn: el.hasAttribute('data-signed-in'),
issuableType: isInIssuePage() || isInIncidentPage() ? 'issue' : 'merge_request',
},
}),
});
}
function mountReviewersComponent(mediator) {
const el = document.getElementById('js-vue-sidebar-reviewers');
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
if (!el) return;
const { iid, fullPath } = getSidebarOptions();
// eslint-disable-next-line no-new
new Vue({
el,
apolloProvider,
components: {
SidebarReviewers,
},
render: createElement =>
createElement('sidebar-reviewers', {
2018-12-13 13:39:08 +05:30
props: {
mediator,
2020-05-24 23:13:21 +05:30
issuableIid: String(iid),
projectPath: fullPath,
2018-12-13 13:39:08 +05:30
field: el.dataset.field,
signedIn: el.hasAttribute('data-signed-in'),
2020-07-28 23:09:34 +05:30
issuableType: isInIssuePage() ? 'issue' : 'merge_request',
2018-12-13 13:39:08 +05:30
},
}),
2018-03-17 18:26:18 +05:30
});
}
2020-11-24 15:15:51 +05:30
export function mountSidebarLabels() {
const el = document.querySelector('.js-sidebar-labels');
if (!el) {
return false;
}
return new Vue({
el,
provide: {
...el.dataset,
allowLabelCreate: parseBoolean(el.dataset.allowLabelCreate),
allowLabelEdit: parseBoolean(el.dataset.canEdit),
allowScopedLabels: parseBoolean(el.dataset.allowScopedLabels),
initiallySelectedLabels: JSON.parse(el.dataset.selectedLabels),
},
render: createElement => createElement(SidebarLabels),
});
}
2018-03-17 18:26:18 +05:30
function mountConfidentialComponent(mediator) {
const el = document.getElementById('js-confidential-entry-point');
2020-07-28 23:09:34 +05:30
const { fullPath, iid } = getSidebarOptions();
2018-03-17 18:26:18 +05:30
if (!el) return;
const dataNode = document.getElementById('js-confidential-issue-data');
const initialData = JSON.parse(dataNode.innerHTML);
2021-01-03 14:25:43 +05:30
import(/* webpackChunkName: 'notesStore' */ '~/notes/stores')
.then(
({ store }) =>
new Vue({
el,
store,
components: {
ConfidentialIssueSidebar,
},
render: createElement =>
createElement('confidential-issue-sidebar', {
props: {
iid: String(iid),
fullPath,
isEditable: initialData.is_editable,
service: mediator.service,
},
}),
}),
)
.catch(() => {
createFlash({ message: __('Failed to load sidebar confidential toggle') });
});
2018-03-17 18:26:18 +05:30
}
2020-10-24 23:57:45 +05:30
function mountLockComponent() {
2018-03-17 18:26:18 +05:30
const el = document.getElementById('js-lock-entry-point');
2021-01-03 14:25:43 +05:30
if (!el) {
return;
}
2020-10-24 23:57:45 +05:30
const { fullPath } = getSidebarOptions();
2018-03-17 18:26:18 +05:30
const dataNode = document.getElementById('js-lock-issue-data');
const initialData = JSON.parse(dataNode.innerHTML);
2021-01-03 14:25:43 +05:30
let importStore;
if (isInIssuePage() || isInIncidentPage()) {
importStore = import(/* webpackChunkName: 'notesStore' */ '~/notes/stores').then(
({ store }) => store,
);
} else {
importStore = import(/* webpackChunkName: 'mrNotesStore' */ '~/mr_notes/stores').then(
store => store.default,
);
}
importStore
.then(
store =>
new Vue({
el,
store,
provide: {
fullPath,
},
render: createElement =>
createElement(IssuableLockForm, {
props: {
isEditable: initialData.is_editable,
},
}),
}),
)
.catch(() => {
createFlash({ message: __('Failed to load sidebar lock status') });
});
2018-03-17 18:26:18 +05:30
}
function mountParticipantsComponent(mediator) {
const el = document.querySelector('.js-sidebar-participants-entry-point');
if (!el) return;
// eslint-disable-next-line no-new
new Vue({
el,
components: {
sidebarParticipants,
},
2018-12-13 13:39:08 +05:30
render: createElement =>
createElement('sidebar-participants', {
props: {
mediator,
},
}),
2018-03-17 18:26:18 +05:30
});
}
function mountSubscriptionsComponent(mediator) {
const el = document.querySelector('.js-sidebar-subscriptions-entry-point');
if (!el) return;
// eslint-disable-next-line no-new
new Vue({
el,
components: {
sidebarSubscriptions,
},
2018-12-13 13:39:08 +05:30
render: createElement =>
createElement('sidebar-subscriptions', {
props: {
mediator,
},
}),
2018-03-17 18:26:18 +05:30
});
}
function mountTimeTrackingComponent() {
const el = document.getElementById('issuable-time-tracker');
if (!el) return;
// eslint-disable-next-line no-new
new Vue({
el,
components: {
SidebarTimeTracking,
},
render: createElement => createElement('sidebar-time-tracking', {}),
});
}
2020-11-24 15:15:51 +05:30
function mountSeverityComponent() {
const severityContainerEl = document.querySelector('#js-severity');
if (!severityContainerEl) {
return false;
}
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(),
});
const { fullPath, iid, severity } = getSidebarOptions();
return new Vue({
el: severityContainerEl,
apolloProvider,
components: {
SidebarSeverity,
},
render: createElement =>
createElement('sidebar-severity', {
props: {
projectPath: fullPath,
iid: String(iid),
initialSeverity: severity.toUpperCase(),
},
}),
});
}
2018-03-17 18:26:18 +05:30
export function mountSidebar(mediator) {
mountAssigneesComponent(mediator);
2021-01-03 14:25:43 +05:30
mountReviewersComponent(mediator);
2018-03-17 18:26:18 +05:30
mountConfidentialComponent(mediator);
2021-01-03 14:25:43 +05:30
mountLockComponent();
2018-03-17 18:26:18 +05:30
mountParticipantsComponent(mediator);
mountSubscriptionsComponent(mediator);
new SidebarMoveIssue(
mediator,
$('.js-move-issue'),
$('.js-move-issue-confirmation-button'),
).init();
mountTimeTrackingComponent();
2020-11-24 15:15:51 +05:30
mountSeverityComponent();
2018-03-17 18:26:18 +05:30
}
2020-05-24 23:13:21 +05:30
export { getSidebarOptions };