Skip to content

Commit fb590db

Browse files
committed
committing code snippet changes
2 parents f272500 + 61538f5 commit fb590db

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default {
4242
},
4343
computed: {
4444
// needs access to current component aka activeComponent
45-
...mapState(['componentMap', 'activeComponent'])
45+
...mapState(['componentMap', 'activeComponent', 'activeComponentObj'])
4646
},
4747
methods: {
4848
getWindowHeight (e) {
@@ -60,10 +60,12 @@ export default {
6060
},
6161
// Creates beginner boilerplate
6262
createTemplate (componentName, children) {
63-
let output = ``
64-
output += ` <div>\n`
63+
// not sure why output was set up like this, was imputted into return statement
64+
// using string literal
65+
// let output = ``
66+
// output += ` <div>\n`
6567
let templateTagStr = this.writeTemplateTag(componentName)
66-
return `<template>\n ${output}${templateTagStr} </div>\n</template>`
68+
return `<template>\n <div>\n${templateTagStr} </div>\n</template>`
6769
},
6870
// Creates <template> boilerplate
6971
writeTemplateTag (componentName) {
@@ -138,16 +140,80 @@ export default {
138140
},
139141
// Creates boiler text for <script> and <style>
140142
createBoiler (componentName, children) {
141-
let str = ''
142-
children.forEach((name) => {
143-
str += `import ${name} from '@/components/${name}.vue';\n`
143+
// add import mapstate and mapactions if they exist
144+
let imports = ''
145+
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length) {
146+
imports += 'import { '
147+
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
148+
imports += 'mapState, mapActions'
149+
} else if (this.activeComponentObj.state.length) imports += 'mapState'
150+
else imports += 'mapActions'
151+
imports += ' } from "vuex"\n'
152+
}
153+
154+
// add imports for children
155+
children.forEach(name => {
156+
imports += `import ${name} from '@/components/${name}.vue';\n`
144157
})
158+
159+
// add components section
145160
let childrenComponentNames = ''
146161
children.forEach((name) => {
147162
childrenComponentNames += ` ${name},\n`
148163
})
164+
165+
// if true add data section and populate with props
166+
let data = ''
167+
if (this.activeComponentObj.props.length) {
168+
data += ' data () {\n return {'
169+
this.activeComponentObj.props.forEach(prop => {
170+
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
171+
})
172+
data += '\n'
173+
data += ' }\n'
174+
data += ' },\n'
175+
}
176+
177+
// if true add computed section and populate with state
178+
let computed = ''
179+
if (this.activeComponentObj.state.length) {
180+
computed += ' computed: {'
181+
computed += '\n ...mapState(['
182+
this.activeComponentObj.state.forEach((state) => {
183+
computed += `\n "${state}",`
184+
})
185+
computed += '\n ]),\n'
186+
computed += ' },\n'
187+
}
188+
189+
// if true add methods section and populate with actions
190+
let methods = ''
191+
if (this.activeComponentObj.actions.length) {
192+
methods += ' methods: {'
193+
methods += '\n ...mapActions(['
194+
this.activeComponentObj.actions.forEach((action) => {
195+
methods += `\n "${action}",`
196+
})
197+
methods += '\n ]),\n'
198+
methods += ' },\n'
199+
}
200+
201+
// concat all code within script tags
202+
let output = '\n\n<script>\n'
203+
output += imports + '\nexport default {\n name: ' + componentName
204+
output += ',\n components: {\n'
205+
output += childrenComponentNames + ' },\n'
206+
output += data
207+
output += computed
208+
output += methods
209+
output += '};\n<\/script>\n\n<style scoped>\n</style>'
210+
// add props/data
211+
149212
// eslint-disable-next-line no-useless-escape
150-
return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n</style>`
213+
// return `\n\n<script>\n${str}\nexport default {\n name: '${componentName}',\n
214+
// components: {\n${childrenComponentNames} }\n};\n<\/script>\n\n<style scoped>\n
215+
// </style>`
216+
return output
151217
}
152218
},
153219
mounted () {

src/components/home_sidebar_items/CreateComponent.vue

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

src/components/home_sidebar_items/EditDeleteComponents.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Description:
136136
</q-list>
137137
</a>
138138
</div>
139-
139+
<p v-else> Select Component to Enable Edit </p>
140140
</div>
141141
</template>
142142

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)