Skip to content

Commit 5377c44

Browse files
Merge pull request #10 from vue-pivottable/feat/dragndrop
Feat/dragndrop
2 parents edb43ad + 7ac7f23 commit 5377c44

File tree

3 files changed

+201
-164
lines changed

3 files changed

+201
-164
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
<template>
22
<td>
3-
<h3>VDragAndDropCell ({{ attrs }})</h3>
3+
<h3>VDragAndDropCell ({{ cellType }})</h3>
44
<Draggable
5-
v-model="modelItems"
6-
:class="classNames"
7-
:group="{ name: 'sharted', pull: true, put: true }"
8-
ghost-class="pvtPlaceholder"
9-
@change="onChange"
105
tag="ul"
6+
:list="modelItems"
7+
:group="{ name: 'sharted', pull: true, put: true }"
8+
ghost-class=".pvtFilterBox"
119
:preventOnfFilter="false"
10+
:class="classes"
11+
@sort="onDrag"
1212
>
13-
<!-- :modelValue="items" -->
14-
<!-- @update:modelValue="onChange" -->
15-
<!-- @sort="onChange"-->
1613
<VDraggableAttribute
1714
v-for="item in modelItems"
1815
:key="item"
19-
:name="item"
20-
:sortable="true"
21-
:draggable="true"
22-
:attrValues="{}"
23-
:sorter="getSort(() => { }, item)"
24-
:menuLimit="500"
25-
:zIndex="1000"
26-
:valueFilter="{}"
27-
:open="false"
28-
:async="false"
29-
:unused="false"
30-
:localeStrings="{}"
16+
:disabled="disabledFromDragDrop.includes(item)"
17+
:sortOnly="restrictedFromDragDrop.includes(item)"
18+
:open="openStatus?.[item]"
19+
:unSelectedFilterValues="valueFilter?.[item]"
20+
:attributeName="item"
21+
:zIndex="zIndices[item]"
22+
:hideDropDown="hideDropDown"
23+
@update:zIndexOfFilterBox="$emit('update:zIndexOfFilterBox')"
24+
@update:unselectedFilterValues="$emit('update:unselectedFilterValues')"
25+
@update:openStatusOfFilterBox="$emit('update:unselectedFilterValues')"
3126
>
3227
<template #pvtAttr="{ attrName }">
3328
{{ attrName }}
@@ -38,40 +33,77 @@
3833
</template>
3934

