Skip to content

Commit 4e51614

Browse files
authored
Merge pull request #14 from allisons11/UndoRedo
Undo redo - works with layering
2 parents 5653461 + 564bda1 commit 4e51614

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

src/components/ComponentDisplay.vue

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
testOptions: ["parent", "child", "grandchild"],
9292
testModel: [],
9393
mockImg: false,
94-
counter: 0,
94+
// counter: 6,
9595
initialPosition:{x:0, y:0,},
9696
initialSize:{w:0,h:0,},
9797
};
@@ -119,7 +119,7 @@ export default {
119119
]),
120120
// used in VueDraggableResizeable component
121121
activeRouteArray() {
122-
// console.log("active route array method", this.routes[this.activeRoute]);
122+
console.log("active route array method", this.routes[this.activeRoute]);
123123
return this.routes[this.activeRoute];
124124
},
125125
// used to delete components
@@ -216,6 +216,7 @@ export default {
216216
"updateActiveComponentChildrenValue",
217217
"updateComponentPosition",
218218
"updateStartingPosition",
219+
"updateComponentLayer",
219220
"updateStartingSize",
220221
"updateComponentSize",
221222
]),
@@ -303,11 +304,6 @@ export default {
303304
this.componentMap[this.activeComponent].y = y;
304305
this.userImage;
305306
},
306-
// onLayer: function(z) {
307-
// this.activeComponentData.z = z;
308-
// // Want to change the "Z" of the component found in Routes[activeRoute][whatever the component is]
309-
// //have to do this via an action or it won't be preserved in our undo/redo
310-
// },
311307
312308
finishedDrag: function(x,y){
313309
console.log("FINISHED DRAGGING")
@@ -374,34 +370,26 @@ export default {
374370
this.updateActiveComponentChildrenValue(value);
375371
// this.updateComponentChildrenMultiselectValue(value)
376372
},
377-
handleLayer(e){
373+
handleLayer(e) {
378374
e.preventDefault()
379-
console.log('event object', e.target.innerText)
380-
console.log('Layer handled')
381-
382-
if(e.target.innerText === '+'){
383-
this.counter++;
384-
// this.activeComponentData.z = z;
385-
}
386-
if(e.target.innerText === '-' && this.counter > 0){
387-
this.counter--;
375+
const payload = {
376+
activeComponent: this.activeComponent,
377+
routeArray: this.routes[this.activeRoute],
378+
activeComponentData: this.activeComponentData,
379+
z: this.activeComponentData.z,
388380
}
389-
console.log('counter', this.counter)
390-
this.activeComponentData.z = this.counter;
391-
this.componentMap[this.activeComponent].z = this.counter;
392-
381+
if(e.target.innerText === '+') payload.z++;
382+
if(e.target.innerText === '-' && payload.z > 0) payload.z--;
383+
this.updateComponentLayer(payload)
393384
},
394385
// @dblclick.native="onDoubleClick(componentData)"
395386
// onDoubleClick (compData) {
396387
// this.setActiveComponent(compData.componentName)
397388
// this.activeComponentData.isActive = true
398389
// }
399390
handleClick(event){
400-
if(event.target.className === "component-display grid-bg")
401-
{
402-
if(!('' === this.activeComponent)){
403-
this.setActiveComponent('');
404-
}
391+
if(event.target.className === "component-display grid-bg") {
392+
if(!('' === this.activeComponent)) this.setActiveComponent('');
405393
}
406394
}
407395
}

src/store/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const actions = {
6363
commit(types.UPDATE_COMPONENT_POSITION, payload)
6464

6565
},
66+
[types.updateComponentLayer]: ({ commit }, payload) => {
67+
commit(types.UPDATE_COMPONENT_LAYER, payload)
68+
},
6669

6770
//does the same as update component position, but needed to record the initial spot of the draggable resizeable in component display
6871
// or else undo/redo won't work

src/store/mutations.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,14 @@ const mutations = {
295295
updatedComponent.x = payload.x
296296
updatedComponent.y = payload.y
297297
},
298-
299-
298+
[types.UPDATE_COMPONENT_LAYER]: (state, payload) => {
299+
const updatedComponent = state.routes[state.activeRoute].filter(element => {
300+
return element.componentName === payload.activeComponent
301+
})[0]
302+
updatedComponent.z = payload.z
303+
state.componentMap[payload.activeComponent].z = payload.z
304+
// payload.activeComponentData.z = payload.z
305+
},
300306
[types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE]: (state, payload) => {
301307
// original line
302308
let temp = state.componentMap[state.activeComponent].children // b c and we are removing c

src/store/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const UPDATE_COMPONENT_NAME_INPUT_VALUE =
3535
export const UPDATE_COMPONENT_CHILDREN_VALUE =
3636
'UPDATE_COMPONENT_CHILDREN_VALUE'
3737
export const UPDATE_COMPONENT_POSITION = "UPDATE_COMPONENT_POSITION"
38+
export const UPDATE_COMPONENT_LAYER = "UPDATE_COMPONENT_LAYER"
3839
export const UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE =
3940
'UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE'
4041
export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
@@ -90,6 +91,7 @@ export const updateActiveComponentChildrenValue =
9091
export const updateComponentChildrenValue = 'updateComponentChildrenValue'
9192
export const updateComponentNameInputValue = 'updateComponentNameInputValue'
9293
export const updateComponentPosition = 'updateComponentPosition'
94+
export const updateComponentLayer = 'updateComponentLayer'
9395
export const updateOpenModal = 'updateOpenModal'
9496
export const parentSelected = 'parentSelected'
9597
export const deleteRoute = 'deleteRoute'

0 commit comments

Comments
 (0)