@tager/admin-administrators 0.2.6 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/constants/paths.d.ts +6 -6
  2. package/dist/constants/routes.d.ts +5 -5
  3. package/dist/dev/App.vue.d.ts +5 -0
  4. package/dist/dev/config.d.ts +2 -0
  5. package/dist/dev/env.d.ts +1 -0
  6. package/dist/dev/main.d.ts +3 -0
  7. package/dist/index.mjs +940 -0
  8. package/dist/locales/apply.d.ts +1 -0
  9. package/dist/locales/en.d.ts +44 -41
  10. package/dist/locales/ru.d.ts +2 -3
  11. package/dist/main.d.ts +3 -3
  12. package/dist/services/requests.d.ts +36 -32
  13. package/dist/style.css +1 -0
  14. package/dist/typings/model.d.ts +27 -25
  15. package/dist/utils/paths.d.ts +8 -8
  16. package/dist/views/AdminForm/AdminForm.helpers.d.ts +15 -14
  17. package/dist/views/AdminForm/AdminForm.vue.d.ts +2686 -61
  18. package/dist/views/AdminForm/index.d.ts +1 -1
  19. package/dist/views/AdminList/AdminList.vue.d.ts +14 -33
  20. package/dist/views/AdminList/index.d.ts +1 -1
  21. package/dist/views/RoleForm/RoleForm.helpers.d.ts +13 -13
  22. package/dist/views/RoleForm/RoleForm.vue.d.ts +24 -59
  23. package/dist/views/RoleForm/index.d.ts +1 -1
  24. package/dist/views/RoleList/RoleList.vue.d.ts +20 -46
  25. package/dist/views/RoleList/index.d.ts +1 -1
  26. package/package.json +52 -50
  27. package/src/constants/routes.ts +19 -19
  28. package/src/dev/App.vue +57 -0
  29. package/src/dev/config.ts +23 -0
  30. package/src/dev/env.ts +17 -0
  31. package/src/dev/main.ts +50 -0
  32. package/src/locales/apply.ts +9 -0
  33. package/src/locales/en.ts +6 -3
  34. package/src/locales/ru.ts +6 -4
  35. package/src/main.ts +5 -9
  36. package/src/services/requests.ts +13 -0
  37. package/src/typings/model.ts +3 -0
  38. package/src/views/AdminForm/AdminForm.helpers.ts +10 -3
  39. package/src/views/AdminForm/AdminForm.vue +136 -43
  40. package/src/views/AdminList/AdminList.vue +54 -49
  41. package/src/views/RoleForm/RoleForm.vue +86 -81
  42. package/src/views/RoleList/RoleList.vue +78 -64
  43. package/CHANGELOG.md +0 -0
  44. package/dist/dev.d.ts +0 -1
  45. package/dist/index.esm.js +0 -1336
  46. package/dist/index.umd.js +0 -1359
  47. package/src/config/config.json +0 -20
  48. package/src/dev.ts +0 -51
  49. package/src/typings/sfc.d.ts +0 -12
  50. package/src/typings/shims-tsx.d.ts +0 -13
  51. package/src/typings/shims-vue.d.ts +0 -11
  52. package/src/views/App.vue +0 -52
