Skip to content

Commit 9679024

Browse files
committed
actually finished export this time [email protected]
co-authored: Terry Tilley [email protected]
1 parent cbba2e2 commit 9679024

File tree

2 files changed

+100
-83
lines changed

2 files changed

+100
-83
lines changed

src/components/file_system_interface/ExportProject.vue

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -223,86 +223,95 @@ export default {
223223
* @description imports child components into <script>
224224
*/
225225
writeScript (componentName, children) {
226-
// let str = ''
227-
// children.forEach(name => {
228-
// str += `import ${name} from '@/components/${name}.vue';\n`
229-
// })
230-
// let childrenComponentNames = ''
231-
// children.forEach(name => {
232-
// childrenComponentNames += `\t\t${name},\n`
233-
// })
234-
// return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}'
235-
// ,\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
236-
// },
237226
// add import mapstate and mapactions if they exist
238-
let imports = ''
239-
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length){
240-
imports += 'import { '
241-
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
242-
imports += 'mapState, mapActions'
243-
}
244-
else if (this.activeComponentObj.state.length) imports += 'mapState'
245-
else imports += 'mapActions'
246-
imports += ' } from "vuex"\n'
247-
}
248-
249-
// add imports for children
250-
children.forEach(name => {
251-
imports += `import ${name} from '@/components/${name}.vue';\n`
252-
})
253-
254-
// add components section
255-
let childrenComponentNames = ''
256-
children.forEach(name => {
257-
childrenComponentNames += ` ${name},\n`
258-
})
227+
const currentComponent = this.componentMap[componentName]
228+
const routes = Object.keys(this.routes)
229+
console.log(componentName)
230+
console.log(currentComponent)
231+
if (!routes.includes(componentName)){
232+
let imports = ''
233+
if (currentComponent.actions.length || currentComponent.state.length){
234+
imports += 'import { '
235+
if (currentComponent.actions.length && currentComponent.state.length) {
236+
imports += 'mapState, mapActions'
237+
}
238+
else if (currentComponent.state.length) imports += 'mapState'
239+
else imports += 'mapActions'
240+
imports += ' } from "vuex"\n'
241+
}
259242
260-
// if true add data section and populate with props
261-
let data = ''
262-
if (this.activeComponentObj.props.length){
263-
data += ' data () {\n return {'
264-
this.activeComponentObj.props.forEach(prop => {
265-
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
243+
// add imports for children
244+
children.forEach(name => {
245+
imports += `import ${name} from '@/components/${name}.vue';\n`
266246
})
267-
data += '\n'
268-
data += ' }\n'
269-
data += ' },\n'
270-
}
271247
272-
// if true add computed section and populate with state
273-
let computed = ''
274-
if (this.activeComponentObj.state.length){
275-
computed += ' computed: {'
276-
computed += '\n ...mapState(['
277-
this.activeComponentObj.state.forEach((state) =>{
278-
computed += `\n "${state}",`
248+
// add components section
249+
let childrenComponentNames = ''
250+
children.forEach(name => {
251+
childrenComponentNames += ` ${name},\n`
279252
})
280-
computed += '\n ]),\n'
281-
computed += ' },\n'
282-
}
283253
284-
// if true add methods section and populate with actions
285-
let methods = ''
286-
if (this.activeComponentObj.actions.length){
287-
methods += ' methods: {'
288-
methods += '\n ...mapActions(['
289-
this.activeComponentObj.actions.forEach((action) => {
290-
methods += `\n "${action}",`
254+
// if true add data section and populate with props
255+
let data = ''
256+
if (currentComponent.props.length){
257+
data += ' data () {\n return {'
258+
currentComponent.props.forEach(prop => {
259+
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
260+
})
261+
data += '\n'
262+
data += ' }\n'
263+
data += ' },\n'
264+
}
265+
266+
// if true add computed section and populate with state
267+
let computed = ''
268+
if (currentComponent.state.length){
269+
computed += ' computed: {'
270+
computed += '\n ...mapState(['
271+
currentComponent.state.forEach((state) =>{
272+
computed += `\n "${state}",`
273+
})
274+
computed += '\n ]),\n'
275+
computed += ' },\n'
276+
}
277+
278+
// if true add methods section and populate with actions
279+
let methods = ''
280+
if (currentComponent.actions.length){
281+
methods += ' methods: {'
282+
methods += '\n ...mapActions(['
283+
currentComponent.actions.forEach((action) => {
284+
methods += `\n "${action}",`
285+
})
286+
methods += '\n ]),\n'
287+
methods += ' },\n'
288+
}
289+
290+
// concat all code within script tags
291+
let output = '\n\n<script>\n'
292+
output += imports + '\nexport default {\n name: ' + componentName
293+
output += ',\n components: {\n'
294+
output += childrenComponentNames + ' },\n'
295+
output += data
296+
output += computed
297+
output += methods
298+
output += '};\n<\/script>'
299+
return output
300+
}
301+
302+
else{
303+
let str = ''
304+
children.forEach(name => {
305+
str += `import ${name} from '@/components/${name}.vue';\n`
306+
})
307+
let childrenComponentNames = ''
308+
children.forEach(name => {
309+
childrenComponentNames += `\t\t${name},\n`
291310
})
292-
methods += '\n ]),\n'
293-
methods += ' },\n'
311+
return `\n\n<script>\n${str}\nexport default {\n\tname: '${componentName}',
312+
\n\tcomponents: {\n${childrenComponentNames}\t}\n};\n<\/script>`
294313
}
295314
296-
// concat all code within script tags
297-
let output = '\n\n<script>\n'
298-
output += imports + '\nexport default {\n name: ' + componentName
299-
output += ',\n components: {\n'
300-
output += childrenComponentNames + ' },\n'
301-
output += data
302-
output += computed
303-
output += methods
304-
output += '};\n<\/script>'
305-
return output
306315
},
307316
/**
308317
* @description writes the <style> in vue component
@@ -472,7 +481,7 @@ export default {
472481
}
473482
},
474483
computed: {
475-
...mapState(['componentMap', 'imagePath', 'activeComponentObj'])
484+
...mapState(['componentMap', 'imagePath', 'routes'])
476485
}
477486
}
478487

src/store/mutations.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ const mutations = {
109109
state.selectedActions = [];
110110
// super weird code, minor changes to objects are not reactive
111111
// setting to null and then resetting to object makes it reactive
112-
state.activeComponentObj = null;
113-
state.activeComponentObj = active;
112+
// state.activeComponentObj = null;
113+
// state.activeComponentObj = active;
114+
state.activeComponentObj = Object.assign({}, active)
115+
116+
state.componentMap = Object.assign({}, state.componentMap, {[state.activeComponent]: state.activeComponentObj})
114117
},
115118

116119
[types.CREATE_PROP]: (state, payload) => {
@@ -139,8 +142,9 @@ const mutations = {
139142
}
140143
}
141144
state.selectedProps = [];
142-
state.activeComponentObj = null;
143-
state.activeComponentObj = active;
145+
state.activeComponentObj = Object.assign({}, active)
146+
147+
state.componentMap = Object.assign({}, state.componentMap, {[state.activeComponent]: state.activeComponentObj})
144148
},
145149

146150
[types.CREATE_STATE]: (state, payload) => {
@@ -154,9 +158,6 @@ const mutations = {
154158
},
155159

156160
[types.ADD_STATE_TO_COMPONENT]: (state, payload) => {
157-
// let active = (state.routes[state.activeRoute].filter(comp => {
158-
// return comp.componentName === state.activeComponent
159-
// })[0])
160161
let active = state.activeComponentObj;
161162

162163
if (!state.activeComponentObj.state) {
@@ -169,8 +170,11 @@ const mutations = {
169170
}
170171
}
171172
state.selectedState = [];
172-
state.activeComponentObj = null;
173-
state.activeComponentObj = active;
173+
// state.activeComponentObj = null;
174+
// state.activeComponentObj = active;
175+
state.activeComponentObj = Object.assign({}, active)
176+
177+
state.componentMap = Object.assign({}, state.componentMap, {[state.activeComponent]: state.activeComponentObj})
174178
},
175179

176180
[types.DELETE_ACTION_FROM_COMPONENT]: (state, payload) => {
@@ -399,7 +403,8 @@ const mutations = {
399403
},
400404
// pushs new component to componentMap
401405
[types.ADD_COMPONENT_TO_COMPONENT_MAP]: (state, payload) => {
402-
const { componentName, htmlList, children, parent, isActive } = payload;
406+
const { componentName, htmlList, children, parent, isActive, actions, props } = payload;
407+
const s = payload.state
403408
state.componentMap = Object.assign({}, state.componentMap, {
404409
[componentName]: {
405410
componentName,
@@ -411,7 +416,10 @@ const mutations = {
411416
children,
412417
parent,
413418
htmlList,
414-
isActive
419+
isActive,
420+
actions,
421+
props,
422+
state: s
415423
}
416424
});
417425
},

0 commit comments

Comments
 (0)