@tager/admin-administrators 0.2.5 → 1.0.0

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 (49) 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 +875 -0
  8. package/dist/locales/apply.d.ts +1 -0
  9. package/dist/locales/en.d.ts +40 -40
  10. package/dist/locales/ru.d.ts +2 -3
  11. package/dist/main.d.ts +3 -3
  12. package/dist/services/requests.d.ts +32 -32
  13. package/dist/style.css +1 -0
  14. package/dist/typings/model.d.ts +25 -25
  15. package/dist/utils/paths.d.ts +8 -8
  16. package/dist/views/AdminForm/AdminForm.helpers.d.ts +14 -14
  17. package/dist/views/AdminForm/AdminForm.vue.d.ts +26 -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 +51 -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 +46 -0
  32. package/src/locales/apply.ts +9 -0
  33. package/src/locales/en.ts +2 -3
  34. package/src/locales/ru.ts +40 -41
  35. package/src/main.ts +5 -9
  36. package/src/views/AdminForm/AdminForm.vue +99 -96
  37. package/src/views/AdminList/AdminList.vue +54 -49
  38. package/src/views/RoleForm/RoleForm.vue +86 -81
  39. package/src/views/RoleList/RoleList.vue +78 -64
  40. package/CHANGELOG.md +0 -0
  41. package/dist/dev.d.ts +0 -1
  42. package/dist/index.esm.js +0 -1334
  43. package/dist/index.umd.js +0 -1357
  44. package/src/config/config.json +0 -20
  45. package/src/dev.ts +0 -51
  46. package/src/typings/sfc.d.ts +0 -12
  47. package/src/typings/shims-tsx.d.ts +0 -13
  48. package/src/typings/shims-vue.d.ts +0 -11
  49. package/src/views/App.vue +0 -52
