[admin] overview of translation contributions

This commit is contained in:
Andrea Vos 2023-03-13 20:27:13 +01:00
parent 49503f8191
commit 40da22794a
2 changed files with 62 additions and 0 deletions

View File

@ -76,6 +76,46 @@
</div>
</details>
</section>
<details v-if="contributors.length" class="border mb-3">
<summary class="bg-light p-3">
Contributors
</summary>
<div class="p-2">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Contributor</th>
<th>Approved translations</th>
</tr>
</thead>
<tbody>
<tr v-for="{username, isMember, count} in contributors">
<td>
<nuxt-link :to="`/@${username}`">@{{username}}</nuxt-link>
<span v-if="isMember" class="badge bg-primary text-white">
<Icon v="collective-logo.svg" class="inverted"/>
<T>contact.team.member</T>
</span>
</td>
<td>
{{ count }}
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2" class="small">
This overview only considers translations submitted via the web interface, got gitlab/gdocs.
Let's use it to consider inviting people to the team.
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</details>
</div>
</Page>
</template>
@ -94,6 +134,7 @@ export default {
async asyncData({ app }) {
return {
translationProposals: await app.$axios.$get(`/translations/proposals`),
contributors: await app.$axios.$get(`/translations/contributors`),
};
},
methods: {

View File

@ -98,4 +98,25 @@ router.post('/translations/proposals-done', handleErrorAsync(async (req, res) =>
return res.json('OK');
}));
router.get('/translations/contributors', handleErrorAsync(async (req, res) => {
if (!req.isGranted('translations')) {
return res.status(401).json({error: 'Unauthorised'});
}
const contributors = [];
for (let {author_id, c} of await req.db.all(SQL`SELECT author_id, count(*) AS c FROM translations
WHERE locale = ${global.config.locale} AND status >= ${TRANSLATION_STATUS.APPROVED}
GROUP BY author_id
`)) {
const { username, roles } = await req.db.get(SQL`SELECT username, roles FROM users WHERE id=${author_id}`);
contributors.push({
username,
isMember: !!roles,
count: c,
});
}
return res.json(contributors);
}));
export default router;