diff --git a/src/api/db/ddl.js b/src/api/db/ddl.js
index 46c3455..63ecf16 100644
--- a/src/api/db/ddl.js
+++ b/src/api/db/ddl.js
@@ -52,6 +52,33 @@ const ddl = [
fix: `
CREATE INDEX "idx_request_userId" ON mpj.request ("userId");
COMMENT ON INDEX "idx_request_userId" IS 'Requests are retrieved by user'`
+ },
+ {
+ name: 'journal View',
+ check: `SELECT 1 FROM pg_views WHERE schemaname='mpj' AND viewname='journal'`,
+ fix: `
+ CREATE VIEW mpj.journal AS
+ SELECT
+ request."requestId",
+ request."userId",
+ (SELECT "text"
+ FROM mpj.history
+ WHERE history."requestId" = request."requestId"
+ AND "text" IS NOT NULL
+ ORDER BY "asOf" DESC
+ LIMIT 1) AS "text",
+ (SELECT "asOf"
+ FROM mpj.history
+ WHERE history."requestId" = request."requestId"
+ ORDER BY "asOf" DESC
+ LIMIT 1) AS "asOf",
+ (SELECT "status"
+ FROM mpj.history
+ WHERE history."requestId" = request."requestId"
+ ORDER BY "asOf" DESC
+ LIMIT 1) AS "lastStatus"
+ FROM mpj.request;
+ COMMENT ON VIEW mpj.journal IS 'Requests with latest text'`
}
]
diff --git a/src/api/db/request.js b/src/api/db/request.js
index 9fe683f..7e810d5 100644
--- a/src/api/db/request.js
+++ b/src/api/db/request.js
@@ -4,24 +4,12 @@ import { Pool } from 'pg'
import cuid from 'cuid'
const currentRequestSql = `
- SELECT
- request."requestId",
- (SELECT "text"
- FROM mpj.history
- WHERE history."requestId" = request."requestId"
- AND "text" IS NOT NULL
- ORDER BY "asOf" DESC
- LIMIT 1) AS "text",
- (SELECT "asOf"
- FROM mpj.history
- WHERE history."requestId" = request."requestId"
- ORDER BY "asOf" DESC
- LIMIT 1) AS "asOf"
- FROM mpj.request`
+ SELECT "requestId", "text", "asOf", "lastStatus"
+ FROM mpj.journal`
const journalSql = `${currentRequestSql}
WHERE "userId" = $1
- GROUP BY request."requestId"`
+ AND "lastStatus" <> 'Answered'`
const requestNotFound = {
requestId: '',
@@ -40,7 +28,10 @@ export default function (pool) {
addHistory: async (requestId, status, updateText) => {
const asOf = Date.now()
await pool.query(`
- INSERT INTO mpj.history ("requestId", "asOf", "status", "text") VALUES ($1, $2, $3, NULLIF($4, ''))`,
+ INSERT INTO mpj.history
+ ("requestId", "asOf", "status", "text")
+ VALUES
+ ($1, $2, $3, NULLIF($4, ''))`,
[ requestId, asOf, status, updateText ])
},
@@ -70,10 +61,10 @@ export default function (pool) {
} finally {
client.release()
}
- return { requestId: id, text: requestText, asOf: enteredOn }
+ return { requestId: id, text: requestText, asOf: enteredOn, lastStatus: 'Created' }
})().catch(e => {
console.error(e.stack)
- return { requestId: '', text: 'error', asOf: 0 }
+ return { requestId: '', text: 'error', asOf: 0, lastStatus: 'Errored' }
})
},
@@ -86,8 +77,7 @@ export default function (pool) {
byId: async (userId, requestId) => {
const reqs = await pool.query(`${currentRequestSql}
WHERE "requestId" = $1
- AND "userId" = $2
- GROUP BY request."requestId"`,
+ AND "userId" = $2`,
[ requestId, userId ])
return (0 < reqs.rowCount) ? reqs.rows[0] : requestNotFound
},
@@ -124,15 +114,7 @@ export default function (pool) {
* @param {string} userId The Id of the user
* @return The requests that make up the current journal
*/
- journal: async userId => (await pool.query(`${journalSql} ORDER BY "asOf" DESC`, [ userId ])).rows,
-
- /**
- * Get the least-recently-updated prayer request for the given user
- * @param {string} userId The Id of the current user
- * @return The least-recently-updated request for the given user
- */
- oldest: async userId => (await pool.query(`${journalSql} ORDER BY "asOf" LIMIT 1`, [ userId ])).rows[0]
-
+ journal: async userId => (await pool.query(`${journalSql} ORDER BY "asOf"`, [ userId ])).rows
}
}
diff --git a/src/app/src/components/Dashboard.vue b/src/app/src/components/Dashboard.vue
index 25cc981..0d92eca 100644
--- a/src/app/src/components/Dashboard.vue
+++ b/src/app/src/components/Dashboard.vue
@@ -4,7 +4,6 @@ article
p(v-if="isLoadingJournal") Loading your prayer journal...
template(v-if="!isLoadingJournal")
new-request
- p journal has {{ journal.length }} entries
el-row
el-col(:span='4'): strong Actions
el-col(:span='16'): strong Request
@@ -38,6 +37,10 @@ export default {
},
async created () {
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
+ this.$message({
+ message: `Loaded ${this.journal.length} prayer requests`,
+ type: 'success'
+ })
}
}
diff --git a/src/app/src/components/request/EditRequest.vue b/src/app/src/components/request/EditRequest.vue
index 77fc260..400230c 100644
--- a/src/app/src/components/request/EditRequest.vue
+++ b/src/app/src/components/request/EditRequest.vue
@@ -49,6 +49,17 @@ export default {
updateText: this.form.requestText,
status: this.form.status
})
+ if (this.form.status === 'Answered') {
+ this.$message({
+ message: 'Request updated and removed from active journal',
+ type: 'success'
+ })
+ } else {
+ this.$message({
+ message: 'Request updated',
+ type: 'success'
+ })
+ }
this.editVisible = false
}
}
diff --git a/src/app/src/components/request/NewRequest.vue b/src/app/src/components/request/NewRequest.vue
index a98b0ef..3ddfb07 100644
--- a/src/app/src/components/request/NewRequest.vue
+++ b/src/app/src/components/request/NewRequest.vue
@@ -1,6 +1,6 @@
div
- el-button(@click='openDialog()') Add a New Request
+ el-button(icon='plus' @click='openDialog()') Add a New Request
el-dialog(title='Add a New Prayer Request' :visible.sync='showNewVisible')
el-form(:model='form' :label-position='top')
el-form-item(label='Prayer Request')
@@ -39,7 +39,11 @@ export default {
progress: this.$Progress,
requestText: this.form.requestText
})
- this.showNewVisible = false
+ this.$message({
+ message: 'New prayer request added',
+ type: 'success'
+ })
+ this.closeDialog()
}
}
}
diff --git a/src/app/src/components/request/RequestListItem.vue b/src/app/src/components/request/RequestListItem.vue
index 3ecd7ab..140ade1 100644
--- a/src/app/src/components/request/RequestListItem.vue
+++ b/src/app/src/components/request/RequestListItem.vue
@@ -4,7 +4,7 @@ el-row.journal-request
el-button(icon='check' @click='markPrayed()' title='Pray')
edit-request(:request='request')
full-request(:request='request')
- el-col(:span='16'): p {{ request.text }}
+ el-col(:span='16'): p {{ text }}
el-col(:span='4'): p {{ asOf }}
@@ -33,11 +33,18 @@ export default {
status: 'Prayed',
updateText: ''
})
+ this.$message({
+ message: 'Request marked as prayed',
+ type: 'success'
+ })
}
},
computed: {
asOf () {
return moment(this.request.asOf).fromNow()
+ },
+ text () {
+ return this.request.text.split('\n').join('
')
}
}
}
diff --git a/src/app/src/store/index.js b/src/app/src/store/index.js
index 3de729e..9e8a66b 100644
--- a/src/app/src/store/index.js
+++ b/src/app/src/store/index.js
@@ -45,11 +45,11 @@ export default new Vuex.Store({
state.journal = journal
},
[mutations.REQUEST_ADDED] (state, newRequest) {
- state.journal.unshift(newRequest)
+ state.journal.push(newRequest)
},
[mutations.REQUEST_UPDATED] (state, request) {
let jrnl = state.journal.filter(it => it.requestId !== request.requestId)
- jrnl.unshift(request)
+ if (request.lastStatus !== 'Answered') jrnl.push(request)
state.journal = jrnl
},
[mutations.USER_LOGGED_OFF] (state) {