2023-12-12 19:17:38 +08:00
|
|
|
<template>
|
|
|
|
<GeneralDropdown @open="loadUsers" @close="closeFlyout">
|
|
|
|
<template v-slot:field>
|
2024-02-01 18:45:13 +08:00
|
|
|
<div v-if="!params.data.folder" class="flex items-center gap-1 cursor-pointer h-9" @click="openAccessModal">
|
2023-12-12 19:17:38 +08:00
|
|
|
<div v-for="(user, i) in visibleUsers" :key="i" :title="user.full_name">
|
2024-03-04 18:07:15 +08:00
|
|
|
<img :src="user.avatar" class="w-7 h-7 rounded-full" />
|
2023-12-12 19:17:38 +08:00
|
|
|
</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 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>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template v-slot:flyout>
|
|
|
|
<div class="sci-input-container-v2 left-icon mb-2.5">
|
|
|
|
<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>
|
|
|
|
</div>
|
2024-01-25 22:49:13 +08:00
|
|
|
<div class="h-64 overflow-y-auto">
|
2023-12-12 19:17:38 +08:00
|
|
|
<div v-for="user in allUsers"
|
2024-01-25 22:49:13 +08:00
|
|
|
:key="user.value"
|
|
|
|
@click="selectUser(user)"
|
2024-02-28 18:23:36 +08:00
|
|
|
:class="{
|
|
|
|
'!bg-sn-super-light-blue': selectedUsers.includes(user.value),
|
|
|
|
'cursor-pointer hover:bg-sn-super-light-grey': canManage
|
|
|
|
}"
|
2024-01-25 22:49:13 +08:00
|
|
|
class="whitespace-nowrap rounded px-3 py-2.5 flex items-center gap-2
|
2024-02-28 18:23:36 +08:00
|
|
|
hover:no-underline leading-5"
|
2023-12-12 19:17:38 +08:00
|
|
|
>
|
2024-01-25 22:49:13 +08:00
|
|
|
<div class="sci-checkbox-container">
|
2024-02-28 18:23:36 +08:00
|
|
|
<input type="checkbox" class="sci-checkbox" :disabled="!canManage" :checked="selectedUsers.includes(user.value)" />
|
2024-01-25 22:49:13 +08:00
|
|
|
<label class="sci-checkbox-label"></label>
|
|
|
|
</div>
|
2023-12-12 19:17:38 +08:00
|
|
|
<img :src="user.params.avatar_url" class="w-7 h-7" />
|
|
|
|
{{ user.label }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</GeneralDropdown>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import axios from '../../../packs/custom_axios.js';
|
|
|
|
import GeneralDropdown from '../../shared/general_dropdown.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DesignatedUsersRenderer',
|
|
|
|
props: {
|
|
|
|
params: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
GeneralDropdown
|
|
|
|
},
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.selectedUsers = this.users.map((user) => (user.id));
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadUsers() {
|
|
|
|
axios.get(`${this.params.data.urls.users_list}?query=${this.query}`)
|
|
|
|
.then((response) => {
|
2024-03-12 21:16:45 +08:00
|
|
|
this.allUsers = response.data.users;
|
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;
|
|
|
|
|
|
|
|
if (this.selectedUsers.includes(user.value)) {
|
|
|
|
axios.delete(user.params.unassign_url, {
|
|
|
|
table: true
|
|
|
|
}).then(() => {
|
|
|
|
this.selectedUsers = this.selectedUsers.filter((id) => id !== user.value);
|
|
|
|
});
|
|
|
|
} 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;
|
2023-12-12 19:17:38 +08:00
|
|
|
this.selectedUsers.push(user.value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|