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

120 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import Sortable from 'sortablejs';
2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2018-11-18 11:00:15 +05:30
import { n__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
import Tooltip from '~/vue_shared/directives/tooltip';
2017-09-10 17:25:29 +05:30
import AccessorUtilities from '../../lib/utils/accessor';
2018-10-15 14:42:47 +05:30
import BoardBlankState from './board_blank_state.vue';
2018-12-13 13:39:08 +05:30
import BoardDelete from './board_delete';
import BoardList from './board_list.vue';
import boardsStore from '../stores/boards_store';
import { getBoardSortableDefaultOptions, sortableEnd } from '../mixins/sortable_default_options';
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
export default Vue.extend({
2017-08-17 22:00:37 +05:30
components: {
2018-10-15 14:42:47 +05:30
BoardBlankState,
2018-12-13 13:39:08 +05:30
BoardDelete,
BoardList,
2018-11-18 11:00:15 +05:30
Icon,
},
directives: {
Tooltip,
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
},
2018-12-13 13:39:08 +05:30
data() {
2017-08-17 22:00:37 +05:30
return {
2018-12-13 13:39:08 +05:30
detailIssue: boardsStore.detail,
filter: boardsStore.filter,
2017-08-17 22:00:37 +05:30
};
},
2018-11-18 11:00:15 +05:30
computed: {
counterTooltip() {
const { issuesSize } = this.list;
return `${n__('%d issue', '%d issues', issuesSize)}`;
},
2018-12-13 13:39:08 +05:30
isNewIssueShown() {
return this.list.type === 'backlog' || (!this.disabled && this.list.type !== 'closed');
},
2018-11-18 11:00:15 +05:30
},
2017-08-17 22:00:37 +05:30
watch: {
filter: {
handler() {
this.list.page = 1;
2018-12-13 13:39:08 +05:30
this.list.getIssues(true).catch(() => {
// TODO: handle request error
});
2017-08-17 22:00:37 +05:30
},
deep: true,
2018-12-13 13:39:08 +05:30
},
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
mounted() {
this.sortableOptions = getBoardSortableDefaultOptions({
2017-08-17 22:00:37 +05:30
disabled: this.disabled,
group: 'boards',
draggable: '.is-draggable',
handle: '.js-board-handle',
2018-12-13 13:39:08 +05:30
onEnd: e => {
sortableEnd();
2017-08-17 22:00:37 +05:30
if (e.newIndex !== undefined && e.oldIndex !== e.newIndex) {
const order = this.sortable.toArray();
2018-12-13 13:39:08 +05:30
const list = boardsStore.findList('id', parseInt(e.item.dataset.id, 10));
2017-08-17 22:00:37 +05:30
this.$nextTick(() => {
2018-12-13 13:39:08 +05:30
boardsStore.moveList(list, order);
2017-08-17 22:00:37 +05:30
});
}
2018-12-13 13:39:08 +05:30
},
2017-08-17 22:00:37 +05:30
});
this.sortable = Sortable.create(this.$el.parentNode, this.sortableOptions);
},
2017-09-10 17:25:29 +05:30
created() {
if (this.list.isExpandable && AccessorUtilities.isLocalStorageAccessSafe()) {
2018-12-13 13:39:08 +05:30
const isCollapsed =
localStorage.getItem(`boards.${this.boardId}.${this.list.type}.expanded`) === 'false';
2017-09-10 17:25:29 +05:30
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()) {
2018-12-13 13:39:08 +05:30
localStorage.setItem(
`boards.${this.boardId}.${this.list.type}.expanded`,
this.list.isExpanded,
);
2018-11-08 19:23:39 +05:30
}
}
},
},
template: '#js-board-template',
2017-08-17 22:00:37 +05:30
});