From 3c3f0a7981fa8f82d3cc904630960ca43c910cd2 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 22 Oct 2017 22:50:26 -0500 Subject: [PATCH] Finished answered request layout (#9) Also: - rearranged API calls to be in alphabetical order (except the bearer stuff at the top) - modified the API base URL and Auth0 renewal URLs to be derived from the browser's location (localhost / prod both work now with no change) --- src/api/src/routes/request.js | 13 +++ src/app/src/api/index.js | 53 ++++++------ src/app/src/components/Answered.vue | 35 ++++---- src/app/src/components/AnsweredDetail.vue | 81 +++++++++++++++++++ src/app/src/components/request/NotesEdit.vue | 4 +- .../components/request/RequestListItem.vue | 2 +- src/app/src/router/index.js | 31 ++++++- src/app/static/silent.html | 4 +- 8 files changed, 171 insertions(+), 52 deletions(-) create mode 100644 src/app/src/components/AnsweredDetail.vue diff --git a/src/api/src/routes/request.js b/src/api/src/routes/request.js index 9cd5ab0..9268780 100644 --- a/src/api/src/routes/request.js +++ b/src/api/src/routes/request.js @@ -56,6 +56,19 @@ export default function (checkJwt) { } await next() }) + // Get a complete request; equivalent to full + notes + .get('/:id/complete', checkJwt, async (ctx, next) => { + const req = await db.request.fullById(ctx.state.user.sub, ctx.params.id) + if ('Not Found' === req.text) { + ctx.response.status = 404 + } else { + ctx.response.status = 200 + req.notes = await db.request.notesById(ctx.state.user.sub, ctx.params.id) + ctx.body = req + } + await next() + }) + // Get all answered requests .get('/answered', checkJwt, async (ctx, next) => { ctx.body = await db.request.answered(ctx.state.user.sub) ctx.response.status = 200 diff --git a/src/app/src/api/index.js b/src/app/src/api/index.js index c35b9aa..e6d6436 100644 --- a/src/app/src/api/index.js +++ b/src/app/src/api/index.js @@ -1,7 +1,7 @@ import axios from 'axios' const http = axios.create({ - baseURL: 'http://localhost:3000/api/' + baseURL: `${location.protocol}//${location.host}/api/` }) /** @@ -20,11 +20,6 @@ export default { */ removeBearer: () => delete http.defaults.headers.common['authorization'], - /** - * Get all prayer requests and their most recent updates - */ - journal: () => http.get('journal/'), - /** * Add a note for a prayer request * @param {string} requestId The Id of the request to which the note applies @@ -39,19 +34,9 @@ export default { addRequest: requestText => http.post('request/', { requestText }), /** - * Update a prayer request - * @param request The request (should have requestId, status, and updateText properties) + * Get all answered requests, along with the text they had when it was answered */ - updateRequest: request => http.post(`request/${request.requestId}/history`, { - status: request.status, - updateText: request.updateText - }), - - /** - * Get a prayer request (journal-style; only latest update) - * @param {string} requestId The Id of the request to retrieve - */ - getRequest: requestId => http.get(`request/${requestId}`), + getAnsweredRequests: () => http.get('request/answered'), /** * Get a prayer request (full; includes all history) @@ -59,15 +44,35 @@ export default { */ getFullRequest: requestId => http.get(`request/${requestId}/full`), - /** - * Get all answered requests, along with the text they had when it was answered - */ - getAnsweredRequests: () => http.get('request/answered'), - /** * Get past notes for a prayer request * @param {string} requestId The Id of the request for which notes should be retrieved */ - getNotes: requestId => http.get(`request/${requestId}/notes`) + getNotes: requestId => http.get(`request/${requestId}/notes`), + + /** + * Get a prayer request (journal-style; only latest update) + * @param {string} requestId The Id of the request to retrieve + */ + getRequest: requestId => http.get(`request/${requestId}`), + + /** + * Get a complete request; equivalent of "full" and "notes" combined + */ + getRequestComplete: requestId => http.get(`request/${requestId}/complete`), + + /** + * Get all prayer requests and their most recent updates + */ + journal: () => http.get('journal/'), + + /** + * Update a prayer request + * @param request The request (should have requestId, status, and updateText properties) + */ + updateRequest: request => http.post(`request/${request.requestId}/history`, { + status: request.status, + updateText: request.updateText + }) } diff --git a/src/app/src/components/Answered.vue b/src/app/src/components/Answered.vue index 2e65fd8..af9da50 100644 --- a/src/app/src/components/Answered.vue +++ b/src/app/src/components/Answered.vue @@ -2,36 +2,29 @@ article page-title(title='Answered Requests') p(v-if='!loaded') Loading answered requests... - div(v-if='loaded') + div(v-if='loaded').mpj-answered-list p.mpj-request-text(v-for='req in requests' :key='req.requestId') - b-btn(@click='showFull(req.requestId)' + | {{ req.text }} + br + br + b-btn(:to='{ name: "AnsweredDetail", params: { id: req.requestId }}' size='sm' variant='outline-secondary') icon(name='search') - |  View Full Request - |     {{ req.text }}   + = ' View Full Request' small.text-muted: em. - (Answered #[date-from-now(:value='req.asOf')]) - full-request(:events='eventBus') +   Answered #[date-from-now(:value='req.asOf')] + + diff --git a/src/app/src/components/AnsweredDetail.vue b/src/app/src/components/AnsweredDetail.vue new file mode 100644 index 0000000..6af0fbb --- /dev/null +++ b/src/app/src/components/AnsweredDetail.vue @@ -0,0 +1,81 @@ + + + diff --git a/src/app/src/components/request/NotesEdit.vue b/src/app/src/components/request/NotesEdit.vue index 4e80026..5053603 100644 --- a/src/app/src/components/request/NotesEdit.vue +++ b/src/app/src/components/request/NotesEdit.vue @@ -21,8 +21,8 @@ b-modal(v-model='notesVisible' small.text-muted: date-from-now(:value='note.asOf') br div.mpj-request-text {{ note.notes }} - div(v-if='noPriorNotes').text-center.text-muted There are no prior notes for this request - div(v-if='!priorNotesLoaded').text-center + div(v-else-if='noPriorNotes').text-center.text-muted There are no prior notes for this request + div(v-else).text-center b-btn(variant='outline-secondary' @click='loadNotes()') Load Prior Notes div.w-100.text-right(slot='modal-footer') diff --git a/src/app/src/components/request/RequestListItem.vue b/src/app/src/components/request/RequestListItem.vue index c284423..8076646 100644 --- a/src/app/src/components/request/RequestListItem.vue +++ b/src/app/src/components/request/RequestListItem.vue @@ -17,7 +17,7 @@ div = '(last activity ' date-from-now(:value='request.asOf') | ) - b-card(v-for='it in 3 - row.length') + b-card(v-for='it in 3 - row.length' key='-1') br diff --git a/src/app/src/router/index.js b/src/app/src/router/index.js index 0ada814..8048c02 100644 --- a/src/app/src/router/index.js +++ b/src/app/src/router/index.js @@ -2,6 +2,7 @@ import Vue from 'vue' import Router from 'vue-router' import Answered from '@/components/Answered' +import AnsweredDetail from '@/components/AnsweredDetail' import Home from '@/components/Home' import Journal from '@/components/Journal' import LogOn from '@/components/user/LogOn' @@ -11,9 +12,31 @@ Vue.use(Router) export default new Router({ mode: 'history', routes: [ - { path: '/', name: 'Home', component: Home }, - { path: '/answered', name: 'Answered', component: Answered }, - { path: '/journal', name: 'Journal', component: Journal }, - { path: '/user/log-on', name: 'LogOn', component: LogOn } + { + path: '/', + name: 'Home', + component: Home + }, + { + path: '/answered/:id', + name: 'AnsweredDetail', + component: AnsweredDetail, + props: true + }, + { + path: '/answered', + name: 'Answered', + component: Answered + }, + { + path: '/journal', + name: 'Journal', + component: Journal + }, + { + path: '/user/log-on', + name: 'LogOn', + component: LogOn + } ] }) diff --git a/src/app/static/silent.html b/src/app/static/silent.html index 1a6cae5..dc6351f 100644 --- a/src/app/static/silent.html +++ b/src/app/static/silent.html @@ -9,12 +9,12 @@ clientID: 'Of2s0RQCQ3mt3dwIkOBY5h85J9sXbF2n', scope: 'openid profile email', responseType: 'token id_token', - redirectUri: 'http://localhost:3000/static/silent.html' + redirectUri: location.protocol + '//' + location.host + '/static/silent.html' })