4035
<script setup>
41-
import VDraggableAttribute from './VDraggableAttribute.vue'
36+
import { ref, onMounted, computed } from 'vue'
4237
import { VueDraggableNext as Draggable } from 'vue-draggable-next'
43-
import { ref, onMounted } from 'vue'
44-
import { PivotData, getSort, sortAs, aggregators } from '../../helper'
38+
import VDraggableAttribute from './VDraggableAttribute.vue'
4539
46-
const emit = defineEmits(['update:filters'])
40+
const emit = defineEmits([
41+
'update:draggedAttribute',
42+
'update:zIndexOfFilterBox',
43+
'update:unselectedFilterValues',
44+
'update:openStatusOfFilterBox'
45+
])
4746
4847
const props = defineProps({
49-
attrs: {
48+
cellType: {
49+
type: String,
50+
required: true
51+
},
52+
// 삭제할 수 있으면 삭제
53+
classes: {
5054
type: String,
5155
default: ''
5256
},
53-
items: {
57+
attributeNames: {
58+
type: Array,
59+
default: () => []
60+
},
61+
valueFilter: {
62+
type: Object,
63+
default: () => ({})
64+
},
65+
// 같은 셀 내 이동만 가능(정렬)
66+
restrictedFromDragDrop: {
5467
type: Array,
5568
default: () => []
5669
},
57-
classNames: {
70+
// 삭제 보류
71+
disabledFromDragDrop: {
5872
type: Array,
5973
default: () => []
74+
},
75+
hideFilterBoxOfUnusedAttributes: {
76+
type: Boolean,
77+
default: false
78+
},
79+
zIndices: {
80+
type: Object,
81+
default: () => ({})
82+
},
83+
openStatus: {
84+
type: Object,
85+
default: () => ({})
6086
}
6187
})
6288
6389
const modelItems = ref([])
6490
65-
const onChange = evt => {
91+
const onDrag = evt => {
6692
console.log('event', Object.keys(evt)[0])
67-
emit('update:filters', { cellType: props.attrs, filters: modelItems.value })
93+
emit('update:draggedAttribute', {
94+
cellType: props.cellType,
95+
attributes: modelItems.value
96+
})
6897
}
6998
7099
onMounted(() => {
71-
modelItems.value = [...props.items]
100+
modelItems.value = [...props.attributeNames]
72101
})
73102
103+
// 이름 변경해야할 것 같음 hideDropDownInUnusedCell
104+
const hideDropDown = computed(() => {
105+
return props.cellType === 'unused' && props.hideFilterBoxOfUnusedAttrs
106+
})
74107
</script>
75108

76-
<style scoped>
77-
</style>
109+
<style scoped></style>
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<template>
2-
<li :data-id="!disabled ? name : undefined">
3-
<span class="pvtAttr" :class="[filtered, { sortonly, disabled }]">
4-
<slot name="pvtAttr" :attrName="name">{{ name }}</slot>
2+
<li>
3+
<span class="pvtAttr" :class="[filtered, { sortOnly, disabled }]">
4+
<slot name="pvtAttr" :attrName="attributeName">{{ attributeName }}</slot>
55
<span
6-
v-if="showDropdown"
6+
v-if="!hideDropDownButton"
7+
@click="toggleFilterBox"
78
class="pvtTriangle"
8-
> ▾</span>
9+
>
10+
11+
</span>
912
<VFilterBox
1013
v-if="open"
11-
:valueFilter="valueFilter"
12-
:name="name"
13-
:attrValues="attrValues"
14-
:sorter="sorter"
15-
:menuLimit="menuLimit"
14+
:unselectedFilterValues="unselectedFilterValues"
15+
:filterBoxKey="attributeName"
16+
:zIndex="zIndex"
17+
@update:zIndexOfFilterBox="$emit('update:zIndexOfFilterBox')"
18+
@update:unselectedFilterValues="$emit('update:unselectedFilterValues')"
1619
>
1720
</VFilterBox>
18-
<!-- <VFilterBox v-if="open" ></VFilterBox> -->
19-
<!-- <slot v-if="open" name="filterbox"></slot> -->
2021
</span>
2122
</li>
2223
</template>
@@ -25,50 +26,62 @@
2526
import VFilterBox from './VFilterBox.vue'
2627
import { computed } from 'vue'
2728
29+
const emit = defineEmits([
30+
'update:zIndexOfFilterBox',
31+
'update:unselectedFilterValues',
32+
'update:openStatusOfFilterBox'
33+
])
34+
2835
const props = defineProps({
29-
draggable: {
30-
type: Boolean,
31-
default: true
36+
attributeName: {
37+
type: String,
38+
required: true
3239
},
33-
sortable: {
40+
disabled: {
3441
type: Boolean,
35-
default: true
42+
default: false
3643
},
37-
name: {
38-
type: String,
39-
required: true
44+
sortOnly: {
45+
type: Boolean,
46+
default: false
4047
},
4148
open: {
4249
type: Boolean,
4350
default: false
4451
},
45-
async: Boolean,
46-
unused: Boolean,
47-
valueFilter: {
52+
unselectedFilterValues: {
4853
type: Object,
49-
default: () => {
50-
return {}
51-
}
54+
default: () => ({})
5255
},
53-
attrValues: {
54-
type: Object,
55-
required: false
56+
zIndex: {
57+
type: Number
5658
},
57-
sorter: {
58-
type: Function,
59-
required: true
59+
hideDropDown: {
60+
type: Boolean,
61+
default: false
6062
},
61-
menuLimit: Number
63+
// 임시 데이터; 필터 목록은 어떻게 할 것인지?
64+
attributeValues: {
65+
type: Array,
66+
default: () => []
67+
}
6268
})
6369
64-
const disabled = computed(() => !props.sortable && !props.draggable)
65-
const sortonly = computed(() => props.sortable && !props.draggable)
70+
const toggleFilterBox = () => {
71+
emit('update:openStatusOfFilterBox', props.attributeName)
72+
}
6673
67-
const filtered = computed(() => Object.keys(props.valueFilter).length !== 0 ? 'pvtFilteredAttribute' : '')
68-
const showDropdown = computed(() => !disabled.value && (props.async ? !props.unused : true))
74+
const hideDropDownButton = computed(
75+
() => props.hideDropDown || !props.attributeValues.length || props.disabled
76+
)
6977
78+
const filtered = computed(() => {
79+
return Object.keys(props.unselectedFilterValues).length !== 0
80+
? 'pvtFilteredAttribute'
81+
: null
82+
})
7083
</script>
7184

7285
<style scoped>
73-
86+
/* css sortonly를 sortOnly로 변경해야함 */
7487
</style>

0 commit comments

Comments
 (0)