From 3788f086799b5aea274e342876aaad8c5656ec8d Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Thu, 1 Sep 2022 15:33:40 +0100 Subject: [PATCH] Nearly finished app --- client/src/components/icons/FeatureSearch.vue | 23 +++ client/src/components/navbar/Index.vue | 8 +- client/src/components/sidebar/Index.vue | 2 +- client/src/components/sidebar/Navlink.vue | 16 +- client/src/router/index.js | 134 ++++++++++------ client/src/stores/answers.js | 1 + client/src/stores/app.js | 8 +- client/src/stores/questions.js | 3 +- client/src/views/Home.vue | 26 ++-- client/src/views/about/About.vue | 146 +++++++++--------- client/src/views/about/Acknowledgements.vue | 41 +++-- client/src/views/about/Licenses.vue | 67 ++++++++ client/src/views/about/Wanderhome.vue | 32 ++-- client/src/views/errors/NotFound.vue | 40 +++-- client/src/views/errors/Refused.vue | 32 ++-- client/src/views/quiz/Index.vue | 19 ++- client/src/views/quiz/Question.vue | 40 ++--- client/src/views/quiz/Quiz.vue | 80 +++++----- client/src/views/results/CompareAnswers.vue | 23 --- client/src/views/results/CompareResults.vue | 8 +- client/src/views/results/Index.vue | 16 ++ client/src/views/results/Results.vue | 9 +- client/src/views/results/Scores.vue | 4 +- client/src/views/results/Statistics.vue | 20 +-- .../compare-answers/CompareQuestion.vue | 125 +++++++++++++++ .../compare-answers/CompareQuestions.vue | 54 +++++++ .../views/results/compare-answers/Index.vue | 63 ++++++++ 27 files changed, 703 insertions(+), 337 deletions(-) create mode 100644 client/src/components/icons/FeatureSearch.vue create mode 100644 client/src/views/about/Licenses.vue delete mode 100644 client/src/views/results/CompareAnswers.vue create mode 100644 client/src/views/results/compare-answers/CompareQuestion.vue create mode 100644 client/src/views/results/compare-answers/CompareQuestions.vue create mode 100644 client/src/views/results/compare-answers/Index.vue diff --git a/client/src/components/icons/FeatureSearch.vue b/client/src/components/icons/FeatureSearch.vue new file mode 100644 index 0000000..66484d5 --- /dev/null +++ b/client/src/components/icons/FeatureSearch.vue @@ -0,0 +1,23 @@ + + + + \ No newline at end of file diff --git a/client/src/components/navbar/Index.vue b/client/src/components/navbar/Index.vue index e26efb8..da1d7a6 100644 --- a/client/src/components/navbar/Index.vue +++ b/client/src/components/navbar/Index.vue @@ -37,20 +37,20 @@
- +
- +
- +
diff --git a/client/src/components/sidebar/Index.vue b/client/src/components/sidebar/Index.vue index 17a061c..288c6a4 100644 --- a/client/src/components/sidebar/Index.vue +++ b/client/src/components/sidebar/Index.vue @@ -18,7 +18,7 @@
- +
diff --git a/client/src/components/sidebar/Navlink.vue b/client/src/components/sidebar/Navlink.vue index 0a33ec3..7cb61de 100644 --- a/client/src/components/sidebar/Navlink.vue +++ b/client/src/components/sidebar/Navlink.vue @@ -7,27 +7,25 @@ export default { }, props: [ 'prefix', - 'svgPath', - 'text', - 'to' + 'route' ] } diff --git a/client/src/router/index.js b/client/src/router/index.js index bc1544f..6535574 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -1,7 +1,8 @@ import { createRouter, createWebHistory } from 'vue-router' -import { mdiAccountBoxMultiple, mdiAccountGroupOutline, mdiAccountQuestion, mdiChartBox, mdiCodeTags, mdiCompare, mdiCounter, mdiEarth, mdiHandCoin, mdiHome, mdiInformation, mdiWeb } from '@mdi/js' +import { mdiAccountBoxMultiple, mdiAccountGroupOutline, mdiAccountQuestion, mdiChartBox, mdiCodeTags, mdiCompare, mdiCounter, mdiForum, mdiHandCoin, mdiHome, mdiInformation, mdiLicense, mdiWeb } from '@mdi/js' import About from '@/views/about/Index.vue' import AboutPage from '@/views/about/About.vue' +import Licenses from '@/views/about/Licenses.vue' import Acknowledgements from '@/views/about/Acknowledgements.vue' import Wanderhome from '@/views/about/Wanderhome.vue' import Home from '@/views/Home.vue' @@ -13,9 +14,11 @@ import Refused from '@/views/errors/Refused.vue' import Results from '@/views/results/Index.vue' import ResultsPage from '@/views/results/Results.vue' import Scores from '@/views/results/Scores.vue' -import CompareAnswers from '@/views/results/CompareAnswers.vue' +import CompareAnswersIndex from '@/views/results/compare-answers/Index.vue' import Statistics from '@/views/results/Statistics.vue' import CompareResults from '@/views/results/CompareResults.vue' +import CompareQuestion from '@/views/results/compare-answers/CompareQuestion.vue' +import CompareQuestions from '@/views/results/compare-answers/CompareQuestions.vue' const routes = [ { @@ -23,7 +26,7 @@ const routes = [ name: 'Home', component: Home, meta: { - index: 0, + indexBase: 0, svgPath: mdiHome, title: 'Home' } @@ -33,7 +36,7 @@ const routes = [ name: 'Quiz', component: Quiz, meta: { - index: 1, + indexBase: 1, svgPath: mdiAccountQuestion, title: 'Take the Quiz' }, @@ -43,8 +46,8 @@ const routes = [ name: 'Quiz', component: QuizPage, meta: { - index: 0, - parentIndex: 1, + indexChild: 0, + indexBase: 1, title: 'Take the Quiz' } }, @@ -56,8 +59,8 @@ const routes = [ id: parseInt(route.params.id) }), meta: { - index: 1, - parentIndex: 1, + indexChild: 1, + indexBase: 1, title: 'Take the Quiz' } } @@ -68,7 +71,7 @@ const routes = [ name: 'About', component: About, meta: { - index: 2, + indexBase: 2, svgPath: mdiInformation, title: 'About' }, @@ -78,19 +81,30 @@ const routes = [ name: 'About', component: AboutPage, meta: { - index: 0, - parentIndex: 2, + indexChild: 0, + indexBase: 2, svgPath: mdiInformation, title: 'Background' } }, + { + path: 'licenses', + name: 'Licenses', + component: Licenses, + meta: { + indexChild: 1, + indexBase: 2, + svgPath: mdiLicense, + title: 'Licenses' + } + }, { path: 'wanderhome', name: 'Wanderhome', component: Wanderhome, meta: { - index: 1, - parentIndex: 2, + indexChild: 2, + indexBase: 2, svgPath: mdiHandCoin, title: 'About Wanderhome' } @@ -100,8 +114,8 @@ const routes = [ name: 'Acknowledgements', component: Acknowledgements, meta: { - index: 2, - parentIndex: 2, + indexChild: 3, + indexBase: 2, svgPath: mdiAccountGroupOutline, title: 'Acknowledgements' } @@ -110,8 +124,8 @@ const routes = [ path: 'https://git.vsnt.uk/viveksantayana/wanderhome-quiz', name: 'SourceCode', meta: { - index: 3, - parentIndex: 2, + indexChild: 4, + indexBase: 2, svgPath: mdiCodeTags, title: 'View Source Code' } @@ -123,7 +137,7 @@ const routes = [ name: 'Results', component: Results, meta: { - index: -1, + indexBase: -1, title: 'Results', svgPath: mdiAccountBoxMultiple }, @@ -133,10 +147,10 @@ const routes = [ name: 'Result', component: ResultsPage, meta: { - index: 0, + indexChild: 0, title: 'Your Results', svgPath: mdiAccountBoxMultiple, - parentIndex: -1 + indexBase: -1 } }, { @@ -144,10 +158,10 @@ const routes = [ name: 'Scores', component: Scores, meta: { - index: 1, + indexChild: 1, title: 'Your Scores', svgPath: mdiCounter, - parentIndex: -1 + indexBase: -1 } }, { @@ -155,10 +169,10 @@ const routes = [ name: 'CompareResults', component: CompareResults, meta: { - index: 2, + indexChild: 2, title: 'Compare Results', svgPath: mdiCompare, - parentIndex: -1 + indexBase: -1 } }, { @@ -166,22 +180,51 @@ const routes = [ name: 'Statistics', component: Statistics, meta: { - index: 3, + indexChild: 3, title: 'Statistics', svgPath: mdiChartBox, - parentIndex: -1 + indexBase: -1 } }, { path: 'answers', name: 'Answers', - component: CompareAnswers, + component: CompareAnswersIndex, meta: { - index: 4, + indexChild: 4, title: 'Compare Answers', - svgPath: mdiEarth, - parentIndex: -1 - } + svgPath: mdiForum, + indexBase: -1 + }, + children: [ + { + path: '', + name: 'RootAnswer', + component: CompareQuestions, + meta: { + indexGrandchild: 0, + title: 'Compare Answers', + svgPath: mdiForum, + indexBase: -1, + indexChild: 4 + } + }, + { + path: ':id', + name: 'CompareQuestion', + component: CompareQuestion, + props: route => ({ + id: parseInt(route.params.id) + }), + meta: { + indexGrandchild: 1, + title: 'Compare Answers', + svgPath: mdiForum, + indexBase: -1, + indexChild: 4 + } + } + ] } ] }, @@ -190,17 +233,17 @@ const routes = [ name: 'NotFound', component: NotFound, meta: { - index: -1, + indexBase: -2, title: 'Error: Not Found', svgPath: mdiWeb } }, { path: "/:catchAll(.*)", - name: 'NotFound', + name: 'CatchAll', redirect: '/err_notfound', meta: { - index: -1, + indexBase: -3, title: 'Error: Not Found', svgPath: mdiWeb } @@ -210,7 +253,7 @@ const routes = [ name: 'Refused', component: Refused, meta: { - index: -1, + indexBase: -4, title: 'Error: Connection Refused', svgPath: mdiWeb } @@ -222,31 +265,36 @@ const Router = createRouter({ routes }) -Router.beforeEach((to, from, next) => { +Router.beforeEach((to, from) => { if (to.meta.title != 'Home') { document.title = `Wanderhome Quiz | V.S. - ${to.meta.title}` } else { document.title = `Wanderhome Quiz | V.S.` } - next() + if (from.meta.indexBase == -1 && to.meta.indexBase != -1) { + if (!confirm('If you navigate away from the Results section, then you will lose your results and need to start the quiz again. Are you sure?')) { + return false + } + to.meta.resetApp = true + } }) Router.afterEach( (to, from) => { const enterActiveClass = 'transition-all duration-300 origin-top ease-in' const leaveActiveClass = 'transition-all duration-300 origin-top ease-out' const baseFromClass = 'transform opacity-0 md:scale-75' - if ( to.fullPath.split('/')[1] !== from.fullPath.split('/')[1] || !from.matched.length ) { - const fromIndex = from.meta.parentIndex ? from.meta.parentIndex : from.meta.index - const toIndex = to.meta.parentIndex ? to.meta.parentIndex : to.meta.index + if ( from.meta.indexBase !== to.meta.indexBase ) { + const fromIndex = from.meta.indexBase + const toIndex = to.meta.indexBase const slideInDirection = toIndex < fromIndex ? 'md:-translate-x-1/3' : 'md:translate-x-1/3' const slideOutDirection = toIndex < fromIndex ? 'md:translate-x-1/3' : 'md:-translate-x-1/3' to.meta.mainEnterActiveClass = enterActiveClass to.meta.mainLeaveActiveClass = leaveActiveClass to.meta.mainEnterFromClass = baseFromClass + ' ' + slideInDirection to.meta.mainLeaveToClass = baseFromClass + ' ' + slideOutDirection - } else if ( to.fullPath.split('/')[1] == from.fullPath.split('/')[1] && from.matched.length ) { - const fromIndex = from.meta.index - const toIndex = to.meta.index + } else if ( from.meta.indexChild !== to.meta.indexChild ) { + const fromIndex = from.meta.indexChild + const toIndex = to.meta.indexChild const slideInDirection = toIndex < fromIndex ? 'md:-translate-y-1/3' : 'md:translate-y-1/3' const slideOutDirection = toIndex < fromIndex ? 'md:translate-y-1/3' : 'md:-translate-y-1/3' to.meta.panelEnterActiveClass = enterActiveClass diff --git a/client/src/stores/answers.js b/client/src/stores/answers.js index 5350a0c..16072da 100644 --- a/client/src/stores/answers.js +++ b/client/src/stores/answers.js @@ -4,6 +4,7 @@ export const useAnswersStore = defineStore({ id: 'answers', state: () => ({ answers: [], + quizCurrent: null }), actions: { isAnswered(index) { diff --git a/client/src/stores/app.js b/client/src/stores/app.js index 79759c2..58423e7 100644 --- a/client/src/stores/app.js +++ b/client/src/stores/app.js @@ -3,18 +3,14 @@ import { defineStore } from 'pinia' export const useAppStore = defineStore({ id: 'app', state: () => ({ - hasData: false, answers: [], playbooks: {}, results: {}, scores: {}, - count: null + count: null, + compareCurrent: null }), actions: { - toggleData() { - this.hasData = !this.hasData - console.log('Toggled Has Data. New value', this.hasData) - }, store(key, data) { this[key] = JSON.parse(JSON.stringify(data)) } diff --git a/client/src/stores/questions.js b/client/src/stores/questions.js index 50d8d63..57624ff 100644 --- a/client/src/stores/questions.js +++ b/client/src/stores/questions.js @@ -3,8 +3,7 @@ import { defineStore } from 'pinia' export const useQuestionStore = defineStore({ id: 'questions', state: () => ({ - questions: [], - currentQuestion: 0 + questions: [] }), actions: { storeQuestions(questionArray) { diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index d81c0e9..d34c073 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/client/src/views/results/CompareAnswers.vue b/client/src/views/results/CompareAnswers.vue deleted file mode 100644 index c892d32..0000000 --- a/client/src/views/results/CompareAnswers.vue +++ /dev/null @@ -1,23 +0,0 @@ - - \ No newline at end of file diff --git a/client/src/views/results/CompareResults.vue b/client/src/views/results/CompareResults.vue index 0eadf36..1415843 100644 --- a/client/src/views/results/CompareResults.vue +++ b/client/src/views/results/CompareResults.vue @@ -29,18 +29,20 @@ getResults() { axios.get(`${Config.SERVER}api/playbooks/`) .then((response) => { - this.error = false + console.log('Fetched playbook stats from the server.') this.appStore.store('playbooks', response.data) }) .catch( error => { + console.log(error) this.$router.push('/err_refused') }) axios.get(`${Config.SERVER}api/count/`) .then((response) => { - this.error = false + console.log('Fetched user count from the server.') this.appStore.store('count', response.data) }) .catch( error => { + console.log(error) this.$router.push('/err_refused') }) } @@ -92,7 +94,7 @@ - Out of a total {{ this.appStore.count }} users + Out of {{ this.appStore.count }} users diff --git a/client/src/views/results/Index.vue b/client/src/views/results/Index.vue index 1ef543a..b0a2c4c 100644 --- a/client/src/views/results/Index.vue +++ b/client/src/views/results/Index.vue @@ -1,9 +1,25 @@ diff --git a/client/src/views/results/Results.vue b/client/src/views/results/Results.vue index c5f5e78..707429b 100644 --- a/client/src/views/results/Results.vue +++ b/client/src/views/results/Results.vue @@ -53,13 +53,10 @@ Pages {{ Object.values(playbook)[0].pages }} -

-

+

+

- {{ Object.values(playbook)[0].blurb }} -

-

- You are alive. Your care is {{ Object.values(playbook)[0].care }}. + You are alive. Your care is .

Your animal form is {{ renderAnimals(Object.values(playbook)[0].animals) }} diff --git a/client/src/views/results/Scores.vue b/client/src/views/results/Scores.vue index 4356a32..2b8c3d8 100644 --- a/client/src/views/results/Scores.vue +++ b/client/src/views/results/Scores.vue @@ -36,7 +36,7 @@ Playbook - Score + Score (%) @@ -46,7 +46,7 @@ The {{ playbook }} - {{ Math.round(100*score/this.appStore.results.max_score) }} % + {{ Math.round(100*score/this.appStore.results.max_score) }} diff --git a/client/src/views/results/Statistics.vue b/client/src/views/results/Statistics.vue index 5d87ef5..372157f 100644 --- a/client/src/views/results/Statistics.vue +++ b/client/src/views/results/Statistics.vue @@ -29,18 +29,20 @@ getScores() { axios.get(`${Config.SERVER}api/scores/`) .then((response) => { - this.error = false + console.log('Fetched score stats from the server.') this.appStore.store('scores', response.data) }) .catch( error => { + console.log(error) this.$router.push('/err_refused') }) axios.get(`${Config.SERVER}api/count/`) .then((response) => { - this.error = false + console.log('Fetched user count from the server.') this.appStore.store('count', response.data) }) .catch( error => { + console.log(error) this.$router.push('/err_refused') }) } @@ -57,7 +59,7 @@ Sometimes, it can help to have some additional insight into the likelihood of meeting different people. Or, indeed, it can provide insight into how the questions we ask of each other bias the way we perceive the world.

- +
- @@ -105,7 +107,7 @@ - +
@@ -67,16 +69,16 @@ Playbook - Your Score + Your Score (%) - Mean Score + Mean - Median Score + Median - Standard Deviation + + σ*
Out of a total {{ this.appStore.count }} usersFrom {{ this.appStore.count }} users
diff --git a/client/src/views/results/compare-answers/CompareQuestion.vue b/client/src/views/results/compare-answers/CompareQuestion.vue new file mode 100644 index 0000000..4f11b08 --- /dev/null +++ b/client/src/views/results/compare-answers/CompareQuestion.vue @@ -0,0 +1,125 @@ + + + \ No newline at end of file diff --git a/client/src/views/results/compare-answers/CompareQuestions.vue b/client/src/views/results/compare-answers/CompareQuestions.vue new file mode 100644 index 0000000..b146541 --- /dev/null +++ b/client/src/views/results/compare-answers/CompareQuestions.vue @@ -0,0 +1,54 @@ + + \ No newline at end of file diff --git a/client/src/views/results/compare-answers/Index.vue b/client/src/views/results/compare-answers/Index.vue new file mode 100644 index 0000000..bd97760 --- /dev/null +++ b/client/src/views/results/compare-answers/Index.vue @@ -0,0 +1,63 @@ + + \ No newline at end of file