package/dist/index.mjs ADDED
@@ -0,0 +1,940 @@
1
+ import { i18n, request, useI18n, useResourceDelete, createId, useToast, useResource, notEmpty, navigateBack, convertRequestErrorToMap } from "@tager/admin-services";
2
+ import { defineComponent, onMounted, resolveComponent, openBlock, createBlock, withCtx, createVNode, createElementVNode, createElementBlock, Fragment, renderList, toDisplayString, createCommentVNode, computed, ref, watch, withModifiers } from "vue";
3
+ import { DataTable, BaseButton, DeleteIcon, EditIcon, useDataTable, TabList, FormFooter, FormField, FormFieldMultiSelect } from "@tager/admin-ui";
4
+ import { universalFieldUtils, DynamicField } from "@tager/admin-dynamic-field";
5
+ import { compile } from "path-to-regexp";
6
+ import { Page } from "@tager/admin-layout";
7
+ import { useRoute, useRouter } from "vue-router";
8
+ const EN = {
9
+ home: "Home",
10
+ administrators: "Administrators",
11
+ role: "Role",
12
+ roles: "Roles",
13
+ admin: "Admin",
14
+ admins: "Admins",
15
+ createRole: "Create role",
16
+ createAdmin: "Create admin",
17
+ createAdministrator: "Create administrator",
18
+ edit: "Edit",
19
+ delete: "Delete",
20
+ email: "Email",
21
+ actions: "Actions",
22
+ updateRole: "Update role",
23
+ updateAdmin: "Update admin",
24
+ password: "Password",
25
+ newPassword: "New password",
26
+ name: "Name",
27
+ success: "Success",
28
+ adminSuccessfullyCreated: "Admin successfully created",
29
+ adminSuccessfullyUpdated: "Admin successfully updated",
30
+ error: "Error",
31
+ adminCreationError: "Admin creation error",
32
+ adminUpdateError: "Admin update error",
33
+ listOfRoles: "List of roles",
34
+ addRole: "Add role",
35
+ noPrivileges: "No privileges",
36
+ privileges: "Privileges",
37
+ all: "All",
38
+ roleSuccessfullyCreated: "Role successfully created",
39
+ roleSuccessfullyUpdate: "Role successfully update",
40
+ roleCreationError: "Role creation error",
41
+ roleUpdateError: "Role update error",
42
+ adminList: "Admin List",
43
+ adminForm: "Admin form",
44
+ roleList: "Role List",
45
+ roleForm: "Role form",
46
+ andMorePrivilege: "and more {{count}} privilege...",
47
+ tabs: {
48
+ general: "General",
49
+ params: "Template"
50
+ }
51
+ };
52
+ const RU = {
53
+ home: "\u0413\u043B\u0430\u0432\u043D\u0430\u044F",
54
+ administrators: "\u0410\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u044B",
55
+ role: "\u0420\u043E\u043B\u044C",
56
+ roles: "\u0420\u043E\u043B\u0438",
57
+ admin: "\u0410\u0434\u043C\u0438\u043D",
58
+ admins: "\u0410\u0434\u043C\u0438\u043D\u044B",
59
+ createRole: "\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0440\u043E\u043B\u044C",
60
+ createAdmin: "\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0430\u0434\u043C\u0438\u043D\u0430",
61
+ createAdministrator: "\u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430",
62
+ edit: "\u0420\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C",
63
+ delete: "\u0423\u0434\u0430\u043B\u0438\u0442\u044C",
64
+ email: "\u042D\u043B\u0435\u043A\u0442\u0440\u043E\u043D\u043D\u0430\u044F \u043F\u043E\u0447\u0442\u0430",
65
+ actions: "\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u044F",
66
+ updateRole: "\u041E\u0431\u043D\u043E\u0432\u0438\u0442\u044C \u0440\u043E\u043B\u044C",
67
+ updateAdmin: "\u041E\u0431\u043D\u043E\u0432\u0438\u0442\u044C \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430",
68
+ password: "\u041F\u0430\u0440\u043E\u043B\u044C",
69
+ newPassword: "\u041D\u043E\u0432\u044B\u0439 \u043F\u0430\u0440\u043E\u043B\u044C",
70
+ name: "\u0418\u043C\u044F",
71
+ success: "\u0423\u0441\u043F\u0435\u0445",
72
+ adminSuccessfullyCreated: "\u0410\u0434\u043C\u0438\u043D \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u0441\u043E\u0437\u0434\u0430\u043D",
73
+ adminSuccessfullyUpdated: "\u0410\u0434\u043C\u0438\u043D \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D",
74
+ error: "\u041E\u0448\u0438\u0431\u043A\u0430",
75
+ adminCreationError: "\u041E\u0448\u0438\u0431\u043A\u0430 \u0441\u043E\u0437\u0434\u0430\u043D\u0438\u044F \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430",
76
+ adminUpdateError: "\u041E\u0448\u0438\u0431\u043A\u0430 \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430",
77
+ listOfRoles: "\u0421\u043F\u0438\u0441\u043E\u043A \u0440\u043E\u043B\u0435\u0439",
78
+ addRole: "\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C \u0440\u043E\u043B\u044C",
79
+ noPrivileges: "\u0411\u0435\u0437 \u043F\u0440\u0438\u0432\u0438\u043B\u0435\u0433\u0438\u0439",
80
+ privileges: "\u041F\u0440\u0438\u0432\u0438\u043B\u0435\u0433\u0438\u0438",
81
+ all: "\u0412\u0441\u0435",
82
+ roleSuccessfullyCreated: "\u0420\u043E\u043B\u044C \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u0441\u043E\u0437\u0434\u0430\u043D\u0430",
83
+ roleSuccessfullyUpdate: "\u0420\u043E\u043B\u044C \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0430",
84
+ roleCreationError: "\u041E\u0448\u0438\u0431\u043A\u0430 \u0441\u043E\u0437\u0434\u0430\u043D\u0438\u044F \u0440\u043E\u043B\u0438",
85
+ roleUpdateError: "\u041E\u0448\u0438\u0431\u043A\u0430 \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u044F \u0440\u043E\u043B\u0438",
86
+ adminList: "\u0421\u043F\u0438\u0441\u043E\u043A \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u043E\u0432",
87
+ adminForm: "\u0424\u043E\u0440\u043C\u0430 \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430",
88
+ roleList: "\u0421\u043F\u0438\u0441\u043E\u043A \u0440\u043E\u043B\u0435\u0439",
89
+ roleForm: "\u0424\u043E\u0440\u043C\u0430 \u0440\u043E\u043B\u0438",
90
+ andMorePrivilege: "\u0438 \u0435\u0449\u0435 {{count}} \u043F\u0440\u0438\u0432\u0438\u043B\u0435\u0433\u0438\u0439...",
91
+ tabs: {
92
+ general: "\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0435",
93
+ params: "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B"
94
+ }
95
+ };
96
+ function applyTranslations() {
97
+ i18n.addTranslations("en", "administrators", EN);
98
+ i18n.addTranslations("ru", "administrators", RU);
99
+ }
100
+ function getFieldList() {
101
+ return request.get({ path: "/admin/admins/fields" });
102
+ }
103
+ function getRoleList() {
104
+ return request.get({ path: "/admin/rbac/roles" });
105
+ }
106
+ function getRole(roleId) {
107
+ return request.get({ path: `/admin/rbac/roles/${roleId}` });
108
+ }
109
+ function createRole(payload) {
110
+ return request.post({ path: "/admin/rbac/roles", body: payload });
111
+ }
112
+ function updateRole(roleId, payload) {
113
+ return request.put({ path: `/admin/rbac/roles/${roleId}`, body: payload });
114
+ }
115
+ function deleteRole(roleId) {
116
+ return request.delete({ path: `/admin/rbac/roles/${roleId}` });
117
+ }
118
+ function getScopes() {
119
+ return request.get({ path: "/admin/rbac/scopes" });
120
+ }
121
+ function getAdminList() {
122
+ return request.get({ path: "/admin/admins" });
123
+ }
124
+ function getAdmin(adminId) {
125
+ return request.get({ path: `/admin/admins/${adminId}` });
126
+ }
127
+ function createAdmin(payload) {
128
+ return request.post({ path: "/admin/admins", body: payload });
129
+ }
130
+ function updateAdmin(adminId, payload) {
131
+ return request.put({ path: `/admin/admins/${adminId}`, body: payload });
132
+ }
133
+ function deleteAdmin(adminId) {
134
+ return request.delete({ path: `/admin/admins/${adminId}` });
135
+ }
136
+ const ADMINISTRATOR_ROUTE_PATHS = {
137
+ ROLE_LIST: "/roles",
138
+ ROLE_FORM: "/roles/:roleId",
139
+ ADMIN_LIST: "/admins",
140
+ ADMIN_FORM: "/admins/:adminId"
141
+ };
142
+ function getRoleListUrl() {
143
+ return ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST;
144
+ }
145
+ function getRoleFormUrl(params) {
146
+ return compile(ADMINISTRATOR_ROUTE_PATHS.ROLE_FORM)(params);
147
+ }
148
+ function getAdminListUrl() {
149
+ return ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST;
150
+ }
151
+ function getAdminFormUrl(params) {
152
+ return compile(ADMINISTRATOR_ROUTE_PATHS.ADMIN_FORM)(params);
153
+ }
154
+ var _export_sfc = (sfc, props) => {
155
+ const target = sfc.__vccOpts || sfc;
156
+ for (const [key, val] of props) {
157
+ target[key] = val;
158
+ }
159
+ return target;
160
+ };
161
+ const _sfc_main$3 = defineComponent({
162
+ name: "AdminList",
163
+ components: {
164
+ Page,
165
+ DataTable,
166
+ BaseButton,
167
+ DeleteIcon,
168
+ EditIcon
169
+ },
170
+ setup() {
171
+ const { t } = useI18n();
172
+ const {
173
+ fetchEntityList: fetchAdminList,
174
+ isLoading: isAdminListLoading,
175
+ rowData: adminList,
176
+ errorMessage: error
177
+ } = useDataTable({
178
+ fetchEntityList: () => getAdminList(),
179
+ initialValue: [],
180
+ resourceName: "Admin list",
181
+ pageSize: 100
182
+ });
183
+ onMounted(() => {
184
+ fetchAdminList();
185
+ });
186
+ const {
187
+ handleResourceDelete: handleAdminDelete,
188
+ isDeleting
189
+ } = useResourceDelete({
190
+ deleteResource: deleteAdmin,
191
+ resourceName: "Admin",
192
+ onSuccess: fetchAdminList
193
+ });
194
+ function isBusy(adminId) {
195
+ return isDeleting(adminId) || isAdminListLoading.value;
196
+ }
197
+ const columnDefs = [
198
+ {
199
+ id: 1,
200
+ name: t("administrators:admin"),
201
+ field: "name"
202
+ },
203
+ {
204
+ id: 2,
205
+ name: t("administrators:email"),
206
+ field: "email"
207
+ },
208
+ {
209
+ id: 3,
210
+ name: t("administrators:roles"),
211
+ field: "roles"
212
+ },
213
+ {
214
+ id: 4,
215
+ name: t("administrators:actions"),
216
+ field: "actions",
217
+ style: { width: "180px", textAlign: "center", whiteSpace: "nowrap" },
218
+ headStyle: { width: "180px", textAlign: "center" }
219
+ }
220
+ ];
221
+ return {
222
+ t,
223
+ columnDefs,
224
+ rowData: adminList,
225
+ isRowDataLoading: isAdminListLoading,
226
+ errorMessage: error,
227
+ isBusy,
228
+ handleAdminDelete,
229
+ getAdminFormUrl
230
+ };
231
+ }
232
+ });
233
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
234
+ const _component_EditIcon = resolveComponent("EditIcon");
235
+ const _component_BaseButton = resolveComponent("BaseButton");
236
+ const _component_DeleteIcon = resolveComponent("DeleteIcon");
237
+ const _component_DataTable = resolveComponent("DataTable");
238
+ const _component_Page = resolveComponent("Page");
239
+ return openBlock(), createBlock(_component_Page, {
240
+ title: _ctx.$i18n.t("administrators:administrators"),
241
+ "header-buttons": [
242
+ {
243
+ text: _ctx.$i18n.t("administrators:createAdministrator"),
244
+ href: _ctx.getAdminFormUrl({ adminId: "create" })
245
+ }
246
+ ]
247
+ }, {
248
+ default: withCtx(() => [
249
+ createVNode(_component_DataTable, {
250
+ "column-defs": _ctx.columnDefs,
251
+ "row-data": _ctx.rowData,
252
+ loading: _ctx.isRowDataLoading,
253
+ "error-message": _ctx.errorMessage
254
+ }, {
255
+ "cell(roles)": withCtx(({ row }) => [
256
+ createElementVNode("ul", null, [
257
+ (openBlock(true), createElementBlock(Fragment, null, renderList(row.roles, (role) => {
258
+ return openBlock(), createElementBlock("li", {
259
+ key: role.id
260
+ }, toDisplayString(role.name), 1);
261
+ }), 128))
262
+ ])
263
+ ]),
264
+ "cell(actions)": withCtx(({ row }) => [
265
+ !row.isSelf ? (openBlock(), createBlock(_component_BaseButton, {
266
+ key: 0,
267
+ variant: "icon",
268
+ title: _ctx.$i18n.t("administrators:edit"),
269
+ disabled: _ctx.isBusy(row.id),
270
+ href: _ctx.getAdminFormUrl({ adminId: row.id })
271
+ }, {
272
+ default: withCtx(() => [
273
+ createVNode(_component_EditIcon)
274
+ ]),
275
+ _: 2
276
+ }, 1032, ["title", "disabled", "href"])) : createCommentVNode("", true),
277
+ !row.isSuperAdmin || !row.isSelf ? (openBlock(), createBlock(_component_BaseButton, {
278
+ key: 1,
279
+ variant: "icon",
280
+ title: _ctx.$i18n.t("administrators:delete"),
281
+ disabled: _ctx.isBusy(row.id),
282
+ onClick: ($event) => _ctx.handleAdminDelete(row.id)
283
+ }, {
284
+ default: withCtx(() => [
285
+ createVNode(_component_DeleteIcon)
286
+ ]),
287
+ _: 2
288
+ }, 1032, ["title", "disabled", "onClick"])) : createCommentVNode("", true)
289
+ ]),
290
+ _: 1
291
+ }, 8, ["column-defs", "row-data", "loading", "error-message"])
292
+ ]),
293
+ _: 1
294
+ }, 8, ["title", "header-buttons"]);
295
+ }
296
+ var AdminList = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
297
+ function convertAdminToFormValues(admin, roleOptionList) {
298
+ if (!admin) {
299
+ return {
300
+ name: "",
301
+ email: "",
302
+ password: createId(),
303
+ roles: []
304
+ };
305
+ }
306
+ const currentRoleOptionList = roleOptionList.filter((role) => admin.roles.some((roles) => roles.id === role.value));
307
+ return {
308
+ name: admin.name,
309
+ email: admin.email,
310
+ password: "",
311
+ roles: currentRoleOptionList
312
+ };
313
+ }
314
+ function convertFormValuesToAdminUpdatePayload(values, paramsValues = []) {
315
+ return {
316
+ name: values.name,
317
+ email: values.email,
318
+ roles: values.roles.map((role) => role.value),
319
+ password: values.password,
320
+ params: paramsValues.map((field) => ({
321
+ value: universalFieldUtils.getOutgoingValue(field),
322
+ name: field.config.name
323
+ }))
324
+ };
325
+ }
326
+ function convertFormValuesToAdminCreationPayload(values, paramsValues = []) {
327
+ return {
328
+ ...convertFormValuesToAdminUpdatePayload(values, paramsValues)
329
+ };
330
+ }
331
+ function convertRoleListToOptions(roleList) {
332
+ return roleList.map((role) => ({
333
+ value: role.id,
334
+ label: role.name
335
+ }));
336
+ }
337
+ const _sfc_main$2 = defineComponent({
338
+ name: "AdminForm",
339
+ components: {
340
+ DynamicField,
341
+ TabList,
342
+ Page,
343
+ FormFooter,
344
+ FormField,
345
+ FormFieldMultiSelect
346
+ },
347
+ setup() {
348
+ const { t } = useI18n();
349
+ const route = useRoute();
350
+ const router = useRouter();
351
+ const toast = useToast();
352
+ const adminId = computed(() => route.params.adminId);
353
+ const isCreation = computed(() => adminId.value === "create");
354
+ const [fetchAdmin, { data: admin, loading: isAdminLoading }] = useResource({
355
+ fetchResource: () => getAdmin(adminId.value),
356
+ initialValue: null,
357
+ resourceName: "Admin"
358
+ });
359
+ const [fetchRoleList, { data: roleList, loading: isRoleListLoading }] = useResource({
360
+ fetchResource: getRoleList,
361
+ initialValue: [],
362
+ resourceName: "Role List"
363
+ });
364
+ const [fetchFieldList, { data: fieldList, loading: isFieldListLoading }] = useResource({
365
+ fetchResource: getFieldList,
366
+ initialValue: [],
367
+ resourceName: "Field List"
368
+ });
369
+ onMounted(() => {
370
+ fetchRoleList();
371
+ fetchFieldList();
372
+ updateTemplateValues();
373
+ if (isCreation.value)
374
+ return;
375
+ fetchAdmin();
376
+ });
377
+ const roleOptionList = computed(() => convertRoleListToOptions(roleList.value));
378
+ const values = ref(convertAdminToFormValues(admin.value, roleOptionList.value));
379
+ const errors = ref({});
380
+ const isSubmitting = ref(false);
381
+ watch([admin, roleOptionList], () => {
382
+ values.value = convertAdminToFormValues(admin.value, roleOptionList.value);
383
+ });
384
+ function submitForm(event) {
385
+ if (admin.value && admin.value.isSelf)
386
+ return;
387
+ const creationBody = convertFormValuesToAdminCreationPayload(values.value, templateValues.value);
388
+ const updateBody = convertFormValuesToAdminUpdatePayload(values.value, templateValues.value);
389
+ const requestPromise = isCreation.value ? createAdmin(creationBody) : updateAdmin(adminId.value, updateBody);
390
+ requestPromise.then(({ data }) => {
391
+ errors.value = {};
392
+ if (event.type === "create") {
393
+ router.push(getAdminFormUrl({ adminId: data.id }));
394
+ }
395
+ if (event.type === "create_exit" || event.type === "save_exit") {
396
+ navigateBack(router, getAdminListUrl());
397
+ }
398
+ if (event.type === "create_create-another") {
399
+ values.value = convertAdminToFormValues(null, roleOptionList.value);
400
+ }
401
+ toast.show({
402
+ variant: "success",
403
+ title: t("administrators:success"),
404
+ body: isCreation.value ? t("administrators:adminSuccessfullyCreated") : t("administrators:adminSuccessfullyUpdated")
405
+ });
406
+ }).catch((error) => {
407
+ console.error(error);
408
+ errors.value = convertRequestErrorToMap(error);
409
+ toast.show({
410
+ variant: "danger",
411
+ title: t("administrators:error"),
412
+ body: isCreation.value ? t("administrators:adminCreationError") : t("administrators:adminUpdateError")
413
+ });
414
+ }).finally(() => {
415
+ isSubmitting.value = false;
416
+ });
417
+ }
418
+ const pageTitle = computed(() => {
419
+ return isCreation.value ? t("administrators:createAdmin") : `${t("administrators:updateAdmin")} "${values.value.name}"`;
420
+ });
421
+ const isContentLoading = computed(() => isAdminLoading.value || isRoleListLoading.value || isFieldListLoading.value);
422
+ const shouldDisplayParamsTab = computed(() => fieldList.value.length > 0);
423
+ const tabList = computed(() => {
424
+ return [
425
+ { id: "general", label: t("administrators:tabs.general") },
426
+ shouldDisplayParamsTab.value ? { id: "params", label: t("administrators:tabs.params") } : null
427
+ ].filter(notEmpty);
428
+ });
429
+ const selectedTabId = ref(tabList.value[0].id);
430
+ const templateValues = ref([]);
431
+ function updateTemplateValues() {
432
+ var _a, _b;
433
+ const incomingFieldList = (_b = (_a = admin.value) == null ? void 0 : _a.params) != null ? _b : [];
434
+ templateValues.value = fieldList.value.map((fieldConfig, index) => {
435
+ var _a2;
436
+ return universalFieldUtils.createFormField(fieldConfig, (_a2 = incomingFieldList[index]) == null ? void 0 : _a2.value);
437
+ });
438
+ }
439
+ watch([admin, fieldList], () => {
440
+ updateTemplateValues();
441
+ });
442
+ return {
443
+ t,
444
+ backButtonUrl: getAdminListUrl(),
445
+ values,
446
+ errors,
447
+ isSubmitting,
448
+ submitForm,
449
+ isContentLoading,
450
+ admin,
451
+ pageTitle,
452
+ isCreation,
453
+ roleOptionList,
454
+ tabList,
455
+ selectedTabId,
456
+ templateValues
457
+ };
458
+ }
459
+ });
460
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
461
+ const _component_TabList = resolveComponent("TabList");
462
+ const _component_FormField = resolveComponent("FormField");
463
+ const _component_FormFieldMultiSelect = resolveComponent("FormFieldMultiSelect");
464
+ const _component_DynamicField = resolveComponent("DynamicField");
465
+ const _component_FormFooter = resolveComponent("FormFooter");
466
+ const _component_Page = resolveComponent("Page");
467
+ return openBlock(), createBlock(_component_Page, {
468
+ title: _ctx.pageTitle,
469
+ "is-content-loading": _ctx.isContentLoading
470
+ }, {
471
+ footer: withCtx(() => [
472
+ createVNode(_component_FormFooter, {
473
+ "back-href": _ctx.backButtonUrl,
474
+ "is-submitting": _ctx.isSubmitting,
475
+ "is-creation": _ctx.isCreation,
476
+ "can-create-another": _ctx.isCreation,
477
+ onSubmit: _ctx.submitForm
478
+ }, null, 8, ["back-href", "is-submitting", "is-creation", "can-create-another", "onSubmit"])
479
+ ]),
480
+ default: withCtx(() => [
481
+ createElementVNode("form", {
482
+ novalidate: "",
483
+ onSubmit: _cache[5] || (_cache[5] = withModifiers(() => {
484
+ }, ["prevent"]))
485
+ }, [
486
+ createVNode(_component_TabList, {
487
+ "tab-id": _ctx.selectedTabId,
488
+ "onUpdate:tab-id": _cache[0] || (_cache[0] = ($event) => _ctx.selectedTabId = $event),
489
+ "tab-list": _ctx.tabList
490
+ }, null, 8, ["tab-id", "tab-list"]),
491
+ _ctx.selectedTabId === "general" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
492
+ createVNode(_component_FormField, {
493
+ value: _ctx.values.name,
494
+ "onUpdate:value": _cache[1] || (_cache[1] = ($event) => _ctx.values.name = $event),
495
+ name: "name",
496
+ error: _ctx.errors.name,
497
+ label: _ctx.$i18n.t("administrators:name")
498
+ }, null, 8, ["value", "error", "label"]),
499
+ createVNode(_component_FormField, {
500
+ value: _ctx.values.email,
501
+ "onUpdate:value": _cache[2] || (_cache[2] = ($event) => _ctx.values.email = $event),
502
+ name: "email",
503
+ error: _ctx.errors.email,
504
+ label: _ctx.$i18n.t("administrators:email")
505
+ }, null, 8, ["value", "error", "label"]),
506
+ createVNode(_component_FormFieldMultiSelect, {
507
+ "selected-options": _ctx.values.roles,
508
+ "onUpdate:selected-options": _cache[3] || (_cache[3] = ($event) => _ctx.values.roles = $event),
509
+ name: "roles",
510
+ label: _ctx.$i18n.t("administrators:roles"),
511
+ options: _ctx.roleOptionList,
512
+ error: _ctx.errors.roles
513
+ }, null, 8, ["selected-options", "label", "options", "error"]),
514
+ createVNode(_component_FormField, {
515
+ value: _ctx.values.password,
516
+ "onUpdate:value": _cache[4] || (_cache[4] = ($event) => _ctx.values.password = $event),
517
+ name: "password",
518
+ error: _ctx.errors.password,
519
+ label: _ctx.isCreation ? _ctx.$i18n.t("administrators:password") : _ctx.$i18n.t("administrators:newPassword")
520
+ }, null, 8, ["value", "error", "label"])
521
+ ], 64)) : createCommentVNode("", true),
522
+ _ctx.selectedTabId === "params" ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.templateValues, (field) => {
523
+ return openBlock(), createBlock(_component_DynamicField, {
524
+ key: field.config.name,
525
+ field
526
+ }, null, 8, ["field"]);
527
+ }), 128)) : createCommentVNode("", true)
528
+ ], 32)
529
+ ]),
530
+ _: 1
531
+ }, 8, ["title", "is-content-loading"]);
532
+ }
533
+ var AdminForm = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
534
+ var RoleList_vue_vue_type_style_index_0_lang = "";
535
+ const _sfc_main$1 = defineComponent({
536
+ name: "RoleList",
537
+ components: {
538
+ Page,
539
+ DeleteIcon,
540
+ EditIcon,
541
+ DataTable,
542
+ BaseButton
543
+ },
544
+ setup() {
545
+ const { t } = useI18n();
546
+ const {
547
+ fetchEntityList: fetchRoleList,
548
+ isLoading: isRoleListLoading,
549
+ rowData: roleList,
550
+ errorMessage: error
551
+ } = useDataTable({
552
+ fetchEntityList: (params) => getRoleList(),
553
+ initialValue: [],
554
+ resourceName: "Role list",
555
+ pageSize: 100
556
+ });
557
+ onMounted(() => {
558
+ fetchRoleList();
559
+ });
560
+ const {
561
+ handleResourceDelete: handleRoleDelete,
562
+ isDeleting
563
+ } = useResourceDelete({
564
+ deleteResource: deleteRole,
565
+ resourceName: "Role",
566
+ onSuccess: fetchRoleList
567
+ });
568
+ function isBusy(roleId) {
569
+ return isDeleting(roleId) || isRoleListLoading.value;
570
+ }
571
+ function getScopeGroupList(scopes) {
572
+ const map = /* @__PURE__ */ new Map();
573
+ scopes.forEach((scope) => {
574
+ var _a;
575
+ const key = scope.module;
576
+ const value = (_a = map.get(key)) != null ? _a : [];
577
+ value.push(scope);
578
+ map.set(key, value);
579
+ });
580
+ return Array.from(map.entries()).map(([key, value]) => ({
581
+ module: key,
582
+ scopes: value
583
+ }));
584
+ }
585
+ function getRestScopesText(restPrivilegesCount) {
586
+ if (restPrivilegesCount === 1) {
587
+ return t("administrators:andMorePrivilege", { count: 1 });
588
+ }
589
+ if (restPrivilegesCount > 1) {
590
+ return t("administrators:andMorePrivilege", {
591
+ count: restPrivilegesCount
592
+ });
593
+ }
594
+ return "";
595
+ }
596
+ const columnDefs = [
597
+ {
598
+ id: 1,
599
+ name: t("administrators:role"),
600
+ field: "name"
601
+ },
602
+ {
603
+ id: 2,
604
+ name: t("administrators:privileges"),
605
+ field: "scope"
606
+ },
607
+ {
608
+ id: 3,
609
+ name: t("administrators:actions"),
610
+ field: "actions",
611
+ style: { width: "180px", textAlign: "center", whiteSpace: "nowrap" },
612
+ headStyle: { width: "180px", textAlign: "center" }
613
+ }
614
+ ];
615
+ return {
616
+ columnDefs,
617
+ rowData: roleList,
618
+ isRowDataLoading: isRoleListLoading,
619
+ errorMessage: error,
620
+ isBusy,
621
+ handleRoleDelete,
622
+ getRoleFormUrl,
623
+ getScopeGroupList,
624
+ getRestScopesText,
625
+ scopesPerModuleCount: 3
626
+ };
627
+ }
628
+ });
629
+ const _hoisted_1 = {
630
+ key: 0,
631
+ class: "no-scopes"
632
+ };
633
+ const _hoisted_2 = { key: 1 };
634
+ const _hoisted_3 = { class: "module-name" };
635
+ const _hoisted_4 = { class: "scope-list" };
636
+ const _hoisted_5 = {
637
+ key: 0,
638
+ class: "rest-scopes-text"
639
+ };
640
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
641
+ const _component_EditIcon = resolveComponent("EditIcon");
642
+ const _component_BaseButton = resolveComponent("BaseButton");
643
+ const _component_DeleteIcon = resolveComponent("DeleteIcon");
644
+ const _component_DataTable = resolveComponent("DataTable");
645
+ const _component_Page = resolveComponent("Page");
646
+ return openBlock(), createBlock(_component_Page, {
647
+ title: _ctx.$i18n.t("administrators:listOfRoles"),
648
+ "header-buttons": [
649
+ {
650
+ text: _ctx.$i18n.t("administrators:addRole"),
651
+ href: _ctx.getRoleFormUrl({ roleId: "create" })
652
+ }
653
+ ]
654
+ }, {
655
+ default: withCtx(() => [
656
+ createVNode(_component_DataTable, {
657
+ "column-defs": _ctx.columnDefs,
658
+ "row-data": _ctx.rowData,
659
+ loading: _ctx.isRowDataLoading,
660
+ "error-message": _ctx.errorMessage
661
+ }, {
662
+ "cell(scope)": withCtx(({ row }) => [
663
+ row.scopes.length === 0 ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(_ctx.$i18n.t("administrators:noPrivileges")), 1)) : createCommentVNode("", true),
664
+ row.isSuperAdmin ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(_ctx.$i18n.t("administrators:all")), 1)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(_ctx.getScopeGroupList(row.scopes), (scopeGroup) => {
665
+ return openBlock(), createElementBlock("div", {
666
+ key: scopeGroup.module,
667
+ class: "scope-group"
668
+ }, [
669
+ createElementVNode("span", _hoisted_3, toDisplayString(scopeGroup.module), 1),
670
+ createElementVNode("ul", _hoisted_4, [
671
+ (openBlock(true), createElementBlock(Fragment, null, renderList(scopeGroup.scopes.slice(0, _ctx.scopesPerModuleCount), (scope) => {
672
+ return openBlock(), createElementBlock("li", {
673
+ key: scope.value
674
+ }, [
675
+ createElementVNode("span", null, "\u2014 " + toDisplayString(scope.label), 1)
676
+ ]);
677
+ }), 128))
678
+ ]),
679
+ scopeGroup.scopes.length > _ctx.scopesPerModuleCount ? (openBlock(), createElementBlock("span", _hoisted_5, toDisplayString(_ctx.getRestScopesText(scopeGroup.scopes.length - _ctx.scopesPerModuleCount)), 1)) : createCommentVNode("", true)
680
+ ]);
681
+ }), 128))
682
+ ]),
683
+ "cell(actions)": withCtx(({ row }) => [
684
+ createVNode(_component_BaseButton, {
685
+ variant: "icon",
686
+ title: _ctx.$i18n.t("administrators:edit"),
687
+ disabled: _ctx.isBusy(row.id),
688
+ href: _ctx.getRoleFormUrl({ roleId: row.id })
689
+ }, {
690
+ default: withCtx(() => [
691
+ createVNode(_component_EditIcon)
692
+ ]),
693
+ _: 2
694
+ }, 1032, ["title", "disabled", "href"]),
695
+ !row.isSuperAdmin ? (openBlock(), createBlock(_component_BaseButton, {
696
+ key: 0,
697
+ variant: "icon",
698
+ title: _ctx.$i18n.t("administrators:delete"),
699
+ disabled: _ctx.isBusy(row.id),
700
+ onClick: ($event) => _ctx.handleRoleDelete(row.id)
701
+ }, {
702
+ default: withCtx(() => [
703
+ createVNode(_component_DeleteIcon)
704
+ ]),
705
+ _: 2
706
+ }, 1032, ["title", "disabled", "onClick"])) : createCommentVNode("", true)
707
+ ]),
708
+ _: 1
709
+ }, 8, ["column-defs", "row-data", "loading", "error-message"])
710
+ ]),
711
+ _: 1
712
+ }, 8, ["title", "header-buttons"]);
713
+ }
714
+ var RoleList = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
715
+ function convertRoleToFormValues(role) {
716
+ if (!role) {
717
+ return {
718
+ name: "",
719
+ scopes: [],
720
+ isSuperAdmin: false
721
+ };
722
+ }
723
+ return {
724
+ name: role.name,
725
+ scopes: role.scopes,
726
+ isSuperAdmin: role.isSuperAdmin
727
+ };
728
+ }
729
+ function convertFormValuesToRoleCreationPayload(values) {
730
+ return {
731
+ name: values.name,
732
+ scopes: values.scopes.map((scope) => scope.value)
733
+ };
734
+ }
735
+ function convertFormValuesToRoleUpdatePayload(values) {
736
+ return {
737
+ ...convertFormValuesToRoleCreationPayload(values)
738
+ };
739
+ }
740
+ function convertScopeDataToOptions(scopeData) {
741
+ if (!scopeData)
742
+ return [];
743
+ return scopeData.groups.map((group) => group.scopes.map((scope) => ({
744
+ value: scope.value,
745
+ label: `${group.name}: ${scope.label}`
746
+ }))).flat();
747
+ }
748
+ var RoleForm_vue_vue_type_style_index_0_scoped_true_lang = "";
749
+ const _sfc_main = defineComponent({
750
+ name: "RoleForm",
751
+ components: { Page, FormFooter, FormField, FormFieldMultiSelect },
752
+ setup() {
753
+ const { t } = useI18n();
754
+ const route = useRoute();
755
+ const router = useRouter();
756
+ const toast = useToast();
757
+ const roleId = computed(() => route.params.roleId);
758
+ const isCreation = computed(() => roleId.value === "create");
759
+ const [fetchRole, { data: role, loading: isRoleLoading }] = useResource({
760
+ fetchResource: () => getRole(roleId.value),
761
+ initialValue: null,
762
+ resourceName: "Role"
763
+ });
764
+ const [
765
+ fetchScopeData,
766
+ { data: scopeData, loading: isScopeDataLoading }
767
+ ] = useResource({
768
+ fetchResource: getScopes,
769
+ initialValue: null,
770
+ resourceName: "Scope list"
771
+ });
772
+ onMounted(() => {
773
+ fetchScopeData();
774
+ if (isCreation.value)
775
+ return;
776
+ fetchRole();
777
+ });
778
+ const scopeOptionList = computed(() => convertScopeDataToOptions(scopeData.value));
779
+ const values = ref(convertRoleToFormValues(role.value));
780
+ const errors = ref({});
781
+ const isSubmitting = ref(false);
782
+ watch(role, () => {
783
+ values.value = convertRoleToFormValues(role.value);
784
+ });
785
+ function submitForm(event) {
786
+ const creationBody = convertFormValuesToRoleCreationPayload(values.value);
787
+ const updateBody = convertFormValuesToRoleUpdatePayload(values.value);
788
+ const requestPromise = isCreation.value ? createRole(creationBody) : updateRole(roleId.value, updateBody);
789
+ requestPromise.then(({ data }) => {
790
+ errors.value = {};
791
+ if (event.type === "create") {
792
+ router.push(getRoleFormUrl({ roleId: data.id }));
793
+ }
794
+ if (event.type === "create_exit" || event.type === "save_exit") {
795
+ navigateBack(router, getRoleListUrl());
796
+ }
797
+ if (event.type === "create_create-another") {
798
+ values.value = convertRoleToFormValues(null);
799
+ }
800
+ toast.show({
801
+ variant: "success",
802
+ title: t("administrators:success"),
803
+ body: isCreation.value ? t("administrators:roleSuccessfullyCreated") : t("administrators:roleSuccessfullyUpdate")
804
+ });
805
+ }).catch((error) => {
806
+ console.error(error);
807
+ errors.value = convertRequestErrorToMap(error);
808
+ toast.show({
809
+ variant: "danger",
810
+ title: t("administrators:error"),
811
+ body: isCreation.value ? t("administrators:roleCreationError") : t("administrators:roleUpdateError")
812
+ });
813
+ }).finally(() => {
814
+ isSubmitting.value = false;
815
+ });
816
+ }
817
+ const pageTitle = computed(() => {
818
+ return isCreation.value ? t("administrators:createRole") : `${t("administrators:updateRole")} "${values.value.name}"`;
819
+ });
820
+ const isContentLoading = computed(() => isRoleLoading.value || isScopeDataLoading.value);
821
+ return {
822
+ backButtonUrl: getRoleListUrl(),
823
+ values,
824
+ errors,
825
+ isSubmitting,
826
+ submitForm,
827
+ isContentLoading,
828
+ role,
829
+ pageTitle,
830
+ isCreation,
831
+ scopeOptionList
832
+ };
833
+ }
834
+ });
835
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
836
+ const _component_FormField = resolveComponent("FormField");
837
+ const _component_FormFieldMultiSelect = resolveComponent("FormFieldMultiSelect");
838
+ const _component_FormFooter = resolveComponent("FormFooter");
839
+ const _component_Page = resolveComponent("Page");
840
+ return openBlock(), createBlock(_component_Page, {
841
+ title: _ctx.pageTitle,
842
+ "is-content-loading": _ctx.isContentLoading
843
+ }, {
844
+ footer: withCtx(() => [
845
+ createVNode(_component_FormFooter, {
846
+ "back-href": _ctx.backButtonUrl,
847
+ onSubmit: _ctx.submitForm,
848
+ "is-submitting": _ctx.isSubmitting,
849
+ "is-creation": _ctx.isCreation,
850
+ "can-create-another": _ctx.isCreation
851
+ }, null, 8, ["back-href", "onSubmit", "is-submitting", "is-creation", "can-create-another"])
852
+ ]),
853
+ default: withCtx(() => [
854
+ createElementVNode("form", {
855
+ novalidate: "",
856
+ onSubmit: _cache[2] || (_cache[2] = withModifiers(() => {
857
+ }, ["prevent"]))
858
+ }, [
859
+ createVNode(_component_FormField, {
860
+ value: _ctx.values.name,
861
+ "onUpdate:value": _cache[0] || (_cache[0] = ($event) => _ctx.values.name = $event),
862
+ name: "name",
863
+ error: _ctx.errors.name,
864
+ label: _ctx.$i18n.t("administrators:name")
865
+ }, null, 8, ["value", "error", "label"]),
866
+ !_ctx.values.isSuperAdmin ? (openBlock(), createBlock(_component_FormFieldMultiSelect, {
867
+ key: 0,
868
+ "selected-options": _ctx.values.scopes,
869
+ "onUpdate:selected-options": _cache[1] || (_cache[1] = ($event) => _ctx.values.scopes = $event),
870
+ name: "scopes",
871
+ label: _ctx.$i18n.t("administrators:privileges"),
872
+ options: _ctx.scopeOptionList,
873
+ error: _ctx.errors.scopes
874
+ }, null, 8, ["selected-options", "label", "options", "error"])) : createCommentVNode("", true)
875
+ ], 32)
876
+ ]),
877
+ _: 1
878
+ }, 8, ["title", "is-content-loading"]);
879
+ }
880
+ var RoleForm = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-501ddc14"]]);
881
+ const ADMIN_LIST_ROUTE = {
882
+ path: ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST,
883
+ component: AdminList,
884
+ name: "AdminList",
885
+ meta: {
886
+ getBreadcrumbs: (route, i18n2) => [
887
+ { url: "/", text: i18n2.t("administrators:home") },
888
+ {
889
+ url: ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST,
890
+ text: i18n2.t("administrators:adminList")
891
+ }
892
+ ]
893
+ }
894
+ };
895
+ const ADMIN_FORM_ROUTE = {
896
+ path: ADMINISTRATOR_ROUTE_PATHS.ADMIN_FORM,
897
+ component: AdminForm,
898
+ name: "AdminForm",
899
+ meta: {
900
+ getBreadcrumbs: (route, i18n2) => [
901
+ { url: "/", text: i18n2.t("administrators:home") },
902
+ {
903
+ url: ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST,
904
+ text: i18n2.t("administrators:adminList")
905
+ },
906
+ { url: route.path, text: i18n2.t("administrators:adminForm") }
907
+ ]
908
+ }
909
+ };
910
+ const ROLE_LIST_ROUTE = {
911
+ path: ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST,
912
+ component: RoleList,
913
+ name: "RoleList",
914
+ meta: {
915
+ getBreadcrumbs: (route, i18n2) => [
916
+ { url: "/", text: i18n2.t("administrators:home") },
917
+ {
918
+ url: ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST,
919
+ text: i18n2.t("administrators:roleList")
920
+ }
921
+ ]
922
+ }
923
+ };
924
+ const ROLE_FORM_ROUTE = {
925
+ path: ADMINISTRATOR_ROUTE_PATHS.ROLE_FORM,
926
+ component: RoleForm,
927
+ name: "RoleForm",
928
+ meta: {
929
+ getBreadcrumbs: (route, i18n2) => [
930
+ { url: "/", text: i18n2.t("administrators:home") },
931
+ {
932
+ url: ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST,
933
+ text: i18n2.t("administrators:roleList")
934
+ },
935
+ { url: route.path, text: i18n2.t("administrators:roleForm") }
936
+ ]
937
+ }
938
+ };
939
+ applyTranslations();
940
+ export { ADMIN_FORM_ROUTE, ADMIN_LIST_ROUTE, ROLE_FORM_ROUTE, ROLE_LIST_ROUTE, createAdmin, createRole, deleteAdmin, deleteRole, getAdmin, getAdminFormUrl, getAdminList, getAdminListUrl, getFieldList, getRole, getRoleFormUrl, getRoleList, getRoleListUrl, getScopes, updateAdmin, updateRole };