Phyks (Lucas Verney) 3 years ago
parent
commit
b94c6bfdf0

+ 1
- 1
app/components/dashboardRSVPRow.vue View File

@@ -2,7 +2,7 @@
2 2
     tr
3 3
         td
4 4
             color-span(v-bind:color="eventTypes[RSVPItem.eventTypeHash].color")
5
-            span {{ RSVPItem.startTime }} - {{ RSVPItem.endTime }}
5
+            span {{ RSVPItem.startTime.format() }} - {{ RSVPItem.endTime.format() }}
6 6
         td
7 7
             template(v-for="(member, index) in RSVPItem.members")
8 8
                 template(v-if="index > 0")

+ 4
- 2
app/components/publicDayPicker.vue View File

@@ -6,8 +6,10 @@
6 6
                 router-link(v-bind:to="{ name: 'publicSlotSelectionView', params: { hash: hash, day: day } }")
7 7
                     | {{ day }}
8 8
 
9
-        p
10
-            em Times are in {{ timezone }} timezone.
9
+        p.
10
+            Times are in
11
+            #[em {{ timezone }}]
12
+            timezone.
11 13
 </template>
12 14
 
13 15
 <style lang="stylus" scoped>

+ 4
- 2
app/components/publicSlotPicker.vue View File

@@ -6,8 +6,10 @@
6 6
                  router-link(v-bind:to="{ name: 'publicContactInfosView', params: { hash: hash, day: day, timeBegin: slot.timeBegin, timeEnd: slot.timeEnd } }")
7 7
                     | {{ slot.timeBegin }} - {{ slot.timeEnd }}
8 8
 
9
-        p
10
-            em Times are in {{ timezone }} timezone.
9
+        p.
10
+            Times are in
11
+            #[em {{ timezone }}]
12
+            timezone.
11 13
 </template>
12 14
 
13 15
 <style lang="stylus" scoped>

+ 38
- 1
app/models/RSVP.js View File

