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