|
|
@@ -1,157 +1,70 @@
|
|
1
|
1
|
<template lang="pug">
|
|
2
|
|
-article
|
|
3
|
|
- form(@submit.prevent="onSubmit")
|
|
4
|
|
- .questionnaire
|
|
5
|
|
- .question(
|
|
6
|
|
- v-for="q in questionnaireQuestions"
|
|
7
|
|
- )
|
|
8
|
|
- label {{q.question}}
|
|
9
|
|
- .question--response
|
|
10
|
|
- .question--answers
|
|
11
|
|
- h3 {{q.answers[0].charAt(0).toUpperCase() + q.answers[0].slice(1)}}
|
|
12
|
|
- h3 {{q.answers[1].charAt(0).toUpperCase() + q.answers[1].slice(1)}}
|
|
13
|
|
- .question--radio-buttons
|
|
14
|
|
- input(type='radio' :id="'q'+(q.id)+'_a1'" :name="'q'+(q.id)" value="a1" v-model="questionnaireAnswers[q.id-1]")
|
|
15
|
|
- input(type='radio' :id="'q'+(q.id)+'_a2'" :name="'q'+(q.id)" value="a2" v-model="questionnaireAnswers[q.id-1]")
|
|
16
|
|
- input(type='radio' :id="'q'+(q.id)+'_a3'" :name="'q'+(q.id)" value="a3" v-model="questionnaireAnswers[q.id-1]")
|
|
17
|
|
- input(type='radio' :id="'q'+(q.id)+'_a4'" :name="'q'+(q.id)" value="a4" v-model="questionnaireAnswers[q.id-1]")
|
|
18
|
|
- input(type='radio' :id="'q'+(q.id)+'_a5'" :name="'q'+(q.id)" value="a5" v-model="questionnaireAnswers[q.id-1]")
|
|
19
|
|
- br
|
|
20
|
|
- w-flex
|
|
|
2
|
+main.view--onboarding
|
|
|
3
|
+ article
|
|
|
4
|
+ form(@submit.prevent="onSubmit").questionnaire
|
|
|
5
|
+ QuestionResponse(v-for="question in questions" :question="question" @updated="onUpdate")
|
|
21
|
6
|
w-button.ma1.grow(type="submit" bg-color="success")
|
|
22
|
7
|
w-icon.mr1 wi-check
|
|
23
|
8
|
| SUBMIT ANSWERS
|
|
24
|
|
-//- br
|
|
25
|
|
-//- h3 Current Step: {{currentStep}}
|
|
26
|
|
-//- br
|
|
27
|
|
-//- ul
|
|
28
|
|
-//- li(v-for="question in onboardingStep")
|
|
29
|
|
-//- p {{question}}
|
|
30
|
|
-//- br
|
|
31
|
|
-//- button(@click="goToStep(currentStep - 1)") previous
|
|
32
|
|
-//- br
|
|
33
|
|
-//- button(@click="goToStep(currentStep + 1)") next
|
|
34
|
|
-//- br
|
|
35
|
|
-//- br
|
|
|
9
|
+ MainNav
|
|
36
|
10
|
</template>
|
|
37
|
|
-<script>
|
|
|
11
|
+
|
|
|
12
|
+<script>
|
|
38
|
13
|
import { surveyFactory } from '@/utils'
|
|
39
|
14
|
import { allSteps, possible } from '@/utils/lang'
|
|
40
|
15
|
|
|
|
16
|
+import QuestionResponse from '../components/QuestionResponse.vue'
|
|
|
17
|
+const SCORED = [1, 2, 3, 4, 5, 6]
|
|
|
18
|
+const _isScored = id => SCORED.includes(id)
|
|
|
19
|
+
|
|
|
20
|
+const _makeCategoryFriendly = responseCategory => {
|
|
|
21
|
+ const labels = responseCategory.split('_vs_')
|
|
|
22
|
+ labels.forEach((a, i) => {
|
|
|
23
|
+ if (a.indexOf('_') == -1) return
|
|
|
24
|
+ labels[i] = a.split('_').join(' ')
|
|
|
25
|
+ })
|
|
|
26
|
+ return labels
|
|
|
27
|
+}
|
|
|
28
|
+
|
|
|
29
|
+const _formatSteps = steps => {
|
|
|
30
|
+ return steps
|
|
|
31
|
+ .map(q => {
|
|
|
32
|
+ if (!_isScored(q.response_key_id)) return null
|
|
|
33
|
+ return {
|
|
|
34
|
+ id: q.response_key_id,
|
|
|
35
|
+ question: q.response_key_prompt,
|
|
|
36
|
+ labels: _makeCategoryFriendly(q.response_key_category),
|
|
|
37
|
+ }
|
|
|
38
|
+ })
|
|
|
39
|
+ .filter(step => step != null)
|
|
|
40
|
+}
|
|
41
|
41
|
|
|
42
|
42
|
export default {
|
|
43
|
|
- name:'OnboardingView',
|
|
|
43
|
+ name: 'OnboardingView',
|
|
|
44
|
+ components: { QuestionResponse },
|
|
44
|
45
|
data: () => {
|
|
45
|
46
|
return {
|
|
46
|
|
- // onboardingQuestions: [],
|
|
47
|
|
- // currentStep: 0,
|
|
48
|
|
- // onboardingAnswers: [],
|
|
49
|
47
|
validSurvey: null,
|
|
50
|
|
- questionnaireQuestions:[],
|
|
51
|
|
- questionnaireAnswers: Array(6).join(".").split(".")
|
|
|
48
|
+ questions: [],
|
|
|
49
|
+ answered: {},
|
|
52
|
50
|
}
|
|
53
|
51
|
},
|
|
54
|
|
- computed:{
|
|
55
|
|
- // onboardingStep(){
|
|
56
|
|
- // if(!this.onboardingQuestions.length) return []
|
|
57
|
|
- // return this.onboardingQuestions[this.currentStep]
|
|
58
|
|
- // },
|
|
59
|
|
- // questionnaireAnswers(){
|
|
60
|
|
- // let num_of_ans = 6 // TODO make dynamic once we know which questions we will be asking
|
|
61
|
|
- // return Array(num_of_ans).join(".").split(".")
|
|
62
|
|
- // }
|
|
63
|
|
- },
|
|
64
|
|
- async created(){
|
|
65
|
|
- this.validSurvey = await surveyFactory.createSurvey(
|
|
|
52
|
+ async created() {
|
|
|
53
|
+ const survey = await surveyFactory.createSurvey(
|
|
66
|
54
|
allSteps['usa'],
|
|
67
|
55
|
possible['usa']['roles'],
|
|
68
|
56
|
)
|
|
69
|
|
- // gather questionnaire questions
|
|
70
|
|
- this.validSurvey.steps.forEach(q => {
|
|
71
|
|
- if(q.response_key_id && q.response_key_id < 7) {
|
|
72
|
|
- let id = q.response_key_id
|
|
73
|
|
- let question = q.response_key_prompt
|
|
74
|
|
- let answers = q.response_key_category.split('_vs_')
|
|
75
|
|
- answers.forEach((a,i) => {
|
|
76
|
|
- if(a.indexOf('_') !== -1){
|
|
77
|
|
- answers[i] = a.split('_').join(' ')
|
|
78
|
|
- }
|
|
79
|
|
- })
|
|
80
|
|
- this.questionnaireQuestions.push({
|
|
81
|
|
- id,
|
|
82
|
|
- question,
|
|
83
|
|
- answers
|
|
84
|
|
- })
|
|
85
|
|
- }
|
|
86
|
|
- })
|
|
87
|
|
- // var step = []
|
|
88
|
|
- // var fooSteps = [...this.validSurvey.steps]
|
|
89
|
|
- // while(fooSteps.length > (this.validSurvey.steps.length % 3)){
|
|
90
|
|
- // var q = fooSteps.shift()
|
|
91
|
|
- // step.push(q)
|
|
92
|
|
- // if(step.length == 3){
|
|
93
|
|
- // this.onboardingQuestions.push(step)
|
|
94
|
|
- // step = []
|
|
95
|
|
- // }
|
|
96
|
|
- // }
|
|
97
|
|
- // var last_step = [...fooSteps]
|
|
98
|
|
- // this.onboardingQuestions.push(last_step)
|
|
|
57
|
+ this.questions = _formatSteps(survey.steps)
|
|
99
|
58
|
},
|
|
100
|
59
|
methods: {
|
|
|
60
|
+ onUpdate(payload) {
|
|
|
61
|
+ this.answered[payload.id] = payload
|
|
|
62
|
+ },
|
|
101
|
63
|
onSubmit() {
|
|
102
|
|
- this.questionnaireAnswers.forEach((ans,ind)=>{
|
|
103
|
|
- console.log(`Question ${ind+1} was ${ans==''? 'left blank.' : `answered ${ans}`}`)
|
|
104
|
|
- })
|
|
|
64
|
+ Object.values(this.answered).forEach(ans =>
|
|
|
65
|
+ console.log(ans.question, ans.answer),
|
|
|
66
|
+ )
|
|
105
|
67
|
},
|
|
106
|
|
- // goToStep(num){
|
|
107
|
|
- // if(num < 0){
|
|
108
|
|
- // this.currentStep = this.onboardingQuestions.length-1
|
|
109
|
|
- // }
|
|
110
|
|
- // else if(num >= this.onboardingQuestions.length) {
|
|
111
|
|
- // this.currentStep = 0
|
|
112
|
|
- // }
|
|
113
|
|
- // else
|
|
114
|
|
- // this.currentStep = num
|
|
115
|
|
- // },
|
|
116
|
68
|
},
|
|
117
|
69
|
}
|
|
118
|
70
|
</script>
|
|
119
|
|
-<style>
|
|
120
|
|
-body{
|
|
121
|
|
- background-color: #1F2024;
|
|
122
|
|
-}
|
|
123
|
|
-article{
|
|
124
|
|
- color: #FFFFFF;
|
|
125
|
|
-}
|
|
126
|
|
-.questionnaire{
|
|
127
|
|
- display: flex;
|
|
128
|
|
- flex-direction:column;
|
|
129
|
|
-}
|
|
130
|
|
-.question{
|
|
131
|
|
- margin-top: 44px;
|
|
132
|
|
-}
|
|
133
|
|
-.question > label{
|
|
134
|
|
- font-size: 18px;
|
|
135
|
|
- line-height: 23px;
|
|
136
|
|
-}
|
|
137
|
|
-.question--response{
|
|
138
|
|
- margin-top: 22px;
|
|
139
|
|
- margin-inline: 19px;
|
|
140
|
|
-}
|
|
141
|
|
-.question--answers{
|
|
142
|
|
- display: flex;
|
|
143
|
|
- flex-direction: row;
|
|
144
|
|
- justify-content: space-between;
|
|
145
|
|
-}
|
|
146
|
|
-.question--radio-buttons{
|
|
147
|
|
- padding: 0 25px;
|
|
148
|
|
- margin: 16px auto auto auto;
|
|
149
|
|
- display: flex;
|
|
150
|
|
- flex-direction: row;
|
|
151
|
|
- justify-content: space-between;
|
|
152
|
|
-}
|
|
153
|
|
-.question--radio-buttons > input {
|
|
154
|
|
- width: 24px;
|
|
155
|
|
- height: 24px;
|
|
156
|
|
-}
|
|
157
|
|
-</style>
|