2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
2020-06-04 05:08:01 -04:00
|
|
|
import { mapActions } from 'vuex';
|
2018-02-26 14:43:34 -05:00
|
|
|
|
2019-12-09 07:07:58 -05:00
|
|
|
import 'ee_else_ce/boards/models/issue';
|
|
|
|
import 'ee_else_ce/boards/models/list';
|
|
|
|
import BoardSidebar from 'ee_else_ce/boards/components/board_sidebar';
|
|
|
|
import initNewListDropdown from 'ee_else_ce/boards/components/new_list_dropdown';
|
|
|
|
import boardConfigToggle from 'ee_else_ce/boards/config_toggle';
|
|
|
|
import toggleLabels from 'ee_else_ce/boards/toggle_labels';
|
2020-05-29 05:08:06 -04:00
|
|
|
import toggleEpicsSwimlanes from 'ee_else_ce/boards/toggle_epics_swimlanes';
|
2019-12-09 07:07:58 -05:00
|
|
|
import {
|
|
|
|
setPromotionState,
|
|
|
|
setWeigthFetchingState,
|
|
|
|
setEpicFetchingState,
|
|
|
|
getMilestoneTitle,
|
|
|
|
getBoardsModalData,
|
|
|
|
} from 'ee_else_ce/boards/ee_functions';
|
|
|
|
|
2020-04-30 05:09:39 -04:00
|
|
|
import VueApollo from 'vue-apollo';
|
2020-08-19 02:10:04 -04:00
|
|
|
import BoardContent from '~/boards/components/board_content.vue';
|
2020-04-30 05:09:39 -04:00
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2020-08-20 05:09:55 -04:00
|
|
|
import { deprecatedCreateFlash as Flash } from '~/flash';
|
2018-02-26 14:43:34 -05:00
|
|
|
import { __ } from '~/locale';
|
2019-06-07 09:23:10 -04:00
|
|
|
import './models/label';
|
|
|
|
import './models/assignee';
|
2020-04-30 05:09:39 -04:00
|
|
|
import { BoardType } from './constants';
|
2018-02-26 14:43:34 -05:00
|
|
|
|
2020-05-13 20:07:47 -04:00
|
|
|
import toggleFocusMode from '~/boards/toggle_focus';
|
2019-07-10 03:18:14 -04:00
|
|
|
import FilteredSearchBoards from '~/boards/filtered_search_boards';
|
|
|
|
import eventHub from '~/boards/eventhub';
|
2018-09-19 18:42:20 -04:00
|
|
|
import sidebarEventHub from '~/sidebar/event_hub';
|
2019-07-10 03:18:14 -04:00
|
|
|
import '~/boards/models/milestone';
|
|
|
|
import '~/boards/models/project';
|
2019-10-28 11:05:58 -04:00
|
|
|
import store from '~/boards/stores';
|
2019-07-10 03:18:14 -04:00
|
|
|
import boardsStore from '~/boards/stores/boards_store';
|
|
|
|
import ModalStore from '~/boards/stores/modal_store';
|
|
|
|
import modalMixin from '~/boards/mixins/modal_mixins';
|
|
|
|
import '~/boards/filters/due_date_filters';
|
|
|
|
import BoardAddIssuesModal from '~/boards/components/modal/index.vue';
|
2019-04-09 06:39:42 -04:00
|
|
|
import {
|
|
|
|
NavigationType,
|
|
|
|
convertObjectPropsToCamelCase,
|
|
|
|
parseBoolean,
|
|
|
|
} from '~/lib/utils/common_utils';
|
2020-04-30 05:09:39 -04:00
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2019-07-17 16:42:33 -04:00
|
|
|
import mountMultipleBoardsSwitcher from './mount_multiple_boards_switcher';
|
2020-04-30 05:09:39 -04:00
|
|
|
import projectBoardQuery from './queries/project_board.query.graphql';
|
|
|
|
import groupQuery from './queries/group_board.query.graphql';
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({
|
|
|
|
defaultClient: createDefaultClient(),
|
|
|
|
});
|
2016-07-28 07:33:04 -04:00
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
let issueBoardsApp;
|
|
|
|
|
2018-02-21 17:28:08 -05:00
|
|
|
export default () => {
|
2017-01-11 22:49:57 -05:00
|
|
|
const $boardApp = document.getElementById('board-app');
|
2016-07-28 07:33:04 -04:00
|
|
|
|
2018-10-02 06:00:58 -04:00
|
|
|
// check for browser back and trigger a hard reload to circumvent browser caching.
|
2018-10-30 16:28:31 -04:00
|
|
|
window.addEventListener('pageshow', event => {
|
|
|
|
const isNavTypeBackForward =
|
|
|
|
window.performance && window.performance.navigation.type === NavigationType.TYPE_BACK_FORWARD;
|
2018-10-02 06:00:58 -04:00
|
|
|
|
|
|
|
if (event.persisted || isNavTypeBackForward) {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
if (issueBoardsApp) {
|
|
|
|
issueBoardsApp.$destroy(true);
|
2016-08-05 09:00:06 -04:00
|
|
|
}
|
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.create();
|
2019-06-11 06:40:01 -04:00
|
|
|
boardsStore.setTimeTrackingLimitToHours($boardApp.dataset.timeTrackingLimitToHours);
|
2017-04-07 15:36:09 -04:00
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
issueBoardsApp = new Vue({
|
2016-08-16 04:02:45 -04:00
|
|
|
el: $boardApp,
|
2016-08-15 05:07:53 -04:00
|
|
|
components: {
|
2020-06-04 05:08:01 -04:00
|
|
|
BoardContent,
|
2020-07-01 05:09:30 -04:00
|
|
|
Board: () => import('ee_else_ce/boards/components/board_column.vue'),
|
2018-10-10 13:08:43 -04:00
|
|
|
BoardSidebar,
|
2018-06-26 08:29:06 -04:00
|
|
|
BoardAddIssuesModal,
|
2020-07-30 08:09:33 -04:00
|
|
|
BoardSettingsSidebar: () => import('~/boards/components/board_settings_sidebar.vue'),
|
2016-08-15 05:07:53 -04:00
|
|
|
},
|
2019-10-28 11:05:58 -04:00
|
|
|
store,
|
2020-04-30 05:09:39 -04:00
|
|
|
apolloProvider,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
state: boardsStore.state,
|
|
|
|
loading: 0,
|
|
|
|
boardsEndpoint: $boardApp.dataset.boardsEndpoint,
|
|
|
|
recentBoardsEndpoint: $boardApp.dataset.recentBoardsEndpoint,
|
|
|
|
listsEndpoint: $boardApp.dataset.listsEndpoint,
|
|
|
|
boardId: $boardApp.dataset.boardId,
|
|
|
|
disabled: parseBoolean($boardApp.dataset.disabled),
|
|
|
|
issueLinkBase: $boardApp.dataset.issueLinkBase,
|
|
|
|
rootPath: $boardApp.dataset.rootPath,
|
|
|
|
bulkUpdatePath: $boardApp.dataset.bulkUpdatePath,
|
|
|
|
detailIssue: boardsStore.detail,
|
|
|
|
parent: $boardApp.dataset.parent,
|
|
|
|
};
|
2016-07-28 07:33:04 -04:00
|
|
|
},
|
2016-10-19 17:26:51 -04:00
|
|
|
computed: {
|
2018-07-25 11:38:43 -04:00
|
|
|
detailIssueVisible() {
|
2016-10-19 17:26:51 -04:00
|
|
|
return Object.keys(this.detailIssue.issue).length;
|
2016-11-04 06:24:59 -04:00
|
|
|
},
|
2016-10-19 17:26:51 -04:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
created() {
|
2020-06-04 05:08:01 -04:00
|
|
|
const endpoints = {
|
2017-09-06 01:02:30 -04:00
|
|
|
boardsEndpoint: this.boardsEndpoint,
|
2019-03-01 11:32:05 -05:00
|
|
|
recentBoardsEndpoint: this.recentBoardsEndpoint,
|
2017-09-06 01:02:30 -04:00
|
|
|
listsEndpoint: this.listsEndpoint,
|
|
|
|
bulkUpdatePath: this.bulkUpdatePath,
|
|
|
|
boardId: this.boardId,
|
2020-03-10 05:08:10 -04:00
|
|
|
fullPath: $boardApp.dataset.fullPath,
|
2020-06-04 05:08:01 -04:00
|
|
|
};
|
2020-08-13 05:10:09 -04:00
|
|
|
this.setInitialBoardData({ ...endpoints, boardType: this.parent });
|
2020-06-04 05:08:01 -04:00
|
|
|
boardsStore.setEndpoints(endpoints);
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.rootPath = this.boardsEndpoint;
|
2017-03-07 06:05:37 -05:00
|
|
|
|
2017-03-14 07:32:58 -04:00
|
|
|
eventHub.$on('updateTokens', this.updateTokens);
|
2017-11-14 01:05:40 -05:00
|
|
|
eventHub.$on('newDetailIssue', this.updateDetailIssue);
|
|
|
|
eventHub.$on('clearDetailIssue', this.clearDetailIssue);
|
|
|
|
sidebarEventHub.$on('toggleSubscription', this.toggleSubscription);
|
2017-03-09 07:32:43 -05:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2017-03-14 07:32:58 -04:00
|
|
|
eventHub.$off('updateTokens', this.updateTokens);
|
2017-11-14 01:05:40 -05:00
|
|
|
eventHub.$off('newDetailIssue', this.updateDetailIssue);
|
|
|
|
eventHub.$off('clearDetailIssue', this.clearDetailIssue);
|
|
|
|
sidebarEventHub.$off('toggleSubscription', this.toggleSubscription);
|
2016-08-08 11:15:05 -04:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
mounted() {
|
2018-10-10 13:08:43 -04:00
|
|
|
this.filterManager = new FilteredSearchBoards(boardsStore.filter, true, boardsStore.cantEdit);
|
2017-09-26 17:19:28 -04:00
|
|
|
this.filterManager.setup();
|
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
boardsStore.disabled = this.disabled;
|
2020-04-30 05:09:39 -04:00
|
|
|
|
|
|
|
if (gon.features.graphqlBoardLists) {
|
|
|
|
this.$apollo.addSmartQuery('lists', {
|
|
|
|
query() {
|
|
|
|
return this.parent === BoardType.group ? groupQuery : projectBoardQuery;
|
|
|
|
},
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
fullPath: this.state.endpoints.fullPath,
|
|
|
|
boardId: `gid://gitlab/Board/${this.boardId}`,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update(data) {
|
|
|
|
return this.getNodes(data);
|
|
|
|
},
|
|
|
|
result({ data, error }) {
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
2016-08-04 11:16:50 -04:00
|
|
|
}
|
|
|
|
|
2020-04-30 05:09:39 -04:00
|
|
|
const lists = this.getNodes(data);
|
|
|
|
|
|
|
|
lists.forEach(list =>
|
|
|
|
boardsStore.addList({
|
|
|
|
...list,
|
|
|
|
id: getIdFromGraphQLId(list.id),
|
|
|
|
}),
|
|
|
|
);
|
2016-11-09 04:23:48 -05:00
|
|
|
|
2020-04-30 05:09:39 -04:00
|
|
|
boardsStore.addBlankState();
|
|
|
|
setPromotionState(boardsStore);
|
|
|
|
},
|
|
|
|
error() {
|
|
|
|
Flash(__('An error occurred while fetching the board lists. Please try again.'));
|
|
|
|
},
|
2017-12-15 03:31:14 -05:00
|
|
|
});
|
2020-04-30 05:09:39 -04:00
|
|
|
} else {
|
|
|
|
boardsStore
|
|
|
|
.all()
|
|
|
|
.then(res => res.data)
|
|
|
|
.then(lists => {
|
|
|
|
lists.forEach(list => boardsStore.addList(list));
|
|
|
|
boardsStore.addBlankState();
|
|
|
|
setPromotionState(boardsStore);
|
|
|
|
this.loading = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
Flash(__('An error occurred while fetching the board lists. Please try again.'));
|
|
|
|
});
|
|
|
|
}
|
2017-03-09 07:32:43 -05:00
|
|
|
},
|
|
|
|
methods: {
|
2020-08-13 05:10:09 -04:00
|
|
|
...mapActions(['setInitialBoardData']),
|
2017-03-09 07:32:43 -05:00
|
|
|
updateTokens() {
|
|
|
|
this.filterManager.updateTokens();
|
2017-11-14 01:05:40 -05:00
|
|
|
},
|
2020-06-22 20:08:58 -04:00
|
|
|
updateDetailIssue(newIssue, multiSelect = false) {
|
2018-06-16 17:50:13 -04:00
|
|
|
const { sidebarInfoEndpoint } = newIssue;
|
2017-11-14 01:05:40 -05:00
|
|
|
if (sidebarInfoEndpoint && newIssue.subscribed === undefined) {
|
|
|
|
newIssue.setFetchingState('subscriptions', true);
|
2019-07-19 03:53:11 -04:00
|
|
|
setWeigthFetchingState(newIssue, true);
|
|
|
|
setEpicFetchingState(newIssue, true);
|
2019-11-25 07:06:13 -05:00
|
|
|
boardsStore
|
|
|
|
.getIssueInfo(sidebarInfoEndpoint)
|
2017-12-15 03:31:14 -05:00
|
|
|
.then(res => res.data)
|
2018-07-25 11:38:43 -04:00
|
|
|
.then(data => {
|
2019-04-09 06:39:42 -04:00
|
|
|
const {
|
|
|
|
subscribed,
|
|
|
|
totalTimeSpent,
|
|
|
|
timeEstimate,
|
|
|
|
humanTimeEstimate,
|
|
|
|
humanTotalTimeSpent,
|
|
|
|
weight,
|
|
|
|
epic,
|
2019-12-13 19:08:27 -05:00
|
|
|
assignees,
|
2019-04-09 06:39:42 -04:00
|
|
|
} = convertObjectPropsToCamelCase(data);
|
|
|
|
|
2017-11-14 01:05:40 -05:00
|
|
|
newIssue.setFetchingState('subscriptions', false);
|
2019-07-19 03:53:11 -04:00
|
|
|
setWeigthFetchingState(newIssue, false);
|
|
|
|
setEpicFetchingState(newIssue, false);
|
2017-11-14 01:05:40 -05:00
|
|
|
newIssue.updateData({
|
2019-04-09 06:39:42 -04:00
|
|
|
humanTimeSpent: humanTotalTimeSpent,
|
|
|
|
timeSpent: totalTimeSpent,
|
|
|
|
humanTimeEstimate,
|
|
|
|
timeEstimate,
|
|
|
|
subscribed,
|
|
|
|
weight,
|
|
|
|
epic,
|
2019-12-13 19:08:27 -05:00
|
|
|
assignees,
|
2017-11-14 01:05:40 -05:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
newIssue.setFetchingState('subscriptions', false);
|
2019-07-19 03:53:11 -04:00
|
|
|
setWeigthFetchingState(newIssue, false);
|
2017-11-14 01:05:40 -05:00
|
|
|
Flash(__('An error occurred while fetching sidebar data'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-15 05:06:09 -04:00
|
|
|
if (multiSelect) {
|
|
|
|
boardsStore.toggleMultiSelect(newIssue);
|
|
|
|
|
|
|
|
if (boardsStore.detail.issue) {
|
|
|
|
boardsStore.clearDetailIssue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-04 11:34:17 -04:00
|
|
|
boardsStore.setIssueDetail(newIssue);
|
2017-11-14 01:05:40 -05:00
|
|
|
},
|
2019-10-15 05:06:09 -04:00
|
|
|
clearDetailIssue(multiSelect = false) {
|
|
|
|
if (multiSelect) {
|
|
|
|
boardsStore.clearMultiSelect();
|
|
|
|
}
|
2019-05-30 03:31:42 -04:00
|
|
|
boardsStore.clearDetailIssue();
|
2017-11-14 01:05:40 -05:00
|
|
|
},
|
|
|
|
toggleSubscription(id) {
|
2018-10-10 13:08:43 -04:00
|
|
|
const { issue } = boardsStore.detail;
|
2017-11-14 01:05:40 -05:00
|
|
|
if (issue.id === id && issue.toggleSubscriptionEndpoint) {
|
|
|
|
issue.setFetchingState('subscriptions', true);
|
2019-11-25 07:06:13 -05:00
|
|
|
boardsStore
|
|
|
|
.toggleIssueSubscription(issue.toggleSubscriptionEndpoint)
|
2017-11-14 01:05:40 -05:00
|
|
|
.then(() => {
|
|
|
|
issue.setFetchingState('subscriptions', false);
|
|
|
|
issue.updateData({
|
|
|
|
subscribed: !issue.subscribed,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
issue.setFetchingState('subscriptions', false);
|
|
|
|
Flash(__('An error occurred when toggling the notification subscription'));
|
|
|
|
});
|
|
|
|
}
|
2018-07-25 11:38:43 -04:00
|
|
|
},
|
2020-04-30 05:09:39 -04:00
|
|
|
getNodes(data) {
|
|
|
|
return data[this.parent]?.board?.lists.nodes;
|
|
|
|
},
|
2017-03-09 07:32:43 -05:00
|
|
|
},
|
2016-07-28 07:33:04 -04:00
|
|
|
});
|
2016-08-30 05:32:19 -04:00
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2017-03-08 07:17:01 -05:00
|
|
|
el: document.getElementById('js-add-list'),
|
2016-08-30 05:32:19 -04:00
|
|
|
data: {
|
2018-10-10 13:08:43 -04:00
|
|
|
filters: boardsStore.state.filters,
|
2019-07-19 03:53:11 -04:00
|
|
|
...getMilestoneTitle($boardApp),
|
2016-11-04 06:24:59 -04:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
mounted() {
|
2018-10-10 13:08:43 -04:00
|
|
|
initNewListDropdown();
|
2017-09-06 01:02:30 -04:00
|
|
|
},
|
2016-08-30 05:32:19 -04:00
|
|
|
});
|
2017-01-24 05:27:41 -05:00
|
|
|
|
2019-07-10 03:18:14 -04:00
|
|
|
boardConfigToggle(boardsStore);
|
|
|
|
|
2018-07-25 11:38:43 -04:00
|
|
|
const issueBoardsModal = document.getElementById('js-add-issues-btn');
|
|
|
|
|
|
|
|
if (issueBoardsModal) {
|
2018-10-10 13:08:43 -04:00
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2018-07-25 11:38:43 -04:00
|
|
|
el: issueBoardsModal,
|
|
|
|
mixins: [modalMixin],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
modal: ModalStore.store,
|
2018-10-10 13:08:43 -04:00
|
|
|
store: boardsStore.state,
|
2020-05-13 20:07:47 -04:00
|
|
|
...getBoardsModalData(),
|
2018-07-25 11:38:43 -04:00
|
|
|
canAdminList: this.$options.el.hasAttribute('data-can-admin-list'),
|
|
|
|
};
|
2017-01-30 10:56:45 -05:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
computed: {
|
|
|
|
disabled() {
|
|
|
|
if (!this.store) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !this.store.lists.filter(list => !list.preset).length;
|
|
|
|
},
|
|
|
|
tooltipTitle() {
|
|
|
|
if (this.disabled) {
|
2019-05-01 11:02:06 -04:00
|
|
|
return __('Please add a list to your board first');
|
2018-07-25 11:38:43 -04:00
|
|
|
}
|
2017-02-10 11:13:13 -05:00
|
|
|
|
2018-07-25 11:38:43 -04:00
|
|
|
return '';
|
|
|
|
},
|
2017-02-10 11:13:13 -05:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
watch: {
|
|
|
|
disabled() {
|
|
|
|
this.updateTooltip();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-01-03 18:14:55 -05:00
|
|
|
this.updateTooltip();
|
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
methods: {
|
|
|
|
updateTooltip() {
|
|
|
|
const $tooltip = $(this.$refs.addIssuesButton);
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
if (this.disabled) {
|
|
|
|
$tooltip.tooltip();
|
|
|
|
} else {
|
|
|
|
$tooltip.tooltip('dispose');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
openModal() {
|
|
|
|
if (!this.disabled) {
|
|
|
|
this.toggleModal(true);
|
2017-02-10 11:13:13 -05:00
|
|
|
}
|
2018-07-25 11:38:43 -04:00
|
|
|
},
|
2017-02-10 11:13:13 -05:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
template: `
|
|
|
|
<div class="board-extra-actions">
|
|
|
|
<button
|
2020-07-17 05:09:43 -04:00
|
|
|
class="btn btn-success gl-ml-3"
|
2018-07-25 11:38:43 -04:00
|
|
|
type="button"
|
|
|
|
data-placement="bottom"
|
|
|
|
ref="addIssuesButton"
|
|
|
|
:class="{ 'disabled': disabled }"
|
|
|
|
:title="tooltipTitle"
|
|
|
|
:aria-disabled="disabled"
|
|
|
|
v-if="canAdminList"
|
|
|
|
@click="openModal">
|
|
|
|
Add issues
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
}
|
2019-07-04 06:53:09 -04:00
|
|
|
|
2020-05-13 20:07:47 -04:00
|
|
|
toggleFocusMode(ModalStore, boardsStore);
|
2019-10-28 11:05:58 -04:00
|
|
|
toggleLabels();
|
2020-05-29 05:08:06 -04:00
|
|
|
toggleEpicsSwimlanes();
|
2019-07-04 06:53:09 -04:00
|
|
|
mountMultipleBoardsSwitcher();
|
2018-02-21 17:28:08 -05:00
|
|
|
};
|