Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from BenShelton/develop
Browse files Browse the repository at this point in the history
CO Updates
  • Loading branch information
BenShelton authored Feb 2, 2019
2 parents 0cb0e87 + 3c0e79a commit 0672c13
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 48 deletions.
35 changes: 35 additions & 0 deletions database/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ export const updateWeekType = async ({ weekID, type }) => {
}
}
}
break

case WEEK_TYPES.coVisit.value:
for (const assignmentName of ['congregationBibleStudy', 'reader']) {
const assignment = week.assignments[assignmentName]
if (assignment) {
for (const field of ASSIGNEE_FIELDS) {
const memberID = assignment[field]
if (memberID) {
const member = await removeAssignment({ memberID, assignment: { type: assignment.type, date: week.date } })
updatedMembers.push(member)
const assignmentPath = `assignments.${assignmentName}.${field}`
update.$set[assignmentPath] = null
}
}
}
}
}

// Update Type
Expand All @@ -133,3 +150,21 @@ export const updateWeekType = async ({ weekID, type }) => {
// Return week and any removed assigned members
return { week: value, members: updatedMembers }
}

export const updateCOName = async ({ weekID, name }) => {
const coll = await getCollection
const query = { _id: ObjectID(weekID) }
const update = { $set: { coName: name } }
const { value } = await coll.findOneAndUpdate(query, update, { returnOriginal: false })
assert.notStrictEqual(null, value, 404)
return value
}

export const updateCOTitle = async ({ weekID, title }) => {
const coll = await getCollection
const query = { _id: ObjectID(weekID) }
const update = { $set: { coTitle: title } }
const { value } = await coll.findOneAndUpdate(query, update, { returnOriginal: false })
assert.notStrictEqual(null, value, 404)
return value
}
16 changes: 16 additions & 0 deletions lambda/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ router.put('/schedule/updateWeekType', (req, res) => {
.catch(handleErrors(res))
})

router.put('/schedule/updateCOName', (req, res) => {
const { weekID, name } = req.body
if (!weekID || name === undefined) return res.status(400).json({ message: 'Required Fields are: weekID, name' })
schedule.updateCOName({ weekID, name })
.then(returnResult(res))
.catch(handleErrors(res))
})

router.put('/schedule/updateCOTitle', (req, res) => {
const { weekID, title } = req.body
if (!weekID || title === undefined) return res.status(400).json({ message: 'Required Fields are: weekID, title' })
schedule.updateCOTitle({ weekID, title })
.then(returnResult(res))
.catch(handleErrors(res))
})

