2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-08-03 16:31:53 -04:00
|
|
|
import _ from 'underscore';
|
2017-03-17 13:21:25 -04:00
|
|
|
import Vue from 'vue';
|
2018-02-26 14:43:34 -05:00
|
|
|
|
|
|
|
import Flash from '~/flash';
|
|
|
|
import { __ } from '~/locale';
|
2018-03-05 07:35:58 -05:00
|
|
|
import '~/vue_shared/models/label';
|
2018-06-07 16:54:24 -04:00
|
|
|
import '~/vue_shared/models/assignee';
|
2018-02-26 14:43:34 -05:00
|
|
|
|
2017-03-07 09:43:17 -05:00
|
|
|
import FilteredSearchBoards from './filtered_search_boards';
|
2017-03-14 07:32:58 -04:00
|
|
|
import eventHub from './eventhub';
|
2018-02-26 14:43:34 -05:00
|
|
|
import sidebarEventHub from '~/sidebar/event_hub'; // eslint-disable-line import/first
|
2017-05-16 16:31:45 -04:00
|
|
|
import './models/issue';
|
|
|
|
import './models/list';
|
|
|
|
import './models/milestone';
|
2018-02-19 14:06:16 -05:00
|
|
|
import './models/project';
|
2017-05-16 16:31:45 -04:00
|
|
|
import './stores/boards_store';
|
2018-04-06 08:12:21 -04:00
|
|
|
import ModalStore from './stores/modal_store';
|
2017-11-14 01:05:40 -05:00
|
|
|
import BoardService from './services/board_service';
|
2018-04-06 08:12:21 -04:00
|
|
|
import modalMixin from './mixins/modal_mixins';
|
2017-05-16 16:31:45 -04:00
|
|
|
import './mixins/sortable_default_options';
|
|
|
|
import './filters/due_date_filters';
|
|
|
|
import './components/board';
|
|
|
|
import './components/board_sidebar';
|
|
|
|
import './components/new_list_dropdown';
|
2018-06-26 08:29:06 -04:00
|
|
|
import BoardAddIssuesModal from './components/modal/index.vue';
|
2018-02-26 14:43:34 -05:00
|
|
|
import '~/vue_shared/vue_resource_interceptor'; // eslint-disable-line import/first
|
2016-07-28 07:33:04 -04:00
|
|
|
|
2018-02-21 17:28:08 -05:00
|
|
|
export default () => {
|
2017-01-11 22:49:57 -05:00
|
|
|
const $boardApp = document.getElementById('board-app');
|
|
|
|
const Store = gl.issueBoards.BoardsStore;
|
2016-08-11 04:51:52 -04:00
|
|
|
|
2016-08-15 04:57:01 -04:00
|
|
|
window.gl = window.gl || {};
|
2016-07-28 07:33:04 -04:00
|
|
|
|
2016-08-05 09:00:06 -04:00
|
|
|
if (gl.IssueBoardsApp) {
|
|
|
|
gl.IssueBoardsApp.$destroy(true);
|
|
|
|
}
|
|
|
|
|
2016-11-04 06:24:59 -04:00
|
|
|
Store.create();
|
|
|
|
|
2017-04-07 15:36:09 -04:00
|
|
|
// hack to allow sidebar scripts like milestone_select manipulate the BoardsStore
|
|
|
|
gl.issueBoards.boardStoreIssueSet = (...args) => Vue.set(Store.detail.issue, ...args);
|
|
|
|
gl.issueBoards.boardStoreIssueDelete = (...args) => Vue.delete(Store.detail.issue, ...args);
|
|
|
|
|
2016-08-05 09:00:06 -04:00
|
|
|
gl.IssueBoardsApp = new Vue({
|
2016-08-16 04:02:45 -04:00
|
|
|
el: $boardApp,
|
2016-08-15 05:07:53 -04:00
|
|
|
components: {
|
2018-07-25 11:38:43 -04:00
|
|
|
board: gl.issueBoards.Board,
|
2017-01-24 05:27:41 -05:00
|
|
|
'board-sidebar': gl.issueBoards.BoardSidebar,
|
2018-06-26 08:29:06 -04:00
|
|
|
BoardAddIssuesModal,
|
2016-08-15 05:07:53 -04:00
|
|
|
},
|
2016-07-28 07:33:04 -04:00
|
|
|
data: {
|
2016-08-16 04:02:45 -04:00
|
|
|
state: Store.state,
|
2016-08-11 04:51:52 -04:00
|
|
|
loading: true,
|
2017-09-06 01:02:30 -04:00
|
|
|
boardsEndpoint: $boardApp.dataset.boardsEndpoint,
|
|
|
|
listsEndpoint: $boardApp.dataset.listsEndpoint,
|
2016-10-11 04:29:47 -04:00
|
|
|
boardId: $boardApp.dataset.boardId,
|
2016-08-16 04:02:45 -04:00
|
|
|
disabled: $boardApp.dataset.disabled === 'true',
|
2016-10-19 17:26:51 -04:00
|
|
|
issueLinkBase: $boardApp.dataset.issueLinkBase,
|
2017-01-31 05:39:44 -05:00
|
|
|
rootPath: $boardApp.dataset.rootPath,
|
2017-01-31 09:35:53 -05:00
|
|
|
bulkUpdatePath: $boardApp.dataset.bulkUpdatePath,
|
2017-05-04 11:33:25 -04:00
|
|
|
detailIssue: Store.detail,
|
|
|
|
defaultAvatar: $boardApp.dataset.defaultAvatar,
|
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() {
|
2017-09-06 01:02:30 -04:00
|
|
|
gl.boardService = new BoardService({
|
|
|
|
boardsEndpoint: this.boardsEndpoint,
|
|
|
|
listsEndpoint: this.listsEndpoint,
|
|
|
|
bulkUpdatePath: this.bulkUpdatePath,
|
|
|
|
boardId: this.boardId,
|
|
|
|
});
|
|
|
|
Store.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-02-19 14:06:16 -05:00
|
|
|
this.filterManager = new FilteredSearchBoards(Store.filter, true, Store.cantEdit);
|
2017-09-26 17:19:28 -04:00
|
|
|
this.filterManager.setup();
|
|
|
|
|
2016-08-16 04:02:45 -04:00
|
|
|
Store.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)
|
2018-07-25 11:38:43 -04:00
|
|
|
.then(data => {
|
|
|
|
data.forEach(board => {
|
2017-05-04 11:33:25 -04:00
|
|
|
const list = Store.addList(board, this.defaultAvatar);
|
2016-08-04 11:16:50 -04:00
|
|
|
|
2017-03-24 08:40:35 -04:00
|
|
|
if (list.type === 'closed') {
|
2016-08-11 04:51:52 -04:00
|
|
|
list.position = Infinity;
|
2017-06-01 11:03:48 -04:00
|
|
|
} else if (list.type === 'backlog') {
|
|
|
|
list.position = -1;
|
2016-08-04 11:16:50 -04:00
|
|
|
}
|
2016-08-17 08:57:36 -04:00
|
|
|
});
|
2016-08-04 11:16:50 -04:00
|
|
|
|
2016-11-09 04:23:48 -05:00
|
|
|
this.state.lists = _.sortBy(this.state.lists, 'position');
|
|
|
|
|
2016-08-16 04:02:45 -04:00
|
|
|
Store.addBlankState();
|
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-03-09 07:32:43 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateTokens() {
|
|
|
|
this.filterManager.updateTokens();
|
2017-11-14 01:05:40 -05:00
|
|
|
},
|
|
|
|
updateDetailIssue(newIssue) {
|
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);
|
|
|
|
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 => {
|
2017-11-14 01:05:40 -05:00
|
|
|
newIssue.setFetchingState('subscriptions', false);
|
|
|
|
newIssue.updateData({
|
|
|
|
subscribed: data.subscribed,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
newIssue.setFetchingState('subscriptions', false);
|
|
|
|
Flash(__('An error occurred while fetching sidebar data'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Store.detail.issue = newIssue;
|
|
|
|
},
|
|
|
|
clearDetailIssue() {
|
|
|
|
Store.detail.issue = {};
|
|
|
|
},
|
|
|
|
toggleSubscription(id) {
|
2018-06-16 17:50:13 -04:00
|
|
|
const { issue } = Store.detail;
|
2017-11-14 01:05:40 -05:00
|
|
|
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
|
|
|
},
|
2017-03-09 07:32:43 -05:00
|
|
|
},
|
2016-07-28 07:33:04 -04:00
|
|
|
});
|
2016-08-30 05:32:19 -04:00
|
|
|
|
|
|
|
gl.IssueBoardsSearch = 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: {
|
2017-09-06 01:02:30 -04:00
|
|
|
filters: Store.state.filters,
|
2016-11-04 06:24:59 -04:00
|
|
|
},
|
2018-07-25 11:38:43 -04:00
|
|
|
mounted() {
|
2016-11-04 06:24:59 -04:00
|
|
|
gl.issueBoards.newListDropdownInit();
|
2017-09-06 01:02:30 -04:00
|
|
|
},
|
2016-08-30 05:32:19 -04:00
|
|
|
});
|
2017-01-24 05:27:41 -05:00
|
|
|
|
2018-07-25 11:38:43 -04:00
|
|
|
const issueBoardsModal = document.getElementById('js-add-issues-btn');
|
|
|
|
|
|
|
|
if (issueBoardsModal) {
|
|
|
|
gl.IssueBoardsModalAddBtn = new Vue({
|
|
|
|
el: issueBoardsModal,
|
|
|
|
mixins: [modalMixin],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
modal: ModalStore.store,
|
|
|
|
store: Store.state,
|
|
|
|
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) {
|
|
|
|
return 'Please add a list to your board first';
|
|
|
|
}
|
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
|
|
|
|
class="btn btn-create prepend-left-10"
|
|
|
|
type="button"
|
|
|
|
data-placement="bottom"
|
|
|
|
ref="addIssuesButton"
|
|
|
|
:class="{ 'disabled': disabled }"
|
|
|
|
:title="tooltipTitle"
|
|
|
|
:aria-disabled="disabled"
|
|
|
|
v-if="canAdminList"
|
|
|
|
@click="openModal">
|
|
|
|
Add issues
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
}
|
2018-02-21 17:28:08 -05:00
|
|
|
};
|