@@ -1,4 +1,8 @@
1
-const RSVP = {
1
+import cozySDK from 'cozysdk-client'
2
+import moment from 'moment-timezone'
3
+
4
+// Define model fields
5
+const RSVPDefaultFields = {
2 6
   startTime: null,
3 7
   endTime: null,
4 8
   members: [],
@@ -6,4 +10,37 @@ const RSVP = {
6 10
   status: null
7 11
 }
8 12
 
13
+// Define view
14
+cozySDK.defineView(
15
+  'rsvp',
16
+  'all',
17
+  doc => emit(doc._id, doc),
18
+  error => error && console.error(error)
19
+)
20
+
21
+cozySDK.defineView(
22
+  'rsvp',
23
+  'by_day',
24
+  (doc) => {
25
+    // TODO
26
+    const day = 'TODO'
27
+    emit(day, doc)
28
+  },
29
+  error => error && console.error(error)
30
+)
31
+
32
+// Constructor
33
+class RSVP {
34
+  constructor (fields={}) {
35
+    Object.assign(this, RSVPDefaultFields, fields)
36
+
37
+    this.startTime = moment.unix(this.startTime)
38
+    this.endTime = moment.unix(this.endTime)
39
+  }
40
+
41
+  static getFromView(view='all') {
42
+    return cozySDK.queryView('rsvp', view, {});
43
+  }
44
+}
45
+
9 46
 export default RSVP

+ 65
- 62
app/views/dashboardView.vue View File

@@ -4,11 +4,15 @@
4 4
 
5 5
     event-types-nav(v-bind:eventTypes="eventTypes")
6 6
 
7
-    ul
7
+    p(v-if="loading") Loading...
8
+
9
+    ul(v-if="RSVPItems")
8 10
         li(v-for="(RSVPItemsForDay, day) in RSVPItems")
9 11
             dashboard-day(v-bind:day="day", v-bind:RSVPItemsForDay="RSVPItemsForDay", v-bind:eventTypes="eventTypes")
10
-    p
11
-        em Times are in {{ timezone }} timezone.
12
+    p.
13
+        Times are in
14
+        #[em {{ timezone }}]
15
+        timezone.
12 16
 </template>
13 17
 
14 18
 <style lang="stylus" scoped>
@@ -27,72 +31,71 @@
27 31
 import cozySDK from 'cozysdk-client'
28 32
 import moment from 'moment-timezone'
29 33
 
34
+// Models import
35
+import RSVP from '../models/RSVP'
36
+
30 37
 // Components imports
31 38
 import eventTypesNav from '../components/eventTypesNav.vue'
32 39
 import dashboardDay from '../components/dashboardDay.vue'
33 40
 
34
-cozySDK.defineView('rsvp', 'test', function complexMap(doc) {
35
-		emit(doc.docType, doc);
36
-}, err => err && console.log(err));
37
-let promise = cozySDK.queryView('rsvp', 'test', {})
38
-promise.then((res) => {
39
-	console.log(res)
40
-})
41
-
42 41
 export default {
43 42
     data () {
44
-        return {
45
-            RSVPItems: {
46
-                "Tuesday, November 8, 2016": [
47
-                    {
48
-                        startTime: "09:30am",
49
-                        endTime: "9:45am",
50
-                        members: [
51
-                            {
52
-                                name: "Phyks",
53
-                                email: "phyks@example.com"
54
-                            }
55
-                        ],
56
-                        eventTypeHash: "15toto",
57
-                        status: null
58
-                    }
59
-                ],
60
-                "Wednesday, November 9, 2016": [
61
-                    {
62
-                        startTime: "09:45am",
63
-                        endTime: "10:15am",
64
-                        members: [
65
-                            {
66
-                                name: "Toto",
67
-                                email: "toto@example.com"
68
-                            },
69
-                            {
70
-                                name: "Toto mother",
71
-                                email: "lameredetoto@example.com"
72
-                            }
73
-                        ],
74
-                        eventTypeHash: "30toto",
75
-                        status: "discarded"
76
-                    }
77
-                ]
78
-            },
79
-            eventTypes: {
80
-                "15toto": {
81
-                    length: 15,
82
-                    color: "yellow"
83
-                },
84
-                "30toto": {
85
-                    length: 30,
86
-                    color: "orange"
87
-                },
88
-                "60toto": {
89
-                    length: 60,
90
-                    color: "red"
91
-                }
92
-            },
93
-            timezone: moment.tz.guess()
94
-        }
43
+			// Default data
44
+			return {
45
+					eventTypes: {
46
+							"15toto": {
47
+									length: 15,
48
+									color: "yellow"
49
+							},
50
+							"30toto": {
51
+									length: 30,
52
+									color: "orange"
53
+							},
54
+							"60toto": {
55
+									length: 60,
56
+									color: "red"
57
+							}
58
+					},
59
+					// Current user timezone
60
+					timezone: moment.tz.guess(),
61
+					// RSVP items
62
+					RSVPItems: null,
63
+					// An error message
64
+					error: null,
65
+					// Loading boolean
66
+   				loading: false
67
+			}
95 68
     },
69
+		created() {
70
+			// Fetch data on component creation
71
+			this.fetchData()
72
+		},
73
+		watch: {
74
+			// Fetch data if the route changes
75
+			'$route': 'fetchData'
76
+		},
77
+		methods: {
78
+			fetchData () {
79
+						this.error = null
80
+						this.RSVPItems = null
81
+						this.loading = true
82
+
83
+						return RSVP.getFromView('by_day').then((data) => {
84
+              this.RSVPItems = {}
85
+							data.forEach((RSVPItem) => {
86
+                  if (!this.RSVPItems[RSVPItem.key]) {
87
+                    this.RSVPItems[RSVPItem.key] = []
88
+                  }
89
+									this.RSVPItems[RSVPItem.key].push(new RSVP(RSVPItem.value))
90
+							})
91
+              this.loading = false
92
+						}).catch((error) => {
93
+              this.RSVPItems = null
94
+              this.loading = false
95
+              this.error = error
96
+            })
97
+			}
98
+		},
96 99
     components: {
97 100
         dashboardDay,
98 101
         eventTypesNav

+ 5
- 5
app/views/publicView.vue View File

@@ -1,10 +1,10 @@
1 1
 <template lang="pug">
2 2
   div
3
-    h1
4
-        color-span(v-bind:color="eventType.color")
5
-        | {{ eventType.length }} minutes meeting
6
-        | with&#32;
7
-        a(v-bind:href="'mailto:' + owner.email") {{ owner.name }}
3
+    h1.
4
+        #[color-span(v-bind:color="eventType.color")]
5
+        {{ eventType.length }} minutes meeting
6
+        with
7
+        #[a(v-bind:href="'mailto:' + owner.email") {{ owner.name }}]
8 8
 
9 9
     router-view
10 10