This commit is contained in:
Lucas Verney 2016-11-09 17:12:42 -05:00
parent 7abed1dbaa
commit b94c6bfdf0
6 changed files with 117 additions and 73 deletions

View File

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

View File

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

View File

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

View File

@ -1,4 +1,8 @@
const RSVP = { import cozySDK from 'cozysdk-client'
import moment from 'moment-timezone'
// Define model fields
const RSVPDefaultFields = {
startTime: null, startTime: null,
endTime: null, endTime: null,
members: [], members: [],
@ -6,4 +10,37 @@ const RSVP = {
status: null status: null
} }
// Define view
cozySDK.defineView(
'rsvp',
'all',
doc => emit(doc._id, doc),
error => error && console.error(error)
)
cozySDK.defineView(
'rsvp',
'by_day',
(doc) => {
// TODO
const day = 'TODO'
emit(day, doc)
},
error => error && console.error(error)
)
// Constructor
class RSVP {
constructor (fields={}) {
Object.assign(this, RSVPDefaultFields, fields)
this.startTime = moment.unix(this.startTime)
this.endTime = moment.unix(this.endTime)
}
static getFromView(view='all') {
return cozySDK.queryView('rsvp', view, {});
}
}
export default RSVP export default RSVP

View File

@ -4,11 +4,15 @@
event-types-nav(v-bind:eventTypes="eventTypes") event-types-nav(v-bind:eventTypes="eventTypes")
ul p(v-if="loading") Loading...
ul(v-if="RSVPItems")
li(v-for="(RSVPItemsForDay, day) in RSVPItems") li(v-for="(RSVPItemsForDay, day) in RSVPItems")
dashboard-day(v-bind:day="day", v-bind:RSVPItemsForDay="RSVPItemsForDay", v-bind:eventTypes="eventTypes") dashboard-day(v-bind:day="day", v-bind:RSVPItemsForDay="RSVPItemsForDay", v-bind:eventTypes="eventTypes")
p p.
em Times are in {{ timezone }} timezone. Times are in
#[em {{ timezone }}]
timezone.
</template> </template>
<style lang="stylus" scoped> <style lang="stylus" scoped>
@ -27,72 +31,71 @@
import cozySDK from 'cozysdk-client' import cozySDK from 'cozysdk-client'
import moment from 'moment-timezone' import moment from 'moment-timezone'
// Models import
import RSVP from '../models/RSVP'
// Components imports // Components imports
import eventTypesNav from '../components/eventTypesNav.vue' import eventTypesNav from '../components/eventTypesNav.vue'
import dashboardDay from '../components/dashboardDay.vue' import dashboardDay from '../components/dashboardDay.vue'
cozySDK.defineView('rsvp', 'test', function complexMap(doc) {
emit(doc.docType, doc);
}, err => err && console.log(err));
let promise = cozySDK.queryView('rsvp', 'test', {})
promise.then((res) => {
console.log(res)
})
export default { export default {
data () { data () {
return { // Default data
RSVPItems: { return {
"Tuesday, November 8, 2016": [ eventTypes: {
{ "15toto": {
startTime: "09:30am", length: 15,
endTime: "9:45am", color: "yellow"
members: [ },
{ "30toto": {
name: "Phyks", length: 30,
email: "phyks@example.com" color: "orange"
} },
], "60toto": {
eventTypeHash: "15toto", length: 60,
status: null color: "red"
} }
], },
"Wednesday, November 9, 2016": [ // Current user timezone
{ timezone: moment.tz.guess(),
startTime: "09:45am", // RSVP items
endTime: "10:15am", RSVPItems: null,
members: [ // An error message
{ error: null,
name: "Toto", // Loading boolean
email: "toto@example.com" loading: false
}, }
{
name: "Toto mother",
email: "lameredetoto@example.com"
}
],
eventTypeHash: "30toto",
status: "discarded"
}
]
},
eventTypes: {
"15toto": {
length: 15,
color: "yellow"
},
"30toto": {
length: 30,
color: "orange"
},
"60toto": {
length: 60,
color: "red"
}
},
timezone: moment.tz.guess()
}
}, },
created() {
// Fetch data on component creation
this.fetchData()
},
watch: {
// Fetch data if the route changes
'$route': 'fetchData'
},
methods: {
fetchData () {
this.error = null
this.RSVPItems = null
this.loading = true
return RSVP.getFromView('by_day').then((data) => {
this.RSVPItems = {}
data.forEach((RSVPItem) => {
if (!this.RSVPItems[RSVPItem.key]) {
this.RSVPItems[RSVPItem.key] = []
}
this.RSVPItems[RSVPItem.key].push(new RSVP(RSVPItem.value))
})
this.loading = false
}).catch((error) => {
this.RSVPItems = null
this.loading = false
this.error = error
})
}
},
components: { components: {
dashboardDay, dashboardDay,
eventTypesNav eventTypesNav

View File

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