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

146 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-09-30 21:07:59 +05:30
import $ from 'jquery';
2018-11-08 19:23:39 +05:30
import Sortable from 'sortablejs';
2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2019-09-30 21:07:59 +05:30
import { n__, s__ } from '~/locale';
2018-11-18 11:00:15 +05:30
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: {
2019-12-04 20:38:33 +05:30
isLoggedIn() {
return Boolean(gon.current_user_id);
},
2018-11-18 11:00:15 +05:30
counterTooltip() {
const { issuesSize } = this.list;
return `${n__('%d issue', '%d issues', issuesSize)}`;
},
2019-09-30 21:07:59 +05:30
caretTooltip() {
return this.list.isExpanded ? s__('Boards|Collapse') : s__('Boards|Expand');
},
2018-12-13 13:39:08 +05:30
isNewIssueShown() {
2019-07-07 11:18:12 +05:30
return (
this.list.type === 'backlog' ||
(!this.disabled && this.list.type !== 'closed' && this.list.type !== 'blank')
);
2018-12-13 13:39:08 +05:30
},
2019-09-30 21:07:59 +05:30
uniqueKey() {
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
return `boards.${this.boardId}.${this.list.type}.${this.list.id}`;
},
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() {
2019-09-30 21:07:59 +05:30
const instance = this;
const sortableOptions = getBoardSortableDefaultOptions({
2017-08-17 22:00:37 +05:30
disabled: this.disabled,
group: 'boards',
draggable: '.is-draggable',
handle: '.js-board-handle',
2019-09-30 21:07:59 +05:30
onEnd(e) {
2018-12-13 13:39:08 +05:30
sortableEnd();
2017-08-17 22:00:37 +05:30
2019-09-30 21:07:59 +05:30
const sortable = this;
2017-08-17 22:00:37 +05:30
if (e.newIndex !== undefined && e.oldIndex !== e.newIndex) {
2019-09-30 21:07:59 +05:30
const order = 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
2019-09-30 21:07:59 +05:30
instance.$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
});
2019-09-30 21:07:59 +05:30
Sortable.create(this.$el.parentNode, sortableOptions);
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
created() {
2019-12-04 20:38:33 +05:30
if (
this.list.isExpandable &&
AccessorUtilities.isLocalStorageAccessSafe() &&
!this.isLoggedIn
) {
2019-09-30 21:07:59 +05:30
const isCollapsed = localStorage.getItem(`${this.uniqueKey}.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;
},
2019-09-30 21:07:59 +05:30
toggleExpanded() {
if (this.list.isExpandable) {
2018-11-08 19:23:39 +05:30
this.list.isExpanded = !this.list.isExpanded;
2019-12-04 20:38:33 +05:30
if (AccessorUtilities.isLocalStorageAccessSafe() && !this.isLoggedIn) {
2019-09-30 21:07:59 +05:30
localStorage.setItem(`${this.uniqueKey}.expanded`, this.list.isExpanded);
2018-11-08 19:23:39 +05:30
}
2019-09-30 21:07:59 +05:30
2019-12-04 20:38:33 +05:30
if (this.isLoggedIn) {
this.list.update();
}
2019-09-30 21:07:59 +05:30
// When expanding/collapsing, the tooltip on the caret button sometimes stays open.
// Close all tooltips manually to prevent dangling tooltips.
$('.tooltip').tooltip('hide');
2018-11-08 19:23:39 +05:30
}
},
},
template: '#js-board-template',
2017-08-17 22:00:37 +05:30
});