[admin][optim] load abuse reports and translation proposals client-side / async

This commit is contained in:
Andrea Vos 2022-07-30 16:37:39 +02:00
parent e83a2334ef
commit 3b5dfe2f38

View File

@ -156,7 +156,9 @@
</div>
</section>
<section v-if="$isGranted('translations') && translationProposals.length">
<template v-if="$isGranted('translations')">
<Loading :value="translationProposals"/>
<section v-if="translationProposals && translationProposals.length">
<h3>
<Icon v="language"/>
Translation proposals ({{translationProposals.length}})
@ -210,6 +212,8 @@
</div>
</details>
</section>
</Loading>
</template>
<section v-if="$isGranted('users')">
<h3>
@ -219,7 +223,9 @@
</h3>
<ModerationRules type="rulesUsers" emphasise/>
<ModerationRules type="susRegexes" label="Keywords for automated triggers"/>
<Loading :value="abuseReports">
<AbuseReports :abuseReports="abuseReports" allowResolving/>
</Loading>
</section>
<section v-for="(locale, k) in stats.locales" :key="k">
@ -291,6 +297,8 @@ import {deepSet, head} from "../src/helpers";
adminNotifications: this.$user().adminNotifications ?? 7,
translator,
missingTranslations: translator.listMissingTranslations(),
abuseReports: undefined,
translationProposals: undefined,
}
},
async asyncData({ app, store }) {
@ -299,22 +307,19 @@ import {deepSet, head} from "../src/helpers";
stats = await app.$axios.$get(`/admin/stats`);
} catch {}
let abuseReports = [];
try {
abuseReports = await app.$axios.$get(`/admin/reports`);
} catch {}
let translationProposals = [];
try {
translationProposals = await app.$axios.$get(`/translations/proposals`);
} catch {}
return {
stats,
abuseReports,
translationProposals
};
},
async mounted() {
this.$axios.$get(`/admin/reports`)
.then(r => this.abuseReports = r)
.catch();
this.$axios.$get(`/translations/proposals`)
.then(r => this.translationProposals = r)
.catch();
},
methods: {
async impersonate(email) {
const { token } = await this.$axios.$get(`/admin/impersonate/${encodeURIComponent(email)}`);
@ -343,11 +348,11 @@ import {deepSet, head} from "../src/helpers";
return r;
},
abuseReportsActiveCount() {
return this.abuseReports.filter(r => !r.isHandled).length;
return this.abuseReports ? this.abuseReports.filter(r => !r.isHandled).length : '';
},
translationsProposalsSuml() {
const data = {};
for (let tp of this.translationProposals) {
for (let tp of this.translationProposals || []) {
deepSet(data, tp.tKey, tp.tValue);
}
return new Suml().dump(data);