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 #89 from BenShelton/develop
Browse files Browse the repository at this point in the history
Fix schedule & second school display preferences
  • Loading branch information
BenShelton authored Oct 19, 2019
2 parents bf00cda + a295390 commit 47ea2e7
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 51 deletions.
8 changes: 6 additions & 2 deletions database/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'types'

const ASSIGNEE_FIELDS = ['assignee', 'assistant', 'assignee2', 'assistant2'] as const
const SECOND_SCHOOL_ASSIGNEE_FIELDS = ['assignee2', 'assistant2'] as const

type CollScheduleWeek = MongoInterface<ScheduleWeek>

Expand Down Expand Up @@ -176,10 +177,13 @@ export const updateWeekType = async (weekID: string, language: Languages, type:
break

case WEEK_TYPES.coVisit.value:
for (const assignmentName of ['congregationBibleStudy', 'reader'] as const) {
for (const assignmentName of ['congregationBibleStudy', 'reader', 'bibleReading', 'studentTalk1', 'studentTalk2', 'studentTalk3', 'studentTalk4'] as const) {
const assignment = week.assignments[assignmentName]
if (assignment) {
for (const field of ASSIGNEE_FIELDS) {
const fieldsToCheck = ['bibleReading', 'studentTalk1', 'studentTalk2', 'studentTalk3', 'studentTalk4'].includes(assignmentName)
? SECOND_SCHOOL_ASSIGNEE_FIELDS
: ASSIGNEE_FIELDS
for (const field of fieldsToCheck) {
const memberID = assignment[field]
if (memberID) {
const member = await removeAssignment(memberID, { type: assignment.type, date: baseWeek.date })
Expand Down
7 changes: 5 additions & 2 deletions database/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { MongoClient } from 'mongodb'

dotenv.config()

const { MONGODB_URI = '', MONGODB_NAME = '' } = process.env
const { MONGODB_URI = '' } = process.env
const connectionOptions = {
useNewUrlParser: true,
validateOptions: true
}

export default MongoClient.connect(MONGODB_URI, connectionOptions)
.then((client: MongoClient) => client.db(MONGODB_NAME))
.then(async (client: MongoClient) => {
const { SETTINGS } = await import('../src/constants')
return client.db(SETTINGS.db)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oclm-planner",
"version": "1.1.0",
"version": "1.1.1",
"private": true,
"scripts": {
"serve": "npm-run-all --parallel serve:**",
Expand Down
4 changes: 1 addition & 3 deletions sample.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
MONGODB_URI=CONNECTION_URI
MONGODB_NAME=OCLM
JWT_SECRET=SUPER_SECRET_PHRASE
PASSWORD=LOGIN_PASSWORD
VUE_APP_LANGUAGES=en,tpo
VUE_APP_SCHOOLS=1
VUE_APP_SLUG=SLUG
6 changes: 4 additions & 2 deletions src/components/Schedule/ScheduleAssignment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export default Vue.extend({
return ['initialCall', 'returnVisit', 'bibleStudy'].includes(details.type)
},
hasSecondSchool (): boolean {
const { details } = this.assignment
const { details, coVisit } = this.assignment
if (!details) return false
return SECOND_SCHOOL && ['initialCall', 'returnVisit', 'bibleStudy', 'studentTalk', 'bibleReading'].includes(details.type)
return SECOND_SCHOOL &&
!coVisit &&
['initialCall', 'returnVisit', 'bibleStudy', 'studentTalk', 'bibleReading'].includes(details.type)
}
},
Expand Down
21 changes: 12 additions & 9 deletions src/components/Schedule/ScheduleWeekView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export default class ScheduleWeekView extends Vue {
}
get assignments (): ScheduleWeekViewAssignmentMap {
const { coVisit } = this
const { assignments } = this.week
const assignmentRefs: { name: Assignments, displayName: string }[] = [
{ name: 'chairman', displayName: 'Chairman' },
Expand All @@ -452,14 +453,14 @@ export default class ScheduleWeekView extends Vue {
const assignment = assignments[name]
const inherit = !!(assignment && assignment.inherit)
const details = inherit ? this.localWeek.en.assignments[name] : assignment
return Object.assign(acc, {
[name]: {
name,
displayName,
inherit,
details
}
})
const value: IScheduleWeekViewAssignment = {
name,
displayName,
inherit,
coVisit,
details
}
return Object.assign(acc, { [name]: value })
}, {}) as ScheduleWeekViewAssignmentMap
}
Expand Down Expand Up @@ -491,7 +492,9 @@ export default class ScheduleWeekView extends Vue {
}
get hasSecondSchool (): boolean {
return SECOND_SCHOOL && ['initialCall', 'returnVisit', 'bibleStudy', 'studentTalk', 'bibleReading'].includes(this.editAssignment.type)
return SECOND_SCHOOL &&
!this.coVisit &&
['initialCall', 'returnVisit', 'bibleStudy', 'studentTalk', 'bibleReading'].includes(this.editAssignment.type)
}
// Methods
Expand Down
10 changes: 6 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Languages } from 'types'
import * as settings from './settings'
import { Languages, Slug } from 'types'

export const SETTINGS = settings[process.env.VUE_APP_SLUG as Slug]

// TODO: Probably just worth having one map of talks with all their information
export const ASSIGNMENT_TYPE_MAP = {
Expand Down Expand Up @@ -52,14 +55,13 @@ export const SUPPORTED_LANGUAGES = [
{ text: 'Portuguese', value: 'tpo' }
] as const

export const USED_LANGUAGES = (process.env.VUE_APP_LANGUAGES || 'en')
.split(',')
export const USED_LANGUAGES = SETTINGS.languages
.reduce((acc: { text: string, value: Languages }[], l) => {
const lang = SUPPORTED_LANGUAGES.find(s => s.value === l)
return lang ? acc.concat(lang) : acc
}, [])

export const SECOND_SCHOOL = Number(process.env.VUE_APP_SCHOOLS || 1) > 1
export const SECOND_SCHOOL = SETTINGS.schools > 1

export const WEEK_TYPES = {
normal: { label: 'Normal', value: 0 },
Expand Down
47 changes: 24 additions & 23 deletions src/plugins/pdfMake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pdfMake, { Content, CurrentNode, TDocumentDefinitions } from 'pdfmake/bui
import pdfFonts from 'pdfmake/build/vfs_fonts'

import { congregationModule, scheduleModule } from '@/store'
import { COLORS, WEEK_TYPES, SECOND_SCHOOL } from '@/constants'
import { COLORS, WEEK_TYPES, SECOND_SCHOOL, SETTINGS } from '@/constants'
import {
IScheduleTranslationMap,
IAssignmentTranslationMap,
Expand All @@ -22,7 +22,6 @@ const TPO_MONTHS = ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set
const SCHEDULE_TRANSLATIONS: { [key in Languages]: IScheduleTranslationMap } = {
en: {
startTime: '7:00',
group: 'CANTON CONGREGATION',
header: 'Our Christian Life & Ministry Schedule',
week: 'WEEK',
weeks: 'WEEKS',
Expand Down Expand Up @@ -50,7 +49,6 @@ const SCHEDULE_TRANSLATIONS: { [key in Languages]: IScheduleTranslationMap } = {
},
tpo: {
startTime: '19:00',
group: 'GROUP PORTUGUÊS',
header: 'Programação de reunião de semana',
week: 'SEMANA',
weeks: 'SEMANAS',
Expand Down Expand Up @@ -186,11 +184,11 @@ function getAssignmentTitle (assignment: IScheduleAssignment): string {
return `${title} (${time})`
}

function getScheduleAssignees (assignment?: IScheduleAssignment): string {
function getScheduleAssignees (assignment: IScheduleAssignment, coVisit: boolean): string {
if (!assignment) return ''
if (assignment.stream) return '(Video Stream)'
const { type, assignee, assistant, assignee2, assistant2 } = assignment
if (SECOND_SCHOOL && ['initialCall', 'returnVisit', 'bibleStudy', 'studentTalk', 'bibleReading'].includes(type)) {
if (SECOND_SCHOOL && !coVisit && ['initialCall', 'returnVisit', 'bibleStudy', 'studentTalk', 'bibleReading'].includes(type)) {
if (['initialCall', 'returnVisit', 'bibleStudy'].includes(type)) {
return getAssigneeName(assignee, '-', true) + ' & ' + getAssigneeName(assistant, '-', true) + ' | ' + getAssigneeName(assignee2, '-', true) + ' & ' + getAssigneeName(assistant2, '-', true)
} else {
Expand Down Expand Up @@ -300,7 +298,7 @@ export const generateSchedule: PDFGenerator = function (weeks, month) {
stack: [
{
columns: [
{ text: translation.group, width: 160, margin: [0, 8, 0, 0], bold: true },
{ text: SETTINGS.displayName.toUpperCase(), width: 160, margin: [0, 8, 0, 0], bold: true },
{ text: translation.header, alignment: 'right', fontSize: 17, bold: true }
]
}
Expand Down Expand Up @@ -344,6 +342,8 @@ export const generateSchedule: PDFGenerator = function (weeks, month) {
// If no assignments & not a special week then this isn't created
if (!assignments) throw new Error('Week not created for the selected language')

const coVisit = type === WEEK_TYPES.coVisit.value

// Extract assignments from the correct language
const baseAssignments = baseWeek.en.assignments
const assignmentMap = ((Object.entries(assignments) as unknown) as [keyof IScheduleWeekAssignments, IScheduleAssignment][])
Expand Down Expand Up @@ -380,17 +380,17 @@ export const generateSchedule: PDFGenerator = function (weeks, month) {

// Introduction Section
stack.push(createScheduleTable(COLORS.TREASURES, [
[setTime(translation.startTime), songs[0], translation.prayer + ':', getScheduleAssignees(openingPrayer), addTime(5), openingPrayer.inherit],
[timer, translation.openingComments + ' (3 min.)', translation.chairman + ':', getScheduleAssignees(chairman), addTime(3), chairman.inherit]
[setTime(translation.startTime), songs[0], translation.prayer + ':', getScheduleAssignees(openingPrayer, coVisit), addTime(5), openingPrayer.inherit],
[timer, translation.openingComments + ' (3 min.)', translation.chairman + ':', getScheduleAssignees(chairman, coVisit), addTime(3), chairman.inherit]
]))

// TREASURES Section
stack.push(createScheduleSubheader(translation.treasures, COLORS.TREASURES))
const bibleReadingTitle = `${translation.bibleReading} (${bibleReading.time}): ${bibleReading.title}`
stack.push(createScheduleTable(COLORS.TREASURES, [
[timer, getAssignmentTitle(highlights), null, getScheduleAssignees(highlights), addTime(highlights.time), highlights.inherit],
[timer, translation.gems + ' (10 min.)', null, getScheduleAssignees(gems), addTime(gems.time), gems.inherit],
[timer, bibleReadingTitle, null, getScheduleAssignees(bibleReading), addTime(bibleReading.time), bibleReading.inherit, true]
[timer, getAssignmentTitle(highlights), null, getScheduleAssignees(highlights, coVisit), addTime(highlights.time), highlights.inherit],
[timer, translation.gems + ' (10 min.)', null, getScheduleAssignees(gems, coVisit), addTime(gems.time), gems.inherit],
[timer, bibleReadingTitle, null, getScheduleAssignees(bibleReading, coVisit), addTime(bibleReading.time), bibleReading.inherit, true]
]))

// MINISTRY Section
Expand All @@ -406,7 +406,7 @@ export const generateSchedule: PDFGenerator = function (weeks, month) {
let assigneeTitle = `${translation.student}/${translation.assistant}:`
if (studentTalk.type === 'ministryVideo') assigneeTitle = ''
if (studentTalk.type === 'studentTalk') assigneeTitle = translation.student + ':'
ministryTableRows.push([timer, getAssignmentTitle(studentTalk), assigneeTitle, getScheduleAssignees(studentTalk), addTime(studentTalk.time), studentTalk.inherit, true])
ministryTableRows.push([timer, getAssignmentTitle(studentTalk), assigneeTitle, getScheduleAssignees(studentTalk, coVisit), addTime(studentTalk.time), studentTalk.inherit, true])
}
stack.push(createScheduleTable(COLORS.MINISTRY, ministryTableRows))

Expand All @@ -415,26 +415,26 @@ export const generateSchedule: PDFGenerator = function (weeks, month) {
setTime(translation.startTime)
const livingTableRows: ScheduleTableRow[] = [
[addTime(47), songs[1], null, null, addTime(5), chairman.inherit],
[timer, getAssignmentTitle(serviceTalk1), null, getScheduleAssignees(serviceTalk1), addTime(serviceTalk1.time), serviceTalk1.inherit],
[timer, getAssignmentTitle(serviceTalk1), null, getScheduleAssignees(serviceTalk1, coVisit), addTime(serviceTalk1.time), serviceTalk1.inherit],
null
]
if (serviceTalk2) livingTableRows[2] = [timer, getAssignmentTitle(serviceTalk2), null, getScheduleAssignees(serviceTalk2), addTime(serviceTalk2.time), serviceTalk2.inherit]
if (type === WEEK_TYPES.coVisit.value) {
if (serviceTalk2) livingTableRows[2] = [timer, getAssignmentTitle(serviceTalk2), null, getScheduleAssignees(serviceTalk2, coVisit), addTime(serviceTalk2.time), serviceTalk2.inherit]
if (coVisit) {
livingTableRows.push(
[timer, translation.review + ' (3 min.)', translation.chairman + ':', getScheduleAssignees(chairman), addTime(3), chairman.inherit],
[timer, translation.review + ' (3 min.)', translation.chairman + ':', getScheduleAssignees(chairman, coVisit), addTime(3), chairman.inherit],
[timer, coTitle + ' (30 min.)', translation.co + ':', coName, addTime(30), true],
[timer, songs[2], translation.prayer + ':', getScheduleAssignees(closingPrayer), addTime(5), closingPrayer.inherit]
[timer, songs[2], translation.prayer + ':', getScheduleAssignees(closingPrayer, coVisit), addTime(5), closingPrayer.inherit]
)
} else {
livingTableRows.push(
[timer, translation.cbs + ' (30 min.)', translation.conductor + ':', getScheduleAssignees(congregationBibleStudy), addTime(30), congregationBibleStudy.inherit],
[null, congregationBibleStudy.title, translation.reader + ':', getScheduleAssignees(reader), null, reader.inherit],
[timer, translation.review + ' (3 min.)', translation.chairman + ':', getScheduleAssignees(chairman), addTime(3), chairman.inherit],
[timer, songs[2], translation.prayer + ':', getScheduleAssignees(closingPrayer), addTime(5), closingPrayer.inherit]
[timer, translation.cbs + ' (30 min.)', translation.conductor + ':', getScheduleAssignees(congregationBibleStudy, coVisit), addTime(30), congregationBibleStudy.inherit],
[null, congregationBibleStudy.title, translation.reader + ':', getScheduleAssignees(reader, coVisit), null, reader.inherit],
[timer, translation.review + ' (3 min.)', translation.chairman + ':', getScheduleAssignees(chairman, coVisit), addTime(3), chairman.inherit],
[timer, songs[2], translation.prayer + ':', getScheduleAssignees(closingPrayer, coVisit), addTime(5), closingPrayer.inherit]
)
}
const livingTable = createScheduleTable(COLORS.LIVING, livingTableRows)
if (type !== WEEK_TYPES.coVisit.value) {
if (!coVisit) {
const coTalk = livingTable.table && livingTable.table.body && livingTable.table.body[3] && livingTable.table.body[3][1]
if (!coTalk) throw new Error('Could not reformat according to CO week')
Object.assign(coTalk, { rowSpan: 2 })
Expand Down Expand Up @@ -612,13 +612,14 @@ export const generateAssignmentSlips: PDFGenerator = function (weeks, month) {
if (!week) throw new Error('Week not created for the selected language')
const { type, assignments } = week
if (type === WEEK_TYPES.assembly.value || type === WEEK_TYPES.memorial.value) continue
const coVisit = type === WEEK_TYPES.coVisit.value
for (let i = 0; i <= 4; i++) {
// treat index 0 as the bibleReading, else extract a student talk
const index = i === 0 ? 'bibleReading' : 'studentTalk' + i as 'bibleReading' | 'studentTalk1' | 'studentTalk2' | 'studentTalk3' | 'studentTalk4'
const talk: IScheduleAssignment | undefined = assignments[index]
if (!talk || talk.inherit || !(VALID_TYPES.includes(talk.type))) continue
slips.push(createSlip(translation, talk, false, date))
if (SECOND_SCHOOL) slips.push(createSlip(translation, talk, true, date))
if (SECOND_SCHOOL && !coVisit) slips.push(createSlip(translation, talk, true, date))
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ISettings } from 'types'

export const test: ISettings = {
slug: 'test',
db: 'test',
displayName: 'Test Congregatiom',
languages: ['en'],
schools: 2
}

export const canton: ISettings = {
slug: 'canton',
db: 'oclm',
displayName: 'Canton Congregation',
languages: ['en', 'tpo'],
schools: 1
}

export const barry: ISettings = {
slug: 'barry',
db: 'barry',
displayName: 'Barry Congregation',
languages: ['en'],
schools: 2
}
2 changes: 1 addition & 1 deletion src/views/Congregation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default Vue.extend({
},
onEdit (member: ICongregationMember): void {
this.editID = member._id
const { name, gender, appointment, languageGroup, school, show, privileges } = member
const { name, gender, appointment, languageGroup, school = null, show, privileges } = member
const updateProperties: Partial<ICongregationMember> = {
name,
gender,
Expand Down
27 changes: 24 additions & 3 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Click the navigation menu on the top left to login and navigate the site
</p>
<h2>Changelog</h2>
<v-expansion-panel class="mt-3">
<v-expansion-panel v-model="panel" expand class="mt-3">
<v-expansion-panel-content v-for="(change, index) of changes" :key="index">
<template v-slot:header>
<v-layout align-center class="no-select">
Expand All @@ -30,6 +30,7 @@
</v-layout>
</template>
<v-card class="grey lighten-4">
<v-card-title class="headline" v-text="change.summary" />
<v-card-text>
<div v-for="update of change.updates" :key="update.title">
<h3 v-text="update.title" />
Expand Down Expand Up @@ -60,11 +61,31 @@ interface IChange {
export default Vue.extend({
name: 'Home',
data: () => ({
panel: [true]
}),
computed: {
changes (): IChange[] {
return [
{
version: '1.1',
version: '1.1.1',
date: '19 Oct 2019',
summary: 'Fix schedule & second school display preferences',
updates: [
{ title: 'Features', items: ['Exclude second school assignments on Circuit Overseer visits'] },
{
title: 'Fixes',
items: [
'Use congregation display name rather than always showing Canton on the PDF',
'Default school preference to Any when editing a member that did not previously set a preference'
]
},
{ title: 'Developer', items: ['Use a settings file rather than multiple env variables'] }
]
},
{
version: '1.1.0',
date: '15 Oct 2019',
summary: 'Adds support for different types of congregations',
updates: [
Expand Down Expand Up @@ -105,7 +126,7 @@ export default Vue.extend({
]
},
{
version: '1.0',
version: '1.0.0',
date: '13 Feb 2019',
summary: 'Initial release of OCLM Planner',
updates: [
Expand Down
Loading

0 comments on commit 47ea2e7

Please sign in to comment.