Completed recurrence work (#16)
Requests can now: - be entered with recurrence - be updated with recurrence - manually skip recurrence period Also did an app-wide clean-up to ensure that everything is done the same way in all places
This commit is contained in:
@@ -38,7 +38,8 @@ export default {
|
||||
...mapState(['journal', 'isLoadingJournal'])
|
||||
},
|
||||
created () {
|
||||
this.$on('requestSnoozed', this.ensureJournal)
|
||||
this.$on('requestUnsnoozed', this.ensureJournal)
|
||||
this.$on('requestNowShown', this.ensureJournal)
|
||||
},
|
||||
methods: {
|
||||
async ensureJournal () {
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
article.mpj-main-content(role='main')
|
||||
page-title(:title='title')
|
||||
.mpj-narrow
|
||||
label(for='request_text') Prayer Request
|
||||
br
|
||||
textarea#request_text(v-model='form.requestText'
|
||||
:rows='10'
|
||||
@blur='trimText()'
|
||||
autofocus)
|
||||
label(for='request_text')
|
||||
| Prayer Request
|
||||
br
|
||||
textarea(v-model='form.requestText'
|
||||
:rows='10'
|
||||
@blur='trimText()'
|
||||
autofocus).mpj-full-width
|
||||
br
|
||||
template(v-if='!isNew')
|
||||
label Also Mark As
|
||||
@@ -50,22 +51,21 @@ article.mpj-main-content(role='main')
|
||||
name='recur'
|
||||
value='other')
|
||||
| Every...
|
||||
input#recur_count(v-model='form.recur.count'
|
||||
type='number'
|
||||
:disabled='!showRecurrence')
|
||||
input(v-model='form.recur.count'
|
||||
type='number'
|
||||
:disabled='!showRecurrence').mpj-recur-count
|
||||
select(v-model='form.recur.other'
|
||||
:disabled='!showRecurrence')
|
||||
:disabled='!showRecurrence').mpj-recur-type
|
||||
option(value='hours') hours
|
||||
option(value='days') days
|
||||
option(value='weeks') weeks
|
||||
.mpj-text-right
|
||||
button(@click.stop='saveRequest()').primary
|
||||
md-icon(icon='save')
|
||||
= ' Save'
|
||||
button(:disabled='!isValidRecurrence'
|
||||
@click.stop='saveRequest()').primary.
|
||||
#[md-icon(icon='save')] Save
|
||||
|
|
||||
button(@click.stop='goBack()')
|
||||
md-icon(icon='arrow_back')
|
||||
= ' Cancel'
|
||||
button(@click.stop='goBack()').
|
||||
#[md-icon(icon='arrow_back')] Cancel
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -100,15 +100,25 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
toast () {
|
||||
return this.$parent.$refs.toast
|
||||
isValidRecurrence () {
|
||||
if (this.form.recur.typ === 'immediate') return true
|
||||
const count = Number.parseInt(this.form.recur.count)
|
||||
if (isNaN(count) || this.form.recur.other === '') return false
|
||||
if (this.form.recur.other === 'hours' && count > (365 * 24)) return false
|
||||
if (this.form.recur.other === 'days' && count > 365) return false
|
||||
if (this.form.recur.other === 'weeks' && count > 52) return false
|
||||
return true
|
||||
},
|
||||
showRecurrence () {
|
||||
this.form.recur.typ !== 'immediate'
|
||||
return this.form.recur.typ !== 'immediate'
|
||||
},
|
||||
toast () {
|
||||
return this.$parent.$refs.toast
|
||||
},
|
||||
...mapState(['journal'])
|
||||
},
|
||||
async mounted () {
|
||||
await this.ensureJournal()
|
||||
if (this.id === 'new') {
|
||||
this.title = 'Add Prayer Request'
|
||||
this.isNew = true
|
||||
@@ -146,11 +156,18 @@ export default {
|
||||
trimText () {
|
||||
this.form.requestText = this.form.requestText.trim()
|
||||
},
|
||||
async ensureJournal () {
|
||||
if (!Array.isArray(this.journal)) {
|
||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
||||
}
|
||||
},
|
||||
async saveRequest () {
|
||||
if (this.isNew) {
|
||||
await this.$store.dispatch(actions.ADD_REQUEST, {
|
||||
progress: this.$Progress,
|
||||
requestText: this.form.requestText
|
||||
requestText: this.form.requestText,
|
||||
recurType: this.form.recur.typ === 'immediate' ? 'immediate' : this.form.recur.other,
|
||||
recurCount: this.form.recur.typ === 'immediate' ? 0 : Number.parseInt(this.form.recur.count)
|
||||
})
|
||||
this.toast.showToast('New prayer request added', { theme: 'success' })
|
||||
} else {
|
||||
@@ -158,7 +175,9 @@ export default {
|
||||
progress: this.$Progress,
|
||||
requestId: this.form.requestId,
|
||||
updateText: this.form.requestText,
|
||||
status: this.form.status
|
||||
status: this.form.status,
|
||||
recurType: this.form.recur.typ === 'immediate' ? 'immediate' : this.form.recur.other,
|
||||
recurCount: this.form.recur.typ === 'immediate' ? 0 : Number.parseInt(this.form.recur.count)
|
||||
})
|
||||
if (this.form.status === 'Answered') {
|
||||
this.toast.showToast('Request updated and removed from active journal', { theme: 'success' })
|
||||
@@ -172,11 +191,14 @@ export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
#request_text {
|
||||
width: 100%;
|
||||
}
|
||||
#recur_count {
|
||||
<style>
|
||||
.mpj-recur-count {
|
||||
width: 3rem;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
.mpj-recur-type {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -55,11 +55,12 @@ export default {
|
||||
.sort(asOfDesc)[0].text.fields[0]
|
||||
},
|
||||
log () {
|
||||
return (this.request.notes || [])
|
||||
const allHistory = (this.request.notes || [])
|
||||
.map(note => ({ asOf: note.asOf, text: { case: 'Some', fields: [ note.notes ] }, status: 'Notes' }))
|
||||
.concat(this.request.history)
|
||||
.sort(asOfDesc)
|
||||
.slice(1)
|
||||
// Skip the first entry for answered requests; that info is already displayed
|
||||
return this.isAnswered ? allHistory.slice(1) : allHistory
|
||||
},
|
||||
openDays () {
|
||||
const asOf = this.isAnswered ? this.answered : Date.now()
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
<template lang="pug">
|
||||
div
|
||||
button(@click='openDialog()')
|
||||
md-icon(icon='add_box')
|
||||
| Add a New Request
|
||||
b-modal(v-model='showNewVisible'
|
||||
header-bg-variant='mpj'
|
||||
header-text-variant='light'
|
||||
size='lg'
|
||||
title='Add a New Prayer Request'
|
||||
@shown='focusRequestText')
|
||||
b-form
|
||||
b-form-group(label='Prayer Request'
|
||||
label-for='request_text')
|
||||
b-textarea#request_text(ref='toFocus'
|
||||
v-model='form.requestText'
|
||||
:rows='10'
|
||||
@blur='trimText()')
|
||||
b-form-group(label='Recurrence')
|
||||
| After prayer, request reappears
|
||||
b-radio(v-model='form.recur.typ'
|
||||
label='Immediately'
|
||||
value='immediately'
|
||||
checked='checked'
|
||||
@click='checkRadios')
|
||||
b-radio(v-model='form.recur.typ'
|
||||
label='Every...'
|
||||
value='other'
|
||||
@click='checkRadios')
|
||||
b-input(v-model='form.recur.count'
|
||||
placeholder='##')
|
||||
b-select(v-model='form.recur.other')
|
||||
b-option(value='hours') hours
|
||||
b-option(value='days') days
|
||||
b-option(value='weeks') weeks
|
||||
div.w-100.text-right(slot='modal-footer')
|
||||
b-btn(variant='primary'
|
||||
:disabled='!isValid'
|
||||
@click='saveRequest()') Save
|
||||
|
|
||||
b-btn(variant='outline-secondary'
|
||||
@click='closeDialog()') Cancel
|
||||
toast(ref='toast')
|
||||
</template>
|
||||
|
||||
<script>
|
||||
'use strict'
|
||||
|
||||
import actions from '@/store/action-types'
|
||||
|
||||
export default {
|
||||
name: 'new-request',
|
||||
data () {
|
||||
return {
|
||||
showNewVisible: false,
|
||||
form: {
|
||||
requestText: '',
|
||||
recur: {
|
||||
typ: 'immediate',
|
||||
other: '',
|
||||
count: ''
|
||||
}
|
||||
},
|
||||
formLabelWidth: '120px'
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.$refs.toast.setOptions({ position: 'bottom right' })
|
||||
},
|
||||
computed: {
|
||||
isValid () {
|
||||
// TODO disallow submission if recurrence is too long
|
||||
return true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
closeDialog () {
|
||||
this.form.requestText = ''
|
||||
this.showNewVisible = false
|
||||
},
|
||||
focusRequestText (e) {
|
||||
this.$refs.toFocus.focus()
|
||||
},
|
||||
openDialog () {
|
||||
this.showNewVisible = true
|
||||
},
|
||||
trimText () {
|
||||
this.form.requestText = this.form.requestText.trim()
|
||||
},
|
||||
async saveRequest () {
|
||||
await this.$store.dispatch(actions.ADD_REQUEST, {
|
||||
progress: this.$Progress,
|
||||
requestText: this.form.requestText
|
||||
})
|
||||
this.$refs.toast.showToast('New prayer request added', { theme: 'success' })
|
||||
this.closeDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -3,11 +3,12 @@
|
||||
.mpj-modal-content.mpj-narrow
|
||||
header.mpj-bg
|
||||
h5 Add Notes to Prayer Request
|
||||
label(for='notes') Notes
|
||||
br
|
||||
textarea#notes(v-model='form.notes'
|
||||
:rows='10'
|
||||
@blur='trimText()')
|
||||
label
|
||||
| Notes
|
||||
br
|
||||
textarea(v-model='form.notes'
|
||||
:rows='10'
|
||||
@blur='trimText()').mpj-full-width
|
||||
.mpj-text-right
|
||||
button(@click='saveNotes()').primary.
|
||||
#[md-icon(icon='save')] Save
|
||||
@@ -75,7 +76,6 @@ export default {
|
||||
try {
|
||||
const notes = await api.getNotes(this.form.requestId)
|
||||
this.priorNotes = notes.data
|
||||
console.log(this.priorNotes)
|
||||
this.$Progress.finish()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
@@ -85,7 +85,6 @@ export default {
|
||||
}
|
||||
},
|
||||
openDialog (request) {
|
||||
console.log('Received openDialog event')
|
||||
this.form.requestId = request.requestId
|
||||
this.notesVisible = true
|
||||
},
|
||||
@@ -108,10 +107,7 @@ export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
#notes {
|
||||
width: 100%;
|
||||
}
|
||||
<style>
|
||||
.mpj-note-list p {
|
||||
border-top: dotted 1px lightgray;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template lang="pug">
|
||||
.mpj-request-card
|
||||
.mpj-request-card(v-if='shouldDisplay')
|
||||
header.mpj-card-header(role='toolbar').
|
||||
#[button.primary(@click='markPrayed()' title='Pray'): md-icon(icon='done')]
|
||||
#[button(@click='markPrayed()' title='Pray').primary: md-icon(icon='done')]
|
||||
#[button(@click.stop='showEdit()' title='Edit'): md-icon(icon='edit')]
|
||||
#[button(@click.stop='showNotes()' title='Add Notes'): md-icon(icon='comment')]
|
||||
#[button(@click.stop='snooze()' title='Snooze Request'): md-icon(icon='schedule')]
|
||||
|
||||
@@ -7,17 +7,23 @@ p.mpj-request-text
|
||||
title='View Full Request').
|
||||
#[md-icon(icon='description')] View Full Request
|
||||
|
|
||||
button(v-if='!isAnswered'
|
||||
@click='editRequest'
|
||||
title='Edit Request').
|
||||
#[md-icon(icon='edit')] Edit Request
|
||||
|
|
||||
button(v-if='isSnoozed'
|
||||
@click='cancelSnooze()').
|
||||
#[md-icon(icon='restore')] Cancel Snooze
|
||||
br(v-if='isSnoozed || isAnswered')
|
||||
template(v-if='!isAnswered')
|
||||
button(@click='editRequest'
|
||||
title='Edit Request').
|
||||
#[md-icon(icon='edit')] Edit Request
|
||||
|
|
||||
template(v-if='isSnoozed')
|
||||
button(@click='cancelSnooze()').
|
||||
#[md-icon(icon='restore')] Cancel Snooze
|
||||
|
|
||||
template(v-if='isPending')
|
||||
button(@click='showNow()').
|
||||
#[md-icon(icon='restore')] Show Now
|
||||
br(v-if='isSnoozed || isPending || isAnswered')
|
||||
small(v-if='isSnoozed').mpj-muted-text: em.
|
||||
Snooze expires #[date-from-now(:value='request.snoozedUntil')]
|
||||
small(v-if='isPending').mpj-muted-text: em.
|
||||
Request scheduled to reappear #[date-from-now(:value='request.showAfter')]
|
||||
small(v-if='isAnswered').mpj-muted-text: em.
|
||||
Answered #[date-from-now(:value='request.asOf')]
|
||||
</template>
|
||||
@@ -43,6 +49,9 @@ export default {
|
||||
isAnswered () {
|
||||
return this.request.lastStatus === 'Answered'
|
||||
},
|
||||
isPending () {
|
||||
return !this.isSnoozed && this.request.showAfter > Date.now()
|
||||
},
|
||||
isSnoozed () {
|
||||
return this.request.snoozedUntil > Date.now()
|
||||
}
|
||||
@@ -60,6 +69,15 @@ export default {
|
||||
editRequest () {
|
||||
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
||||
},
|
||||
async showNow () {
|
||||
await this.$store.dispatch(actions.SHOW_REQUEST_NOW, {
|
||||
progress: this.$Progress,
|
||||
requestId: this.request.requestId,
|
||||
showAfter: Date.now()
|
||||
})
|
||||
this.toast.showToast('Recurrence skipped; request now shows in journal', { theme: 'success' })
|
||||
this.$parent.$emit('requestNowShown')
|
||||
},
|
||||
viewFull () {
|
||||
this.$router.push({ name: 'FullRequest', params: { id: this.request.requestId } })
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
header.mpj-bg
|
||||
h5 Snooze Prayer Request
|
||||
p.mpj-text-center
|
||||
label(for='until') Until
|
||||
= ' '
|
||||
input#until(type='date'
|
||||
v-model='form.snoozedUntil'
|
||||
autofocus)
|
||||
label
|
||||
= 'Until '
|
||||
input(v-model='form.snoozedUntil'
|
||||
type='date'
|
||||
autofocus)
|
||||
br
|
||||
.mpj-text-right
|
||||
button.primary(:disabled='!isValid'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template lang="pug">
|
||||
article
|
||||
article.mpj-main-content(role='main')
|
||||
pageTitle(title='Logging On')
|
||||
p Logging you on...
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user