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

196 lines
5.3 KiB
JavaScript
Raw Normal View History

2017-03-08 12:21:07 +00:00
/* eslint-disable one-var, quote-props, comma-dangle, space-before-function-paren */
/* global BoardService */
/* global Flash */
import _ from 'underscore';
2017-03-17 17:21:25 +00:00
import Vue from 'vue';
import VueResource from 'vue-resource';
import FilteredSearchBoards from './filtered_search_boards';
import eventHub from './eventhub';
import './models/issue';
import './models/label';
import './models/list';
import './models/milestone';
import './models/assignee';
import './stores/boards_store';
import './stores/modal_store';
import './services/board_service';
import './mixins/modal_mixins';
import './mixins/sortable_default_options';
import './filters/due_date_filters';
import './components/board';
import './components/board_sidebar';
import './components/new_list_dropdown';
import './components/modal/index';
import '../vue_shared/vue_resource_interceptor';
2016-07-28 11:33:04 +00:00
2017-03-17 17:21:25 +00:00
Vue.use(VueResource);
$(() => {
2017-01-12 03:49:57 +00:00
const $boardApp = document.getElementById('board-app');
const Store = gl.issueBoards.BoardsStore;
2017-01-25 16:53:09 +00:00
const ModalStore = gl.issueBoards.ModalStore;
window.gl = window.gl || {};
2016-07-28 11:33:04 +00:00
if (gl.IssueBoardsApp) {
gl.IssueBoardsApp.$destroy(true);
}
Store.create();
// 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);
gl.IssueBoardsApp = new Vue({
el: $boardApp,
components: {
2016-10-04 14:27:02 +00:00
'board': gl.issueBoards.Board,
'board-sidebar': gl.issueBoards.BoardSidebar,
'board-add-issues-modal': gl.issueBoards.IssuesModal,
},
2016-07-28 11:33:04 +00:00
data: {
state: Store.state,
loading: true,
boardsEndpoint: $boardApp.dataset.boardsEndpoint,
listsEndpoint: $boardApp.dataset.listsEndpoint,
boardId: $boardApp.dataset.boardId,
disabled: $boardApp.dataset.disabled === 'true',
issueLinkBase: $boardApp.dataset.issueLinkBase,
rootPath: $boardApp.dataset.rootPath,
bulkUpdatePath: $boardApp.dataset.bulkUpdatePath,
2017-05-04 15:33:25 +00:00
detailIssue: Store.detail,
defaultAvatar: $boardApp.dataset.defaultAvatar,
2016-07-28 11:33:04 +00:00
},
computed: {
detailIssueVisible () {
return Object.keys(this.detailIssue.issue).length;
},
},
created () {
gl.boardService = new BoardService({
boardsEndpoint: this.boardsEndpoint,
listsEndpoint: this.listsEndpoint,
bulkUpdatePath: this.bulkUpdatePath,
boardId: this.boardId,
});
Store.rootPath = this.boardsEndpoint;
this.filterManager = new FilteredSearchBoards(Store.filter, true);
this.filterManager.setup();
// Listen for updateTokens event
eventHub.$on('updateTokens', this.updateTokens);
},
beforeDestroy() {
eventHub.$off('updateTokens', this.updateTokens);
2016-08-08 15:15:05 +00:00
},
2016-11-03 00:37:33 +00:00
mounted () {
Store.disabled = this.disabled;
gl.boardService.all()
2017-07-12 14:47:09 +00:00
.then(response => response.json())
2016-08-19 13:16:07 +00:00
.then((resp) => {
2017-07-12 14:47:09 +00:00
resp.forEach((board) => {
2017-05-04 15:33:25 +00:00
const list = Store.addList(board, this.defaultAvatar);
if (list.type === 'closed') {
list.position = Infinity;
list.label = { description: 'Shows all closed issues. Moving an issue to this list closes it' };
} else if (list.type === 'backlog') {
list.position = -1;
}
2016-08-17 12:57:36 +00:00
});
2016-11-09 09:23:48 +00:00
this.state.lists = _.sortBy(this.state.lists, 'position');
Store.addBlankState();
2016-08-08 15:15:05 +00:00
this.loading = false;
2017-07-12 14:47:09 +00:00
})
.catch(() => new Flash('An error occurred. Please try again.'));
},
methods: {
updateTokens() {
this.filterManager.updateTokens();
}
},
2016-07-28 11:33:04 +00:00
});
gl.IssueBoardsSearch = new Vue({
2017-03-08 12:17:01 +00:00
el: document.getElementById('js-add-list'),
data: {
filters: Store.state.filters,
},
mounted () {
gl.issueBoards.newListDropdownInit();
},
});
gl.IssueBoardsModalAddBtn = new Vue({
2017-01-31 16:46:57 +00:00
mixins: [gl.issueBoards.ModalMixins],
2017-02-03 20:42:30 +00:00
el: document.getElementById('js-add-issues-btn'),
data() {
return {
modal: ModalStore.store,
store: Store.state,
};
},
watch: {
disabled() {
this.updateTooltip();
},
},
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';
}
return '';
},
},
methods: {
updateTooltip() {
const $tooltip = $(this.$refs.addIssuesButton);
this.$nextTick(() => {
if (this.disabled) {
$tooltip.tooltip();
} else {
$tooltip.tooltip('destroy');
}
});
},
openModal() {
if (!this.disabled) {
this.toggleModal(true);
}
},
},
mounted() {
this.updateTooltip();
},
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"
@click="openModal">
Add issues
</button>
</div>
`,
});
2016-07-28 11:33:04 +00:00
});