Parcourir la source

survey setup, bring in sidebar and start adding css

tags/0.0.1
diaseu il y a 4 ans
Parent
révision
11e92e402f

+ 6
- 7
frontend/src/App.vue Voir le fichier

@@ -1,18 +1,17 @@
1 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 6
 </template>
7 7
 
8 8
 <script>
9 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 13
 export default {
14 14
     name: 'app',
15
-    components: { sidebar, mainNav },
16 15
 }
17 16
 </script>
18 17
 

frontend/src/components/Archive/form.vue → frontend/src/components/form.vue Voir le fichier

@@ -21,6 +21,23 @@
21 21
                     @click='respondFromTag'
22 22
                     v-for='response in prompt.responses'
23 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 42
     footer.f-row.w-full
26 43
         button.p-1(:disabled='state.step == 1' @click='back') back

+ 1
- 1
frontend/src/entities/profile/profile.js Voir le fichier

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

+ 1
- 1
frontend/src/entities/survey/index.js Voir le fichier

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

+ 33
- 0
frontend/src/entities/survey/survey.js Voir le fichier

@@ -0,0 +1,33 @@
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 Voir le fichier

@@ -1,4 +1,3 @@
1
-/** @module entities/surveySchema */
2 1
 import Joi from 'joi'
3 2
 import { allModules } from '..'
4 3
 
@@ -17,16 +16,21 @@ const surveySchema = {
17 16
         lastUpdatedAt: Joi.string(),
18 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 32
     /** fields required before saving */
29
-    required: ['email'],
33
+    required: ['steps'],
30 34
     validate(instance) {
31 35
         return this.properties.validate(instance)
32 36
     },

+ 6
- 0
frontend/src/router/index.js Voir le fichier

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

+ 1
- 0
frontend/src/services/index.js Voir le fichier

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

+ 51
- 0
frontend/src/services/survey.service.js Voir le fichier

@@ -0,0 +1,51 @@
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 Voir le fichier

@@ -0,0 +1,58 @@
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 Voir le fichier

@@ -1,18 +1,21 @@
1 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 8
 </template>
8 9
 
9 10
 <script>
11
+import sidebar from '../components/Sidebar.vue'
12
+import mainNav from '../components/MainNav.vue'
10 13
 import profileCardList from '../components/ProfileCardList.vue'
11 14
 import batch20 from '../../../backend/db/generated/_batch_20.js'
12 15
 
13 16
 export default {
14 17
     name: 'HomeView',
15
-    components: { profileCardList },
18
+    components: { profileCardList, sidebar, mainNav },
16 19
     data: () => ({
17 20
         swipables: [   
18 21
             // { 
@@ -75,5 +78,11 @@ export default {
75 78
 </script>
76 79
 
77 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 88
 </style>

Chargement…
Annuler
Enregistrer