Skip to content

Commit 7f3e3f1

Browse files
authored
Merge pull request #15 from JojuOlaode/undoRedo
Undo redo
2 parents 4e51614 + b14b778 commit 7f3e3f1

16 files changed

+191
-103
lines changed

HomeView.png

Lines changed: 1 addition & 0 deletions
Loading

Route2.png

Lines changed: 1 addition & 0 deletions
Loading

Route3.png

Lines changed: 1 addition & 0 deletions
Loading

src/components/ComponentDisplay.vue

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default {
8383
components: {
8484
VueDraggableResizable
8585
},
86-
data() {
86+
data () {
8787
// console.log("Component Map", this.componentMap);
8888
return {
8989
modalOpen: false,
@@ -96,13 +96,13 @@ export default {
9696
initialSize:{w:0,h:0,},
9797
};
9898
},
99-
mounted() {
99+
mounted () {
100100
// when component is mounted add ability to delete
101101
102102
window.addEventListener("keyup", event => {
103103
if (event.key === "Backspace") {
104-
if (this.activeComponent && this.activeComponentData.isActive) {
105-
// console.log('this:', this)
104+
if (this.activeComponent /*&& this.activeComponentData.isActive*/) {
105+
// console.log('this:', this)
106106
this.$store.dispatch("deleteActiveComponent");
107107
}
108108
}
@@ -138,7 +138,7 @@ export default {
138138
// console.log('component parent',component.parent)
139139
// console.log('component parent parent', component.parent.parent)
140140
if (!Object.keys(component.parent).length) return lineage;
141-
for(var parents in component.parent){
141+
for(var parents in component.parent) {
142142
//for each parent in our component
143143
console.log('parents', parents)
144144
lineage.push(parents); //push the parent into lineage
@@ -168,21 +168,21 @@ export default {
168168
});
169169
},
170170
userImage() {
171-
const imgSrc = this.imagePath.length ? `file://` + this.imagePath[0] : "";
171+
console.log('userImage is working')
172+
const imgSrc = `file://` + this.imagePath[this.activeRoute];
172173
// const imgSrc1 = this.imagePath;
173174
console.log(`imgSrc: ${imgSrc}`);
174175
return imgSrc;
175176
},
176177
mockBg() {
177-
return this.imagePath.length
178+
console.log('mockBg is working', this.imagePath[this.activeRoute])
179+
return this.imagePath[this.activeRoute]
178180
? {
179-
background: `url("${this.userImage}") no-repeat center`,
180-
"background-size": "cover"
181-
}
182-
: {};
181+
background: `url("${this.userImage}") center/contain no-repeat`
182+
}
183+
: {}
183184
}
184185
},
185-
186186
updated() {
187187
//console.log("updated")
188188
if(this.activeComponent === '')
@@ -194,20 +194,18 @@ export default {
194194
element.$emit('update:active', false)
195195
196196
})}
197+
} else {
198+
this.$refs.boxes.forEach((element)=>{
199+
// added "element.enabled === false to stop it from emitting a change every frame the box moves
200+
// may need to re-enable to track box movement and resizing since that stuff isn't part of a single source of truth.
201+
if (this.activeComponent === element.$attrs.id && element.enabled === false) {
202+
element.enabled = true
203+
element.$emit('activated')
204+
element.$emit('update:active', true)
205+
}
206+
})
197207
}
198-
else{
199-
this.$refs.boxes.forEach((element)=>{
200-
// added "element.enabled === false to stop it from emitting a change every frame the box moves
201-
//may need to re-enable to track box movement and resizing since that stuff isn't part of a single source of truth.
202-
if(this.activeComponent === element.$attrs.id && element.enabled === false)
203-
{
204-
element.enabled = true
205-
element.$emit('activated')
206-
element.$emit('update:active', true)
207-
}
208-
})
209-
}
210-
},
208+
},
211209
212210
methods: {
213211
...mapActions([
@@ -236,8 +234,8 @@ export default {
236234
console.log("we started a drag")
237235
console.log("this.intialPosition",this.initialPosition)
238236
console.log("WHAT IS THIS", this)
239-
if(this.activeComponent !== e.target.id){
240-
this.setActiveComponent(e.target.id)
237+
if (this.activeComponent !== e.target.id) {
238+
this.setActiveComponent(e.target.id)
241239
}
242240
this.initialPosition.x = this.activeComponentData.x
243241
this.initialPosition.y = this.activeComponentData.y
@@ -246,7 +244,7 @@ export default {
246244
// console.log(this.initialPosition.x)
247245
// console.log(this.initialPosition.y)
248246
249-
let payload = {
247+
let payload = {
250248
x: this.initialPosition.x,
251249
y: this.initialPosition.y,
252250
activeComponent: this.activeComponent,
@@ -257,15 +255,14 @@ export default {
257255
//this.updateStartingPosition(payload);
258256
},
259257
260-
recordInitialSize: function(e){
261-
console.log("MAKE MY MONSTER GROW!")
262-
258+
recordInitialSize: function (e) {
259+
// console.log("MAKE MY MONSTER GROW!")
263260
this.initialSize.h = this.activeComponentData.h
264261
this.initialSize.w = this.activeComponentData.w
265262
this.initialPosition.x = this.activeComponentData.x
266263
this.initialPosition.y = this.activeComponentData.y
267264
268-
let payload = {
265+
let payload = {
269266
h: this.initialSize.h,
270267
w: this.initialSize.w,
271268
x: this.activeComponentData.x,
@@ -279,7 +276,7 @@ export default {
279276
280277
},
281278
282-
finishedResize: function(x,y,w,h){
279+
finishedResize: function(x,y,w,h) {
283280
console.log("FINISHED RESIZING")
284281
let payload = {
285282
x: x,
@@ -290,8 +287,8 @@ export default {
290287
routeArray: this.routes[this.activeRoute],
291288
activeComponentData: this.activeComponentData
292289
}
293-
if(payload.x !== this.initialPosition.x || payload.y !== this.initialPosition.y ||
294-
payload.w !== this.initialSize.w || payload.h !==this.initialSize.h){
290+
if (payload.x !== this.initialPosition.x || payload.y !== this.initialPosition.y ||
291+
payload.w !== this.initialSize.w || payload.h !==this.initialSize.h) {
295292
this.updateComponentSize(payload)
296293
}
297294
},
@@ -305,7 +302,7 @@ export default {
305302
this.userImage;
306303
},
307304
308-
finishedDrag: function(x,y){
305+
finishedDrag: function(x,y) {
309306
console.log("FINISHED DRAGGING")
310307
let payload = {
311308
x: x,
@@ -316,7 +313,7 @@ export default {
316313
}
317314
// console.log("Payload.x = ", payload.x, "this.initialPosition.x", this.initialPosition.x)
318315
// console.log("Payload.y = ", payload.y, "this.initialPosition.y", this.initialPosition.y)
319-
if(payload.x !== this.initialPosition.x || payload.y !== this.initialPosition.y){
316+
if (payload.x !== this.initialPosition.x || payload.y !== this.initialPosition.y) {
320317
this.updateComponentPosition(payload);
321318
}
322319
},
@@ -333,29 +330,27 @@ export default {
333330
// console.log("this is what is currently active",this.activeComponent)
334331
// console.log("this is this", this)
335332
// console.log('!(componentData.componentName === this.activeComponent)?',!(componentData.componentName === this.activeComponent))
336-
if(!(componentData.componentName === this.activeComponent)){
333+
if (!(componentData.componentName === this.activeComponent)) {
337334
this.setActiveComponent(componentData.componentName);
338335
}
339336
this.activeComponentData.isActive = true;
340-
341-
342337
},
343338
344339
// deactivated is emitted before activated
345340
346-
onDeactivated(componentData) {
347-
if(this.activeComponent !== ''){
348-
this.activeComponentData.isActive = false;
341+
onDeactivated (componentData) {
342+
if (this.activeComponent !== '') {
343+
this.activeComponentData.isActive = false;
349344
}
350-
// console.log("Componentdataname", componentData.componentName)
351-
// console.log("active component",this.activeComponent)
345+
// console.log("Componentdataname", componentData.componentName)
346+
// console.log("active component",this.activeComponent)
352347
// if(componentData.componentName === this.activeComponent)
353348
// {
354349
// console.log("We just clicked without making a new active component")
355350
// }
356351
},
357-
onDoubleClick(compData) {
358-
if(!(componentData.componentName === this.activeComponent)){
352+
onDoubleClick (compData) {
353+
if (!(componentData.componentName === this.activeComponent)) {
359354
this.setActiveComponent(componentData.componentName);
360355
}
361356
this.activeComponentData.isActive = true;
@@ -411,7 +406,7 @@ export default {
411406
z-index: -1;
412407
}
413408
.component-children {
414-
position: absolute;
409+
position: relative;
415410
top: 0rem;
416411
left: 2px;
417412
color: black;

src/components/CreateComponent.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default {
6868
return false;
6969
}
7070
const component = {
71-
componentName: this.componentNameInputValue,
71+
componentName: this.componentNameInputValue.replace(/[^a-z0-9-_.]/gi, ''),
7272
x: 0,
7373
y: 20,
7474
z: 0,
@@ -84,10 +84,9 @@ export default {
8484
8585
},
8686
resetActiveComponent () {
87-
if(!this.activeComponent === ''){
88-
this.setActiveComponent('')
89-
}
90-
87+
if (this.activeComponent !== '') {
88+
this.setActiveComponent('')
89+
}
9190
},
9291
handleIconClick () {
9392
if (this.activeComponent === '') this.setClickedElementList()

src/components/ExportProject.vue

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default {
9999
children = this.componentMap[componentName].children
100100
)
101101
*/
102-
createComponentCode(componentLocation, componentName, children) {
102+
createComponentCode (componentLocation, componentName, children) {
103103
if (componentName === "App") {
104104
fs.writeFileSync(
105105
componentLocation + ".vue",
@@ -115,13 +115,19 @@ export default {
115115
);
116116
}
117117
},
118+
createAssetFile (targetLocation, assetLocation) {
119+
let saved = remote.nativeImage.createFromPath(assetLocation)
120+
let urlData = saved.toPNG()
121+
// console.log('urlData is ', urlData);
122+
fs.writeFileSync(targetLocation + ".png", urlData);
123+
},
118124
/**
119125
* @description helper function for writeTemplate
120126
* @name writeTemplateTag
121127
* - gets objects from htmlList from appropriate component and adds them to the template string, then inserts into writeTemplate return str
122128
* @input: componentMap['component'].htmlList[tag elements]
123129
*/
124-
writeTemplateTag(compName) {
130+
writeTemplateTag (compName) {
125131
console.log("writeTemplateTag invoked!");
126132
// create reference object
127133
const htmlElementMap = {
@@ -327,7 +333,7 @@ export default {
327333
str += `\n}`;
328334
fs.writeFileSync(path.join(location, "package.json"), str);
329335
},
330-
exportFile(data){
336+
exportFile(data) {
331337
if (!fs.existsSync(data)) {
332338
fs.mkdirSync(data);
333339
console.log("FOLDER CREATED!");
@@ -343,23 +349,32 @@ export default {
343349
this.createMainFile(data);
344350
this.createBabel(data);
345351
this.createPackage(data);
346-
// main logic below for creating components?
352+
// main logic below for creating components
347353
this.createRouter(data);
354+
for (let [routeImage, imageLocation] of Object.entries(this.imagePath)) {
355+
// console.log('routeImage is ', routeImage);
356+
this.createAssetFile(path.join(data, "src", "assets", routeImage), imageLocation)
357+
};
348358
for (let componentName in this.componentMap) {
359+
// if componentName is a route:
349360
if (componentName !== "App") {
350361
if (this.$store.state.routes[componentName]) {
362+
// console.log('THIS IS JUST A ROUTE ', componentName)
351363
this.createComponentCode(
352364
path.join(data, "src", "views", componentName),
353365
componentName,
354366
this.componentMap[componentName].children
355367
);
368+
// if componentName is a just a component
356369
} else {
370+
// console.log('THIS IS JUST A COMPONENT ', componentName)
357371
this.createComponentCode(
358372
path.join(data, "src", "components", componentName),
359373
componentName,
360374
this.componentMap[componentName].children
361375
);
362376
}
377+
// if componentName is App
363378
} else {
364379
this.createComponentCode(
365380
path.join(data, "src", componentName),
@@ -371,7 +386,7 @@ export default {
371386
}
372387
},
373388
computed: {
374-
...mapState(["componentMap"])
389+
...mapState(["componentMap", "imagePath"])
375390
}
376391
}
377392

src/components/OpenProjectComponent.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ export default {
1414
name: 'OpenProjectComponent',
1515
methods: {
1616
...mapActions([
17-
'setComponentMap',
18-
'setRoutes',
17+
// 'setComponentMap',
18+
// 'setRoutes',
19+
// 'setImagePath',
20+
'openProject'
1921
]),
2022
parseFileName(file) {
2123
//Obtains json file name from file path
2224
return file.split('/').pop();
2325
},
24-
openJSONFile(data){
26+
openJSONFile (data) {
2527
const jsonFile = JSON.parse(fs.readFileSync(data[0], 'utf8'))
26-
this.setComponentMap(jsonFile.componentMap)
27-
this.setRoutes(jsonFile.routes)
28+
console.log('json file', jsonFile.imagePath)
29+
// this.setComponentMap(jsonFile.componentMap)
30+
// this.setRoutes(jsonFile.routes)
31+
// if (jsonFile.imagePath) {
32+
// this.setImagePath(jsonFile.imagePath)
33+
// }
34+
// open project action
35+
this.openProject(jsonFile)
2836
},
29-
showOpenJSONDialog(){
37+
showOpenJSONDialog () {
3038
remote.dialog.showOpenDialog({
3139
properties: ['openFile'],
3240
filters: [{

src/components/RouteDisplay.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
Routes
2828
},
2929
computed: {
30-
...mapState(['routes'])
30+
...mapState(['routes', 'componentMap'])
3131
},
3232
data () {
3333
return {
@@ -37,7 +37,12 @@ export default {
3737
methods: {
3838
...mapActions(['addRouteToRouteMap', 'setRoutes']),
3939
handleEnterKeyPress () {
40-
this.addRouteToRouteMap(this.newRoute)
40+
const newRouteName = this.newRoute.replace(/[^a-z0-9-_.]/gi, '')
41+
if (!this.newRoute.trim() || this.routes[newRouteName] || this.componentMap[newRouteName] ) {
42+
event.preventDefault();
43+
return false;
44+
}
45+
this.addRouteToRouteMap(newRouteName)
4146
.then(() => {
4247
this.newRoute = ''
4348
})

0 commit comments

Comments
 (0)