Skip to content

Commit 61538f5

Browse files
authored
Merge pull request #16 from ziggrace/sean/edit
Sean/edit
2 parents e3d9a0d + a1aedf4 commit 61538f5

File tree

4 files changed

+83
-11
lines changed

4 files changed

+83
-11
lines changed

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
},
4141
computed: {
4242
// needs access to current component aka activeComponent
43-
...mapState(['componentMap', 'activeComponent'])
43+
...mapState(['componentMap', 'activeComponent', 'activeComponentObj'])
4444
},
4545
methods: {
4646
getWindowHeight (e) {
@@ -58,10 +58,12 @@ export default {
5858
},
5959
// Creates beginner boilerplate
6060
createTemplate (componentName, children) {
61-
let output = ``
62-
output += ` <div>\n`
61+
// not sure why output was set up like this, was imputted into return statement
62+
// using string literal
63+
// let output = ``
64+
// output += ` <div>\n`
6365
let templateTagStr = this.writeTemplateTag(componentName)
64-
return `<template>\n ${output}${templateTagStr} </div>\n</template>`
66+
return `<template>\n <div>\n${templateTagStr} </div>\n</template>`
6567
},
6668
// Creates <template> boilerplate
6769
writeTemplateTag (componentName) {
@@ -132,16 +134,83 @@ export default {
132134
},
133135
// Creates boiler text for <script> and <style>
134136
createBoiler (componentName, children) {
135-
let str = ''
137+
138+
// add import mapstate and mapactions if they exist
139+
let imports = ''
140+
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length){
141+
imports += 'import { '
142+
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
143+
imports += 'mapState, mapActions'
144+
}
145+
else if (this.activeComponentObj.state.length) imports += 'mapState'
146+
else imports += 'mapActions'
147+
imports += ' } from "vuex"\n'
148+
}
149+
150+
// add imports for children
136151
children.forEach(name => {
137-
str += `import ${name} from '@/components/${name}.vue';\n`
152+
imports += `import ${name} from '@/components/${name}.vue';\n`
138153
})
154+
155+
// add components section
139156
let childrenComponentNames = ''
140157
children.forEach(name => {
141158
childrenComponentNames += ` ${name},\n`
142159
})
160+
161+
// if true add data section and populate with props
162+
let data = ''
163+
if (this.activeComponentObj.props.length){
164+
data += ' data () {\n return {'
165+
this.activeComponentObj.props.forEach(prop => {
166+
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
167+
})
168+
data += '\n'
169+
data += ' }\n'
170+
data += ' },\n'
171+
}
172+
173+
// if true add computed section and populate with state
174+
let computed = ''
175+
if (this.activeComponentObj.state.length){
176+
computed += ' computed: {'
177+
computed += '\n ...mapState(['
178+
this.activeComponentObj.state.forEach((state) =>{
179+
computed += `\n "${state}",`
180+
})
181+
computed += '\n ]),\n'
182+
computed += ' },\n'
183+
}
184+
185+
// if true add methods section and populate with actions
186+
let methods = ''
187+
if (this.activeComponentObj.actions.length){
188+
methods += ' methods: {'
189+
methods += '\n ...mapActions(['
190+
this.activeComponentObj.actions.forEach((action) => {
191+
methods += `\n "${action}",`
192+
})
193+
methods += '\n ]),\n'
194+
methods += ' },\n'
195+
}
196+
197+
// concat all code within script tags
198+
let output = '\n\n<script>\n'
199+
output += imports + '\nexport default {\n name: ' + componentName
200+
output += ',\n components: {\n'
201+
output += childrenComponentNames + ' },\n'
202+
output += data
203+
output += computed
204+
output += methods
205+
output += '};\n<\/script>\n\n<style scoped>\n</style>'
206+
// add props/data
207+
208+
143209
// eslint-disable-next-line no-useless-escape
144-
return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n</style>`
210+
// return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n
211+
// components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n
212+
// </style>`
213+
return output
145214
}
146215
},
147216
mounted () {

src/components/home_sidebar_items/ComponentList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Description:
108108
</q-list>
109109
</a>
110110
</div>
111-
111+
<p v-else> Select Component to Enable Edit </p>
112112
</div>
113113
</template>
114114

src/components/home_sidebar_items/CreateComponent.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export default {
9898
h: 200,
9999
htmlList: this.selectedElementList,
100100
children: [],
101+
actions: [],
102+
props: [],
103+
state: [],
101104
parent: {},
102105
isActive: false
103106
}

src/components/home_sidebar_items/VuexForm.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Description:
4040
:option-height="20"
4141
open-direction="top"
4242
:options="actionOptions"
43-
:searchable="true"
43+
:searchable="false"
4444
@search-change="stopDelete($event)"
4545
>
4646
<span slot="noResult">No actions found.</span>
@@ -86,7 +86,7 @@ Description:
8686
:option-height="20"
8787
open-direction="top"
8888
:options="stateOptions"
89-
:searchable="true"
89+
:searchable="false"
9090
@search-change="stopDelete($event)"
9191
>
9292
<span slot="noResult">No state found.</span>
@@ -132,7 +132,7 @@ Description:
132132
:option-height="20"
133133
open-direction="top"
134134
:options="propsOptions"
135-
:searchable="true"
135+
:searchable="false"
136136
@search-change="stopDelete($event)"
137137
>
138138
<span slot="noResult">No props found.</span>

0 commit comments

Comments
 (0)