From 1ba4564b201d17a24c00c4494c954316581442ba Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Sun, 8 Dec 2019 11:26:42 +0300 Subject: [PATCH] Add report notes --- CHANGELOG.md | 1 + package.json | 2 +- src/api/reports.js | 19 ++++ src/lang/en.js | 10 +- src/store/modules/reports.js | 47 ++++++++- src/views/reports/components/NoteCard.vue | 119 ++++++++++++++++++++++ src/views/reports/components/Report.vue | 39 ++++++- src/views/statuses/index.vue | 6 +- yarn.lock | 8 +- 9 files changed, 240 insertions(+), 11 deletions(-) create mode 100644 src/views/reports/components/NoteCard.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index be8ddcde..7f2e2eba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Ability to fetch all statuses from a given instance - Grouped reports: now you can view reports, which are grouped by status (pagination is not implemented yet, though) - Ability to confirm users' emails and resend confirmation emails +- Report notes ### Fixed diff --git a/package.json b/package.json index 0327b45b..73c2fc16 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "driver.js": "0.8.1", "dropzone": "5.2.0", "echarts": "4.1.0", - "element-ui": "^2.10.0", + "element-ui": "^2.13.0", "file-saver": "1.3.8", "fuse.js": "3.4.2", "js-cookie": "2.2.0", diff --git a/src/api/reports.js b/src/api/reports.js index 373e5bd5..3454da2f 100644 --- a/src/api/reports.js +++ b/src/api/reports.js @@ -33,4 +33,23 @@ export async function fetchGroupedReports(authHost, token) { }) } +export async function createNote(content, reportID, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/reports/${reportID}/notes`, + method: `post`, + headers: authHeaders(token), + data: { content } + }) +} + +export async function deleteNote(noteID, reportID, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/reports/${reportID}/notes/${noteID}`, + method: `delete`, + headers: authHeaders(token) + }) +} + const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} diff --git a/src/lang/en.js b/src/lang/en.js index dd3326e5..3dcd9bdd 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -240,9 +240,10 @@ export default { resendConfirmation: 'Resend confirmation email' }, statuses: { - statuses: 'Statuses', + statuses: 'Statuses by instance', instanceFilter: 'Instance filter', - loadMore: 'Load more' + loadMore: 'Load more', + noInstances: 'No other instances found' }, userProfile: { tags: 'Tags', @@ -308,7 +309,10 @@ export default { actors: 'Actors', content: 'Content', reportedStatus: 'Reported status', - statusDeleted: 'This status has been deleted' + statusDeleted: 'This status has been deleted', + leaveNote: 'Leave a note', + postNote: 'Send', + deleteNote: 'Delete' }, reportsFilter: { inputPlaceholder: 'Select filter', diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index d62f1b55..f64c520d 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -1,4 +1,5 @@ -import { changeState, fetchReports, fetchGroupedReports } from '@/api/reports' +import { Message } from 'element-ui' +import { changeState, fetchReports, fetchGroupedReports, createNote, deleteNote } from '@/api/reports' const reports = { state: { @@ -79,6 +80,50 @@ const reports = { }, ToggleReportsGrouping({ commit }) { commit('SET_REPORTS_GROUPING') + }, + CreateReportNote({ commit, getters, state, rootState }, { content, reportID }) { + createNote(content, reportID, getters.authHost, getters.token) + + const optimisticNote = { + user: { + avatar: rootState.user.avatar, + display_name: rootState.user.name, + url: `${rootState.user.authHost}/${rootState.user.name}`, + acct: rootState.user.name + }, + content: content, + created_at: new Date().getTime() + } + + const updatedReports = state.fetchedReports.map(report => { + if (report.id === reportID) { + report.notes = [...report.notes, optimisticNote] + } + + return report + }) + + commit('SET_REPORTS', updatedReports) + }, + DeleteReportNote({ commit, getters, state }, { noteID, reportID }) { + deleteNote(noteID, reportID, getters.authHost, getters.token) + + const updatedReports = state.fetchedReports.map(report => { + if (report.id === reportID) { + report.notes = report.notes.filter(note => note.id !== noteID) + } + + return report + }) + + commit('SET_REPORTS', updatedReports) + }, + SuccessMessage(text) { + return Message({ + message: text, + type: 'success', + duration: 5 * 1000 + }) } } } diff --git a/src/views/reports/components/NoteCard.vue b/src/views/reports/components/NoteCard.vue new file mode 100644 index 00000000..fdc81d91 --- /dev/null +++ b/src/views/reports/components/NoteCard.vue @@ -0,0 +1,119 @@ + + + + + diff --git a/src/views/reports/components/Report.vue b/src/views/reports/components/Report.vue index fbcd5e00..20e6e217 100644 --- a/src/views/reports/components/Report.vue +++ b/src/views/reports/components/Report.vue @@ -63,6 +63,23 @@ +
+ + + + + +
+ +
+ {{ $t('reports.postNote') }} +
+
+
@@ -81,18 +98,24 @@