base_ui/pages/admin/permit/user-access-customization.vue

311 lines
10 KiB
Vue
Raw Normal View History

2025-02-01 09:34:55 +00:00
<template>
<div class="pages access-page p-3">
<sub-header-with-select
@open-form="toggleRolesPanel()"
:showProjectSelect="$attrs.showProjectSelect"
2025-02-11 07:08:54 +00:00
title="تنظیم دسترسی کاربران"
>
2025-02-01 09:34:55 +00:00
<!-- <button-->
<!-- @click="toggleRolesPanel()"-->
<!-- class="btn btn-outline-primary position-relative"-->
<!-- type="button">-->
<!-- اختصاص نقش جدید-->
<!-- </button>-->
</sub-header-with-select>
<div class="pages-content d-flex">
<div class="table-responsive">
<table class="table table-borderless table-hover">
<thead>
2025-02-11 07:08:54 +00:00
<tr>
<th colspan="12" class="px-0">
<form class="table-search-form" role="search">
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<svg
class=""
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="search"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 512 512"
data-fa-i2svg=""
>
<path
fill="currentColor"
d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"
></path>
</svg>
</span>
</div>
<input
v-model="searchForm.query"
type="search"
required
class="form-control"
id="search-query"
placeholder="جستجو..."
name="search-query"
aria-label="جستجو در اسناد، عناوین و واژگان"
aria-describedby="basic-addon1"
size="50"
/>
<div class="input-group-append">
<button
:class="{
'show-reset-btn': searchForm.query.length > 0,
}"
type="button"
class="input-group-text"
id="basic-addon1"
>
<i class="tavasi tavasi-Component-294--1"></i>
</button>
</div>
</div>
2025-02-01 09:34:55 +00:00
</div>
2025-02-11 07:08:54 +00:00
</form>
</th>
</tr>
2025-02-01 09:34:55 +00:00
</thead>
<thead>
2025-02-11 07:08:54 +00:00
<tr>
<th scope="col">#</th>
<th scope="col">نام</th>
<th scope="col">نقش</th>
<th scope="col">تاریخ ثبت نام</th>
<th scope="col">عملیات</th>
</tr>
2025-02-01 09:34:55 +00:00
</thead>
<tbody>
2025-02-11 07:08:54 +00:00
<template v-if="userRoles.length">
<tr
v-for="({ user, ...item }, index) in userRoles"
:class="{ active: item.active ?? false }"
:key="index"
>
<th scope="row">{{ index + 1 }}</th>
<td>
<div class="user-info">
<div class="user-info-avatar">
<img :src="userAvatar(user)" :alt="fullName(user)" />
</div>
<div class="user-info-details">
<p class="name">
{{ fullName(user) }}
</p>
<p class="username">
@{{ user.username ?? "بدون نام کاربری" }}
</p>
</div>
2025-02-01 09:34:55 +00:00
</div>
2025-02-11 07:08:54 +00:00
</td>
<td>
<span>{{ item.role_name ?? "--" }}</span>
</td>
<td>
<span
>از
{{ convertUnixToPersianDateTime(item.created_at) }}</span
>
</td>
<td>
<button
@click="toggleRolesPanel(index)"
title="ویرایش"
class="btn edit-btn"
data-bs-toggle="modal"
data-bs-target="#edit-paper"
>
<i class="tavasi tavasi-Component-242--1"></i>
</button>
<!-- <button @click="deleteItem(item.id)" title="حذف"-->
<!-- class="btn delete-btn"-->
<!-- type="button"-->
<!-- >-->
<!-- <img class="" src="@assets/common/img/Component 295 1.svg" alt="حذف"/>-->
<!-- </button>-->
</td>
</tr>
</template>
<table-no-data v-else></table-no-data>
2025-02-01 09:34:55 +00:00
</tbody>
</table>
</div>
<div class="side-panel" v-if="showPanel">
<div class="side-panel-header">
2025-02-11 07:08:54 +00:00
<h6 class="">مدیریت نقش ها</h6>
2025-02-01 09:34:55 +00:00
</div>
2025-02-11 07:08:54 +00:00
<div class="side-panel-content">
2025-02-01 09:34:55 +00:00
<!-- <div class="mb-5">-->
<!-- <label for="role_id">انتخاب بخش</label>-->
<!-- <select @change="getUserPermission()" name="role_id" id="role_id"-->
<!-- class="form-control text__14">-->
<!-- <template v-if="sections.length">-->
<!-- <option disabled :value="undefined" selected>انتخاب بخش</option>-->
<!-- <option v-for="({project_id,section_title},index) in sections"-->
<!-- :key="index" :value="project_id">{{ section_title }}-->
<!-- </option>-->
<!-- </template>-->
<!-- <option v-else :value="undefined" selected>بخشی ثبت نشده است.</option>-->
<!-- </select>-->
<!-- </div>-->
2025-02-11 07:08:54 +00:00
<accordion v-if="user_id" :user_id="user_id"></accordion>
2025-02-01 09:34:55 +00:00
<div class="side-panel-footer mt-4">
2025-02-11 07:08:54 +00:00
<div></div>
2025-02-01 09:34:55 +00:00
<div>
<button
2025-02-11 07:08:54 +00:00
@click.prevent="showPanel = false"
type="button"
class="btn btn-primary"
data-dismiss="modal"
2025-02-01 09:34:55 +00:00
>
بستن
</button>
</div>
</div>
</div>
</div>
</div>
<Share @onCloseModal="showModal = false" v-if="showModal"></Share>
</div>
</template>
<script>
import apis from "@permission/permitApi";
2025-02-11 07:08:54 +00:00
import { mapGetters } from "vuex";
2025-02-01 09:34:55 +00:00
export default {
2025-02-11 07:08:54 +00:00
name: "UserAccessCustomization",
2025-02-01 09:34:55 +00:00
components: {
2025-02-11 07:08:54 +00:00
BreadCrumb: () => import("@components/BreadCrumb.vue"),
Share: () => import("@view/modal/Share.vue"),
Accordion: () => import("@permission/components/Accordion.vue"),
2025-02-01 09:34:55 +00:00
},
computed: {
2025-02-11 07:08:54 +00:00
...mapGetters(["projectGetter"]),
2025-02-01 09:34:55 +00:00
},
props: {
items: {
default() {
2025-02-11 07:08:54 +00:00
return {};
},
},
2025-02-01 09:34:55 +00:00
},
data() {
return {
section_user_id: undefined,
section_role_id: undefined,
user_id: undefined,
role_id: undefined,
loading: false,
showPanel: false,
userRoles: [],
sections: [],
selectedItem: {},
showModal: false,
typingTimer: 0,
doneTypingInterval: 1000,
collapseAll: false,
editMode: false,
searchForm: {
2025-02-11 07:08:54 +00:00
query: "",
replaceWith: "",
2025-02-01 09:34:55 +00:00
wholeWord: false,
},
};
},
methods: {
getUserPermission() {
this.user_id = this.selectedItem.user.id;
},
fullName(user) {
2025-02-11 07:08:54 +00:00
if (user.name && user.lastname) return user.name + " " + user.lastname;
else if (user.name && !user.lastname) return user.name;
else if (!user.name && user.lastname) return user.lastname;
return "بدون نام";
2025-02-01 09:34:55 +00:00
},
2025-02-11 07:08:54 +00:00
deleteItem() {},
2025-02-01 09:34:55 +00:00
getUserRole() {
2025-02-11 07:08:54 +00:00
ApiService.formData(apis.permissions.listUserRole, {
project_id: this.projectGetter?.id,
})
.then((response) => {
this.userRoles = response.data.data;
})
.catch((err) => {})
.finally(() => {
this.loading = false;
});
2025-02-01 09:34:55 +00:00
},
save() {
// actions
},
toggleRolesPanel(userRolesIndex = 0) {
2025-02-11 07:08:54 +00:00
this.getSections().then((res) => {
2025-02-01 09:34:55 +00:00
this.sections = res.data.data;
this.role_id = this.userRoles[userRolesIndex].role_id ?? undefined;
this.user_id = this.userRoles[userRolesIndex].user.id ?? undefined;
this.showPanel = true;
2025-02-11 07:08:54 +00:00
});
2025-02-01 09:34:55 +00:00
},
getSections() {
2025-02-11 07:08:54 +00:00
return ApiService.formData(apis.sections.list, {
project_id: this.projectGetter?.id,
});
2025-02-01 09:34:55 +00:00
},
collapseAllPanels() {
this.collapseAll = true;
},
expandAllPanels() {
this.collapseAll = false;
},
sendQuery() {
// todo: show loading.
// todo: send query and show result.
// todo: hide loading.
clearTimeout(this.typingTimer);
this.typingTimer = setTimeout(() => {
this.highLight();
}, this.doneTypingInterval);
},
onKeyDown() {
clearTimeout(this.typingTimer);
},
},
mounted() {
this.getUserRole();
// this.cloneItems = structuredClone(this.items);
},
watch: {
projectGetter() {
this.showPanel = false;
this.getUserRole();
2025-02-11 07:08:54 +00:00
},
},
};
2025-02-01 09:34:55 +00:00
</script>
2025-02-11 07:08:54 +00:00
<style scoped lang="scss"></style>