Skip to content

Commit

Permalink
Fixed most of the form/show pages
Browse files Browse the repository at this point in the history
  • Loading branch information
JhumanJ committed Dec 20, 2023
1 parent af5656c commit bab8517
Show file tree
Hide file tree
Showing 19 changed files with 317 additions and 335 deletions.
2 changes: 1 addition & 1 deletion client/components/global/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default {
helpUrl: () => this.config.links.help_url,
form () {
if (this.$route.name && this.$route.name.startsWith('forms.show_public')) {
return this.formsStore.getBySlug(this.$route.params.slug)
return this.formsStore.getByKey(this.$route.params.slug)
}
return null
},
Expand Down
4 changes: 2 additions & 2 deletions client/components/global/WorkspaceDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export default {
switchWorkspace (workspace) {
this.workspacesStore.setCurrentId(workspace.id)
this.formsStore.resetState()
this.formsStore.load(workspace.id)
this.formsStore.loadAll(workspace.id)
const router = useRouter()
const route = useRoute()
if (route.name !== 'home') {
router.push({ name: 'home' })
}
this.formsStore.load(workspace.id)
this.formsStore.loadAll(workspace.id)
},
isUrl (str) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
</h3>
</div>
</template>
<toggle-switch-input :value="value.hide_title" name="hide_title" class="mt-4"
<toggle-switch-input :model-value="modelValue.hide_title" name="hide_title" class="mt-4"
label="Hide Form Title"
:disabled="(form.hide_title===true)?true:null"
:help="hideTitleHelp"
@update:model-value="onChangeHideTitle"
/>
<toggle-switch-input :value="value.auto_submit" name="auto_submit" class="mt-4"
<toggle-switch-input :model-value="modelValue.auto_submit" name="auto_submit" class="mt-4"
label="Auto Submit Form"
help="Form will auto submit immediate after open URL"
@update:model-value="onChangeAutoSubmit"
Expand All @@ -33,7 +33,7 @@ export default {
type: Object,
required: true
},
value: {
modelValue: {
type: Object,
required: true
}
Expand All @@ -56,10 +56,10 @@ export default {
methods: {
onChangeHideTitle (val) {
this.value.hide_title = val
this.modelValue.hide_title = val
},
onChangeAutoSubmit (val) {
this.value.auto_submit = val
this.modelValue.auto_submit = val
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/components/open/forms/components/FormEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default {
computed: {
createdForm () {
return this.formsStore.getBySlug(this.createdFormSlug)
return this.formsStore.getByKey(this.createdFormSlug)
},
steps () {
return [
Expand Down Expand Up @@ -246,7 +246,7 @@ export default {
this.form.put('/open/forms/{id}/'.replace('{id}', this.form.id)).then((data) => {
this.formsStore.addOrUpdate(data.form)
this.$emit('on-save')
this.$router.push({ name: 'forms.show', params: { slug: this.form.slug } })
this.$router.push({ name: 'forms-slug-show', params: { slug: this.form.slug } })
this.amplitude.logEvent('form_saved', { form_id: this.form.id, form_slug: this.form.slug })
this.displayFormModificationAlert(data)
}).catch((error) => {
Expand Down
3 changes: 1 addition & 2 deletions client/components/open/forms/components/FormStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export default {
getChartData () {
if (!this.form) { return null }
this.isLoading = true
axios.get('/api/open/workspaces/' + this.form.workspace_id + '/form-stats/' + this.form.id).then((response) => {
const statsData = response.data
opnFetch('/open/workspaces/' + this.form.workspace_id + '/form-stats/' + this.form.id).then((statsData) => {
if (statsData && statsData.views !== undefined) {
this.chartData.labels = Object.keys(statsData.views)
this.chartData.datasets[0].data = statsData.views
Expand Down
5 changes: 2 additions & 3 deletions client/components/open/forms/components/FormSubmissions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ export default {
return
}
this.isLoading = true
axios.get('/api/open/forms/' + this.form.id + '/submissions?page=' + this.currentPage).then((response) => {
const resData = response.data
opnFetch('/open/forms/' + this.form.id + '/submissions?page=' + this.currentPage).then((resData) => {
this.tableData = this.tableData.concat(resData.data.map((record) => record.data))
this.dataChanged()
Expand All @@ -235,6 +233,7 @@ export default {
}
},
onChangeDisplayColumns () {
if (process.client)
window.localStorage.setItem('display-columns-formid-' + this.form.id, JSON.stringify(this.displayColumns))
this.form.properties = this.properties.concat(this.removed_properties).filter((field) => {
return this.displayColumns[field.id] === true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
related_templates: null,
questions: []
})
this.templatesStore.loadIfEmpty()
loadAllTemplates(this.templatesStore)
},
computed: {
Expand Down
10 changes: 5 additions & 5 deletions client/components/pages/forms/show/ExtraMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default {
}),
computed: {
formEndpoint: () => '/api/open/forms/{id}'
formEndpoint: () => '/open/forms/{id}'
},
methods: {
Expand All @@ -185,17 +185,17 @@ export default {
duplicateForm () {
if (this.loadingDuplicate) return
this.loadingDuplicate = true
axios.post(this.formEndpoint.replace('{id}', this.form.id) + '/duplicate').then((response) => {
this.formsStore.addOrUpdate(response.data.new_form)
this.$router.push({ name: 'forms.show', params: { slug: response.data.new_form.slug } })
opnFetch(this.formEndpoint.replace('{id}', this.form.id) + '/duplicate',{method: 'POST'}).then((data) => {
this.formsStore.save(data.new_form)
this.$router.push({ name: 'forms-show', params: { slug: data.new_form.slug } })
this.alertSuccess('Form was successfully duplicated.')
this.loadingDuplicate = false
})
},
deleteForm () {
if (this.loadingDelete) return
this.loadingDelete = true
axios.delete(this.formEndpoint.replace('{id}', this.form.id)).then(() => {
opnFetch(this.formEndpoint.replace('{id}', this.form.id),{method:'DELETE'}).then(() => {
this.formsStore.remove(this.form)
this.$router.push({ name: 'home' })
this.alertSuccess('Form was deleted.')
Expand Down
2 changes: 1 addition & 1 deletion client/components/pages/forms/show/RegenerateFormLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
this.loadingNewLink = true
axios.put(this.formEndpoint.replace('{id}', this.form.id) + '/regenerate-link/' + option).then((response) => {
this.formsStore.addOrUpdate(response.data.form)
this.$router.push({name: 'forms.show', params: {slug: response.data.form.slug}})
this.$router.push({name: 'forms-slug-show', params: {slug: response.data.form.slug}})
this.alertSuccess(response.data.message)
this.loadingNewLink = false
}).finally(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/composables/stores/useContentStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useContentStore = (mapKey = 'id') => {
})
}
function remove(item) {
content.value.remove(item[mapKey])
content.value.delete( typeof item === 'object' ? item[mapKey] : item)
}

function startLoading() {
Expand Down
34 changes: 9 additions & 25 deletions client/pages/forms/[slug]/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,15 @@
<script>
import { computed } from 'vue'
import Form from 'vform'
import { useFormsStore } from '../../../stores/forms.js'
import { useWorkingFormStore } from '../../../stores/working_form.js'
import { useWorkspacesStore } from '../../../stores/workspaces.js'
import Breadcrumb from '~/components/global/Breadcrumb.vue'
import SeoMeta from '../../../mixins/seo-meta.js'
const loadForms = function () {
const formsStore = useFormsStore()
const workspacesStore = useWorkspacesStore()
formsStore.startLoading()
workspacesStore.loadIfEmpty().then(() => {
formsStore.load(workspacesStore.currentId)
})
}
export default {
name: 'EditForm',
components: { Breadcrumb },
mixins: [SeoMeta],
middleware: 'auth',
beforeRouteEnter (to, from, next) {
const formsStore = useFormsStore()
const workingFormStore = useWorkingFormStore()
if (!formsStore.getBySlug(to.params.slug)) {
loadForms()
}
workingFormStore.set(null) // Reset old working form
next()
},
beforeRouteLeave (to, from, next) {
if (this.isDirty()) {
return this.alertConfirm('Changes you made may not be saved. Are you sure want to leave?', () => {
Expand All @@ -61,11 +39,17 @@ export default {
const formsStore = useFormsStore()
const workingFormStore = useWorkingFormStore()
const workspacesStore = useWorkspacesStore()
if (!formsStore.allLoaded) {
formsStore.loadAll(useWorkspacesStore().currentId)
}
workingFormStore.set(null) // Reset old working form
return {
formsStore,
workingFormStore,
workspacesStore,
formsLoading : computed(() => formsStore.loading)
formsLoading: computed(() => formsStore.loading)
}
},
Expand All @@ -88,7 +72,7 @@ export default {
}
},
form () {
return this.formsStore.getBySlug(this.$route.params.slug)
return this.formsStore.getByKey(this.$route.params.slug)
},
pageLoaded () {
return !this.loading && this.updatedForm !== null
Expand All @@ -114,7 +98,7 @@ export default {
}
}
this.closeAlert()
// this.closeAlert()
if (!this.form) {
loadForms()
} else {
Expand Down
Loading

0 comments on commit bab8517

Please sign in to comment.