debian-mirror-gitlab/app/assets/javascripts/boards/components/board_content.vue

123 lines
3.2 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2021-02-22 17:27:13 +05:30
import Draggable from 'vuedraggable';
2020-11-24 15:15:51 +05:30
import { mapState, mapGetters, mapActions } from 'vuex';
2021-01-03 14:25:43 +05:30
import { sortBy } from 'lodash';
2020-11-24 15:15:51 +05:30
import { GlAlert } from '@gitlab/ui';
2021-03-08 18:12:59 +05:30
import BoardColumnDeprecated from './board_column_deprecated.vue';
2021-02-22 17:27:13 +05:30
import BoardColumn from './board_column.vue';
2020-10-24 23:57:45 +05:30
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2021-02-22 17:27:13 +05:30
import defaultSortableConfig from '~/sortable/sortable_config';
import { sortableEnd, sortableStart } from '~/boards/mixins/sortable_default_options';
2020-06-23 00:09:42 +05:30
export default {
components: {
2021-03-08 18:12:59 +05:30
BoardColumn: gon.features?.graphqlBoardLists ? BoardColumn : BoardColumnDeprecated,
2020-11-24 15:15:51 +05:30
BoardContentSidebar: () => import('ee_component/boards/components/board_content_sidebar.vue'),
EpicsSwimlanes: () => import('ee_component/boards/components/epics_swimlanes.vue'),
GlAlert,
2020-06-23 00:09:42 +05:30
},
mixins: [glFeatureFlagMixin()],
props: {
lists: {
type: Array,
2021-03-08 18:12:59 +05:30
required: false,
default: () => [],
2020-06-23 00:09:42 +05:30
},
canAdminList: {
type: Boolean,
required: true,
},
disabled: {
type: Boolean,
required: true,
},
},
computed: {
2020-11-24 15:15:51 +05:30
...mapState(['boardLists', 'error']),
...mapGetters(['isSwimlanesOn']),
boardListsToUse() {
2021-02-22 17:27:13 +05:30
return this.glFeatures.graphqlBoardLists || this.isSwimlanesOn
? sortBy([...Object.values(this.boardLists)], 'position')
: this.lists;
},
canDragColumns() {
return this.glFeatures.graphqlBoardLists && this.canAdminList;
},
boardColumnWrapper() {
return this.canDragColumns ? Draggable : 'div';
},
draggableOptions() {
const options = {
...defaultSortableConfig,
disabled: this.disabled,
draggable: '.is-draggable',
fallbackOnBody: false,
group: 'boards-list',
tag: 'div',
2021-03-08 18:12:59 +05:30
value: this.boardListsToUse,
2021-02-22 17:27:13 +05:30
};
return this.canDragColumns ? options : {};
2020-06-23 00:09:42 +05:30
},
2020-11-24 15:15:51 +05:30
},
methods: {
2021-02-22 17:27:13 +05:30
...mapActions(['moveList']),
handleDragOnStart() {
sortableStart();
},
handleDragOnEnd(params) {
sortableEnd();
const { item, newIndex, oldIndex, to } = params;
const listId = item.dataset.id;
const replacedListId = to.children[newIndex].dataset.id;
this.moveList({
listId,
replacedListId,
newIndex,
adjustmentValue: newIndex < oldIndex ? 1 : -1,
});
},
2020-11-24 15:15:51 +05:30
},
2020-06-23 00:09:42 +05:30
};
</script>
<template>
<div>
2020-11-24 15:15:51 +05:30
<gl-alert v-if="error" variant="danger" :dismissible="false">
{{ error }}
</gl-alert>
2021-02-22 17:27:13 +05:30
<component
:is="boardColumnWrapper"
2020-06-23 00:09:42 +05:30
v-if="!isSwimlanesOn"
2021-02-22 17:27:13 +05:30
ref="list"
v-bind="draggableOptions"
2020-07-28 23:09:34 +05:30
class="boards-list gl-w-full gl-py-5 gl-px-3 gl-white-space-nowrap"
2021-02-22 17:27:13 +05:30
@start="handleDragOnStart"
@end="handleDragOnEnd"
2020-06-23 00:09:42 +05:30
>
<board-column
2020-11-24 15:15:51 +05:30
v-for="list in boardListsToUse"
2020-06-23 00:09:42 +05:30
:key="list.id"
ref="board"
:can-admin-list="canAdminList"
:list="list"
:disabled="disabled"
/>
2021-02-22 17:27:13 +05:30
</component>
2020-11-24 15:15:51 +05:30
2021-03-08 18:12:59 +05:30
<epics-swimlanes
v-else
ref="swimlanes"
:lists="boardListsToUse"
:can-admin-list="canAdminList"
:disabled="disabled"
/>
<board-content-sidebar v-if="isSwimlanesOn || glFeatures.graphqlBoardLists" />
2020-06-23 00:09:42 +05:30
</div>
</template>