// The lambda function route must match the netlify path
app.use('/.netlify/functions/api', router)
app.use((req, res) => {
Expand Down
4 changes: 3 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default {
month: ({ month }) => api.get(`/schedule/month/${month}`),
scrape: ({ weekID }) => api.put(`/schedule/scrape/`, { weekID }),
updateAssignment: ({ weekID, name, assignment }) => api.put(`/schedule/updateAssignment`, { weekID, name, assignment }),
updateWeekType: ({ weekID, type }) => api.put(`/schedule/updateWeekType`, { weekID, type })
updateWeekType: ({ weekID, type }) => api.put(`/schedule/updateWeekType`, { weekID, type }),
updateCOName: ({ weekID, name }) => api.put(`/schedule/updateCOName`, { weekID, name }),
updateCOTitle: ({ weekID, title }) => api.put(`/schedule/updateCOTitle`, { weekID, title })
}
}
117 changes: 78 additions & 39 deletions src/components/Schedule/ScheduleWeek.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
<VIcon>settings</VIcon>
</VBtn>
<VCard class="pa-3">
<VBtn
color="primary"
:loading="scrapeLoading"
:disabled="scrapeLoading"
@click="onScrape"
>
Redownload
<VIcon right>
cloud_download
</VIcon>
</VBtn>
<VLayout justify-center>
<VBtn
color="primary"
:loading="scrapeLoading"
:disabled="scrapeLoading"
@click="onScrape"
>
Redownload
<VIcon right>
cloud_download
</VIcon>
</VBtn>
</VLayout>
<VDivider class="mt-3" />
<VRadioGroup
v-model="weekType"
Expand All @@ -42,6 +44,20 @@
:value="type.value"
/>
</VRadioGroup>
<template v-if="week.type === WEEK_TYPES.coVisit.value">
<VDivider class="my-3" />
<label class="v-label theme--light py-2">
Circuit Overseer Details
</label>
<VTextField :value="week.coName" label="Name" @change="onUpdateCOName" />
<VTextarea
label="Talk Title"
:value="week.coTitle"
:rows="1"
:auto-grow="true"
@change="onUpdateCOTitle"
/>
</template>
</VCard>
</Vmenu>
</VToolbar>
Expand Down Expand Up @@ -106,36 +122,40 @@
</VLayout>

<!-- Assignment Display -->
<VList
v-else
two-line
subheader
class="pa-0"
>
<ScheduleAssignment :assignment="assignments.chairman" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.openingPrayer" @edit="onEdit" />
<template v-else>
<div v-if="coVisit" class="pa-0">
<p class="headline text-xs-center primary--text py-2 ma-0">
Circuit Overseer Visit
</p>
<VDivider />
</div>

<ScheduleSection title="TREASURES FROM GOD'S WORD" color="TREASURES">
<ScheduleAssignment :assignment="assignments.highlights" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.gems" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.bibleReading" @edit="onEdit" />
</ScheduleSection>
<VList two-line subheader class="pa-0">
<ScheduleAssignment :assignment="assignments.chairman" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.openingPrayer" @edit="onEdit" />

<ScheduleSection title="APPLY YOURSELF TO THE FIELD MINISTRY" color="MINISTRY">
<ScheduleAssignment :assignment="assignments.studentTalk1" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.studentTalk2" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.studentTalk3" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.studentTalk4" @edit="onEdit" />
</ScheduleSection>
<ScheduleSection title="TREASURES FROM GOD'S WORD" color="TREASURES">
<ScheduleAssignment :assignment="assignments.highlights" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.gems" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.bibleReading" @edit="onEdit" />
</ScheduleSection>

<ScheduleSection title="LIVING AS CHRISTIANS" color="LIVING">
<ScheduleAssignment :assignment="assignments.serviceTalk1" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.serviceTalk2" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.congregationBibleStudy" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.reader" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.closingPrayer" @edit="onEdit" />
</ScheduleSection>
</VList>
<ScheduleSection title="APPLY YOURSELF TO THE FIELD MINISTRY" color="MINISTRY">
<ScheduleAssignment :assignment="assignments.studentTalk1" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.studentTalk2" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.studentTalk3" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.studentTalk4" @edit="onEdit" />
</ScheduleSection>

<ScheduleSection title="LIVING AS CHRISTIANS" color="LIVING">
<ScheduleAssignment :assignment="assignments.serviceTalk1" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.serviceTalk2" @edit="onEdit" />
<ScheduleAssignment v-if="!coVisit" :assignment="assignments.congregationBibleStudy" @edit="onEdit" />
<ScheduleAssignment v-if="!coVisit" :assignment="assignments.reader" @edit="onEdit" />
<ScheduleAssignment :assignment="assignments.closingPrayer" @edit="onEdit" />
</ScheduleSection>
</VList>
</template>

<!-- Edit Assignment Dialog -->
<VDialog
Expand Down Expand Up @@ -368,6 +388,9 @@ export default {
}
})
}, {})
},
coVisit () {
return this.weekType === WEEK_TYPES.coVisit.value
}
},
Expand All @@ -376,14 +399,30 @@ export default {
loadWeek: 'schedule/loadWeek',
scrapeWeek: 'schedule/scrapeWeek',
updateAssignment: 'schedule/updateAssignment',
updateWeekType: 'schedule/updateWeekType'
updateWeekType: 'schedule/updateWeekType',
updateCOName: 'schedule/updateCOName',
updateCOTitle: 'schedule/updateCOTitle'
}),
...mapMutations({
alert: 'alert/UPDATE_ALERT'
}),
loadLocalWeek (week) {
this.week = Object.assign({}, { loaded: true }, week)
},
onUpdateCOName (name) {
this.updateCOName({ weekID: this.week._id, name })
.then(this.loadLocalWeek)
.catch(() => {
this.alert({ text: 'Circuit Overseer Name could not be updated.', color: 'error' })
})
},
onUpdateCOTitle (title) {
this.updateCOTitle({ weekID: this.week._id, title })
.then(this.loadLocalWeek)
.catch(() => {
this.alert({ text: 'Circuit Overseer Talk Title could not be updated.', color: 'error' })
})
},
onScrape () {
this.scrapeLoading = true
this.scrapeWeek({ weekID: this.week._id })
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ export const LANGUAGE_GROUPS = ['English', 'Portuguese']
export const WEEK_TYPES = {
normal: { label: 'Normal', value: 0 },
assembly: { label: 'Assembly', value: 1 },
coVisit: { label: 'CO Visit', value: 2 },
coVisit: { label: 'Circuit Overseer Visit', value: 2 },
memorial: { label: 'Memorial', value: 3 }
}
22 changes: 15 additions & 7 deletions src/plugins/pdfMake.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,22 @@ export function generateSchedule (weeks, month) {
null
]
if (serviceTalk2) livingTableRows[2] = [timer, getAssignmentTitle(serviceTalk2), null, getScheduleAssignees(serviceTalk2), addTime(serviceTalk2.time)]
livingTableRows.push(
[timer, 'Congregation Bible Study (30 min.)', 'Conductor:', getScheduleAssignees(congregationBibleStudy), addTime(30)],
[null, congregationBibleStudy.title, 'Reader:', getScheduleAssignees(reader), null],
[timer, 'Review/Preview/Announcements (3 min.)', 'Chairman:', getScheduleAssignees(chairman), addTime(3)],
[timer, songs[2], 'Prayer:', getScheduleAssignees(closingPrayer), addTime(5)]
)
if (type === WEEK_TYPES.coVisit.value) {
livingTableRows.push(
[timer, 'Review/Preview/Announcements (3 min.)', 'Chairman:', getScheduleAssignees(chairman), addTime(3)],
[timer, week.coTitle + ' (30 min.)', 'Circuit Overseer:', week.coName, addTime(30)],
[timer, songs[2], 'Prayer:', getScheduleAssignees(closingPrayer), addTime(5)]
)
} else {
livingTableRows.push(
[timer, 'Congregation Bible Study (30 min.)', 'Conductor:', getScheduleAssignees(congregationBibleStudy), addTime(30)],
[null, congregationBibleStudy.title, 'Reader:', getScheduleAssignees(reader), null],
[timer, 'Review/Preview/Announcements (3 min.)', 'Chairman:', getScheduleAssignees(chairman), addTime(3)],
[timer, songs[2], 'Prayer:', getScheduleAssignees(closingPrayer), addTime(5)]
)
}
const livingTable = createScheduleTable(COLORS.LIVING, livingTableRows)
Object.assign(livingTable.table.body[3][1], { rowSpan: 2 })
if (type !== WEEK_TYPES.coVisit.value) Object.assign(livingTable.table.body[3][1], { rowSpan: 2 })
stack.push(livingTable)
stack.push(createScheduleSeparator())
})
Expand Down
16 changes: 16 additions & 0 deletions src/store/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ const actions = {
}
return week
})
},
updateCOName ({ commit }, { weekID, name }) {
return api.schedule.updateCOName({ weekID, name })
.then(res => {
const week = res.data.result
commit('UPDATE_WEEK', week)
return week
})
},
updateCOTitle ({ commit }, { weekID, title }) {
return api.schedule.updateCOTitle({ weekID, title })
.then(res => {
const week = res.data.result
commit('UPDATE_WEEK', week)
return week
})
}
}

Expand Down

0 comments on commit 0672c13

Please sign in to comment.