From 3657b49a5c2fe1ab8801cd4590a7bbbf9d709925 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Thu, 23 May 2019 21:33:52 +0200 Subject: [PATCH] Add ability to change state of reports --- src/api/reports.js | 10 ++++++++++ src/lang/en.js | 3 ++- src/store/modules/reports.js | 15 ++++++++++----- src/views/reports/components/TimelineItem.vue | 13 ++++++++++++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/api/reports.js b/src/api/reports.js index d6ecf061..6e2ca530 100644 --- a/src/api/reports.js +++ b/src/api/reports.js @@ -2,6 +2,16 @@ import request from '@/utils/request' import { getToken } from '@/utils/auth' import { baseName } from './utils' +export async function changeState(state, id, authHost, token) { + return await request({ + baseURL: baseName(authHost), + url: `/api/pleroma/admin/reports/${id}`, + method: 'put', + headers: authHeaders(token), + data: { state } + }) +} + export async function fetchReports(limit, max_id, authHost, token) { return await request({ baseURL: baseName(authHost), diff --git a/src/lang/en.js b/src/lang/en.js index f3b90d6f..9f9b248c 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -212,7 +212,8 @@ export default { cancel: 'Cancel', deleteCompleted: 'Delete comleted', deleteCanceled: 'Delete canceled', - noNotes: 'No notes to display' + noNotes: 'No notes to display', + changeState: 'Change state' }, reportsFilter: { inputPlaceholder: 'Select filter', diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index c34ac938..b4c9548f 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -1,4 +1,4 @@ -import { fetchReports, filterReports } from '@/api/reports' +import { changeState, fetchReports, filterReports } from '@/api/reports' const reports = { state: { @@ -15,18 +15,23 @@ const reports = { SET_LOADING: (state, status) => { state.loading = status }, + SET_REPORT: (state, { reportIndex, data }) => { + state.fetchedReports[reportIndex] = data + }, SET_REPORTS: (state, reports) => { state.fetchedReports = reports }, SET_REPORTS_FILTER: (state, filter) => { state.stateFilter = filter } - // SET_REPORT: (state, { index, report }) => { - // state.fetchedReports[index] = report - // }, }, actions: { - async FetchReports({ commit, state, getters }) { + async ChangeReportState({ commit, getters, state }, { reportState, reportId }) { + const { data } = await changeState(reportState, reportId, getters.authHost, getters.token) + const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) + commit('SET_REPORT', { reportIndex, data }) + }, + async FetchReports({ commit, getters, state }) { commit('SET_LOADING', true) const response = await fetchReports(state.page_limit, state.idOfLastReport, getters.authHost, getters.token) const reports = state.fetchedReports.concat(response.data.reports) diff --git a/src/views/reports/components/TimelineItem.vue b/src/views/reports/components/TimelineItem.vue index e244b7aa..3a45a9d2 100644 --- a/src/views/reports/components/TimelineItem.vue +++ b/src/views/reports/components/TimelineItem.vue @@ -4,7 +4,15 @@

Report on {{ report.account.display_name }}

- {{ capitalizeFirstLetter(report.state) }} + {{ capitalizeFirstLetter(report.state) }} + + {{ $t('reports.changeState') }} + + Resolve + Open + Close + +
@@ -121,6 +129,9 @@ export default { this.$data.note = '' } }, + changeReportState(reportState, reportId) { + this.$store.dispatch('ChangeReportState', { reportState, reportId }) + }, deleteNote(reportId, noteId) { this.$confirm(i18n.t('reports.confirmMsg'), { confirmButtonText: i18n.t('reports.delete'),