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