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

268 lines
7.5 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2019-10-12 21:52:04 +05:30
/* eslint-disable @gitlab/vue-i18n/no-bare-strings */
2018-11-08 19:23:39 +05:30
import Sortable from 'sortablejs';
2019-02-15 15:39:39 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2018-03-27 19:54:05 +05:30
import boardNewIssue from './board_new_issue.vue';
2018-03-17 18:26:18 +05:30
import boardCard from './board_card.vue';
2017-08-17 22:00:37 +05:30
import eventHub from '../eventhub';
2018-12-13 13:39:08 +05:30
import boardsStore from '../stores/boards_store';
import { getBoardSortableDefaultOptions, sortableStart } from '../mixins/sortable_default_options';
2017-08-17 22:00:37 +05:30
export default {
name: 'BoardList',
2018-03-17 18:26:18 +05:30
components: {
boardCard,
boardNewIssue,
2018-12-13 13:39:08 +05:30
GlLoadingIcon,
2018-03-17 18:26:18 +05:30
},
2017-08-17 22:00:37 +05:30
props: {
2018-03-27 19:54:05 +05:30
groupId: {
type: Number,
required: false,
default: 0,
},
2017-08-17 22:00:37 +05:30
disabled: {
type: Boolean,
required: true,
},
list: {
type: Object,
required: true,
},
issues: {
type: Array,
required: true,
},
loading: {
type: Boolean,
required: true,
},
issueLinkBase: {
type: String,
required: true,
},
rootPath: {
type: String,
required: true,
},
},
data() {
return {
scrollOffset: 250,
2018-12-13 13:39:08 +05:30
filters: boardsStore.state.filters,
2017-08-17 22:00:37 +05:30
showCount: false,
showIssueForm: false,
};
},
watch: {
filters: {
handler() {
this.list.loadingMore = false;
this.$refs.list.scrollTop = 0;
},
deep: true,
},
issues() {
this.$nextTick(() => {
2018-12-13 13:39:08 +05:30
if (
this.scrollHeight() <= this.listHeight() &&
this.list.issuesSize > this.list.issues.length
) {
2017-08-17 22:00:37 +05:30
this.list.page += 1;
2018-12-13 13:39:08 +05:30
this.list.getIssues(false).catch(() => {
// TODO: handle request error
});
2017-08-17 22:00:37 +05:30
}
if (this.scrollHeight() > Math.ceil(this.listHeight())) {
this.showCount = true;
} else {
this.showCount = false;
}
});
},
},
created() {
eventHub.$on(`hide-issue-form-${this.list.id}`, this.toggleForm);
2017-09-10 17:25:29 +05:30
eventHub.$on(`scroll-board-list-${this.list.id}`, this.scrollToTop);
2017-08-17 22:00:37 +05:30
},
mounted() {
2018-12-13 13:39:08 +05:30
const options = getBoardSortableDefaultOptions({
2018-03-17 18:26:18 +05:30
scroll: true,
2017-08-17 22:00:37 +05:30
disabled: this.disabled,
filter: '.board-list-count, .is-disabled',
dataIdAttr: 'data-issue-id',
2018-11-08 19:23:39 +05:30
group: {
name: 'issues',
/**
* Dynamically determine between which containers
* items can be moved or copied as
* Assignee lists (EE feature) require this behavior
*/
pull: (to, from, dragEl, e) => {
// As per Sortable's docs, `to` should provide
// reference to exact sortable container on which
// we're trying to drag element, but either it is
// a library's bug or our markup structure is too complex
// that `to` never points to correct container
// See https://github.com/RubaXa/Sortable/issues/1037
//
// So we use `e.target` which is always accurate about
// which element we're currently dragging our card upon
// So from there, we can get reference to actual container
// and thus the container type to enable Copy or Move
if (e.target) {
2018-12-13 13:39:08 +05:30
const containerEl =
e.target.closest('.js-board-list') || e.target.querySelector('.js-board-list');
2018-11-08 19:23:39 +05:30
const toBoardType = containerEl.dataset.boardType;
2018-11-18 11:00:15 +05:30
const cloneActions = {
label: ['milestone', 'assignee'],
assignee: ['milestone', 'label'],
milestone: ['label', 'assignee'],
};
2018-11-08 19:23:39 +05:30
if (toBoardType) {
const fromBoardType = this.list.type;
2018-11-18 11:00:15 +05:30
// For each list we check if the destination list is
// a the list were we should clone the issue
2018-12-13 13:39:08 +05:30
const shouldClone = Object.entries(cloneActions).some(
entry => fromBoardType === entry[0] && entry[1].includes(toBoardType),
);
2018-11-08 19:23:39 +05:30
2018-11-18 11:00:15 +05:30
if (shouldClone) {
2018-11-08 19:23:39 +05:30
return 'clone';
}
}
}
return true;
},
revertClone: true,
},
2018-12-13 13:39:08 +05:30
onStart: e => {
2017-08-17 22:00:37 +05:30
const card = this.$refs.issue[e.oldIndex];
card.showDetail = false;
2019-09-04 21:01:54 +05:30
const { list } = card;
const issue = list.findIssue(Number(e.item.dataset.issueId));
boardsStore.startMoving(list, issue);
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
sortableStart();
2017-08-17 22:00:37 +05:30
},
2018-12-13 13:39:08 +05:30
onAdd: e => {
boardsStore.moveIssueToList(
boardsStore.moving.list,
this.list,
boardsStore.moving.issue,
e.newIndex,
);
2017-08-17 22:00:37 +05:30
this.$nextTick(() => {
e.item.remove();
});
},
2018-12-13 13:39:08 +05:30
onUpdate: e => {
const sortedArray = this.sortable.toArray().filter(id => id !== '-1');
boardsStore.moveIssueInList(
this.list,
boardsStore.moving.issue,
e.oldIndex,
e.newIndex,
sortedArray,
);
2017-08-17 22:00:37 +05:30
},
onMove(e) {
return !e.related.classList.contains('board-list-count');
},
});
this.sortable = Sortable.create(this.$refs.list, options);
// Scroll event on list to load more
this.$refs.list.addEventListener('scroll', this.onScroll);
},
beforeDestroy() {
eventHub.$off(`hide-issue-form-${this.list.id}`, this.toggleForm);
2017-09-10 17:25:29 +05:30
eventHub.$off(`scroll-board-list-${this.list.id}`, this.scrollToTop);
2017-08-17 22:00:37 +05:30
this.$refs.list.removeEventListener('scroll', this.onScroll);
},
2018-03-17 18:26:18 +05:30
methods: {
listHeight() {
return this.$refs.list.getBoundingClientRect().height;
},
scrollHeight() {
return this.$refs.list.scrollHeight;
},
scrollTop() {
return this.$refs.list.scrollTop + this.listHeight();
},
scrollToTop() {
this.$refs.list.scrollTop = 0;
},
loadNextPage() {
const getIssues = this.list.nextPage();
const loadingDone = () => {
this.list.loadingMore = false;
};
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
if (getIssues) {
this.list.loadingMore = true;
2018-12-13 13:39:08 +05:30
getIssues.then(loadingDone).catch(loadingDone);
2018-03-17 18:26:18 +05:30
}
},
toggleForm() {
this.showIssueForm = !this.showIssueForm;
},
onScroll() {
2018-12-13 13:39:08 +05:30
if (!this.list.loadingMore && this.scrollTop() > this.scrollHeight() - this.scrollOffset) {
2018-03-17 18:26:18 +05:30
this.loadNextPage();
}
},
},
};
</script>
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
<template>
2019-07-31 22:56:46 +05:30
<div
:class="{ 'd-none': !list.isExpanded, 'd-flex flex-column': list.isExpanded }"
class="board-list-component position-relative h-100"
2019-12-04 20:38:33 +05:30
data-qa-selector="board_list_cards_area"
2019-07-31 22:56:46 +05:30
>
2019-09-30 21:07:59 +05:30
<div v-if="loading" class="board-list-loading text-center" :aria-label="__('Loading issues')">
2018-12-05 23:21:45 +05:30
<gl-loading-icon />
2017-08-17 22:00:37 +05:30
</div>
2018-03-17 18:26:18 +05:30
<board-new-issue
2018-11-08 19:23:39 +05:30
v-if="list.type !== 'closed' && showIssueForm"
2018-03-27 19:54:05 +05:30
:group-id="groupId"
2019-02-15 15:39:39 +05:30
:list="list"
/>
2018-03-17 18:26:18 +05:30
<ul
v-show="!loading"
ref="list"
:data-board="list.id"
2018-11-08 19:23:39 +05:30
:data-board-type="list.type"
:class="{ 'is-smaller': showIssueForm }"
2019-07-31 22:56:46 +05:30
class="board-list w-100 h-100 list-unstyled mb-0 p-1 js-board-list"
2019-02-15 15:39:39 +05:30
>
2018-03-17 18:26:18 +05:30
<board-card
v-for="(issue, index) in issues"
ref="issue"
2018-12-05 23:21:45 +05:30
:key="issue.id"
2018-03-17 18:26:18 +05:30
:index="index"
:list="list"
:issue="issue"
:issue-link-base="issueLinkBase"
2018-03-27 19:54:05 +05:30
:group-id="groupId"
2018-03-17 18:26:18 +05:30
:root-path="rootPath"
2019-02-15 15:39:39 +05:30
:disabled="disabled"
/>
<li v-if="showCount" class="board-list-count text-center" data-issue-id="-1">
<gl-loading-icon v-show="list.loadingMore" label="Loading more issues" />
2019-09-30 21:07:59 +05:30
<span v-if="list.issues.length === list.issuesSize">{{ __('Showing all issues') }}</span>
2019-02-15 15:39:39 +05:30
<span v-else> Showing {{ list.issues.length }} of {{ list.issuesSize }} issues </span>
2018-03-17 18:26:18 +05:30
</li>
</ul>
</div>
</template>