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 #78 from BenShelton/develop
Browse files Browse the repository at this point in the history
New Domain Finalisation
  • Loading branch information
BenShelton authored Oct 13, 2019
2 parents 9ba0d2a + 5d33271 commit 4866b0c
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 117 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
|:------:|:------:|
| Test | [![Netlify Status](https://api.netlify.com/api/v1/badges/16fc3682-78d9-4cf6-8774-123ff23ac3a8/deploy-status)](https://app.netlify.com/sites/optimistic-aryabhata-1c388b/deploys) |
| Canton | [![Netlify Status](https://api.netlify.com/api/v1/badges/584fa026-9c25-4c14-99c6-78b5b79898f1/deploy-status)](https://app.netlify.com/sites/oclm-planner/deploys) |
| Barry | [![Netlify Status](https://api.netlify.com/api/v1/badges/bd2a4417-571b-4cfc-961e-89f4f06789b4/deploy-status)](https://app.netlify.com/sites/quizzical-banach-ac38d7/deploys) |

## Features

Expand Down
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Languages } from 'types'

// TODO: Probably just worth having one map of talks with all their information
export const ASSIGNMENT_TYPE_MAP = {
chairman: 'chairman',
Expand Down Expand Up @@ -52,7 +54,10 @@ export const SUPPORTED_LANGUAGES = [

export const USED_LANGUAGES = (process.env.VUE_APP_LANGUAGES || 'en')
.split(',')
.map(l => SUPPORTED_LANGUAGES.find(s => s.value === l))
.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

Expand Down
246 changes: 130 additions & 116 deletions src/views/Congregation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<v-select v-model="editMember.appointment" label="Appointment" :items="APPOINTMENTS" />
</v-flex>
<v-flex xs12 sm6 md4>
<v-select v-model="editMember.languageGroup" label="Language Group" :items="SUPPORTED_LANGUAGES" />
<v-select v-model="editMember.languageGroup" label="Language Group" :items="USED_LANGUAGES" />
</v-flex>
<v-flex xs12 sm6 md4>
<v-checkbox v-model="editMember.show" label="Show On Schedule" />
Expand All @@ -46,7 +46,7 @@
</p>
<v-layout wrap>
<v-flex
v-for="privilege in PRIVILEGES"
v-for="privilege of PRIVILEGES"
:key="privilege.key"
xs12
sm6
Expand Down Expand Up @@ -137,7 +137,7 @@
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import Vue from 'vue'
import { alertModule, congregationModule } from '@/store'
import BooleanIcon from '@/components/BooleanIcon.vue'
Expand All @@ -146,137 +146,151 @@ import {
GENDERS,
APPOINTMENTS,
SUPPORTED_LANGUAGES,
USED_LANGUAGES,
PRIVILEGES
} from '@/constants'
import { ICongregationMember } from 'types'
import { ICongregationMember, Languages } from 'types'
export default Vue.extend({
name: 'Congregation',
@Component({
components: {
BooleanIcon
}
})
export default class Schedule extends Vue {
// Data
GENDERS = GENDERS
APPOINTMENTS = APPOINTMENTS
SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES
PRIVILEGES = PRIVILEGES
languageGroups = SUPPORTED_LANGUAGES.reduce((acc, { text, value }) => Object.assign(acc, { [value]: text }), {})
headers = [
{ text: 'Name', value: 'name' },
{ text: 'Gender', value: 'gender' },
{ text: 'Appointment', value: 'appointment' },
{ text: 'Language Group', value: 'languageGroup' },
{ text: 'Show On Schedule', value: 'show', align: 'center' },
{ text: 'Privileges', value: '', align: 'center', sortable: false },
{ text: 'Actions', value: '', align: 'center', sortable: false }
]
rowsPerPageItems = [20, 50, 100, { text: 'All', value: -1 }]
search: string = ''
editDialog: boolean = false
editID: string | null = null
editTitle: string = ''
editMember: ICongregationMember = {
_id: '',
name: '',
gender: GENDERS[0],
appointment: APPOINTMENTS[0],
languageGroup: SUPPORTED_LANGUAGES[0].value,
show: true,
privileges: {}
}
// Computed
get members (): ICongregationMember[] {
return congregationModule.members
}
get loading (): boolean {
return congregationModule.loading
}
// Methods
expandRow (props: { expanded: boolean }): void {
props.expanded = !props.expanded
}
closeEditor (): void {
this.editDialog = false
}
prettyPrivileges (privileges: ICongregationMember['privileges']): { name: string, selected: boolean}[] {
if (!privileges) return []
return PRIVILEGES.map(({ name, key }) => ({ name, selected: !!privileges[key] }))
}
},
onAdd (): void {
this.editID = null
Object.assign(this.editMember, {
data: () => ({
search: '',
editDialog: false,
editID: null as string | null,
editTitle: '',
editMember: {
_id: '',
name: '',
gender: GENDERS[0],
appointment: APPOINTMENTS[0],
languageGroup: SUPPORTED_LANGUAGES[0].value,
languageGroup: USED_LANGUAGES[0].value,
show: true,
privileges: {}
})
this.editTitle = 'Add New Congregation Member'
this.editDialog = true
}
onEdit (member: ICongregationMember): void {
this.editID = member._id
const { name, gender, appointment, languageGroup, show, privileges } = member
Object.assign(this.editMember, {
name,
gender,
appointment,
languageGroup,
show,
privileges: { ...privileges }
})
this.editTitle = 'Edit Existing Congregation Member'
this.editDialog = true
}
} as unknown as ICongregationMember
}),
onDelete ({ _id: memberID, name }: ICongregationMember): void {
if (!window.confirm(`Are you sure you want to delete ${name}?`)) return
congregationModule.delete({ memberID })
.then(() => {
alertModule.UPDATE_ALERT({ text: `${name} was successfully deleted`, color: 'success' })
this.closeEditor()
})
.catch(err => {
alertModule.UPDATE_ALERT({ text: 'An error occured whilst deleting this member', color: 'error' })
console.error(err)
})
}
onSave (): void {
if (!this.editMember.name) {
alertModule.UPDATE_ALERT({ text: 'Name is required', color: 'error' })
return
computed: {
members (): ICongregationMember[] {
return congregationModule.members
},
loading (): boolean {
return congregationModule.loading
},
GENDERS (): typeof GENDERS {
return GENDERS
},
APPOINTMENTS (): typeof APPOINTMENTS {
return APPOINTMENTS
},
USED_LANGUAGES (): typeof USED_LANGUAGES {
return USED_LANGUAGES
},
PRIVILEGES (): typeof PRIVILEGES {
return PRIVILEGES
},
languageGroups (): { [key in Languages]: string } {
return SUPPORTED_LANGUAGES.reduce((acc, { text, value }) => Object.assign(acc, { [value]: text }), {}) as { [key in Languages]: string }
},
headers (): { text: string, value: string, align?: string, sortable?: boolean }[] {
return [
{ text: 'Name', value: 'name' },
{ text: 'Gender', value: 'gender' },
{ text: 'Appointment', value: 'appointment' },
{ text: 'Language Group', value: 'languageGroup' },
{ text: 'Show On Schedule', value: 'show', align: 'center' },
{ text: 'Privileges', value: '', align: 'center', sortable: false },
{ text: 'Actions', value: '', align: 'center', sortable: false }
]
},
rowsPerPageItems (): (number | { text: string, value: number })[] {
return [20, 50, 100, { text: 'All', value: -1 }]
}
if (this.editID) {
congregationModule.update({ memberID: this.editID, member: this.editMember })
.then(() => {
alertModule.UPDATE_ALERT({ text: `${this.editMember.name} was successfully updated`, color: 'success' })
this.closeEditor()
})
.catch((err: Error) => {
alertModule.UPDATE_ALERT({ text: 'An error occured whilst updating this member', color: 'error' })
console.error(err)
})
} else {
congregationModule.add(this.editMember)
},
methods: {
expandRow (props: { expanded: boolean }): void {
props.expanded = !props.expanded
},
closeEditor (): void {
this.editDialog = false
},
prettyPrivileges (privileges: ICongregationMember['privileges']): { name: string, selected: boolean }[] {
if (!privileges) return []
return PRIVILEGES.map(({ name, key }) => ({ name, selected: !!privileges[key] }))
},
onAdd (): void {
this.editID = null
const baseProperties: Partial<ICongregationMember> = {
name: '',
gender: GENDERS[0],
appointment: APPOINTMENTS[0],
languageGroup: USED_LANGUAGES[0].value,
show: true,
privileges: {}
}
Object.assign(this.editMember, baseProperties)
this.editTitle = 'Add New Congregation Member'
this.editDialog = true
},
onEdit (member: ICongregationMember): void {
this.editID = member._id
const { name, gender, appointment, languageGroup, show, privileges } = member
const updateProperties: Partial<ICongregationMember> = {
name,
gender,
appointment,
languageGroup,
show,
privileges: { ...privileges }
}
Object.assign(this.editMember, updateProperties)
this.editTitle = 'Edit Existing Congregation Member'
this.editDialog = true
},
onDelete ({ _id: memberID, name }: ICongregationMember): void {
if (!window.confirm(`Are you sure you want to delete ${name}?`)) return
congregationModule.delete({ memberID })
.then(() => {
alertModule.UPDATE_ALERT({ text: `${this.editMember.name} was successfully added`, color: 'success' })
alertModule.UPDATE_ALERT({ text: `${name} was successfully deleted`, color: 'success' })
this.closeEditor()
})
.catch((err: Error) => {
alertModule.UPDATE_ALERT({ text: 'An error occured whilst adding this member', color: 'error' })
.catch(err => {
alertModule.UPDATE_ALERT({ text: 'An error occured whilst deleting this member', color: 'error' })
console.error(err)
})
},
onSave (): void {
if (!this.editMember.name) {
alertModule.UPDATE_ALERT({ text: 'Name is required', color: 'error' })
return
}
if (this.editID) {
congregationModule.update({ memberID: this.editID, member: this.editMember })
.then(() => {
alertModule.UPDATE_ALERT({ text: `${this.editMember.name} was successfully updated`, color: 'success' })
this.closeEditor()
})
.catch((err: Error) => {
alertModule.UPDATE_ALERT({ text: 'An error occured whilst updating this member', color: 'error' })
console.error(err)
})
} else {
congregationModule.add(this.editMember)
.then(() => {
alertModule.UPDATE_ALERT({ text: `${this.editMember.name} was successfully added`, color: 'success' })
this.closeEditor()
})
.catch((err: Error) => {
alertModule.UPDATE_ALERT({ text: 'An error occured whilst adding this member', color: 'error' })
console.error(err)
})
}
}
}
}
})
</script>

0 comments on commit 4866b0c

Please sign in to comment.