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