2023-12-05 03:59:16 +08:00
|
|
|
<template>
|
2024-01-29 22:19:25 +08:00
|
|
|
<div class="mb-6">
|
|
|
|
<div class="sci-label mb-2">
|
|
|
|
{{ i18n.t('access_permissions.partials.new_assignments_form.grant_access') }}
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
<GeneralDropdown @open="$emit('assigningNewUsers', true)" @close="$emit('assigningNewUsers', false)" :fieldOnlyOpen="true">
|
|
|
|
<template v-slot:field>
|
2023-12-05 03:59:16 +08:00
|
|
|
<div class="sci-input-container-v2 left-icon">
|
2023-12-11 22:41:03 +08:00
|
|
|
<input type="text" v-model="query" class="sci-input-field"
|
2024-01-29 22:19:25 +08:00
|
|
|
autofocus="true"
|
2024-02-27 20:03:41 +08:00
|
|
|
ref="input"
|
2024-01-29 22:19:25 +08:00
|
|
|
:placeholder="i18n.t('access_permissions.partials.new_assignments_form.find_people_html')" />
|
2023-12-05 03:59:16 +08:00
|
|
|
<i class="sn-icon sn-icon-search"></i>
|
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
</template>
|
|
|
|
<template v-slot:flyout>
|
|
|
|
<div v-if="!visible && roles.length > 0" class="py-2 flex border-solid border-0 border-b border-b-sn-sleepy-grey items-center gap-2">
|
2023-12-05 03:59:16 +08:00
|
|
|
<div>
|
|
|
|
<img src="/images/icon/team.png" class="rounded-full w-8 h-8">
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{{ i18n.t('user_assignment.assign_all_team_members') }}
|
|
|
|
</div>
|
|
|
|
<MenuDropdown
|
|
|
|
class="ml-auto"
|
|
|
|
:listItems="rolesFromatted"
|
|
|
|
btnText="Assign"
|
|
|
|
:position="'right'"
|
|
|
|
:caret="true"
|
|
|
|
@setRole="(...args) => this.assignRole('all', ...args)"
|
|
|
|
></MenuDropdown>
|
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
<perfect-scrollbar class="h-80 relative">
|
|
|
|
<div v-for="user in filteredUsers" :key="user.id" class="py-2 flex items-center gap-2">
|
|
|
|
<div>
|
|
|
|
<img :src="user.attributes.avatar_url" class="rounded-full w-8 h-8">
|
|
|
|
</div>
|
2024-02-23 03:26:15 +08:00
|
|
|
<div>
|
|
|
|
{{
|
|
|
|
`${user.attributes.name}${user.attributes.current_user ? ` (${i18n.t('access_permissions.you')})` : ''}`
|
|
|
|
}}
|
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
<MenuDropdown
|
|
|
|
class="ml-auto"
|
|
|
|
:listItems="rolesFromatted"
|
|
|
|
btnText="Assign"
|
|
|
|
:position="'right'"
|
|
|
|
:caret="true"
|
|
|
|
@setRole="(...args) => this.assignRole(user.id, ...args)"
|
|
|
|
></MenuDropdown>
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
2024-01-29 22:19:25 +08:00
|
|
|
</perfect-scrollbar>
|
|
|
|
</template>
|
|
|
|
</GeneralDropdown>
|
2023-12-05 03:59:16 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-12-11 22:41:03 +08:00
|
|
|
/* global HelperModule */
|
|
|
|
import MenuDropdown from '../menu_dropdown.vue';
|
2024-01-29 22:19:25 +08:00
|
|
|
import GeneralDropdown from '../general_dropdown.vue';
|
2023-12-05 03:59:16 +08:00
|
|
|
import axios from '../../../packs/custom_axios.js';
|
|
|
|
|
|
|
|
export default {
|
2024-01-29 22:19:25 +08:00
|
|
|
emits: ['modified', 'usersReloaded', 'changeVisibility'],
|
2023-12-05 03:59:16 +08:00
|
|
|
props: {
|
|
|
|
params: {
|
|
|
|
type: Object,
|
2024-01-29 22:19:25 +08:00
|
|
|
required: true
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
visible: {
|
2024-01-29 22:19:25 +08:00
|
|
|
type: Boolean
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
default_role: {
|
2024-01-29 22:19:25 +08:00
|
|
|
type: Number
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
2024-01-29 22:19:25 +08:00
|
|
|
reloadUsers: {
|
|
|
|
type: Boolean
|
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getUnAssignedUsers();
|
|
|
|
this.getRoles();
|
2024-02-27 20:03:41 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.input?.focus();
|
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
MenuDropdown,
|
2024-01-29 22:19:25 +08:00
|
|
|
GeneralDropdown
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
rolesFromatted() {
|
2023-12-11 22:41:03 +08:00
|
|
|
return this.roles.map((role) => (
|
|
|
|
{
|
2023-12-05 03:59:16 +08:00
|
|
|
emit: 'setRole',
|
|
|
|
text: role[1],
|
2024-01-29 22:19:25 +08:00
|
|
|
params: role[0]
|
2023-12-05 03:59:16 +08:00
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
));
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
filteredUsers() {
|
2023-12-11 22:41:03 +08:00
|
|
|
return this.unAssignedUsers.filter((user) => (
|
|
|
|
user.attributes.name.toLowerCase().includes(this.query.toLowerCase())
|
|
|
|
));
|
2024-01-29 22:19:25 +08:00
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
unAssignedUsers: [],
|
|
|
|
roles: [],
|
2024-01-29 22:19:25 +08:00
|
|
|
query: ''
|
2023-12-05 03:59:16 +08:00
|
|
|
};
|
|
|
|
},
|
2024-01-29 22:19:25 +08:00
|
|
|
watch: {
|
|
|
|
reloadUsers() {
|
|
|
|
if (this.reloadUsers) {
|
|
|
|
this.getUnAssignedUsers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-12-05 03:59:16 +08:00
|
|
|
methods: {
|
|
|
|
getUnAssignedUsers() {
|
|
|
|
axios.get(this.params.object.urls.new_access)
|
|
|
|
.then((response) => {
|
|
|
|
this.unAssignedUsers = response.data.data;
|
2024-01-29 22:19:25 +08:00
|
|
|
this.$emit('usersReloaded');
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
|
|
|
getRoles() {
|
|
|
|
axios.get(this.params.roles_path)
|
|
|
|
.then((response) => {
|
|
|
|
this.roles = response.data.data;
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2023-12-05 03:59:16 +08:00
|
|
|
},
|
2023-12-11 22:41:03 +08:00
|
|
|
assignRole(id, roleId) {
|
2023-12-05 03:59:16 +08:00
|
|
|
axios.post(this.params.object.urls.create_access, {
|
|
|
|
user_assignment: {
|
|
|
|
user_id: id,
|
2024-01-29 22:19:25 +08:00
|
|
|
user_role_id: roleId
|
|
|
|
}
|
2023-12-05 03:59:16 +08:00
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
this.$emit('modified');
|
|
|
|
HelperModule.flashAlertMsg(response.data.message, 'success');
|
|
|
|
this.getUnAssignedUsers();
|
|
|
|
|
|
|
|
if (id === 'all') {
|
2023-12-11 22:41:03 +08:00
|
|
|
this.$emit('changeVisibility', true, roleId);
|
2023-12-05 03:59:16 +08:00
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
});
|
2024-01-29 22:19:25 +08:00
|
|
|
}
|
|
|
|
}
|
2023-12-11 22:41:03 +08:00
|
|
|
};
|
|
|
|
</script>
|