Skip to content

Commit 9fe3b29

Browse files
authored
Merge pull request #9 from allisons11/parentState
Parent state
2 parents 3773c82 + f620462 commit 9fe3b29

File tree

6 files changed

+114
-21
lines changed

6 files changed

+114
-21
lines changed

src/components/ComponentDisplay.vue

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:key="componentData.componentName"
88
:x="componentData.x"
99
:y="componentData.y + 20"
10+
:z="componentData.z"
1011
:w="componentData.w"
1112
:h="componentData.h"
1213
:parent="true"
@@ -25,19 +26,22 @@
2526
<!-- <p v-for="child in childList" :key="childList.indexOf(child)"> {{ child.text }}</p> -->
2627
</ul>
2728
<q-menu context-menu>
28-
<q-list class="menu">
29+
<q-list color='black' class="menu">
2930
<q-item clickable v-ripple v-close-popup @click="handleAddChild">
3031
<q-item-section style="color: white">Update Children</q-item-section>
3132
<q-item-section avatar>
3233
<q-icon color="primary" name="add" />
3334
</q-item-section>
3435
</q-item>
35-
<!-- <q-item clickable v-ripple v-close-popup auto-close>
36-
<q-item-section style="color: pink">Delete Children</q-item-section>
37-
<q-item-section avatar>
38-
<q-icon color="primary" name="delete" />
39-
</q-item-section>
40-
</q-item> -->
36+
<q-item clickable v-ripple v-close-popup>
37+
<q-item-section class='layer' style="color: pink">Layer</q-item-section>
38+
<q-btn class='btn' color='transparent' text-color='primary' label='-' @click='(e)=>handleLayer(e)'/>
39+
<p id='counter' style="color: white"> {{componentData.z}} </p>
40+
<q-btn class='btn' color='transparent' text-color='primary' label='+' @click='(e)=>handleLayer(e)'/>
41+
<!-- <q-item-section avatar>
42+
<q-icon color="primary" name="layer" />
43+
</q-item-section> -->
44+
</q-item>
4145
</q-list>
4246
</q-menu>
4347
</VueDraggableResizable>
@@ -77,7 +81,8 @@ export default {
7781
abilityToDelete: false,
7882
testOptions: ["parent", "child", "grandchild"],
7983
testModel: [],
80-
mockImg: false
84+
mockImg: false,
85+
counter: 0
8186
};
8287
},
8388
mounted() {
@@ -116,16 +121,37 @@ export default {
116121
return this.componentMap[componentData.componentName].children;
117122
},
118123
options() {
124+
const checkParents = (component, lineage=[component.componentName]) => {
125+
// console.log('component', component)
126+
// component parent is an object of parents
127+
// console.log('component parent',component.parent)
128+
// console.log('component parent parent', component.parent.parent)
129+
if (!Object.keys(component.parent).length) return lineage;
130+
for(var parents in component.parent){
131+
//for each parent in our component
132+
console.log('parents', parents)
133+
lineage.push(parents); //push the parent into lineage
134+
console.log('lineage pre push', component, lineage)
135+
checkParents(component.parent[parents], lineage);
136+
console.log('lineage post recursive call', lineage)
137+
}
138+
// lineage.push(component.parent[component.componentName]);
139+
// return checkParents(component.parent, lineage);
140+
return lineage
141+
};
142+
let lineage = [this.activeComponent];
119143
// PROBLEM: the objects on childrenmultiselectvalue are applied
120144
// check to see if there are any existing children
121145
if (this.componentMap[this.activeComponent]) {
122146
// console.log('active component', this.activeComponent)
123147
// console.log('testmodel', this.testModel)
124148
// console.log(this.componentMap[this.activeComponent].children)
125149
this.testModel = this.componentMap[this.activeComponent].children;
150+
lineage = checkParents(this.componentMap[this.activeComponent]);
151+
console.log('Lineage', lineage);
126152
}
127153
const routes = Object.keys(this.routes);
128-
const exceptions = new Set(["App", this.activeComponent, ...routes, ...this.testModel]);
154+
const exceptions = new Set(["App", ...lineage, ...routes, ...this.testModel]);
129155
return Object.keys(this.componentMap).filter(component => {
130156
if (!exceptions.has(component)) return component;
131157
});
@@ -170,6 +196,9 @@ export default {
170196
this.componentMap[this.activeComponent].y = y;
171197
this.userImage;
172198
},
199+
onLayer: function(z) {
200+
this.activeComponentData.z = z;
201+
},
173202
onActivated(componentData) {
174203
this.setActiveComponent(componentData.componentName);
175204
this.activeComponentData.isActive = true;
@@ -190,6 +219,23 @@ export default {
190219
console.log("Multiselect: ", value);
191220
this.updateActiveComponentChildrenValue(value);
192221
// this.updateComponentChildrenMultiselectValue(value)
222+
},
223+
handleLayer(e){
224+
e.preventDefault()
225+
console.log('event object', e.target.innerText)
226+
console.log('Layer handled')
227+
228+
if(e.target.innerText === '+'){
229+
this.counter++;
230+
// this.activeComponentData.z = z;
231+
}
232+
if(e.target.innerText === '-' && this.counter > 0){
233+
this.counter--;
234+
}
235+
console.log('counter', this.counter)
236+
this.activeComponentData.z = this.counter;
237+
this.componentMap[this.activeComponent].z = this.counter;
238+
193239
}
194240
// @dblclick.native="onDoubleClick(componentData)"
195241
// onDoubleClick (compData) {
@@ -212,6 +258,7 @@ export default {
212258
/* width: 1rem; */
213259
line-height: 1.2;
214260
/* margin: 10px; */
261+
z-index: 0;
215262
}
216263
.component-children {
217264
position: absolute;
@@ -272,4 +319,23 @@ export default {
272319
background-color: rgba(105, 179, 190, 0.514);
273320
border: 1px dashed rgb(227, 203, 71);
274321
}
322+
.btn {
323+
font-size: 25px;
324+
/* margin-top: 0;
325+
margin-bottom: 0; */
326+
padding: 0 20px;
327+
width: 10px;
328+
height: 10px;
329+
transition: none;
330+
}
331+
.btn:hover, .btn:focus, .btn:active {
332+
color: white;
333+
background-color: transparent;
334+
}
335+
#counter {
336+
margin-top: 20px;
337+
}
338+
/* .layer {
339+
padding: 0 20px;
340+
} */
275341
</style>

src/components/CreateComponent.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ export default {
7171
componentName: this.componentNameInputValue,
7272
x: 0,
7373
y: 0,
74+
z: 0,
7475
w: 200,
7576
h: 200,
7677
htmlList: this.selectedElementList,
7778
children: [],
79+
parent: {},
7880
isActive: false
7981
}
8082

src/components/ParentMultiselect.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ export default {
3737
},
3838
methods: {
3939
...mapActions([
40-
'setActiveComponent',
40+
// 'addParent',
4141
'parentSelected'
4242
]),
4343
handleSelect (value) {
4444
// Set Active Component to selected Parent
45-
this.setActiveComponent(value)
45+
// this.setActiveComponent(value)
46+
// this.addParent(value)
4647
// Set parentSelected to true IF VALUE IS A VALID PARENT (not null)
47-
this.parentSelected(true)
48+
this.parentSelected(value)
4849
}
4950
}
5051
}

src/store/actions.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import * as types from './types'
22

33
const actions = {
4+
5+
// add selected parent to component
6+
// [types.addParent]: ({ commit }, payload) => {
7+
// commit(types.ADD_PARENT, payload)
8+
// },
9+
410
// creates a new component in componentMap
511
[types.registerComponent]: ({ state, commit }, payload) => {
612
const { componentName } = payload
713
if (!state.componentMap[componentName]) {
814
commit(types.ADD_COMPONENT_TO_COMPONENT_MAP, payload)
9-
if (!state.parentSelected) {
15+
if (!state.parentSelected.length) {
1016
commit(
1117
types.ADD_COMPONENT_TO_ACTIVE_ROUTE_CHILDREN,
1218
payload.componentName
@@ -20,19 +26,22 @@ const actions = {
2026
return state.componentMap[component]
2127
})
2228

23-
if (state.parentSelected) {
24-
commit(types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE, [
25-
...state.componentMap[state.activeComponent].children,
26-
payload.componentName
27-
])
29+
if (state.parentSelected.length) {
30+
// we want to replace this with an 'add parent' mutation
31+
commit(types.ADD_PARENT, payload)
32+
// commit(types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE, [
33+
// ...state.componentMap[state.activeComponent].children,
34+
// payload.componentName
35+
// ])
2836
}
2937

3038
commit(types.UPDATE_COMPONENT_CHILDREN_VALUE, { component, value })
3139
commit(types.UPDATE_COMPONENT_CHILDREN_MULTISELECT_VALUE, [])
3240
commit(types.UPDATE_COMPONENT_NAME_INPUT_VALUE, '')
3341
commit(types.SET_SELECTED_ELEMENT_LIST, [])
3442
commit(types.SET_ACTIVE_COMPONENT, '')
35-
commit(types.PARENT_SELECTED, false)
43+
// commit(types.PARENT_SELECTED, false)
44+
commit(types.PARENT_SELECTED, '')
3645
}
3746
},
3847
// sets component inside componentDisplay

src/store/mutations.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import localforage from 'localforage'
55
const mutations = {
66
// pushs new component to componentMap
77
[types.ADD_COMPONENT_TO_COMPONENT_MAP]: (state, payload) => {
8-
const { componentName, htmlList, children, isActive } = payload
8+
const { componentName, htmlList, children, parent, isActive } = payload
99
state.componentMap = Object.assign({},state.componentMap,{[componentName]: {
1010
componentName,
1111
x: 0,
1212
y: 0,
13+
z: 0,
1314
w: 200,
1415
h: 200,
1516
children,
17+
parent,
1618
htmlList,
1719
isActive
1820
}})
@@ -32,6 +34,12 @@ const mutations = {
3234
// }
3335
//}
3436
},
37+
// add parent
38+
[types.ADD_PARENT]: (state, payload) => {
39+
state.componentMap[payload.componentName].parent[state.parentSelected] = state.componentMap[state.parentSelected]
40+
state.componentMap[state.parentSelected].children.push(payload.componentName)
41+
},
42+
3543
// adds a html tag from the Icons.vue to the HomeQueue.vue
3644
// event: getClickedIcon @Icons.vue
3745
[types.ADD_TO_SELECTED_ELEMENT_LIST]: (state, payload) => {
@@ -164,15 +172,21 @@ const mutations = {
164172
[types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE]: (state, payload) => {
165173
// original line
166174
let temp = state.componentMap[state.activeComponent].children // b c and we are removing c
167-
if (payload.length<temp.length){ // we will get a payload of [b] and our temp is currently [b,c]
175+
if (payload.length<temp.length) { // we will get a payload of [b] and our temp is currently [b,c]
176+
let child = temp.filter(el => !payload.includes(el))
177+
console.log('delete child: ', child)
168178
state.componentMap[state.activeComponent].children = payload
169179
state.componentMap[state.activeRoute].children.push(...temp.filter(el => !payload.includes(el)))
180+
delete state.componentMap[child[0]].parent[state.activeComponent]
170181
}
171182
else {
183+
let child = payload.filter(el => !temp.includes(el))
184+
console.log('child added', child)
172185
state.componentMap[state.activeComponent].children = payload
173186
state.componentMap[state.activeRoute].children = state.componentMap[
174187
state.activeRoute
175188
].children.filter(el => !payload.includes(el))
189+
state.componentMap[child[0]].parent[state.activeComponent] = state.componentMap[state.activeComponent]
176190
}
177191

178192
},

src/store/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
3939
'ADD_COMPONENT_TO_COMPONENT_CHILDREN'
4040
export const UPDATE_OPEN_MODAL = 'UPDATE_OPEN_MODAL'
4141
export const PARENT_SELECTED = 'PARENT_SELECTED'
42+
export const ADD_PARENT = 'ADD_PARENT'
4243
export const DELETE_ROUTE = 'DELETE_ROUTE'
4344
export const DELETE_COMPONENT = 'DELETE_COMPONENT'
4445
// Image upload mutations

0 commit comments

Comments
 (0)