debian-mirror-gitlab/app/assets/javascripts/boards/components/board.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
/* eslint-disable comma-dangle */
2018-05-09 12:01:36 +05:30
2018-11-08 19:23:39 +05:30
import Sortable from 'sortablejs';
2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2017-09-10 17:25:29 +05:30
import AccessorUtilities from '../../lib/utils/accessor';
2018-03-17 18:26:18 +05:30
import boardList from './board_list.vue';
2018-10-15 14:42:47 +05:30
import BoardBlankState from './board_blank_state.vue';
2017-09-10 17:25:29 +05:30
import './board_delete';
2017-08-17 22:00:37 +05:30
const Store = gl.issueBoards.BoardsStore;
window.gl = window.gl || {};
window.gl.issueBoards = window.gl.issueBoards || {};
gl.issueBoards.Board = Vue.extend({
components: {
boardList,
'board-delete': gl.issueBoards.BoardDelete,
2018-10-15 14:42:47 +05:30
BoardBlankState,
2017-08-17 22:00:37 +05:30
},
props: {
2018-11-08 19:23:39 +05:30
list: {
type: Object,
default: () => ({}),
},
disabled: {
type: Boolean,
required: true,
},
issueLinkBase: {
type: String,
required: true,
},
rootPath: {
type: String,
required: true,
},
2017-09-10 17:25:29 +05:30
boardId: {
type: String,
required: true,
},
2017-08-17 22:00:37 +05:30
},
data () {
return {
detailIssue: Store.detail,
filter: Store.filter,
};
},
watch: {
filter: {
handler() {
this.list.page = 1;
this.list.getIssues(true)
.catch(() => {
// TODO: handle request error
});
},
deep: true,
}
},
mounted () {
this.sortableOptions = gl.issueBoards.getBoardSortableDefaultOptions({
disabled: this.disabled,
group: 'boards',
draggable: '.is-draggable',
handle: '.js-board-handle',
onEnd: (e) => {
gl.issueBoards.onEnd();
if (e.newIndex !== undefined && e.oldIndex !== e.newIndex) {
const order = this.sortable.toArray();
const list = Store.findList('id', parseInt(e.item.dataset.id, 10));
this.$nextTick(() => {
Store.moveList(list, order);
});
}
}
});
this.sortable = Sortable.create(this.$el.parentNode, this.sortableOptions);
},
2017-09-10 17:25:29 +05:30
created() {
if (this.list.isExpandable && AccessorUtilities.isLocalStorageAccessSafe()) {
const isCollapsed = localStorage.getItem(`boards.${this.boardId}.${this.list.type}.expanded`) === 'false';
this.list.isExpanded = !isCollapsed;
}
},
2018-11-08 19:23:39 +05:30
methods: {
showNewIssueForm() {
this.$refs['board-list'].showIssueForm = !this.$refs['board-list'].showIssueForm;
},
toggleExpanded(e) {
if (this.list.isExpandable && !e.target.classList.contains('js-no-trigger-collapse')) {
this.list.isExpanded = !this.list.isExpanded;
if (AccessorUtilities.isLocalStorageAccessSafe()) {
localStorage.setItem(`boards.${this.boardId}.${this.list.type}.expanded`, this.list.isExpanded);
}
}
},
},
template: '#js-board-template',
2017-08-17 22:00:37 +05:30
});