Clean loading results

Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
Jonas Rittershofer 2020-05-11 15:58:32 +02:00
parent 6a52d83675
commit c54698f950
3 changed files with 24 additions and 24 deletions

View file

@ -649,16 +649,8 @@ class ApiController extends Controller {
$submissions[] = $submission;
}
// Load question-texts, including deleted ones.
try {
$questionEntities = $this->questionMapper->findByForm($form->getId());
} catch (DoesNotExistException $e) {
//handle silently
}
$questions = [];
foreach ($questionEntities as $questionEntity) {
$questions[] = $questionEntity->read();
}
// Load currently active questions
$questions = $this->formsService->getQuestions($form->getId());
$response = [
'submissions' => $submissions,

View file

@ -78,7 +78,12 @@ class FormsService {
$this->userSession = $userSession;
}
/**
* Load options corresponding to question
*
* @param integer $questionId
* @return array
*/
public function getOptions(int $questionId): array {
$optionList = [];
try {
@ -93,6 +98,12 @@ class FormsService {
}
}
/**
* Load questions corresponding to form
*
* @param integer $formId
* @return array
*/
public function getQuestions(int $formId): array {
$questionList = [];
try {

View file

@ -71,10 +71,10 @@
<section v-else>
<Submission
v-for="submission in submissions"
v-for="submission in form.submissions"
:key="submission.id"
:submission="submission"
:questions="questions"
:questions="form.questions"
@delete="deleteSubmission(submission.id)" />
</section>
</AppContent>
@ -117,14 +117,12 @@ export default {
data() {
return {
loadingResults: true,
submissions: [],
questions: [],
}
},
computed: {
noSubmissions() {
return this.submissions && this.submissions.length === 0
return this.form.submissions?.length === 0
},
/**
@ -178,9 +176,8 @@ export default {
const response = await axios.get(generateUrl('/apps/forms/api/v1/submissions/{hash}', {
hash: this.form.hash,
}))
this.submissions = response.data.submissions
this.questions = response.data.questions
console.debug(this.submissions)
this.form.submissions = response.data.submissions
this.form.questions = response.data.questions
} catch (error) {
console.error(error)
showError(t('forms', 'There was an error while loading results'))
@ -194,8 +191,8 @@ export default {
try {
await axios.delete(generateUrl('/apps/forms/api/v1/submission/{id}', { id }))
const index = this.submissions.findIndex(search => search.id === id)
this.submissions.splice(index, 1)
const index = this.form.submissions.findIndex(search => search.id === id)
this.form.submissions.splice(index, 1)
} catch (error) {
console.error(error)
showError(t('forms', 'There was an error while removing this response'))
@ -212,7 +209,7 @@ export default {
this.loadingResults = true
try {
await axios.delete(generateUrl('/apps/forms/api/v1/submissions/{formId}', { formId: this.form.id }))
this.submissions = []
this.form.submissions = []
} catch (error) {
console.error(error)
showError(t('forms', 'There was an error while removing responses'))
@ -229,14 +226,14 @@ export default {
})
const formattedSubmissions = []
this.submissions.forEach(submission => {
this.form.submissions.forEach(submission => {
const formattedSubmission = {
userDisplayName: submission.userDisplayName,
timestamp: moment(submission.timestamp, 'X').format('L LT'),
}
submission.answers.forEach(answer => {
const questionText = this.questions.find(question => question.id === answer.questionId).text
const questionText = this.form.questions.find(question => question.id === answer.questionId).text
if (questionText in formattedSubmission) {
formattedSubmission[questionText] = formattedSubmission[questionText].concat('; ').concat(answer.text)
} else {