This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/routes/admin.vue

99 lines
3.2 KiB
Vue
Raw Normal View History

2020-10-29 15:41:40 -07:00
<template>
<NotFound v-if="!$admin()"/>
2020-11-16 11:43:44 -08:00
<div v-else>
2020-10-29 15:41:40 -07:00
<h2>
<Icon v="user-cog"/>
<T>admin.header</T>
</h2>
2020-11-03 12:00:32 -08:00
<Table :data="Object.values(users)" :columns="4" count>
2020-10-29 15:41:40 -07:00
<template v-slot:header>
<th class="text-nowrap">
<T>admin.user.user</T>
</th>
<th class="text-nowrap">
<T>admin.user.email</T>
</th>
<th class="text-nowrap">
<T>admin.user.roles</T>
</th>
<th class="text-nowrap">
<T>admin.user.profiles</T>
</th>
</template>
<template v-slot:row="s">
<td>
<Avatar :user="s.el" dsize="2rem"/>
{{s.el.username}}
</td>
<td>
2020-11-02 12:45:45 -08:00
<p>
<a :href="`mailto:${s.el.email}`" target="_blank" rel="noopener">
{{s.el.email}}
</a>
</p>
<ul v-if="s.el.socialConnections.length" class="list-inline">
<li v-for="conn in s.el.socialConnections" class="list-inline-item">
<Icon :v="socialProviders[conn].icon || conn" set="b"/>
</li>
</ul>
2020-10-29 15:41:40 -07:00
</td>
<td>
2020-11-03 01:03:07 -08:00
<a href="#" :class="['badge', s.el.roles === 'admin' ? 'badge-primary' : 'badge-light']"
@click.prevent="setRole(s.el.id, s.el.roles === 'admin' ? 'user' : 'admin')">
2020-10-29 15:41:40 -07:00
{{s.el.roles}}
2020-11-03 01:03:07 -08:00
</a>
2020-10-29 15:41:40 -07:00
</td>
<td>
<ul class="list-unstyled">
<li v-for="locale in s.el.profiles" v-if="locales[locale]">
<LocaleLink :link="`/@${s.el.username}`" :locale="locale">
{{ locales[locale].name }}
</LocaleLink>
</li>
</ul>
</td>
</template>
</Table>
</div>
</template>
<script>
import {head} from "../src/helpers";
2020-11-02 12:45:45 -08:00
import {socialProviders} from "../src/data";
2020-10-29 15:41:40 -07:00
export default {
2020-11-02 12:45:45 -08:00
data() {
return { socialProviders }
},
2020-10-29 15:41:40 -07:00
async asyncData({ app, store }) {
if (!store.state.user || store.state.user.roles !== 'admin') {
return {};
}
const users = await app.$axios.$get(`/admin/users`, { headers: {
authorization: 'Bearer ' + store.state.token,
} });
return {
2020-11-03 01:03:07 -08:00
users,
2020-10-29 15:41:40 -07:00
};
},
2020-11-03 01:03:07 -08:00
methods: {
async setRole(userId, role) {
await this.$confirm(this.$t('admin.user.confirmRole', {username: this.users[userId].username, role}));
const response = await this.$axios.$post(`/user/${userId}/set-roles`, { roles: role });
this.users[userId].roles = role;
}
},
2020-10-29 15:41:40 -07:00
head() {
return head({
title: this.$t('admin.header'),
});
},
}
</script>