Skip to content

Commit 794039a

Browse files
authored
Merge pull request #2770 from mitre/drag-ability
Change moving abilities on adversary dashboard from swap to insert
2 parents e2bfa85 + 5dd3d77 commit 794039a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

templates/adversaries.html

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,20 @@ <h3 x-text="selectedProfileName" class="pointer tooltip has-tooltip-arrow" data-
125125
<template x-for="(ability, index) of selectedProfileAbilities">
126126
<tr @click="selectAbility(ability.ability_id)" class="ability-row"
127127
x-bind:class="{ 'orange-row': needsParser.indexOf(ability.name) > -1 ,
128-
'row-hover': ability.ability_id === abilityTableDragHoverId && abilityTableDragHoverId != undefined,
129-
'red-row-unclickable': undefinedAbilities.indexOf(ability.ability_id) > -1 }"
130-
x-on:mouseenter="setAbilityHover(ability.ability_id)" x-on:mouseleave="clearAbilityHover()" x-on:dragenter="abilityTableDragHoverId = ability.ability_id">
131-
<td class="has-text-centered drag" @click.stop draggable="true" x-on:dragstart="startAbilitySwap" x-on:dragover.prevent="swapAbilitiesHover" x-on:dragend="swapAbilities">&#9776;</td>
128+
'row-hover-above':
129+
ability.ability_id === abilityTableDragHoverId
130+
&& abilityTableDragHoverId != undefined
131+
&& abilityTableDragEndIndex < abilityTableDragTargetIndex,
132+
'row-hover-below':
133+
ability.ability_id === abilityTableDragHoverId
134+
&& abilityTableDragHoverId != undefined
135+
&& abilityTableDragEndIndex > abilityTableDragTargetIndex,
136+
'red-row-unclickable': undefinedAbilities.indexOf(ability.ability_id) > -1 }"
137+
x-on:mouseenter="setAbilityHover(ability.ability_id)" x-on:mouseleave="clearAbilityHover()">
138+
<td class="has-text-centered drag"
139+
@click.stop draggable="true" x-on:dragstart="startAbilitySwap" x-on:dragenter="abilityTableDragHoverId = ability.ability_id" x-on:dragover.prevent="swapAbilitiesHover" x-on:dragend="dragAbility">
140+
&#9776;
141+
</td>
132142
<td>
133143
<div class="icon-text">
134144
<span x-text="index + 1"></span>
@@ -820,7 +830,7 @@ <h3>Create a profile</h3>
820830
// Global page variables
821831
adversaries: [],
822832
abilities: [],
823-
abilityIDs: [],
833+
abilityIDs: [],
824834
objectives: [],
825835
platforms: JSON.parse('{{ platforms | tojson }}'),
826836
payloads: JSON.parse('{{ payloads | tojson }}').sort(),
@@ -847,6 +857,7 @@ <h3>Create a profile</h3>
847857

848858
// Table on drag and drop
849859
abilityTableDragTarget: undefined,
860+
abilityTableDragTargetIndex: undefined,
850861
abilityTableDragEndIndex: undefined,
851862
abilityTableDragHoverId: undefined,
852863

@@ -1404,6 +1415,7 @@ <h3>Create a profile</h3>
14041415

14051416
startAbilitySwap(event) {
14061417
this.abilityTableDragTarget = event.target.parentNode;
1418+
this.abilityTableDragTargetIndex = parseInt(this.abilityTableDragTarget.children[1].children[0].children[0].innerHTML, 10);
14071419
},
14081420

14091421
swapAbilitiesHover(event) {
@@ -1415,13 +1427,13 @@ <h3>Create a profile</h3>
14151427
this.abilityTableDragEndIndex = parseInt(event.target.parentNode.children[1].children[0].children[0].innerHTML, 10);
14161428
}
14171429
},
1418-
1419-
swapAbilities(event) {
1420-
const fromIndex = parseInt(this.abilityTableDragTarget.children[1].children[0].children[0].innerHTML, 10) - 1;
1430+
1431+
dragAbility(event){
1432+
const fromIndex = this.abilityTableDragTargetIndex - 1;
14211433
const toIndex = this.abilityTableDragEndIndex - 1;
14221434
const temp = this.selectedProfileAbilities[fromIndex];
1423-
this.selectedProfileAbilities[fromIndex] = this.selectedProfileAbilities[toIndex];
1424-
this.selectedProfileAbilities[toIndex] = temp;
1435+
this.selectedProfileAbilities.splice(fromIndex, 1);
1436+
this.selectedProfileAbilities.splice(toIndex, 0, temp);
14251437

14261438
this.unsavedChanges = true;
14271439
this.abilityTableDragHoverId = undefined;
@@ -1523,6 +1535,14 @@ <h3>Create a profile</h3>
15231535
background-color: #484848 !important;
15241536
}
15251537

1538+
.row-hover-above {
1539+
border-top: 2px solid green;
1540+
}
1541+
1542+
.row-hover-below {
1543+
border-bottom: 2px solid green;
1544+
}
1545+
15261546
.tactic-breakdown {
15271547
display: table;
15281548
width: 100%;

0 commit comments

Comments
 (0)