Skip to content

Commit cf6029c

Browse files
committed
fix drag and drop selection
Signed-off-by: Mark Herwege <[email protected]>
1 parent 41801be commit cf6029c

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

bundles/org.openhab.ui/web/src/components/model/model-treeview.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
:includeItemTags="includeItemTags"
2828
:canDragDrop="canDragDrop"
2929
@selected="nodeSelected"
30+
@clear-selected="clearSelection"
3031
:selected="selected"
3132
@checked="(item, check) => $emit('checked', item, check)"
3233
@reload="$emit('reload')" />
@@ -78,7 +79,7 @@ export default {
7879
includeItemTags: Boolean,
7980
canDragDrop: Boolean
8081
},
81-
emits: ['reload', 'checked', 'selected'],
82+
emits: ['reload', 'checked', 'selected', 'clear-selected'],
8283
components: {
8384
Draggable,
8485
ModelTreeviewItem

bundles/org.openhab.ui/web/src/components/model/treeview-item.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:icon-md="icon('md')"
77
:textColor="iconColor"
88
:color="(model.item.created !== false) ? 'blue' : 'orange'"
9-
:selected="selected && selected.item.name === model.item.name ? true : null"
9+
:selected="itemSelected"
1010
:opened="model.opened"
1111
:toggle="canHaveChildren"
1212
@treeview:open="model.opened = true"
@@ -37,7 +37,8 @@
3737
:parentNode="model"
3838
:rootNode="rootNode"
3939
@selected="(event) => $emit('selected', event)"
40-
:selected="node.selected"
40+
@clear-selected="clearSelection"
41+
:selected="selected"
4142
:includeItemName="includeItemName"
4243
:includeItemTags="includeItemTags"
4344
:canDragDrop="canDragDrop"
@@ -94,7 +95,7 @@ export default {
9495
includeItemTags: Boolean,
9596
canDragDrop: Boolean
9697
},
97-
emits: ['reload', 'selected', 'checked'],
98+
emits: ['reload', 'selected', 'clear-selected', 'checked'],
9899
components: {
99100
Draggable,
100101
ModelTreeviewItem: 'model-treeview-item'
@@ -118,6 +119,9 @@ export default {
118119
? semantics.config.relatesTo : null
119120
return this.model.class.substring(this.model.class.lastIndexOf('_') + 1) +
120121
((property) ? ' (' + property.replace('Property_', '') + ')' : '')
122+
},
123+
itemSelected () {
124+
return this.selected && this.selected.item.name === this.model.item.name ? true : null
121125
}
122126
},
123127
methods: {

bundles/org.openhab.ui/web/src/pages/settings/model/model-dragdrop-mixin.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import ItemMixin from '@/components/item/item-mixin'
66
import TagMixin from '@/components/tags/tag-mixin'
77
import fastDeepEqual from 'fast-deep-equal/es6'
88

9-
// TODO-V3.1 console.debug calls with cloneDeep - do we need to remove them?
10-
119
export default {
1210
mixins: [ItemMixin, TagMixin],
11+
emits: ['clear-selected'],
1312
watch: {
1413
canSave (val) {
1514
if (val) this.saveUpdate()
@@ -64,6 +63,7 @@ export default {
6463
},
6564
methods: {
6665
onDragStart (event) {
66+
this.$emit('clear-selected')
6767
this.moveState.node = this.children[event.oldIndex]
6868
if (!this.moveState.node.item.editable) return
6969
console.time('Timer: Drag')
@@ -257,8 +257,6 @@ export default {
257257
} else {
258258
this.addIntoRoot(node, parentNode)
259259
}
260-
this.moveState.canAdd = false
261-
this.moveState.adding = false
262260
console.timeEnd('Timer: validateAdd')
263261
},
264262
isValidGroupType (node, parentNode) {
@@ -538,6 +536,9 @@ export default {
538536
if (updateRequired) {
539537
this.moveState.nodesToUpdate.push(node)
540538
}
539+
this.moveState.canAdd = false
540+
this.moveState.adding = false
541+
if (!this.moveState.canRemove) this.moveState.dragFinished = true
541542
console.debug('Add - finished, new moveState:', cloneDeep(this.moveState))
542543
console.timeEnd('Timer: updateAfterAdd')
543544
},
@@ -583,6 +584,7 @@ export default {
583584
const groupNameIndex = node.item.groupNames.findIndex((g) => g === parentNode.item?.name)
584585
if (groupNameIndex >= 0) {
585586
node.item.groupNames.splice(groupNameIndex, 1)
587+
this.moveState.nodesToUpdate.push(node)
586588
}
587589
const newChildren = this.nodeChildren(parentNode)
588590
newChildren.splice(oldIndex, 1)
@@ -601,7 +603,7 @@ export default {
601603
console.time('Timer: updateAfterRemove')
602604
this.moveState.canRemove = false
603605
this.moveState.removing = false
604-
this.moveState.dragFinished = true
606+
if (!this.moveState.canAdd) this.moveState.dragFinished = true
605607
console.timeEnd('Timer: updateAfterRemove')
606608
},
607609
saveUpdate () {
@@ -661,6 +663,9 @@ export default {
661663
console.timeEnd('Timer: Drag')
662664
this.moveState.cancelled = true
663665
}
666+
},
667+
clearSelection () {
668+
this.$emit('clear-selected')
664669
}
665670
}
666671
}

bundles/org.openhab.ui/web/src/pages/settings/model/model-mixin.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,16 @@ export default {
173173
}
174174

175175
if (this.includeNonSemantic) {
176-
// Only non-semantic groups in groups, avoids showing semantic groups as child of the wrong semantic group
177-
parent.children.groups = this.items
178-
.filter((i) => i.type === 'Group' && !i.metadata?.semantics && i.groupNames.indexOf(parent.item.name) >= 0)
176+
const nonSemanticItems = this.items
177+
.filter((i) => !i.metadata?.semantics && i.groupNames.indexOf(parent.item.name) >= 0)
179178
.map(this.modelItem).sort(compareModelItems)
179+
180+
// Only non-semantic groups in groups
181+
parent.children.groups = nonSemanticItems.filter((i) => i.item.type === 'Group')
180182
parent.children.groups.forEach(this.getChildren)
181183

182-
if (!parent.item.metadata?.semantics) {
183-
// Items in non-semantic groups
184-
parent.children.items = this.items
185-
.filter((i) => i.type !== 'Group' && i.groupNames.indexOf(parent.item.name) >= 0)
186-
.map(this.modelItem).sort(compareModelItems)
187-
} else {
188-
// Only non-semantic items in semantic groups, avoids showing semantic item as child of the wrong semantic group
189-
parent.children.items = this.items
190-
.filter((i) => i.type !== 'Group' && !i.metadata?.semantics && i.groupNames.indexOf(parent.item.name) >= 0)
191-
.map(this.modelItem).sort(compareModelItems)
192-
}
184+
// Only non-semantic items in groups
185+
parent.children.items = nonSemanticItems.filter((i) => i.item.type !== 'Group')
193186
}
194187
},
195188
/**

bundles/org.openhab.ui/web/src/pages/settings/model/model.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
:includeItemTags="includeItemTags"
116116
:canDragDrop="true"
117117
@selected="selectItem"
118+
@clear-selected="clearSelection"
118119
:selected="selectedItem"
119120
@reload="load"
120121
@click.stop />
@@ -482,8 +483,9 @@ export default {
482483
}
483484
},
484485
clearSelection (ev) {
485-
if (ev.target && ev.currentTarget && ev.target === ev.currentTarget) {
486+
if (!ev || (ev.target && ev.currentTarget && ev.target === ev.currentTarget)) {
486487
this.selectedItem = null
488+
this.previousSelection = null
487489
this.detailsOpened = false
488490
}
489491
},

0 commit comments

Comments
 (0)