Skip to content

Commit f6d4c44

Browse files
authored
Merge pull request #10 from LOLDragoon/deletetree
Deletetree
2 parents 9fe3b29 + fae60c8 commit f6d4c44

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

src/components/ComponentDisplay.vue

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<template>
2-
<div class="component-display grid-bg" :style="mockBg">
2+
<div class="component-display grid-bg" :style="mockBg" v-on:click ="handleClick">
33
<!-- <p>{{ userImage }}</p> -->
44
<VueDraggableResizable
55
class-name="component-box"
66
v-for="componentData in activeRouteArray"
7+
ref ="boxes"
78
:key="componentData.componentName"
9+
:id ="componentData.componentName"
810
:x="componentData.x"
911
:y="componentData.y + 20"
1012
:z="componentData.z"
1113
:w="componentData.w"
1214
:h="componentData.h"
1315
:parent="true"
16+
:preventDeactivation="true"
1417
@activated="onActivated(componentData)"
1518
@deactivated="onDeactivated(componentData)"
1619
@dragging="onDrag"
@@ -68,7 +71,7 @@ import { mapState, mapActions } from "vuex";
6871
import VueDraggableResizable from "vue-draggable-resizable";
6972
// import ChildrenMultiselect from '../components/ChildrenMultiselect'
7073
import "vue-draggable-resizable/dist/VueDraggableResizable.css";
71-
74+
// :preventDeactivation="true"
7275
export default {
7376
name: "ComponentDisplay",
7477
components: {
@@ -91,7 +94,7 @@ export default {
9194
window.addEventListener("keyup", event => {
9295
if (event.key === "Backspace") {
9396
if (this.activeComponent && this.activeComponentData.isActive) {
94-
console.log('this:', this)
97+
// console.log('this:', this)
9598
this.$store.dispatch("deleteActiveComponent");
9699
}
97100
}
@@ -171,6 +174,30 @@ export default {
171174
: {};
172175
}
173176
},
177+
178+
updated() {
179+
console.log("updated")
180+
if(this.activeComponent === '')
181+
{
182+
this.$refs.boxes.forEach((element)=> {
183+
element.enabled = false;
184+
element.$emit('deactivated')
185+
element.$emit('update:active', false)
186+
187+
})
188+
}
189+
else{
190+
this.$refs.boxes.forEach((element)=>{
191+
if(this.activeComponent === element.$attrs.id)
192+
{
193+
element.enabled = true
194+
element.$emit('activated')
195+
element.$emit('update:active', true)
196+
}
197+
})
198+
}
199+
},
200+
174201
methods: {
175202
...mapActions([
176203
"setActiveComponent",
@@ -200,11 +227,30 @@ export default {
200227
this.activeComponentData.z = z;
201228
},
202229
onActivated(componentData) {
230+
this.$refs.boxes.forEach((element)=> {
231+
if (element.$attrs.id !== componentData.componentName){
232+
element.enabled = false;
233+
element.$emit('deactivated')
234+
element.$emit('update:active', false)
235+
}
236+
})
203237
this.setActiveComponent(componentData.componentName);
204238
this.activeComponentData.isActive = true;
239+
205240
},
206-
onDeactivated() {
241+
242+
// deactivated is emitted before activated
243+
244+
onDeactivated(componentData) {
245+
if(this.activeComponent !== ''){
207246
this.activeComponentData.isActive = false;
247+
}
248+
// console.log("Componentdataname", componentData.componentName)
249+
// console.log("active component",this.activeComponent)
250+
// if(componentData.componentName === this.activeComponent)
251+
// {
252+
// console.log("We just clicked without making a new active component")
253+
// }
208254
},
209255
onDoubleClick(compData) {
210256
this.setActiveComponent(compData.componentName);
@@ -236,12 +282,18 @@ export default {
236282
this.activeComponentData.z = this.counter;
237283
this.componentMap[this.activeComponent].z = this.counter;
238284
239-
}
285+
},
240286
// @dblclick.native="onDoubleClick(componentData)"
241287
// onDoubleClick (compData) {
242288
// this.setActiveComponent(compData.componentName)
243289
// this.activeComponentData.isActive = true
244290
// }
291+
handleClick(event){
292+
if(event.target.className === "component-display grid-bg")
293+
{
294+
this.setActiveComponent('')
295+
}
296+
}
245297
}
246298
};
247299
</script>

src/components/CreateComponent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default {
8585
},
8686
resetActiveComponent () {
8787
this.setActiveComponent('')
88+
8889
},
8990
handleIconClick () {
9091
if (this.activeComponent === '') this.setClickedElementList()

src/store/mutations.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,27 @@ const mutations = {
7171
},
7272
// deletes selected component
7373
[types.DELETE_ACTIVE_COMPONENT]: state => {
74-
const { componentMap, activeComponent } = state
74+
const { componentMap, activeComponent, activeRoute } = state
7575

7676
let newObj = Object.assign({}, componentMap)
77+
//gotta save the children of the active component
78+
//and make sure they are placed as children of the active route or they will be lost to the graph.
79+
80+
const activeObjChildrenArray = newObj[activeComponent].children
81+
console.log(newObj[activeComponent])
82+
console.log("he saves the children but not the british children", activeObjChildrenArray)
83+
7784
delete newObj[activeComponent]
7885

86+
// goes in to make sure no children are the selected component any longer
7987
for (let compKey in newObj) {
8088
let children = newObj[compKey].children
8189
children.forEach((child, index) => {
8290
if (activeComponent === child) children.splice(index, 1)
8391
})
8492
}
93+
94+
newObj[activeRoute].children.push(...activeObjChildrenArray)
8595
state.componentMap = newObj
8696
},
8797
// used by setComponentMap for OpenProjectComponent.vue

0 commit comments

Comments
 (0)