2023-12-12 19:17:38 +08:00
|
|
|
<template>
|
2024-03-14 20:26:20 +08:00
|
|
|
<div v-if="params.data.designated_users.length > 0 || params.data.permissions.manage_designated_users">
|
|
|
|
<GeneralDropdown @open="() => loadUsers(true)" @close="closeFlyout">
|
|
|
|
<template v-slot:field>
|
|
|
|
<div v-if="!params.data.folder" class="flex items-center gap-1 cursor-pointer h-9" @click="openAccessModal">
|
|
|
|
<div v-for="(user, i) in visibleUsers" :key="i" :title="user.full_name">
|
|
|
|
<img :src="user.avatar" class="w-6 h-6 rounded-full" />
|
|
|
|
</div>
|
|
|
|
<div v-if="hiddenUsers.length > 0" :title="hiddenUsersTitle"
|
|
|
|
class="flex shrink-0 items-center justify-center w-7 h-7 text-xs
|
|
|
|
rounded-full bg-sn-dark-grey text-sn-white">
|
|
|
|
+{{ hiddenUsers.length }}
|
|
|
|
</div>
|
|
|
|
<div v-if="canManage" class="flex items-center shrink-0 justify-center w-7 h-7 rounded-full bg-sn-light-grey text-sn-dark-grey">
|
|
|
|
<i class="sn-icon sn-icon-new-task"></i>
|
|
|
|
</div>
|
2023-12-12 19:17:38 +08:00
|
|
|
</div>
|
2024-03-14 20:26:20 +08:00
|
|
|
</template>
|
|
|
|
<template v-slot:flyout>
|
|
|
|
<div v-if="canManage" class="sci-input-container-v2 left-icon mb-1">
|
|
|
|
<input type="text"
|
|
|
|
v-model="query"
|
|
|
|
class="sci-input-field"
|
|
|
|
autofocus="true"
|
|
|
|
:placeholder="i18n.t('experiments.table.search')" />
|
|
|
|
<i class="sn-icon sn-icon-search"></i>
|
2023-12-12 19:17:38 +08:00
|
|
|
</div>
|
2024-03-14 20:26:20 +08:00
|
|
|
<perfect-scrollbar class="relative max-h-96 overflow-y-auto max-w-[280px] pr-4 gap-y-px">
|
|
|
|
<div v-for="user in allUsers"
|
|
|
|
:key="user.value"
|
|
|
|
@click="selectUser(user)"
|
|
|
|
:class="{
|
|
|
|
'!bg-sn-super-light-blue': selectedUsers.some(({ value }) => value === user.value) && canManage,
|
|
|
|
'cursor-pointer hover:bg-sn-super-light-grey px-3': canManage
|
|
|
|
}"
|
|
|
|
class="whitespace-nowrap rounded py-2.5 flex items-center gap-2
|
|
|
|
hover:no-underline leading-5"
|
|
|
|
>
|
|
|
|
<div v-if="canManage" class="sci-checkbox-container">
|
|
|
|
<input type="checkbox" class="sci-checkbox" :checked="selectedUsers.some(({ value }) => value === user.value)" />
|
|
|
|
<label class="sci-checkbox-label"></label>
|
|
|
|
</div>
|
|
|
|
<img :src="user.params.avatar_url" class="w-6 h-6 rounded-full" />
|
|
|
|
<span class="truncate">{{ user.label }}</span>
|
|
|
|
</div>
|
|
|
|
</perfect-scrollbar>
|
|
|
|
</template>
|
|
|
|
</GeneralDropdown>
|
|
|
|
</div>
|
|
|
|
<span v-else>{{ i18n.t('experiments.table.not_set') }}</span>
|
2023-12-12 19:17:38 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import axios from '../../../packs/custom_axios.js';
|
|
|
|
import GeneralDropdown from '../../shared/general_dropdown.vue';
|
2024-03-14 20:26:20 +08:00
|
|
|
import { PerfectScrollbar } from 'vue3-perfect-scrollbar';
|
2023-12-12 19:17:38 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DesignatedUsersRenderer',
|
|
|
|
props: {
|
|
|
|
params: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2024-03-14 20:26:20 +08:00
|
|
|
GeneralDropdown,
|
|
|
|
PerfectScrollbar
|
2023-12-12 19:17:38 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
users() {
|
|
|
|
return this.params.data.designated_users;
|
|
|
|
},
|
2024-02-28 18:23:36 +08:00
|
|
|
canManage() {
|
|
|
|
return this.params.data.permissions.manage_designated_users;
|
|
|
|
},
|
2023-12-12 19:17:38 +08:00
|
|
|
visibleUsers() {
|
|
|
|
return this.users.slice(0, 4);
|
|
|
|
},
|
|
|
|
hiddenUsers() {
|
|
|
|
return this.users.slice(4);
|
|
|
|
},
|
|
|
|
hiddenUsersTitle() {
|
|
|
|
return this.hiddenUsers.map((user) => user.name).join('\u000d');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedUsers: [],
|
|
|
|
allUsers: [],
|
|
|
|
query: '',
|
|
|
|
changed: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
query() {
|
|
|
|
this.loadUsers();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-03-13 23:24:58 +08:00
|
|
|
loadUsers(setSelectedUsers = false) {
|
2024-03-14 20:26:20 +08:00
|
|
|
axios.get(`${this.params.data.urls.users_list}`, {
|
|
|
|
params: {
|
|
|
|
query: this.query,
|
|
|
|
skip_unassigned: !this.canManage
|
|
|
|
}
|
|
|
|
})
|
2023-12-12 19:17:38 +08:00
|
|
|
.then((response) => {
|
2024-03-13 23:24:58 +08:00
|
|
|
if (setSelectedUsers) {
|
|
|
|
this.selectedUsers = response.data.users.filter((item) => this.users.some((user) => user.id === item.value));
|
|
|
|
this.allUsers = response.data.users;
|
|
|
|
this.flyoutLoaded = true;
|
|
|
|
} else {
|
|
|
|
const nonAssignedUsers = response.data.users.filter((item) => !this.selectedUsers.some(({ value }) => value === item.value));
|
|
|
|
this.allUsers = this.selectedUsers.concat(nonAssignedUsers);
|
|
|
|
}
|
2023-12-12 19:17:38 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
closeFlyout() {
|
|
|
|
this.query = '';
|
|
|
|
if (this.changed) {
|
2024-01-25 22:49:13 +08:00
|
|
|
this.params.dtComponent.updateTable();
|
2023-12-12 19:17:38 +08:00
|
|
|
this.changed = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectUser(user) {
|
2024-02-28 18:23:36 +08:00
|
|
|
if (!this.canManage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-12 19:17:38 +08:00
|
|
|
this.changed = true;
|
|
|
|
|
2024-03-13 23:24:58 +08:00
|
|
|
if (this.selectedUsers.some(({ value }) => value === user.value)) {
|
2023-12-12 19:17:38 +08:00
|
|
|
axios.delete(user.params.unassign_url, {
|
|
|
|
table: true
|
|
|
|
}).then(() => {
|
2024-03-13 23:24:58 +08:00
|
|
|
this.selectedUsers = this.selectedUsers.filter(({ value }) => value !== user.value);
|
2023-12-12 19:17:38 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
axios.post(user.params.assign_url, {
|
|
|
|
table: true,
|
|
|
|
user_my_module: {
|
|
|
|
my_module_id: this.params.data.id,
|
|
|
|
user_id: user.value
|
|
|
|
}
|
2024-01-25 22:49:13 +08:00
|
|
|
}).then((response) => {
|
|
|
|
this.allUsers.find((u) => u.value === user.value).params.unassign_url = response.data.unassign_url;
|
2024-03-13 23:24:58 +08:00
|
|
|
this.selectedUsers.push(user);
|
2023-12-12 19:17:38 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|