Skip to content

Commit

Permalink
generalized on all question types
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Dec 19, 2022
1 parent ee6db12 commit 9baa9ac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 72 deletions.
4 changes: 4 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<screenshot>https://raw.githubusercontent.com/nextcloud/forms/master/screenshots/forms2.png</screenshot>
<screenshot>https://raw.githubusercontent.com/nextcloud/forms/master/screenshots/forms3.png</screenshot>

<dependencies>
<nextcloud min-version="25" max-version="26" />
</dependencies>

<navigations>
<navigation>
<name>Forms</name>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Questions/AnswerInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { showError } from '@nextcloud/dialogs'
import { generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import pDebounce from 'p-debounce'
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
import PQueue from 'p-queue'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
Expand Down
15 changes: 0 additions & 15 deletions src/components/Questions/QuestionDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ export default {
},
mixins: [QuestionMixin],
props: {
dropDownState: {
type: Object,
},
},
data() {
return {
Expand Down Expand Up @@ -145,16 +140,6 @@ export default {
},
watch: {
dropDownState: {
handler(val) {
if (val) {
const prop = val.value
this.selectedOption = { id: prop.id, questionId: prop.questionId, text: prop.text }
}
},
deep: true,
immediate: true,
},
edit(edit) {
// When leaving edit mode, filter and delete empty options
if (!edit) {
Expand Down
78 changes: 22 additions & 56 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
:max-string-lengths="maxStringLengths"
v-bind="question"
:values.sync="answers[question.id]"
:drop-down-state="formValuesForLocalStorage[question.id]"
@keydown.enter="onKeydownEnter"
@keydown.ctrl.enter="onKeydownCtrlEnter"
@update:values="addFormFieldToLocalStorage(question,answers[question.id],answerTypes[question.type])" />
Expand Down Expand Up @@ -214,26 +213,6 @@ export default {
return message
},
},
mounted() {
if (localStorage.getItem('formFields')) {
this.formValuesForLocalStorage = JSON.parse(localStorage.getItem('formFields'));
this.formValuesForLocalStorage.forEach(answer => {
if (answer) {
switch (answer?.type) {
case "QuestionMultiple":
this.answers[answer.id] = answer.value;
break;
case "QuestionDate":
break;
default:
this.answers[answer.id] = [answer.value];
break;
}
}
});
}
},
watch: {
hash() {
// If public view, abort. Should normally not occur.
Expand All @@ -247,38 +226,37 @@ export default {
SetWindowTitle(this.formTitle)
},
},
mounted() {
beforeMount() {
// Public Views get their form by initial-state from parent. No fetch necessary.
if (this.publicView) {
this.isLoadingForm = false
} else {
this.fetchFullForm(this.form.id)
}
SetWindowTitle(this.formTitle)
if (localStorage.getItem(`${this.shareHash}`)) {
this.formValuesForLocalStorage = JSON.parse(localStorage.getItem(`${this.shareHash}`))
this.formValuesForLocalStorage.forEach(answer => {
if (answer) {
const arrofStr = []
switch (answer?.type) {
case 'QuestionMultiple':
this.answers[answer.id] = answer.value
break
case 'QuestionDate':
this.answers[answer.id] = [answer.value]
answer.value.forEach(num => {
arrofStr.push(num.toString())
})
this.answers[answer.id] = arrofStr
break
default:
this.answers[answer.id] = [answer.value]
this.answers[answer.id] = answer.value
break
}
}
})
}
},
beforeMount() {
// Public Views get their form by initial-state from parent. No fetch necessary.
if (this.publicView) {
this.isLoadingForm = false
} else {
this.fetchFullForm(this.form.id)
}
SetWindowTitle(this.formTitle)
},
methods: {
/**
* On Enter, focus next form-element
Expand All @@ -303,34 +281,22 @@ export default {
this.$refs.submitButton.click()
},
addFormFieldToLocalStorage(question, value, type) {
if (question.type === "dropdown") {
for (let option in question.options) {
if (question.options[option].id == value) {
this.formValuesForLocalStorage[question.id] = { id: question.id, value: question.options[option], type: type.component.name };
break;
}
}
}
else {
this.formValuesForLocalStorage[question.id] = { id: question.id, value, type: type.component.name };
}
const parsed = JSON.stringify(this.formValuesForLocalStorage);
localStorage.setItem('formFields', parsed);
this.formValuesForLocalStorage[question.id] = { id: question.id, value, type: type.component.name }
const parsed = JSON.stringify(this.formValuesForLocalStorage)
localStorage.setItem(`${this.shareHash}`, parsed)
},
deleteFormFieldFromLocalStorage() {
this.formValuesForLocalStorage = [];
const parsed = JSON.stringify(this.formValuesForLocalStorage);
localStorage.setItem('formFields', parsed);
this.formValuesForLocalStorage = []
const parsed = JSON.stringify(this.formValuesForLocalStorage)
localStorage.setItem(`${this.shareHash}`, parsed)
},
/**
* Submit the form after the browser validated it 🚀
*/
async onSubmit() {
this.deleteFormFieldFromLocalStorage();
this.deleteFormFieldFromLocalStorage()
this.loading = true
try {
Expand Down

0 comments on commit 9baa9ac

Please sign in to comment.