Semaphore/web/src/views/Users.vue
2024-09-29 13:14:04 +05:00

157 lines
3.6 KiB
Vue

<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
<div v-if="items != null">
<EditDialog
v-model="editDialog"
save-button-text="Save"
:title="$t('editUser')"
@save="loadItems()"
>
<template v-slot:form="{ onSave, onError, needSave, needReset }">
<UserForm
:project-id="projectId"
:item-id="itemId"
@save="onSave"
@error="onError"
:need-save="needSave"
:need-reset="needReset"
:is-admin="true"
/>
</template>
</EditDialog>
<YesNoDialog
:title="$t('deleteUser')"
:text="$t('askDeleteUser')"
v-model="deleteItemDialog"
@yes="deleteItem(itemId)"
/>
<v-toolbar flat >
<v-btn
icon
class="mr-4"
@click="returnToProjects()"
>
<v-icon>mdi-arrow-left</v-icon>
</v-btn>
<v-toolbar-title>{{ $t('users') }}</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
color="primary"
@click="editItem('new')"
>{{ $t('newUser') }}</v-btn>
</v-toolbar>
<v-data-table
:headers="headers"
:items="items"
class="mt-4"
:footer-props="{ itemsPerPageOptions: [20] }"
>
<template v-slot:item.external="{ item }">
<v-icon v-if="item.external">mdi-checkbox-marked</v-icon>
<v-icon v-else>mdi-checkbox-blank-outline</v-icon>
</template>
<template v-slot:item.alert="{ item }">
<v-icon v-if="item.alert">mdi-checkbox-marked</v-icon>
<v-icon v-else>mdi-checkbox-blank-outline</v-icon>
</template>
<template v-slot:item.admin="{ item }">
<v-icon v-if="item.admin">mdi-checkbox-marked</v-icon>
<v-icon v-else>mdi-checkbox-blank-outline</v-icon>
</template>
<template v-slot:item.actions="{ item }">
<div style="white-space: nowrap">
<v-btn
icon
class="mr-1"
@click="askDeleteItem(item.id)"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
<v-btn
icon
class="mr-1"
@click="editItem(item.id)"
>
<v-icon>mdi-pencil</v-icon>
</v-btn>
</div>
</template>
</v-data-table>
</div>
</template>
<script>
import EventBus from '@/event-bus';
import YesNoDialog from '@/components/YesNoDialog.vue';
import ItemListPageBase from '@/components/ItemListPageBase';
import EditDialog from '@/components/EditDialog.vue';
import UserForm from '@/components/UserForm.vue';
export default {
mixins: [ItemListPageBase],
components: {
YesNoDialog,
UserForm,
EditDialog,
},
methods: {
getHeaders() {
return [{
text: this.$i18n.t('name'),
value: 'name',
width: '50%',
},
{
text: this.$i18n.t('username'),
value: 'username',
},
{
text: this.$i18n.t('email'),
value: 'email',
},
{
text: this.$i18n.t('alert'),
value: 'alert',
},
{
text: this.$i18n.t('admin'),
value: 'admin',
},
{
text: this.$i18n.t('external'),
value: 'external',
width: '50%',
},
{
text: this.$i18n.t('actions'),
value: 'actions',
sortable: false,
}];
},
async returnToProjects() {
EventBus.$emit('i-open-last-project');
},
getItemsUrl() {
return '/api/users';
},
getSingleItemUrl() {
return `/api/users/${this.itemId}`;
},
getEventName() {
return 'i-user';
},
},
};
</script>