package/dist/index.esm.js DELETED
@@ -1,1334 +0,0 @@
1
- import { request, useResource, useResourceDelete, createId, convertRequestErrorToMap, i18n } from '@tager/admin-services';
2
- import { defineComponent, onMounted, computed, ref, watch } from '@vue/composition-api';
3
- import { useTranslation, FormFooter } from '@tager/admin-ui';
4
- import { compile } from 'path-to-regexp';
5
-
6
- const EN = {
7
- administrators: 'Administrators',
8
- role: 'Role',
9
- roles: 'Roles',
10
- admin: 'Admin',
11
- admins: 'Admins',
12
- createRole: 'Create role',
13
- createAdmin: 'Create admin',
14
- createAdministrator: 'Create administrator',
15
- edit: 'Edit',
16
- delete: 'Delete',
17
- email: 'Email',
18
- actions: 'Actions',
19
- updateRole: 'Update role',
20
- updateAdmin: 'Update admin',
21
- password: 'Password',
22
- newPassword: 'New password',
23
- name: 'Name',
24
- success: 'Success',
25
- adminSuccessfullyCreated: 'Admin successfully created',
26
- adminSuccessfullyUpdated: 'Admin successfully updated',
27
- error: 'Error',
28
- adminCreationError: 'Admin creation error',
29
- adminUpdateError: 'Admin update error',
30
- listOfRoles: 'List of roles',
31
- addRole: 'Add role',
32
- noPrivileges: 'No privileges',
33
- privileges: 'Privileges',
34
- all: 'All',
35
- roleSuccessfullyCreated: 'Role successfully created',
36
- roleSuccessfullyUpdate: 'Role successfully update',
37
- roleCreationError: 'Role creation error',
38
- roleUpdateError: 'Role update error',
39
- adminList: 'Admin List',
40
- adminForm: 'Admin form',
41
- roleList: 'Role List',
42
- roleForm: 'Role form',
43
- andMorePrivilege: 'and more {{count}} privilege...',
44
- };
45
-
46
- const RU = {
47
- administrators: 'Администраторы',
48
- role: 'Роль',
49
- roles: 'Роли',
50
- admin: 'Админ',
51
- admins: 'Админы',
52
- createRole: 'Создать роль',
53
- createAdmin: 'Создать админа',
54
- createAdministrator: 'Создать администратора',
55
- edit: 'Редактировать',
56
- delete: 'Удалить',
57
- email: 'Электронная почта',
58
- actions: 'Действия',
59
- updateRole: 'Обновить роль',
60
- updateAdmin: 'Обновить администратора',
61
- password: 'Пароль',
62
- newPassword: 'Новый пароль',
63
- name: 'Имя',
64
- success: 'Успех',
65
- adminSuccessfullyCreated: 'Админ успешно создан',
66
- adminSuccessfullyUpdated: 'Админ успешно обновлен',
67
- error: 'Ошибка',
68
- adminCreationError: 'Ошибка создания администратора',
69
- adminUpdateError: 'Ошибка обновления администратора',
70
- listOfRoles: 'Список ролей',
71
- addRole: 'Добавить роль',
72
- noPrivileges: 'Без привилегий',
73
- privileges: 'Привилегии',
74
- all: 'Все',
75
- roleSuccessfullyCreated: 'Роль успешно создана',
76
- roleSuccessfullyUpdate: 'Роль успешно обновлена',
77
- roleCreationError: 'Ошибка создания роли',
78
- roleUpdateError: 'Ошибка обновления роли',
79
- adminList: 'Список администраторов',
80
- adminForm: 'Форма администратора',
81
- roleList: 'Список ролей',
82
- roleForm: 'Форма роли',
83
- andMorePrivilege: 'и еще {{count}} привилегий...',
84
- };
85
-
86
- /** Roles */
87
- function getRoleList() {
88
- return request.get({ path: '/admin/rbac/roles' });
89
- }
90
- function getRole(roleId) {
91
- return request.get({ path: `/admin/rbac/roles/${roleId}` });
92
- }
93
- function createRole(payload) {
94
- return request.post({ path: '/admin/rbac/roles', body: payload });
95
- }
96
- function updateRole(roleId, payload) {
97
- return request.put({ path: `/admin/rbac/roles/${roleId}`, body: payload });
98
- }
99
- function deleteRole(roleId) {
100
- return request.delete({ path: `/admin/rbac/roles/${roleId}` });
101
- }
102
- /** Scopes */
103
- function getScopes() {
104
- return request.get({ path: '/admin/rbac/scopes' });
105
- }
106
- /** Admin */
107
- function getAdminList() {
108
- return request.get({ path: '/admin/admins' });
109
- }
110
- function getAdmin(adminId) {
111
- return request.get({ path: `/admin/admins/${adminId}` });
112
- }
113
- function createAdmin(payload) {
114
- return request.post({ path: '/admin/admins', body: payload });
115
- }
116
- function updateAdmin(adminId, payload) {
117
- return request.put({ path: `/admin/admins/${adminId}`, body: payload });
118
- }
119
- function deleteAdmin(adminId) {
120
- return request.delete({ path: `/admin/admins/${adminId}` });
121
- }
122
-
123
- const ADMINISTRATOR_ROUTE_PATHS = {
124
- ROLE_LIST: '/roles',
125
- ROLE_FORM: '/roles/:roleId',
126
- ADMIN_LIST: '/admins',
127
- ADMIN_FORM: '/admins/:adminId',
128
- };
129
-
130
- function getRoleListUrl() {
131
- return ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST;
132
- }
133
- function getRoleFormUrl(params) {
134
- return compile(ADMINISTRATOR_ROUTE_PATHS.ROLE_FORM)(params);
135
- }
136
- function getAdminListUrl() {
137
- return ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST;
138
- }
139
- function getAdminFormUrl(params) {
140
- return compile(ADMINISTRATOR_ROUTE_PATHS.ADMIN_FORM)(params);
141
- }
142
-
143
- var script = defineComponent({
144
- name: 'AdminList',
145
- setup(props, context) {
146
- const { t } = useTranslation(context);
147
- const [fetchAdminList, { data: adminList, loading: isAdminLoading, error },] = useResource({
148
- fetchResource: getAdminList,
149
- initialValue: [],
150
- context,
151
- resourceName: 'Admin list',
152
- });
153
- onMounted(() => {
154
- fetchAdminList();
155
- });
156
- const { handleResourceDelete: handleAdminDelete, isDeleting, } = useResourceDelete({
157
- deleteResource: deleteAdmin,
158
- resourceName: 'Admin',
159
- onSuccess: fetchAdminList,
160
- context,
161
- });
162
- function isBusy(adminId) {
163
- return isDeleting(adminId) || isAdminLoading.value;
164
- }
165
- const columnDefs = [
166
- {
167
- id: 1,
168
- name: t('administrators:admin'),
169
- field: 'name',
170
- },
171
- {
172
- id: 2,
173
- name: t('administrators:email'),
174
- field: 'email',
175
- },
176
- {
177
- id: 3,
178
- name: t('administrators:roles'),
179
- field: 'roles',
180
- },
181
- {
182
- id: 4,
183
- name: t('administrators:actions'),
184
- field: 'actions',
185
- style: { width: '180px', textAlign: 'center', whiteSpace: 'nowrap' },
186
- headStyle: { width: '180px', textAlign: 'center' },
187
- },
188
- ];
189
- return {
190
- t,
191
- columnDefs,
192
- rowData: adminList,
193
- isRowDataLoading: isAdminLoading,
194
- errorMessage: error,
195
- isBusy,
196
- handleAdminDelete,
197
- getAdminFormUrl,
198
- };
199
- },
200
- });
201
-
202
- function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
203
- if (typeof shadowMode !== 'boolean') {
204
- createInjectorSSR = createInjector;
205
- createInjector = shadowMode;
206
- shadowMode = false;
207
- }
208
- // Vue.extend constructor export interop.
209
- const options = typeof script === 'function' ? script.options : script;
210
- // render functions
211
- if (template && template.render) {
212
- options.render = template.render;
213
- options.staticRenderFns = template.staticRenderFns;
214
- options._compiled = true;
215
- // functional template
216
- if (isFunctionalTemplate) {
217
- options.functional = true;
218
- }
219
- }
220
- // scopedId
221
- if (scopeId) {
222
- options._scopeId = scopeId;
223
- }
224
- let hook;
225
- if (moduleIdentifier) {
226
- // server build
227
- hook = function (context) {
228
- // 2.3 injection
229
- context =
230
- context || // cached call
231
- (this.$vnode && this.$vnode.ssrContext) || // stateful
232
- (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
233
- // 2.2 with runInNewContext: true
234
- if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
235
- context = __VUE_SSR_CONTEXT__;
236
- }
237
- // inject component styles
238
- if (style) {
239
- style.call(this, createInjectorSSR(context));
240
- }
241
- // register component module identifier for async chunk inference
242
- if (context && context._registeredComponents) {
243
- context._registeredComponents.add(moduleIdentifier);
244
- }
245
- };
246
- // used by ssr in case component is cached and beforeCreate
247
- // never gets called
248
- options._ssrRegister = hook;
249
- }
250
- else if (style) {
251
- hook = shadowMode
252
- ? function (context) {
253
- style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
254
- }
255
- : function (context) {
256
- style.call(this, createInjector(context));
257
- };
258
- }
259
- if (hook) {
260
- if (options.functional) {
261
- // register for functional component in vue file
262
- const originalRender = options.render;
263
- options.render = function renderWithStyleInjection(h, context) {
264
- hook.call(context);
265
- return originalRender(h, context);
266
- };
267
- }
268
- else {
269
- // inject component registration as beforeCreate hook
270
- const existing = options.beforeCreate;
271
- options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
272
- }
273
- }
274
- return script;
275
- }
276
-
277
- const isOldIE = typeof navigator !== 'undefined' &&
278
- /msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());
279
- function createInjector(context) {
280
- return (id, style) => addStyle(id, style);
281
- }
282
- let HEAD;
283
- const styles = {};
284
- function addStyle(id, css) {
285
- const group = isOldIE ? css.media || 'default' : id;
286
- const style = styles[group] || (styles[group] = { ids: new Set(), styles: [] });
287
- if (!style.ids.has(id)) {
288
- style.ids.add(id);
289
- let code = css.source;
290
- if (css.map) {
291
- // https://developer.chrome.com/devtools/docs/javascript-debugging
292
- // this makes source maps inside style tags work properly in Chrome
293
- code += '\n/*# sourceURL=' + css.map.sources[0] + ' */';
294
- // http://stackoverflow.com/a/26603875
295
- code +=
296
- '\n/*# sourceMappingURL=data:application/json;base64,' +
297
- btoa(unescape(encodeURIComponent(JSON.stringify(css.map)))) +
298
- ' */';
299
- }
300
- if (!style.element) {
301
- style.element = document.createElement('style');
302
- style.element.type = 'text/css';
303
- if (css.media)
304
- style.element.setAttribute('media', css.media);
305
- if (HEAD === undefined) {
306
- HEAD = document.head || document.getElementsByTagName('head')[0];
307
- }
308
- HEAD.appendChild(style.element);
309
- }
310
- if ('styleSheet' in style.element) {
311
- style.styles.push(code);
312
- style.element.styleSheet.cssText = style.styles
313
- .filter(Boolean)
314
- .join('\n');
315
- }
316
- else {
317
- const index = style.ids.size - 1;
318
- const textNode = document.createTextNode(code);
319
- const nodes = style.element.childNodes;
320
- if (nodes[index])
321
- style.element.removeChild(nodes[index]);
322
- if (nodes.length)
323
- style.element.insertBefore(textNode, nodes[index]);
324
- else
325
- style.element.appendChild(textNode);
326
- }
327
- }
328
- }
329
-
330
- /* script */
331
- const __vue_script__ = script;
332
-
333
- /* template */
334
- var __vue_render__ = function () {
335
- var _vm = this;
336
- var _h = _vm.$createElement;
337
- var _c = _vm._self._c || _h;
338
- return _c("page", {
339
- attrs: {
340
- title: _vm.t("administrators:administrators"),
341
- "header-buttons": [
342
- {
343
- text: _vm.t("administrators:createAdministrator"),
344
- href: _vm.getAdminFormUrl({ adminId: "create" }),
345
- },
346
- ],
347
- },
348
- scopedSlots: _vm._u([
349
- {
350
- key: "content",
351
- fn: function () {
352
- return [
353
- _c("base-table", {
354
- attrs: {
355
- "column-defs": _vm.columnDefs,
356
- "row-data": _vm.rowData,
357
- loading: _vm.isRowDataLoading,
358
- "error-message": _vm.errorMessage,
359
- },
360
- scopedSlots: _vm._u([
361
- {
362
- key: "cell(roles)",
363
- fn: function (ref) {
364
- var row = ref.row;
365
- return [
366
- _c(
367
- "ul",
368
- _vm._l(row.roles, function (role) {
369
- return _c("li", { key: role.id }, [
370
- _vm._v(
371
- "\n " +
372
- _vm._s(role.name) +
373
- "\n "
374
- ),
375
- ])
376
- }),
377
- 0
378
- ),
379
- ]
380
- },
381
- },
382
- {
383
- key: "cell(actions)",
384
- fn: function (ref) {
385
- var row = ref.row;
386
- return [
387
- !row.isSelf
388
- ? _c(
389
- "base-button",
390
- {
391
- attrs: {
392
- variant: "icon",
393
- title: _vm.t("administrators:edit"),
394
- disabled: _vm.isBusy(row.id),
395
- href: _vm.getAdminFormUrl({ adminId: row.id }),
396
- },
397
- },
398
- [_c("svg-icon", { attrs: { name: "edit" } })],
399
- 1
400
- )
401
- : _vm._e(),
402
- _vm._v(" "),
403
- !row.isSuperAdmin || !row.isSelf
404
- ? _c(
405
- "base-button",
406
- {
407
- attrs: {
408
- variant: "icon",
409
- title: _vm.t("administrators:delete"),
410
- disabled: _vm.isBusy(row.id),
411
- },
412
- on: {
413
- click: function ($event) {
414
- return _vm.handleAdminDelete(row.id)
415
- },
416
- },
417
- },
418
- [_c("svg-icon", { attrs: { name: "delete" } })],
419
- 1
420
- )
421
- : _vm._e(),
422
- ]
423
- },
424
- },
425
- ]),
426
- }),
427
- ]
428
- },
429
- proxy: true,
430
- },
431
- ]),
432
- })
433
- };
434
- var __vue_staticRenderFns__ = [];
435
- __vue_render__._withStripped = true;
436
-
437
- /* style */
438
- const __vue_inject_styles__ = function (inject) {
439
- if (!inject) return
440
- inject("data-v-72fbb6c4_0", { source: "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", map: {"version":3,"sources":[],"names":[],"mappings":"","file":"AdminList.vue"}, media: undefined });
441
-
442
- };
443
- /* scoped */
444
- const __vue_scope_id__ = "data-v-72fbb6c4";
445
- /* module identifier */
446
- const __vue_module_identifier__ = undefined;
447
- /* functional template */
448
- const __vue_is_functional_template__ = false;
449
- /* style inject SSR */
450
-
451
- /* style inject shadow dom */
452
-
453
-
454
-
455
- const __vue_component__ = /*#__PURE__*/normalizeComponent(
456
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
457
- __vue_inject_styles__,
458
- __vue_script__,
459
- __vue_scope_id__,
460
- __vue_is_functional_template__,
461
- __vue_module_identifier__,
462
- false,
463
- createInjector,
464
- undefined,
465
- undefined
466
- );
467
-
468
- function convertAdminToFormValues(admin, roleOptionList) {
469
- if (!admin) {
470
- return {
471
- name: '',
472
- email: '',
473
- password: createId(),
474
- roles: [],
475
- };
476
- }
477
- const currentRoleOptionList = roleOptionList.filter((role) => admin.roles.some((roles) => roles.id === role.value));
478
- return {
479
- name: admin.name,
480
- email: admin.email,
481
- password: '',
482
- roles: currentRoleOptionList,
483
- };
484
- }
485
- function convertFormValuesToAdminUpdatePayload(values) {
486
- return {
487
- name: values.name,
488
- email: values.email,
489
- roles: values.roles.map((role) => role.value),
490
- password: values.password,
491
- };
492
- }
493
- function convertFormValuesToAdminCreationPayload(values) {
494
- return Object.assign({}, convertFormValuesToAdminUpdatePayload(values));
495
- }
496
- function convertRoleListToOptions(roleList) {
497
- return roleList.map((role) => ({
498
- value: role.id,
499
- label: role.name,
500
- }));
501
- }
502
-
503
- var script$1 = defineComponent({
504
- name: 'AdminForm',
505
- components: { FormFooter },
506
- setup(props, context) {
507
- const { t } = useTranslation(context);
508
- const adminId = computed(() => context.root.$route.params.adminId);
509
- const isCreation = computed(() => adminId.value === 'create');
510
- const [fetchAdmin, { data: admin, loading: isAdminLoading }] = useResource({
511
- fetchResource: () => getAdmin(adminId.value),
512
- initialValue: null,
513
- context,
514
- resourceName: 'Admin',
515
- });
516
- /** Fetch role list */
517
- const [fetchRoleList, { data: roleList, loading: isRoleListLoading },] = useResource({
518
- fetchResource: getRoleList,
519
- initialValue: [],
520
- context,
521
- resourceName: 'Role list',
522
- });
523
- onMounted(() => {
524
- fetchRoleList();
525
- if (isCreation.value)
526
- return;
527
- fetchAdmin();
528
- });
529
- /** Role Options */
530
- const roleOptionList = computed(() => convertRoleListToOptions(roleList.value));
531
- const values = ref(convertAdminToFormValues(admin.value, roleOptionList.value));
532
- const errors = ref({});
533
- const isSubmitting = ref(false);
534
- watch([admin, roleOptionList], () => {
535
- values.value = convertAdminToFormValues(admin.value, roleOptionList.value);
536
- });
537
- /** Submit Form */
538
- function submitForm(event) {
539
- /** Admin can't update self */
540
- if (admin.value && admin.value.isSelf)
541
- return;
542
- const creationBody = convertFormValuesToAdminCreationPayload(values.value);
543
- const updateBody = convertFormValuesToAdminUpdatePayload(values.value);
544
- const requestPromise = isCreation.value
545
- ? createAdmin(creationBody)
546
- : updateAdmin(adminId.value, updateBody);
547
- requestPromise
548
- .then(({ data }) => {
549
- errors.value = {};
550
- if (event.type === 'create') {
551
- context.root.$router.push(getAdminFormUrl({ adminId: data.id }));
552
- }
553
- if (event.type === 'create_exit' || event.type === 'save_exit') {
554
- context.root.$router.push(getAdminListUrl());
555
- }
556
- if (event.type === 'create_create-another') {
557
- values.value = convertAdminToFormValues(null, roleOptionList.value);
558
- }
559
- context.root.$toast({
560
- variant: 'success',
561
- title: t('administrators:success'),
562
- body: isCreation.value
563
- ? t('administrators:adminSuccessfullyCreated')
564
- : t('administrators:adminSuccessfullyUpdated'),
565
- });
566
- })
567
- .catch((error) => {
568
- console.error(error);
569
- errors.value = convertRequestErrorToMap(error);
570
- context.root.$toast({
571
- variant: 'danger',
572
- title: t('administrators:error'),
573
- body: isCreation.value
574
- ? t('administrators:adminCreationError')
575
- : t('administrators:adminUpdateError'),
576
- });
577
- })
578
- .finally(() => {
579
- isSubmitting.value = false;
580
- });
581
- }
582
- const pageTitle = computed(() => {
583
- return isCreation.value
584
- ? t('administrators:createAdmin')
585
- : `${t('administrators:updateAdmin')} "${values.value.name}"`;
586
- });
587
- const isContentLoading = computed(() => isAdminLoading.value || isRoleListLoading.value);
588
- return {
589
- t,
590
- backButtonUrl: getAdminListUrl(),
591
- values,
592
- errors,
593
- isSubmitting,
594
- submitForm,
595
- isContentLoading,
596
- admin,
597
- pageTitle,
598
- isCreation,
599
- roleOptionList,
600
- };
601
- },
602
- });
603
-
604
- /* script */
605
- const __vue_script__$1 = script$1;
606
-
607
- /* template */
608
- var __vue_render__$1 = function () {
609
- var _vm = this;
610
- var _h = _vm.$createElement;
611
- var _c = _vm._self._c || _h;
612
- return _c(
613
- "page",
614
- {
615
- attrs: {
616
- title: _vm.pageTitle,
617
- "is-content-loading": _vm.isContentLoading,
618
- },
619
- scopedSlots: _vm._u([
620
- {
621
- key: "footer",
622
- fn: function () {
623
- return [
624
- _c("FormFooter", {
625
- attrs: {
626
- "back-href": _vm.backButtonUrl,
627
- "on-submit": _vm.submitForm,
628
- "is-submitting": _vm.isSubmitting,
629
- "is-creation": _vm.isCreation,
630
- "can-create-another": _vm.isCreation,
631
- },
632
- }),
633
- ]
634
- },
635
- proxy: true,
636
- },
637
- ]),
638
- },
639
- [
640
- _c(
641
- "form",
642
- {
643
- attrs: { novalidate: "" },
644
- on: {
645
- submit: function ($event) {
646
- $event.preventDefault();
647
- },
648
- },
649
- },
650
- [
651
- [
652
- _c("form-field", {
653
- attrs: {
654
- name: "name",
655
- error: _vm.errors.name,
656
- label: _vm.t("administrators:name"),
657
- },
658
- model: {
659
- value: _vm.values.name,
660
- callback: function ($$v) {
661
- _vm.$set(_vm.values, "name", $$v);
662
- },
663
- expression: "values.name",
664
- },
665
- }),
666
- _vm._v(" "),
667
- _c("form-field", {
668
- attrs: {
669
- name: "email",
670
- error: _vm.errors.email,
671
- label: _vm.t("administrators:email"),
672
- },
673
- model: {
674
- value: _vm.values.email,
675
- callback: function ($$v) {
676
- _vm.$set(_vm.values, "email", $$v);
677
- },
678
- expression: "values.email",
679
- },
680
- }),
681
- _vm._v(" "),
682
- _c("form-field-multi-select", {
683
- attrs: {
684
- name: "roles",
685
- label: _vm.t("administrators:roles"),
686
- options: _vm.roleOptionList,
687
- error: _vm.errors.roles,
688
- },
689
- model: {
690
- value: _vm.values.roles,
691
- callback: function ($$v) {
692
- _vm.$set(_vm.values, "roles", $$v);
693
- },
694
- expression: "values.roles",
695
- },
696
- }),
697
- _vm._v(" "),
698
- _c("form-field", {
699
- attrs: {
700
- name: "password",
701
- error: _vm.errors.password,
702
- label: _vm.isCreation
703
- ? _vm.t("administrators:password")
704
- : _vm.t("administrators:newPassword"),
705
- },
706
- model: {
707
- value: _vm.values.password,
708
- callback: function ($$v) {
709
- _vm.$set(_vm.values, "password", $$v);
710
- },
711
- expression: "values.password",
712
- },
713
- }),
714
- ],
715
- ],
716
- 2
717
- ),
718
- ]
719
- )
720
- };
721
- var __vue_staticRenderFns__$1 = [];
722
- __vue_render__$1._withStripped = true;
723
-
724
- /* style */
725
- const __vue_inject_styles__$1 = function (inject) {
726
- if (!inject) return
727
- inject("data-v-4b0de0ac_0", { source: "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", map: {"version":3,"sources":[],"names":[],"mappings":"","file":"AdminForm.vue"}, media: undefined });
728
-
729
- };
730
- /* scoped */
731
- const __vue_scope_id__$1 = "data-v-4b0de0ac";
732
- /* module identifier */
733
- const __vue_module_identifier__$1 = undefined;
734
- /* functional template */
735
- const __vue_is_functional_template__$1 = false;
736
- /* style inject SSR */
737
-
738
- /* style inject shadow dom */
739
-
740
-
741
-
742
- const __vue_component__$1 = /*#__PURE__*/normalizeComponent(
743
- { render: __vue_render__$1, staticRenderFns: __vue_staticRenderFns__$1 },
744
- __vue_inject_styles__$1,
745
- __vue_script__$1,
746
- __vue_scope_id__$1,
747
- __vue_is_functional_template__$1,
748
- __vue_module_identifier__$1,
749
- false,
750
- createInjector,
751
- undefined,
752
- undefined
753
- );
754
-
755
- var script$2 = defineComponent({
756
- name: 'RoleList',
757
- setup(props, context) {
758
- const { t } = useTranslation(context);
759
- const [fetchRoleList, { data: roleList, loading: isRoleLoading, error },] = useResource({
760
- fetchResource: getRoleList,
761
- initialValue: [],
762
- context,
763
- resourceName: 'Role list',
764
- });
765
- onMounted(() => {
766
- fetchRoleList();
767
- });
768
- const { handleResourceDelete: handleRoleDelete, isDeleting, } = useResourceDelete({
769
- deleteResource: deleteRole,
770
- resourceName: 'Role',
771
- onSuccess: fetchRoleList,
772
- context,
773
- });
774
- function isBusy(roleId) {
775
- return isDeleting(roleId) || isRoleLoading.value;
776
- }
777
- function getScopeGroupList(scopes) {
778
- const map = new Map();
779
- scopes.forEach((scope) => {
780
- var _a;
781
- const key = scope.module;
782
- const value = (_a = map.get(key)) !== null && _a !== void 0 ? _a : [];
783
- value.push(scope);
784
- map.set(key, value);
785
- });
786
- return Array.from(map.entries()).map(([key, value]) => ({
787
- module: key,
788
- scopes: value,
789
- }));
790
- }
791
- function getRestScopesText(restPrivilegesCount) {
792
- if (restPrivilegesCount === 1) {
793
- return t('administrators:andMorePrivilege', { count: 1 });
794
- }
795
- if (restPrivilegesCount > 1) {
796
- return t('administrators:andMorePrivilege', {
797
- count: restPrivilegesCount,
798
- });
799
- }
800
- return '';
801
- }
802
- const columnDefs = [
803
- {
804
- id: 1,
805
- name: t('administrators:role'),
806
- field: 'name',
807
- },
808
- {
809
- id: 2,
810
- name: t('administrators:privileges'),
811
- field: 'scope',
812
- },
813
- {
814
- id: 3,
815
- name: t('administrators:actions'),
816
- field: 'actions',
817
- style: { width: '180px', textAlign: 'center', whiteSpace: 'nowrap' },
818
- headStyle: { width: '180px', textAlign: 'center' },
819
- },
820
- ];
821
- return {
822
- t,
823
- columnDefs,
824
- rowData: roleList,
825
- isRowDataLoading: isRoleLoading,
826
- errorMessage: error,
827
- isBusy,
828
- handleRoleDelete,
829
- getRoleFormUrl,
830
- getScopeGroupList,
831
- getRestScopesText,
832
- scopesPerModuleCount: 3,
833
- };
834
- },
835
- });
836
-
837
- /* script */
838
- const __vue_script__$2 = script$2;
839
-
840
- /* template */
841
- var __vue_render__$2 = function () {
842
- var _vm = this;
843
- var _h = _vm.$createElement;
844
- var _c = _vm._self._c || _h;
845
- return _c("page", {
846
- attrs: {
847
- title: _vm.t("administrators:listOfRoles"),
848
- "header-buttons": [
849
- {
850
- text: _vm.t("administrators:addRole"),
851
- href: _vm.getRoleFormUrl({ roleId: "create" }),
852
- },
853
- ],
854
- },
855
- scopedSlots: _vm._u([
856
- {
857
- key: "content",
858
- fn: function () {
859
- return [
860
- _c("base-table", {
861
- attrs: {
862
- "column-defs": _vm.columnDefs,
863
- "row-data": _vm.rowData,
864
- loading: _vm.isRowDataLoading,
865
- "error-message": _vm.errorMessage,
866
- },
867
- scopedSlots: _vm._u([
868
- {
869
- key: "cell(scope)",
870
- fn: function (ref) {
871
- var row = ref.row;
872
- return [
873
- row.scopes.length === 0
874
- ? _c("span", { staticClass: "no-scopes" }, [
875
- _vm._v(
876
- "\n " +
877
- _vm._s(_vm.t("administrators:noPrivileges")) +
878
- "\n "
879
- ),
880
- ])
881
- : _vm._e(),
882
- _vm._v(" "),
883
- row.isSuperAdmin
884
- ? _c("span", [
885
- _vm._v(_vm._s(_vm.t("administrators:all"))),
886
- ])
887
- : _vm._l(_vm.getScopeGroupList(row.scopes), function (
888
- scopeGroup
889
- ) {
890
- return _c(
891
- "div",
892
- {
893
- key: scopeGroup.module,
894
- staticClass: "scope-group",
895
- },
896
- [
897
- _c("span", { staticClass: "module-name" }, [
898
- _vm._v(
899
- "\n " +
900
- _vm._s(scopeGroup.module) +
901
- "\n "
902
- ),
903
- ]),
904
- _vm._v(" "),
905
- _c(
906
- "ul",
907
- { staticClass: "scope-list" },
908
- _vm._l(
909
- scopeGroup.scopes.slice(
910
- 0,
911
- _vm.scopesPerModuleCount
912
- ),
913
- function (scope) {
914
- return _c("li", { key: scope.value }, [
915
- _c("span", [
916
- _vm._v("— " + _vm._s(scope.label)),
917
- ]),
918
- ])
919
- }
920
- ),
921
- 0
922
- ),
923
- _vm._v(" "),
924
- scopeGroup.scopes.length >
925
- _vm.scopesPerModuleCount
926
- ? _c(
927
- "span",
928
- { staticClass: "rest-scopes-text" },
929
- [
930
- _vm._v(
931
- "\n " +
932
- _vm._s(
933
- _vm.getRestScopesText(
934
- scopeGroup.scopes.length -
935
- _vm.scopesPerModuleCount
936
- )
937
- ) +
938
- "\n "
939
- ),
940
- ]
941
- )
942
- : _vm._e(),
943
- ]
944
- )
945
- }),
946
- ]
947
- },
948
- },
949
- {
950
- key: "cell(actions)",
951
- fn: function (ref) {
952
- var row = ref.row;
953
- return [
954
- _c(
955
- "base-button",
956
- {
957
- attrs: {
958
- variant: "icon",
959
- title: _vm.t("administrators:edit"),
960
- disabled: _vm.isBusy(row.id),
961
- href: _vm.getRoleFormUrl({ roleId: row.id }),
962
- },
963
- },
964
- [_c("svg-icon", { attrs: { name: "edit" } })],
965
- 1
966
- ),
967
- _vm._v(" "),
968
- !row.isSuperAdmin
969
- ? _c(
970
- "base-button",
971
- {
972
- attrs: {
973
- variant: "icon",
974
- title: _vm.t("administrators:delete"),
975
- disabled: _vm.isBusy(row.id),
976
- },
977
- on: {
978
- click: function ($event) {
979
- return _vm.handleRoleDelete(row.id)
980
- },
981
- },
982
- },
983
- [_c("svg-icon", { attrs: { name: "delete" } })],
984
- 1
985
- )
986
- : _vm._e(),
987
- ]
988
- },
989
- },
990
- ]),
991
- }),
992
- ]
993
- },
994
- proxy: true,
995
- },
996
- ]),
997
- })
998
- };
999
- var __vue_staticRenderFns__$2 = [];
1000
- __vue_render__$2._withStripped = true;
1001
-
1002
- /* style */
1003
- const __vue_inject_styles__$2 = function (inject) {
1004
- if (!inject) return
1005
- inject("data-v-4f7e99db_0", { source: ".no-scopes {\n font-style: italic;\n}\n.scope-group {\n margin-bottom: 0.5rem;\n}\n.module-name {\n display: block;\n font-weight: bold;\n margin-bottom: 0.3rem;\n}\n.scope-list {\n padding-left: 1rem;\n}\n.rest-scopes-text {\n padding-left: 35px;\n}\n\n/*# sourceMappingURL=RoleList.vue.map */", map: {"version":3,"sources":["/home/runner/work/tager-admin-administrators/tager-admin-administrators/src/views/RoleList/RoleList.vue","RoleList.vue"],"names":[],"mappings":"AA6LA;EACA,kBAAA;AC5LA;AD+LA;EACA,qBAAA;AC5LA;AD+LA;EACA,cAAA;EACA,iBAAA;EACA,qBAAA;AC5LA;AD+LA;EACA,kBAAA;AC5LA;AD+LA;EACA,kBAAA;AC5LA;;AAEA,uCAAuC","file":"RoleList.vue","sourcesContent":["<template>\n <page\n :title=\"t('administrators:listOfRoles')\"\n :header-buttons=\"[\n {\n text: t('administrators:addRole'),\n href: getRoleFormUrl({ roleId: 'create' }),\n },\n ]\"\n >\n <template v-slot:content>\n <base-table\n :column-defs=\"columnDefs\"\n :row-data=\"rowData\"\n :loading=\"isRowDataLoading\"\n :error-message=\"errorMessage\"\n >\n <template v-slot:cell(scope)=\"{ row }\">\n <span v-if=\"row.scopes.length === 0\" class=\"no-scopes\">\n {{ t('administrators:noPrivileges') }}\n </span>\n <span v-if=\"row.isSuperAdmin\">{{ t('administrators:all') }}</span>\n <div\n v-for=\"scopeGroup in getScopeGroupList(row.scopes)\"\n v-else\n :key=\"scopeGroup.module\"\n class=\"scope-group\"\n >\n <span class=\"module-name\">\n {{ scopeGroup.module }}\n </span>\n <ul class=\"scope-list\">\n <li\n v-for=\"scope of scopeGroup.scopes.slice(\n 0,\n scopesPerModuleCount\n )\"\n :key=\"scope.value\"\n >\n <span>— {{ scope.label }}</span>\n </li>\n </ul>\n <span\n v-if=\"scopeGroup.scopes.length > scopesPerModuleCount\"\n class=\"rest-scopes-text\"\n >\n {{\n getRestScopesText(\n scopeGroup.scopes.length - scopesPerModuleCount\n )\n }}\n </span>\n </div>\n </template>\n <template v-slot:cell(actions)=\"{ row }\">\n <base-button\n variant=\"icon\"\n :title=\"t('administrators:edit')\"\n :disabled=\"isBusy(row.id)\"\n :href=\"getRoleFormUrl({ roleId: row.id })\"\n >\n <svg-icon name=\"edit\"></svg-icon>\n </base-button>\n <base-button\n v-if=\"!row.isSuperAdmin\"\n variant=\"icon\"\n :title=\"t('administrators:delete')\"\n :disabled=\"isBusy(row.id)\"\n @click=\"handleRoleDelete(row.id)\"\n >\n <svg-icon name=\"delete\"></svg-icon>\n </base-button>\n </template>\n </base-table>\n </template>\n </page>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, onMounted, SetupContext } from '@vue/composition-api';\n\nimport { useResource, useResourceDelete } from '@tager/admin-services';\nimport { ColumnDefinition, useTranslation } from '@tager/admin-ui';\n\nimport { RoleType, ScopeType } from '../../typings/model';\nimport { deleteRole, getRoleList } from '../../services/requests';\nimport { getRoleFormUrl } from '../../utils/paths';\n\nexport default defineComponent({\n name: 'RoleList',\n setup(props, context: SetupContext) {\n const { t } = useTranslation(context);\n\n const [\n fetchRoleList,\n { data: roleList, loading: isRoleLoading, error },\n ] = useResource<Array<RoleType>>({\n fetchResource: getRoleList,\n initialValue: [],\n context,\n resourceName: 'Role list',\n });\n\n onMounted(() => {\n fetchRoleList();\n });\n\n const {\n handleResourceDelete: handleRoleDelete,\n isDeleting,\n } = useResourceDelete({\n deleteResource: deleteRole,\n resourceName: 'Role',\n onSuccess: fetchRoleList,\n context,\n });\n\n function isBusy(roleId: number): boolean {\n return isDeleting(roleId) || isRoleLoading.value;\n }\n\n function getScopeGroupList(\n scopes: Array<ScopeType>\n ): Array<{ module: string; scopes: ScopeType }> {\n const map = new Map();\n scopes.forEach((scope) => {\n const key = scope.module;\n const value = map.get(key) ?? [];\n value.push(scope);\n map.set(key, value);\n });\n return Array.from(map.entries()).map(([key, value]) => ({\n module: key,\n scopes: value,\n }));\n }\n\n function getRestScopesText(restPrivilegesCount: number): string {\n if (restPrivilegesCount === 1) {\n return t('administrators:andMorePrivilege', { count: 1 });\n }\n\n if (restPrivilegesCount > 1) {\n return t('administrators:andMorePrivilege', {\n count: restPrivilegesCount,\n });\n }\n\n return '';\n }\n\n const columnDefs: Array<ColumnDefinition<RoleType>> = [\n {\n id: 1,\n name: t('administrators:role'),\n field: 'name',\n },\n {\n id: 2,\n name: t('administrators:privileges'),\n field: 'scope',\n },\n {\n id: 3,\n name: t('administrators:actions'),\n field: 'actions',\n style: { width: '180px', textAlign: 'center', whiteSpace: 'nowrap' },\n headStyle: { width: '180px', textAlign: 'center' },\n },\n ];\n\n return {\n t,\n columnDefs,\n rowData: roleList,\n isRowDataLoading: isRoleLoading,\n errorMessage: error,\n isBusy,\n handleRoleDelete,\n getRoleFormUrl,\n getScopeGroupList,\n getRestScopesText,\n scopesPerModuleCount: 3,\n };\n },\n});\n</script>\n\n<style lang=\"scss\">\n.no-scopes {\n font-style: italic;\n}\n\n.scope-group {\n margin-bottom: 0.5rem;\n}\n\n.module-name {\n display: block;\n font-weight: bold;\n margin-bottom: 0.3rem;\n}\n\n.scope-list {\n padding-left: 1rem;\n}\n\n.rest-scopes-text {\n padding-left: 35px;\n}\n</style>\n",".no-scopes {\n font-style: italic;\n}\n\n.scope-group {\n margin-bottom: 0.5rem;\n}\n\n.module-name {\n display: block;\n font-weight: bold;\n margin-bottom: 0.3rem;\n}\n\n.scope-list {\n padding-left: 1rem;\n}\n\n.rest-scopes-text {\n padding-left: 35px;\n}\n\n/*# sourceMappingURL=RoleList.vue.map */"]}, media: undefined });
1006
-
1007
- };
1008
- /* scoped */
1009
- const __vue_scope_id__$2 = undefined;
1010
- /* module identifier */
1011
- const __vue_module_identifier__$2 = undefined;
1012
- /* functional template */
1013
- const __vue_is_functional_template__$2 = false;
1014
- /* style inject SSR */
1015
-
1016
- /* style inject shadow dom */
1017
-
1018
-
1019
-
1020
- const __vue_component__$2 = /*#__PURE__*/normalizeComponent(
1021
- { render: __vue_render__$2, staticRenderFns: __vue_staticRenderFns__$2 },
1022
- __vue_inject_styles__$2,
1023
- __vue_script__$2,
1024
- __vue_scope_id__$2,
1025
- __vue_is_functional_template__$2,
1026
- __vue_module_identifier__$2,
1027
- false,
1028
- createInjector,
1029
- undefined,
1030
- undefined
1031
- );
1032
-
1033
- function convertRoleToFormValues(role) {
1034
- if (!role) {
1035
- return {
1036
- name: '',
1037
- scopes: [],
1038
- isSuperAdmin: false,
1039
- };
1040
- }
1041
- return {
1042
- name: role.name,
1043
- scopes: role.scopes,
1044
- isSuperAdmin: role.isSuperAdmin,
1045
- };
1046
- }
1047
- function convertFormValuesToRoleCreationPayload(values) {
1048
- return {
1049
- name: values.name,
1050
- scopes: values.scopes.map((scope) => scope.value),
1051
- };
1052
- }
1053
- function convertFormValuesToRoleUpdatePayload(values) {
1054
- return Object.assign({}, convertFormValuesToRoleCreationPayload(values));
1055
- }
1056
- function convertScopeDataToOptions(scopeData) {
1057
- if (!scopeData)
1058
- return [];
1059
- return scopeData.groups
1060
- .map((group) => group.scopes.map((scope) => ({
1061
- value: scope.value,
1062
- label: `${group.name}: ${scope.label}`,
1063
- })))
1064
- .flat();
1065
- }
1066
-
1067
- var script$3 = defineComponent({
1068
- name: 'RoleForm',
1069
- components: { FormFooter },
1070
- setup(props, context) {
1071
- const { t } = useTranslation(context);
1072
- const roleId = computed(() => context.root.$route.params.roleId);
1073
- const isCreation = computed(() => roleId.value === 'create');
1074
- const [fetchRole, { data: role, loading: isRoleLoading }] = useResource({
1075
- fetchResource: () => getRole(roleId.value),
1076
- initialValue: null,
1077
- context,
1078
- resourceName: 'Role',
1079
- });
1080
- /** Fetch scope list */
1081
- const [fetchScopeData, { data: scopeData, loading: isScopeDataLoading },] = useResource({
1082
- fetchResource: getScopes,
1083
- initialValue: null,
1084
- context,
1085
- resourceName: 'Scope list',
1086
- });
1087
- onMounted(() => {
1088
- fetchScopeData();
1089
- if (isCreation.value)
1090
- return;
1091
- fetchRole();
1092
- });
1093
- /** Scope Options */
1094
- const scopeOptionList = computed(() => convertScopeDataToOptions(scopeData.value));
1095
- const values = ref(convertRoleToFormValues(role.value));
1096
- const errors = ref({});
1097
- const isSubmitting = ref(false);
1098
- watch(role, () => {
1099
- values.value = convertRoleToFormValues(role.value);
1100
- });
1101
- /** Submit Form */
1102
- function submitForm(event) {
1103
- const creationBody = convertFormValuesToRoleCreationPayload(values.value);
1104
- const updateBody = convertFormValuesToRoleUpdatePayload(values.value);
1105
- const requestPromise = isCreation.value
1106
- ? createRole(creationBody)
1107
- : updateRole(roleId.value, updateBody);
1108
- requestPromise
1109
- .then(({ data }) => {
1110
- errors.value = {};
1111
- if (event.type === 'create') {
1112
- context.root.$router.push(getRoleFormUrl({ roleId: data.id }));
1113
- }
1114
- if (event.type === 'create_exit' || event.type === 'save_exit') {
1115
- context.root.$router.push(getRoleListUrl());
1116
- }
1117
- if (event.type === 'create_create-another') {
1118
- values.value = convertRoleToFormValues(null);
1119
- }
1120
- context.root.$toast({
1121
- variant: 'success',
1122
- title: t('administrators:success'),
1123
- body: isCreation.value
1124
- ? t('administrators:roleSuccessfullyCreated')
1125
- : t('administrators:roleSuccessfullyUpdate'),
1126
- });
1127
- })
1128
- .catch((error) => {
1129
- console.error(error);
1130
- errors.value = convertRequestErrorToMap(error);
1131
- context.root.$toast({
1132
- variant: 'danger',
1133
- title: t('administrators:error'),
1134
- body: isCreation.value
1135
- ? t('administrators:roleCreationError')
1136
- : t('administrators:roleUpdateError'),
1137
- });
1138
- })
1139
- .finally(() => {
1140
- isSubmitting.value = false;
1141
- });
1142
- }
1143
- const pageTitle = computed(() => {
1144
- return isCreation.value
1145
- ? t('administrators:createRole')
1146
- : `${t('administrators:updateRole')} "${values.value.name}"`;
1147
- });
1148
- const isContentLoading = computed(() => isRoleLoading.value || isScopeDataLoading.value);
1149
- return {
1150
- t,
1151
- backButtonUrl: getRoleListUrl(),
1152
- values,
1153
- errors,
1154
- isSubmitting,
1155
- submitForm,
1156
- isContentLoading,
1157
- role,
1158
- pageTitle,
1159
- isCreation,
1160
- scopeOptionList,
1161
- };
1162
- },
1163
- });
1164
-
1165
- /* script */
1166
- const __vue_script__$3 = script$3;
1167
-
1168
- /* template */
1169
- var __vue_render__$3 = function () {
1170
- var _vm = this;
1171
- var _h = _vm.$createElement;
1172
- var _c = _vm._self._c || _h;
1173
- return _c(
1174
- "page",
1175
- {
1176
- attrs: {
1177
- title: _vm.pageTitle,
1178
- "is-content-loading": _vm.isContentLoading,
1179
- footer: {
1180
- backHref: _vm.backButtonUrl,
1181
- onSubmit: _vm.submitForm,
1182
- isSubmitting: _vm.isSubmitting,
1183
- },
1184
- },
1185
- },
1186
- [
1187
- _c(
1188
- "form",
1189
- {
1190
- attrs: { novalidate: "" },
1191
- on: {
1192
- submit: function ($event) {
1193
- $event.preventDefault();
1194
- },
1195
- },
1196
- },
1197
- [
1198
- [
1199
- _c("form-field", {
1200
- attrs: {
1201
- name: "name",
1202
- error: _vm.errors.name,
1203
- label: _vm.t("administrators:name"),
1204
- },
1205
- model: {
1206
- value: _vm.values.name,
1207
- callback: function ($$v) {
1208
- _vm.$set(_vm.values, "name", $$v);
1209
- },
1210
- expression: "values.name",
1211
- },
1212
- }),
1213
- _vm._v(" "),
1214
- !_vm.values.isSuperAdmin
1215
- ? _c("form-field-multi-select", {
1216
- attrs: {
1217
- name: "scopes",
1218
- label: _vm.t("administrators:privileges"),
1219
- options: _vm.scopeOptionList,
1220
- error: _vm.errors.scopes,
1221
- },
1222
- model: {
1223
- value: _vm.values.scopes,
1224
- callback: function ($$v) {
1225
- _vm.$set(_vm.values, "scopes", $$v);
1226
- },
1227
- expression: "values.scopes",
1228
- },
1229
- })
1230
- : _vm._e(),
1231
- ],
1232
- ],
1233
- 2
1234
- ),
1235
- ]
1236
- )
1237
- };
1238
- var __vue_staticRenderFns__$3 = [];
1239
- __vue_render__$3._withStripped = true;
1240
-
1241
- /* style */
1242
- const __vue_inject_styles__$3 = function (inject) {
1243
- if (!inject) return
1244
- inject("data-v-31a65f62_0", { source: "[data-v-31a65f62] [data-multi-select-list] {\n max-height: 500px;\n}\n\n/*# sourceMappingURL=RoleForm.vue.map */", map: {"version":3,"sources":["/home/runner/work/tager-admin-administrators/tager-admin-administrators/src/views/RoleForm/RoleForm.vue","RoleForm.vue"],"names":[],"mappings":"AAuMA;EACA,iBAAA;ACtMA;;AAEA,uCAAuC","file":"RoleForm.vue","sourcesContent":["<template>\n <page\n :title=\"pageTitle\"\n :is-content-loading=\"isContentLoading\"\n :footer=\"{\n backHref: backButtonUrl,\n onSubmit: submitForm,\n isSubmitting: isSubmitting,\n }\"\n >\n <form novalidate @submit.prevent>\n <template>\n <form-field\n v-model=\"values.name\"\n name=\"name\"\n :error=\"errors.name\"\n :label=\"t('administrators:name')\"\n />\n <form-field-multi-select\n v-if=\"!values.isSuperAdmin\"\n v-model=\"values.scopes\"\n name=\"scopes\"\n :label=\"t('administrators:privileges')\"\n :options=\"scopeOptionList\"\n :error=\"errors.scopes\"\n />\n </template>\n </form>\n </page>\n</template>\n\n<script lang=\"ts\">\nimport {\n computed,\n defineComponent,\n onMounted,\n ref,\n SetupContext,\n watch,\n} from '@vue/composition-api';\n\nimport {\n convertRequestErrorToMap,\n Nullable,\n useResource,\n} from '@tager/admin-services';\nimport {\n OptionType,\n FormFooter,\n TagerFormSubmitEvent,\n useTranslation,\n} from '@tager/admin-ui';\n\nimport {\n createRole,\n getRole,\n getScopes,\n updateRole,\n} from '../../services/requests';\nimport { RoleType, ScopeGroupsData } from '../../typings/model';\nimport { getRoleFormUrl, getRoleListUrl } from '../../utils/paths';\n\nimport {\n convertFormValuesToRoleCreationPayload,\n convertFormValuesToRoleUpdatePayload,\n convertRoleToFormValues,\n convertScopeDataToOptions,\n FormValues,\n} from './RoleForm.helpers';\n\nexport default defineComponent({\n name: 'RoleForm',\n components: { FormFooter },\n setup(props, context: SetupContext) {\n const { t } = useTranslation(context);\n\n const roleId = computed<string>(() => context.root.$route.params.roleId);\n\n const isCreation = computed<boolean>(() => roleId.value === 'create');\n\n const [fetchRole, { data: role, loading: isRoleLoading }] = useResource<\n Nullable<RoleType>\n >({\n fetchResource: () => getRole(roleId.value),\n initialValue: null,\n context,\n resourceName: 'Role',\n });\n\n /** Fetch scope list */\n const [\n fetchScopeData,\n { data: scopeData, loading: isScopeDataLoading },\n ] = useResource<Nullable<ScopeGroupsData>>({\n fetchResource: getScopes,\n initialValue: null,\n context,\n resourceName: 'Scope list',\n });\n\n onMounted(() => {\n fetchScopeData();\n\n if (isCreation.value) return;\n\n fetchRole();\n });\n\n /** Scope Options */\n const scopeOptionList = computed<Array<OptionType>>(() =>\n convertScopeDataToOptions(scopeData.value)\n );\n\n const values = ref<FormValues>(convertRoleToFormValues(role.value));\n\n const errors = ref<Record<string, string>>({});\n const isSubmitting = ref<boolean>(false);\n\n watch(role, () => {\n values.value = convertRoleToFormValues(role.value);\n });\n\n /** Submit Form */\n function submitForm(event: TagerFormSubmitEvent) {\n const creationBody = convertFormValuesToRoleCreationPayload(values.value);\n\n const updateBody = convertFormValuesToRoleUpdatePayload(values.value);\n const requestPromise = isCreation.value\n ? createRole(creationBody)\n : updateRole(roleId.value, updateBody);\n\n requestPromise\n .then(({ data }) => {\n errors.value = {};\n\n if (event.type === 'create') {\n context.root.$router.push(getRoleFormUrl({ roleId: data.id }));\n }\n\n if (event.type === 'create_exit' || event.type === 'save_exit') {\n context.root.$router.push(getRoleListUrl());\n }\n\n if (event.type === 'create_create-another') {\n values.value = convertRoleToFormValues(null);\n }\n\n context.root.$toast({\n variant: 'success',\n title: t('administrators:success'),\n body: isCreation.value\n ? t('administrators:roleSuccessfullyCreated')\n : t('administrators:roleSuccessfullyUpdate'),\n });\n })\n .catch((error) => {\n console.error(error);\n errors.value = convertRequestErrorToMap(error);\n context.root.$toast({\n variant: 'danger',\n title: t('administrators:error'),\n body: isCreation.value\n ? t('administrators:roleCreationError')\n : t('administrators:roleUpdateError'),\n });\n })\n .finally(() => {\n isSubmitting.value = false;\n });\n }\n\n const pageTitle = computed<string>(() => {\n return isCreation.value\n ? t('administrators:createRole')\n : `${t('administrators:updateRole')} \"${values.value.name}\"`;\n });\n\n const isContentLoading = computed<boolean>(\n () => isRoleLoading.value || isScopeDataLoading.value\n );\n\n return {\n t,\n backButtonUrl: getRoleListUrl(),\n values,\n errors,\n isSubmitting,\n submitForm,\n isContentLoading,\n role,\n pageTitle,\n isCreation,\n scopeOptionList,\n };\n },\n});\n</script>\n\n<style scoped lang=\"scss\">\n::v-deep [data-multi-select-list] {\n max-height: 500px;\n}\n</style>\n","::v-deep [data-multi-select-list] {\n max-height: 500px;\n}\n\n/*# sourceMappingURL=RoleForm.vue.map */"]}, media: undefined });
1245
-
1246
- };
1247
- /* scoped */
1248
- const __vue_scope_id__$3 = "data-v-31a65f62";
1249
- /* module identifier */
1250
- const __vue_module_identifier__$3 = undefined;
1251
- /* functional template */
1252
- const __vue_is_functional_template__$3 = false;
1253
- /* style inject SSR */
1254
-
1255
- /* style inject shadow dom */
1256
-
1257
-
1258
-
1259
- const __vue_component__$3 = /*#__PURE__*/normalizeComponent(
1260
- { render: __vue_render__$3, staticRenderFns: __vue_staticRenderFns__$3 },
1261
- __vue_inject_styles__$3,
1262
- __vue_script__$3,
1263
- __vue_scope_id__$3,
1264
- __vue_is_functional_template__$3,
1265
- __vue_module_identifier__$3,
1266
- false,
1267
- createInjector,
1268
- undefined,
1269
- undefined
1270
- );
1271
-
1272
- const ADMIN_LIST_ROUTE = {
1273
- path: ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST,
1274
- component: __vue_component__,
1275
- name: 'AdminList',
1276
- meta: {
1277
- getBreadcrumbs: (route, t) => [
1278
- { url: '/', text: t('administrators:home') },
1279
- {
1280
- url: ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST,
1281
- text: t('administrators:adminList'),
1282
- },
1283
- ],
1284
- },
1285
- };
1286
- const ADMIN_FORM_ROUTE = {
1287
- path: ADMINISTRATOR_ROUTE_PATHS.ADMIN_FORM,
1288
- component: __vue_component__$1,
1289
- name: 'AdminForm',
1290
- meta: {
1291
- getBreadcrumbs: (route, t) => [
1292
- { url: '/', text: t('administrators:home') },
1293
- {
1294
- url: ADMINISTRATOR_ROUTE_PATHS.ADMIN_LIST,
1295
- text: t('administrators:adminList'),
1296
- },
1297
- { url: route.path, text: t('administrators:adminForm') },
1298
- ],
1299
- },
1300
- };
1301
- const ROLE_LIST_ROUTE = {
1302
- path: ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST,
1303
- component: __vue_component__$2,
1304
- name: 'RoleList',
1305
- meta: {
1306
- getBreadcrumbs: (route, t) => [
1307
- { url: '/', text: t('administrators:home') },
1308
- {
1309
- url: ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST,
1310
- text: t('administrators:roleList'),
1311
- },
1312
- ],
1313
- },
1314
- };
1315
- const ROLE_FORM_ROUTE = {
1316
- path: ADMINISTRATOR_ROUTE_PATHS.ROLE_FORM,
1317
- component: __vue_component__$3,
1318
- name: 'RoleForm',
1319
- meta: {
1320
- getBreadcrumbs: (route, t) => [
1321
- { url: '/', text: t('administrators:home') },
1322
- {
1323
- url: ADMINISTRATOR_ROUTE_PATHS.ROLE_LIST,
1324
- text: t('administrators:roleList'),
1325
- },
1326
- { url: route.path, text: t('administrators:roleForm') },
1327
- ],
1328
- },
1329
- };
1330
-
1331
- i18n.addTranslations('en', 'administrators', EN);
1332
- i18n.addTranslations('ru', 'administrators', RU);
1333
-
1334
- export { ADMIN_FORM_ROUTE, ADMIN_LIST_ROUTE, ROLE_FORM_ROUTE, ROLE_LIST_ROUTE, createAdmin, createRole, deleteAdmin, deleteRole, getAdmin, getAdminFormUrl, getAdminList, getAdminListUrl, getRole, getRoleFormUrl, getRoleList, getRoleListUrl, getScopes, updateAdmin, updateRole };