gitlab-org--gitlab-foss/app/assets/javascripts/boards/index.js

306 lines
9.4 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
2017-03-17 13:21:25 -04:00
import Vue from 'vue';
import Flash from '~/flash';
import { __ } from '~/locale';
import './models/label';
import './models/assignee';
2019-07-10 03:18:14 -04:00
import FilteredSearchBoards from '~/boards/filtered_search_boards';
import eventHub from '~/boards/eventhub';
import sidebarEventHub from '~/sidebar/event_hub';
2019-07-10 03:18:14 -04:00
import 'ee_else_ce/boards/models/issue';
import 'ee_else_ce/boards/models/list';
import '~/boards/models/milestone';
import '~/boards/models/project';
import boardsStore from '~/boards/stores/boards_store';
import ModalStore from '~/boards/stores/modal_store';
import BoardService from 'ee_else_ce/boards/services/board_service';
import modalMixin from '~/boards/mixins/modal_mixins';
import '~/boards/filters/due_date_filters';
import Board from 'ee_else_ce/boards/components/board';
import BoardSidebar from 'ee_else_ce/boards/components/board_sidebar';
import initNewListDropdown from 'ee_else_ce/boards/components/new_list_dropdown';
2019-07-10 03:18:14 -04:00
import BoardAddIssuesModal from '~/boards/components/modal/index.vue';
import '~/vue_shared/vue_resource_interceptor';
import {
NavigationType,
convertObjectPropsToCamelCase,
parseBoolean,
} from '~/lib/utils/common_utils';
2019-07-10 03:18:14 -04:00
import boardConfigToggle from 'ee_else_ce/boards/config_toggle';
import toggleFocusMode from 'ee_else_ce/boards/toggle_focus';
import {
setPromotionState,
setWeigthFetchingState,
setEpicFetchingState,
getMilestoneTitle,
getBoardsModalData,
} from 'ee_else_ce/boards/ee_functions';
import mountMultipleBoardsSwitcher from './mount_multiple_boards_switcher';
2016-07-28 07:33:04 -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
// check for browser back and trigger a hard reload to circumvent browser caching.
window.addEventListener('pageshow', event => {
const isNavTypeBackForward =
window.performance && window.performance.navigation.type === NavigationType.TYPE_BACK_FORWARD;
if (event.persisted || isNavTypeBackForward) {
window.location.reload();
}
});
if (issueBoardsApp) {
issueBoardsApp.$destroy(true);
}
boardsStore.create();
boardsStore.setTimeTrackingLimitToHours($boardApp.dataset.timeTrackingLimitToHours);
issueBoardsApp = new Vue({
el: $boardApp,
components: {
Board,
BoardSidebar,
BoardAddIssuesModal,
},
2016-07-28 07:33:04 -04:00
data: {
state: boardsStore.state,
loading: true,
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,
2017-05-04 11:33:25 -04:00
defaultAvatar: $boardApp.dataset.defaultAvatar,
2016-07-28 07:33:04 -04:00
},
computed: {
2018-07-25 11:38:43 -04:00
detailIssueVisible() {
return Object.keys(this.detailIssue.issue).length;
},
},
2018-07-25 11:38:43 -04:00
created() {
boardsStore.setEndpoints({
boardsEndpoint: this.boardsEndpoint,
recentBoardsEndpoint: this.recentBoardsEndpoint,
listsEndpoint: this.listsEndpoint,
bulkUpdatePath: this.bulkUpdatePath,
boardId: this.boardId,
});
gl.boardService = new BoardService();
boardsStore.rootPath = this.boardsEndpoint;
eventHub.$on('updateTokens', this.updateTokens);
eventHub.$on('newDetailIssue', this.updateDetailIssue);
eventHub.$on('clearDetailIssue', this.clearDetailIssue);
sidebarEventHub.$on('toggleSubscription', this.toggleSubscription);
},
beforeDestroy() {
eventHub.$off('updateTokens', this.updateTokens);
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() {
this.filterManager = new FilteredSearchBoards(boardsStore.filter, true, boardsStore.cantEdit);
2017-09-26 17:19:28 -04:00
this.filterManager.setup();
boardsStore.disabled = this.disabled;
2018-07-25 11:38:43 -04:00
gl.boardService
.all()
2017-12-15 03:31:14 -05:00
.then(res => res.data)
.then(lists => {
lists.forEach(listObj => {
let { position } = listObj;
if (listObj.list_type === 'closed') {
position = Infinity;
} else if (listObj.list_type === 'backlog') {
position = -1;
}
boardsStore.addList(
{
...listObj,
position,
},
this.defaultAvatar,
);
});
2016-11-09 04:23:48 -05:00
boardsStore.addBlankState();
setPromotionState(boardsStore);
2016-08-08 11:15:05 -04:00
this.loading = false;
2017-07-12 10:47:09 -04:00
})
2017-12-15 03:31:14 -05:00
.catch(() => {
Flash(__('An error occurred while fetching the board lists. Please try again.'));
2017-12-15 03:31:14 -05:00
});
},
methods: {
updateTokens() {
this.filterManager.updateTokens();
},
updateDetailIssue(newIssue) {
const { sidebarInfoEndpoint } = newIssue;
if (sidebarInfoEndpoint && newIssue.subscribed === undefined) {
newIssue.setFetchingState('subscriptions', true);
setWeigthFetchingState(newIssue, true);
setEpicFetchingState(newIssue, true);
BoardService.getIssueInfo(sidebarInfoEndpoint)
2017-12-15 03:31:14 -05:00
.then(res => res.data)
2018-07-25 11:38:43 -04:00
.then(data => {
const {
subscribed,
totalTimeSpent,
timeEstimate,
humanTimeEstimate,
humanTotalTimeSpent,
weight,
epic,
} = convertObjectPropsToCamelCase(data);
newIssue.setFetchingState('subscriptions', false);
setWeigthFetchingState(newIssue, false);
setEpicFetchingState(newIssue, false);
newIssue.updateData({
humanTimeSpent: humanTotalTimeSpent,
timeSpent: totalTimeSpent,
humanTimeEstimate,
timeEstimate,
subscribed,
weight,
epic,
});
})
.catch(() => {
newIssue.setFetchingState('subscriptions', false);
setWeigthFetchingState(newIssue, false);
Flash(__('An error occurred while fetching sidebar data'));
});
}
boardsStore.setIssueDetail(newIssue);
},
clearDetailIssue() {
boardsStore.clearDetailIssue();
},
toggleSubscription(id) {
const { issue } = boardsStore.detail;
if (issue.id === id && issue.toggleSubscriptionEndpoint) {
issue.setFetchingState('subscriptions', true);
BoardService.toggleIssueSubscription(issue.toggleSubscriptionEndpoint)
.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
},
},
2016-07-28 07:33:04 -04:00
});
// eslint-disable-next-line no-new
new Vue({
2017-03-08 07:17:01 -05:00
el: document.getElementById('js-add-list'),
data: {
filters: boardsStore.state.filters,
...getMilestoneTitle($boardApp),
},
2018-07-25 11:38:43 -04:00
mounted() {
initNewListDropdown();
},
});
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) {
// 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,
store: boardsStore.state,
...getBoardsModalData($boardApp),
2018-07-25 11:38:43 -04:00
canAdminList: this.$options.el.hasAttribute('data-can-admin-list'),
};
},
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) {
return __('Please add a list to your board first');
2018-07-25 11:38:43 -04:00
}
2018-07-25 11:38:43 -04:00
return '';
},
},
2018-07-25 11:38:43 -04:00
watch: {
disabled() {
this.updateTooltip();
},
},
mounted() {
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);
}
2018-07-25 11:38:43 -04:00
},
},
2018-07-25 11:38:43 -04:00
template: `
<div class="board-extra-actions">
<button
class="btn btn-success prepend-left-10"
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>
`,
});
}
toggleFocusMode(ModalStore, boardsStore, $boardApp);
mountMultipleBoardsSwitcher();
2018-02-21 17:28:08 -05:00
};