|
| 1 | +<script setup> |
| 2 | +import { ref } from "vue" |
| 3 | +import { useI18n } from "vue-i18n" |
| 4 | +import { useRouter } from "vue-router" |
| 5 | +import SectionHeader from "../../components/layout/SectionHeader.vue" |
| 6 | +import BaseButton from "../../components/basecomponents/BaseButton.vue" |
| 7 | +import BaseToolbar from "../../components/basecomponents/BaseToolbar.vue" |
| 8 | +import BaseSelect from "../../components/basecomponents/BaseSelect.vue" |
| 9 | +import BaseTable from "../../components/basecomponents/BaseTable.vue" |
| 10 | +import baseService from "../../services/baseService" |
| 11 | +import { findAll as listAccessUrl } from "../../services/accessurlService" |
| 12 | +import userService from "../../services/userService" |
| 13 | +import { useNotification } from "../../composables/notification" |
| 14 | +
|
| 15 | +const { t } = useI18n() |
| 16 | +const router = useRouter() |
| 17 | +
|
| 18 | +const { showErrorNotification, showSuccessNotification } = useNotification() |
| 19 | +
|
| 20 | +const accessUrlList = ref([]) |
| 21 | +const authSourceList = ref([]) |
| 22 | +const userList = ref([]) |
| 23 | +const userListTotal = ref(0) |
| 24 | +
|
| 25 | +const accessUrl = ref(null) |
| 26 | +const authSource = ref(null) |
| 27 | +const selectedUsers = ref([]) |
| 28 | +const isLoadingUserList = ref(true) |
| 29 | +const isLoadingAssign = ref(false) |
| 30 | +
|
| 31 | +async function listAuthSourcesByAccessUrl({ value: accessUrlIri }) { |
| 32 | + authSourceList.value = [] |
| 33 | + authSource.value = null |
| 34 | +
|
| 35 | + try { |
| 36 | + const data = await baseService.get("/access-url/auth-sources/list", { access_url: accessUrlIri }) |
| 37 | +
|
| 38 | + authSourceList.value = data.map((methodName) => ({ label: methodName, value: methodName })) |
| 39 | + } catch (error) { |
| 40 | + showErrorNotification(error) |
| 41 | + } |
| 42 | +} |
| 43 | +
|
| 44 | +async function listUsers({ page, rows }) { |
| 45 | + isLoadingUserList.value = true |
| 46 | +
|
| 47 | + try { |
| 48 | + const { totalItems, items } = await userService.findAll({ |
| 49 | + page: page + 1, |
| 50 | + itemsPerPage: rows, |
| 51 | + }) |
| 52 | +
|
| 53 | + userListTotal.value = totalItems |
| 54 | + userList.value = items |
| 55 | + } catch (error) { |
| 56 | + showErrorNotification(error) |
| 57 | + } finally { |
| 58 | + isLoadingUserList.value = false |
| 59 | + } |
| 60 | +} |
| 61 | +
|
| 62 | +async function onPage({ page, rows }) { |
| 63 | + await listUsers({ page, rows }) |
| 64 | +} |
| 65 | +
|
| 66 | +async function assignAuthSources() { |
| 67 | + isLoadingAssign.value = true |
| 68 | +
|
| 69 | + try { |
| 70 | + await baseService.post( |
| 71 | + "/access-url/auth-sources/assign", |
| 72 | + { |
| 73 | + users: selectedUsers.value.map((userInfo) => userInfo["@id"]), |
| 74 | + auth_source: authSource.value, |
| 75 | + access_url: accessUrl.value, |
| 76 | + }, |
| 77 | + true, |
| 78 | + ) |
| 79 | +
|
| 80 | + showSuccessNotification(t("Auth sources assigned successfully")) |
| 81 | +
|
| 82 | + selectedUsers.value = [] |
| 83 | + } catch (e) { |
| 84 | + showErrorNotification(e) |
| 85 | + } finally { |
| 86 | + isLoadingAssign.value = false |
| 87 | + } |
| 88 | +} |
| 89 | +
|
| 90 | +listAccessUrl().then((items) => (accessUrlList.value = items)) |
| 91 | +listUsers({ page: 0, rows: 20 }) |
| 92 | +</script> |
| 93 | + |
| 94 | +<template> |
| 95 | + <SectionHeader :title="t('Assign auth sources to users')" /> |
| 96 | + |
| 97 | + <BaseToolbar> |
| 98 | + <template #start> |
| 99 | + <BaseButton |
| 100 | + :title="t('Back to user assignment page')" |
| 101 | + icon="back" |
| 102 | + only-icon |
| 103 | + type="black" |
| 104 | + @click="router.back()" |
| 105 | + /> |
| 106 | + </template> |
| 107 | + </BaseToolbar> |
| 108 | + |
| 109 | + <div class="grid grid-flow-row-dense md:grid-cols-3 gap-4"> |
| 110 | + <div class="md:col-span-2"> |
| 111 | + <BaseTable |
| 112 | + v-model:selected-items="selectedUsers" |
| 113 | + :is-loading="isLoadingUserList" |
| 114 | + :total-items="userListTotal" |
| 115 | + :values="userList" |
| 116 | + data-key="@id" |
| 117 | + lazy |
| 118 | + @page="onPage" |
| 119 | + > |
| 120 | + <Column selectionMode="multiple" /> |
| 121 | + |
| 122 | + <Column |
| 123 | + field="fullName" |
| 124 | + :header="t('Full name')" |
| 125 | + /> |
| 126 | + </BaseTable> |
| 127 | + </div> |
| 128 | + |
| 129 | + <div> |
| 130 | + <BaseSelect |
| 131 | + id="access_url" |
| 132 | + v-model="accessUrl" |
| 133 | + :disabled="0 === accessUrlList.length" |
| 134 | + :label="t('Access URL')" |
| 135 | + :options="accessUrlList" |
| 136 | + option-label="url" |
| 137 | + option-value="@id" |
| 138 | + @change="listAuthSourcesByAccessUrl" |
| 139 | + /> |
| 140 | + |
| 141 | + <BaseSelect |
| 142 | + id="auth_source" |
| 143 | + v-model="authSource" |
| 144 | + :disabled="0 === authSourceList.length" |
| 145 | + :label="t('Auth source')" |
| 146 | + :options="authSourceList" |
| 147 | + /> |
| 148 | + |
| 149 | + <BaseButton |
| 150 | + :disabled="!accessUrl || !authSource || 0 === selectedUsers.length || isLoadingAssign" |
| 151 | + :is-loading="isLoadingAssign" |
| 152 | + :label="t('Assign')" |
| 153 | + icon="save" |
| 154 | + type="primary" |
| 155 | + @click="assignAuthSources" |
| 156 | + /> |
| 157 | + </div> |
| 158 | + </div> |
| 159 | +</template> |
0 commit comments