diff --git a/client/src/main.js b/client/src/main.js index 0ec9bfd7..5ea42271 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -20,7 +20,10 @@ import VueModal from '@/plugins/modal'; import VueRemoveEdges from '@/plugins/edges'; import VueMatomo from 'vue-matomo'; import VueToast from 'vue-toast-notification'; +import VueLogger from 'vuejs-logger'; + Vue.config.productionTip = false; +const isProduction = process.env.NODE_ENV === 'production'; Vue.use(VueModal); Vue.use(VueRemoveEdges); @@ -28,6 +31,12 @@ Vue.use(VueApollo); Vue.use(VueAxios, axios); Vue.use(VueVimeoPlayer); Vue.use(VueToast); +Vue.use(VueLogger, { + isEnabled: true, + logLevel: isProduction ? 'error' : 'debug', + stringifyArguments: false, + showConsoleColors: true +}); Vue.use(VueScrollTo, { duration: 500, diff --git a/client/src/pages/survey.vue b/client/src/pages/survey.vue index 1594cf9c..2eda3250 100644 --- a/client/src/pages/survey.vue +++ b/client/src/pages/survey.vue @@ -35,7 +35,7 @@ components: { Solution, - Survey + Survey, }, data() { @@ -45,9 +45,9 @@ module: {}, completed: false, me: { - permissions: [] + permissions: [], }, - saveDisabled: false + saveDisabled: false, }; }, @@ -80,7 +80,7 @@
${answer.answer}
`; } - }, '') + }, ''), }; }, answers() { @@ -90,7 +90,7 @@ }, isTeacher() { return isTeacher(this); - } + }, }, methods: { @@ -100,9 +100,14 @@ for (let k in answers) { flatAnswers[k] = answers[k].answer; } - survey.data = flatAnswers; + this.$log.debug('flatAnswers', flatAnswers); + this.$log.debug('data', survey.data); + if (Object.keys(flatAnswers).length > 0) { + // answers are not empty + survey.data = flatAnswers; + } - const saveSurvey = (sender) => { + const saveSurvey = (sender, options) => { if (this.saveDisabled) { return; } @@ -116,21 +121,26 @@ let question = sender.getQuestionByName(k); data[k] = { answer: survey.data[k], - correct: question && question.correctAnswer ? question.correctAnswer : '' + correct: question && question.correctAnswer ? question.correctAnswer : '', }; } } + if (Object.keys(data).length === 0) { + // data is empty + return; + } const answer = { surveyId: this.id, - data: JSON.stringify(data) + data: JSON.stringify(data), }; + this.$log.debug('saving survey', answer); this.$apollo.mutate({ mutation: UPDATE_ANSWER, variables: { input: { - answer - } + answer, + }, }, update: (store, {data: {updateAnswer: {answer}}}) => { const query = SURVEY_QUERY; @@ -140,7 +150,7 @@ queryData.survey.answer = answer; store.writeQuery({query, variables, data: queryData}); } - } + }, }); }; @@ -151,6 +161,7 @@ survey.locale = 'de'; survey.showProgressBar = 'bottom'; survey.pageNextText = 'Speichern & Weiter'; + this.$log.debug(survey.data); return survey; }, reopen() { @@ -160,7 +171,7 @@ this.survey.clear(); this.survey.data = data; // reapply it this.saveDisabled = false; - } + }, }, apollo: { @@ -168,7 +179,7 @@ query: SURVEY_QUERY, variables() { return { - id: this.id + id: this.id, }; }, manual: true, @@ -190,14 +201,14 @@ this.$apollo.addSmartQuery('module', { query: MODULE_QUERY, variables: { - id: module.id - } + id: module.id, + }, }); } }, }, - me: meQuery - } + me: meQuery, + }, }; diff --git a/package-lock.json b/package-lock.json index ef862fe6..cbf42765 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,11 @@ "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz", "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==" }, + "es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw=" + }, "regenerator-runtime": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", @@ -44,6 +49,20 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/unfetch/-/unfetch-3.1.1.tgz", "integrity": "sha512-syDl3htvM56w0HC0PTVA5jEEknOCJ3dWgWGDuaEtQUno8ORDCfZQbm12RzfWO3AC3YhWDoP61dlgmo8Z05Y97g==" + }, + "vue": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.11.tgz", + "integrity": "sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ==" + }, + "vuejs-logger": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/vuejs-logger/-/vuejs-logger-1.5.5.tgz", + "integrity": "sha512-wESz1F4KWk98YANEDg2yeS+fpwk2WrR41ZslLfZgTD+EYFm/7VMMUjRThhHT8CCOLOCQdsS4Ge2C9bIs68v8Ww==", + "requires": { + "es6-object-assign": "1.1.0", + "vue": "2.6.11" + } } } } diff --git a/package.json b/package.json index cf540ff8..1fcb1657 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "babel-polyfill": "^6.26.0", - "unfetch": "^3.0.0" + "unfetch": "^3.0.0", + "vuejs-logger": "1.5.5" } }