Przeglądaj źródła

survey setup, bring in sidebar and start adding css

tags/0.0.1
diaseu 4 lat temu
rodzic
commit
11e92e402f

+ 6
- 7
frontend/src/App.vue Wyświetl plik

1
 <template lang="pug">
1
 <template lang="pug">
2
-sidebar
3
-main.f-col.start.w-full
4
-    router-view
5
-    main-nav
2
+
3
+
4
+router-view
5
+
6
 </template>
6
 </template>
7
 
7
 
8
 <script>
8
 <script>
9
 import * as sss from '@/sss/import.css'
9
 import * as sss from '@/sss/import.css'
10
-import sidebar from './components/Sidebar.vue'
11
-import mainNav from './components/MainNav.vue'
10
+
11
+
12
 
12
 
13
 export default {
13
 export default {
14
     name: 'app',
14
     name: 'app',
15
-    components: { sidebar, mainNav },
16
 }
15
 }
17
 </script>
16
 </script>
18
 
17
 

frontend/src/components/Archive/form.vue → frontend/src/components/form.vue Wyświetl plik

21
                     @click='respondFromTag'
21
                     @click='respondFromTag'
22
                     v-for='response in prompt.responses'
22
                     v-for='response in prompt.responses'
23
                 ) {{ response }}
23
                 ) {{ response }}
24
+            //- TODO: Checklist
25
+            .response-wrapper(v-if='prompt.type === "checklist"')
26
+                .checklist(v-for='response in prompt.responses')
27
+                    input(
28
+                        type='checkbox'
29
+                        :id='response'
30
+                        :name='response'
31
+                        v-model='answers[makeKebob(prompt.question)]')
32
+                    label {{ response}}
33
+            //- TODO: Slider from -3 to 0 to +3 (increments of 1)
34
+            .response-wrapper(v-if='prompt.type === "slider"')
35
+                label {{ prompt.type }}
36
+                input(
37
+                    type='range'
38
+                    min='-3'
39
+                    max='3'
40
+                    v-model='answers[makeKebob(prompt.question)]')
24
 
41
 
25
     footer.f-row.w-full
42
     footer.f-row.w-full
26
         button.p-1(:disabled='state.step == 1' @click='back') back
43
         button.p-1(:disabled='state.step == 1' @click='back') back

+ 1
- 1
frontend/src/entities/profile/profile.js Wyświetl plik

14
     constructor({ email, ...profileData }) {
14
     constructor({ email, ...profileData }) {
15
         super()
15
         super()
16
 
16
 
17
-        this.type = this.constructor.name.toLowerCase()
17
+        this.type = this.constructor.name.toLowerCase() 
18
 
18
 
19
         /**  Fields */
19
         /**  Fields */
20
         this.email = email // ! required
20
         this.email = email // ! required

+ 1
- 1
frontend/src/entities/survey/index.js Wyświetl plik

1
 export * from './survey'
1
 export * from './survey'
2
-export * from './survey.schema'
2
+export * from './survey.schema'

+ 33
- 0
frontend/src/entities/survey/survey.js Wyświetl plik

1
+/** @module survey/survey */
2
+import { _baseRecord } from '..'
3
+import { surveySchema } from './survey.schema'
4
+
5
+class Survey extends _baseRecord {
6
+    constructor(questionArray) {
7
+        super()
8
+
9
+        this.type = this.constructor.name.toLowerCase()
10
+
11
+        /**  Fields */
12
+        this.steps = questionArray // ! required
13
+
14
+        return this
15
+    }
16
+
17
+    isValid() {
18
+        const validate = surveySchema.validate(this)
19
+
20
+        /**
21
+         * Log out some useful error messages
22
+         */
23
+        if (validate.error) {
24
+            console.error(`error: ${validate.error} - ${this.type} validation`)
25
+        }
26
+
27
+        /** validate(this) always returns something so force it to a bool */
28
+        return !validate.error ? true : false
29
+    }
30
+
31
+}
32
+
33
+export { Survey }

+ 13
- 9
frontend/src/entities/survey/survey.schema.js Wyświetl plik

1
-/** @module entities/surveySchema */
2
 import Joi from 'joi'
1
 import Joi from 'joi'
3
 import { allModules } from '..'
2
 import { allModules } from '..'
4
 
3
 
17
         lastUpdatedAt: Joi.string(),
16
         lastUpdatedAt: Joi.string(),
18
         type: Joi.string(),
17
         type: Joi.string(),
19
 
18
 
20
-        /** our fields */
21
-        email: Joi.string()
22
-            .email({
23
-                minDomainSegments: 2,
24
-                tlds: { allow: ['com', 'net'] },
25
-            })
26
-            .required(),
19
+        /** Survey fields */
20
+        steps: Joi.array().items(
21
+            Joi.array().items(
22
+                Joi.object({
23
+                    id: Joi.number(),
24
+                    type: Joi.string(),
25
+                    question: Joi.string(),
26
+                    // TODO: specify responses to be array or null later
27
+                    responses: Joi.any(),
28
+                })
29
+            )
30
+        ).required(),
27
     }),
31
     }),
28
     /** fields required before saving */
32
     /** fields required before saving */
29
-    required: ['email'],
33
+    required: ['steps'],
30
     validate(instance) {
34
     validate(instance) {
31
         return this.properties.validate(instance)
35
         return this.properties.validate(instance)
32
     },
36
     },

+ 6
- 0
frontend/src/router/index.js Wyświetl plik

5
 import Chats from '../views/Chats.vue'
5
 import Chats from '../views/Chats.vue'
6
 import Login from '../views/Login.vue'
6
 import Login from '../views/Login.vue'
7
 import Register from '../views/Register.vue'
7
 import Register from '../views/Register.vue'
