From bc9cadaa77d95a906ed41eb5a6f96fd78dd2cbc1 Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Mon, 27 Jan 2020 09:34:50 -0800 Subject: [PATCH] fixed reorder bugs --- .../components/ConditionCollection.vue | 60 +++++++++++++------ .../condition/components/ConditionEdit.vue | 7 +-- .../condition/components/condition.scss | 9 ++- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index f19ec6cad1..6363426cf6 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -34,22 +34,19 @@ :key="conditionIdentifier.key" >
-
-
-
@@ -85,7 +82,8 @@ export default { parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier), conditionCollection: [], conditions: [], - currentConditionIdentifier: this.currentConditionIdentifier || {} + currentConditionIdentifier: this.currentConditionIdentifier || {}, + moveIndex: null }; }, destroyed() { @@ -106,23 +104,49 @@ export default { } }, methods: { + setMoveIndex(index) { + this.moveIndex = index; + }, dropCondition(e) { - const moveIndex = Number(e.dataTransfer.getData('conditionIndex')); - const targetIndex = Number(e.target.id.slice(4)); - - function moveArrIndex(arr, from, to) { - arr.splice(to, 0, arr.splice(from, 1)[0]); + let targetIndex = Array.from(document.querySelectorAll('.c-c__drag-ghost')).indexOf(e.target); + if (targetIndex > this.moveIndex) { targetIndex-- } + const oldIndexArr = Object.keys(this.conditionCollection); + const move = function (arr, old_index, new_index) { + while (old_index < 0) { + old_index += arr.length; + } + while (new_index < 0) { + new_index += arr.length; + } + if (new_index >= arr.length) { + var k = new_index - arr.length; + while ((k--) + 1) { + arr.push(undefined); + } + } + arr.splice(new_index, 0, arr.splice(old_index, 1)[0]); return arr; } - - const oldIndexArr = Object.keys(this.conditionCollection); - const newIndexArr = moveArrIndex(Object.keys(this.conditionCollection), moveIndex, targetIndex); - + const newIndexArr = move(oldIndexArr, this.moveIndex, targetIndex); const reorderPlan = []; + for (let i = 0; i < oldIndexArr.length; i++) { - reorderPlan.push({oldIndex: i, newIndex: newIndexArr[i]}); + reorderPlan.push({oldIndex: Number(newIndexArr[i]), newIndex: i}); } + this.reorder(reorderPlan); + + e.target.classList.remove("dragging"); + }, + dragEnter(e) { + let targetIndex = Array.from(document.querySelectorAll('.c-c__drag-ghost')).indexOf(e.target); + + if (targetIndex > this.moveIndex) { targetIndex-- } + if (this.moveIndex === targetIndex) { return } + e.target.classList.add("dragging"); + }, + dragLeave(e) { + e.target.classList.remove("dragging"); }, handleConditionResult(args) { let idAsString = this.openmct.objects.makeKeyString(args.id); diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index 4e41596f92..883fd135b7 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -11,12 +11,11 @@
{{ condition.definition.name }} @@ -215,8 +214,8 @@ export default { this.persist(); }, methods: { - dragStart: e => { - e.dataTransfer.setData('conditionIndex', e.target.getAttribute('data-condition-index')); + dragStart(e) { + this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index'))); }, handleConditionResult(args) { // console.log('ConditionEdit::Result', args); diff --git a/src/plugins/condition/components/condition.scss b/src/plugins/condition/components/condition.scss index 298e4817f6..939ac627e1 100644 --- a/src/plugins/condition/components/condition.scss +++ b/src/plugins/condition/components/condition.scss @@ -157,5 +157,12 @@ .c-c__drag-ghost { width: 100%; - min-height: 10px; + min-height: 5px; + &.dragging { + min-height: 20px; + border: solid 1px blue; + background-color: lightblue; + border-radius: 2px; + } + } \ No newline at end of file