8
+import Survey from '../views/Survey.vue'
8
 
9
 
9
 const routes = [
10
 const routes = [
10
     {
11
     {
37
         component: Login,
38
         component: Login,
38
         name: `login`,
39
         name: `login`,
39
     },
40
     },
41
+    {
42
+        path: `/survey`,
43
+        component: Survey,
44
+        name: `survey`,
45
+    },
40
     {
46
     {
41
         path: `/register`,
47
         path: `/register`,
42
         component: Register,
48
         component: Register,

+ 1
- 0
frontend/src/services/index.js Wyświetl plik

1
 export * from './profile.service'
1
 export * from './profile.service'
2
 export * from './grouping.service'
2
 export * from './grouping.service'
3
+export * from './survey.service'

+ 51
- 0
frontend/src/services/survey.service.js Wyświetl plik

1
+import { db } from '../utils/db'
2
+import { Survey } from '../entities/survey'
3
+
4
+/**
5
+ * Get Survey for first time profile creation from the database and
6
+ * create a class from the data and
7
+ * validate the incoming against the schema
8
+ * @param {number} profileId
9
+ * @returns {array} instantiated Profile objects (see: /entites/profile)
10
+ */
11
+const fetchSurveyByProfileId = profileId => {
12
+    // const surveyForProfileId = await db.get(`/user/${profileId}/profiles`)
13
+    const myquestions = [
14
+        [
15
+            {
16
+                id: 1,
17
+                type: 'input-string',
18
+                question: 'whats your favorite color',
19
+                responses: null,
20
+            },
21
+        ],
22
+        [
23
+            {
24
+                id: 2,
25
+                type: 'tag-cloud',
26
+                question: 'whats your favorite number',
27
+                responses: ['1', '2', '3'],
28
+            },
29
+        ],
30
+        [
31
+            {
32
+                id: 3,
33
+                type: 'checklist',
34
+                question: 'what is your current status',
35
+                responses: ['employed', 'unemployed'],
36
+            },
37
+        ],
38
+        [
39
+            {
40
+                id: 4,
41
+                type: 'slider',
42
+                question: 'whats your favorite number',
43
+                responses: ['1', '2', '3'],
44
+            },
45
+        ],
46
+    ]
47
+    const mysurvey = new Survey(myquestions)
48
+    return mysurvey
49
+}
50
+
51
+export { fetchSurveyByProfileId }

+ 58
- 0
frontend/src/views/Survey.vue Wyświetl plik

1
+<template lang="pug">
2
+sidebar
3
+main.f-col.start.w-full
4
+    article.match
5
+        h1 Survey Page
6
+        siimeform(:form="validSurvey.steps")
7
+    mainNav
8
+</template>
9
+
10
+<script>
11
+import siimeform from '../components/form.vue'
12
+import sidebar from '../components/Sidebar.vue'
13
+import mainNav from '../components/MainNav.vue'
14
+import { fetchSurveyByProfileId } from '../services'
15
+
16
+export default {
17
+    components: { siimeform, sidebar, mainNav },
18
+    computed: { 
19
+        validSurvey: () => fetchSurveyByProfileId(),
20
+    },
21
+}
22
+</script>
23
+
24
+<style lang="postcss">
25
+h1
26
+    color: white
27
+
28
+main
29
+    padding: 5vh
30
+    display: flex
31
+
32
+article
33
+    height: 100%
34
+    width: 100%
35
+    flex-direction: column
36
+
37
+.form
38
+    border: 1px solid #fff
39
+    width: 100%
40
+    header
41
+        color: #ccc
42
+        font-style: italic
43
+    > *
44
+        padding: 1vh
45
+    ul
46
+        display: flex
47
+        color: blue
48
+        width: 100%
49
+        li
50
+            flex-direction: column
51
+            border: 0px solid yellow
52
+            width: 100%
53
+            label
54
+                margin-right: 1vh
55
+            > *
56
+                text-transform: capitalize
57
+                padding: 1vh
58
+</style>

+ 16
- 7
frontend/src/views/home.vue Wyświetl plik

1
 <template lang="pug">
1
 <template lang="pug">
2
-article#home
3
-    h1(v-if="user") {{ user.user_name }}
4
-    profile-card-list(:uid='mypid' :profiles='swipables')
5
-    
6
-
2
+sidebar
3
+main.f-col.start.w-full
4
+    article#home
5
+        h1(v-if="user") {{ user.user_name }}
6
+        profile-card-list(:uid='mypid' :profiles='swipables')
7
+    main-nav
7
 </template>
8
 </template>
8
 
9
 
9
 <script>
10
 <script>
11
+import sidebar from '../components/Sidebar.vue'
12
+import mainNav from '../components/MainNav.vue'
10
 import profileCardList from '../components/ProfileCardList.vue'
13
 import profileCardList from '../components/ProfileCardList.vue'
11
 import batch20 from '../../../backend/db/generated/_batch_20.js'
14
 import batch20 from '../../../backend/db/generated/_batch_20.js'
12
 
15
 
13
 export default {
16
 export default {
14
     name: 'HomeView',
17
     name: 'HomeView',
15
-    components: { profileCardList },
18
+    components: { profileCardList, sidebar, mainNav },
16
     data: () => ({
19
     data: () => ({
17
         swipables: [   
20
         swipables: [   
18
             // { 
21
             // { 
75
 </script>
78
 </script>
76
 
79
 
77
 <style lang="postcss">
80
 <style lang="postcss">
78
-#home
81
+main
82
+    position: relative
83
+    height: 100%
84
+    > article
85
+        height: 100%
86
+        width: 100%
87
+        flex-direction: column
79
 </style>
88
 </style>

Ładowanie…
Anuluj
Zapisz