@tager/admin-administrators 1.0.0 → 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.
@@ -1,3 +1,3 @@
1
- import "@tager/admin-ui/css";
2
- import "@tager/admin-layout/css";
3
- import "@tager/admin-dynamic-field/css";
1
+ import '@tager/admin-ui/css';
2
+ import '@tager/admin-layout/css';
3
+ import '@tager/admin-dynamic-field/css';
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { i18n, request, useI18n, useResourceDelete, createId, useToast, useResource, navigateBack, convertRequestErrorToMap } from "@tager/admin-services";
1
+ import { i18n, request, useI18n, useResourceDelete, createId, useToast, useResource, notEmpty, navigateBack, convertRequestErrorToMap } from "@tager/admin-services";
2
2
  import { defineComponent, onMounted, resolveComponent, openBlock, createBlock, withCtx, createVNode, createElementVNode, createElementBlock, Fragment, renderList, toDisplayString, createCommentVNode, computed, ref, watch, withModifiers } from "vue";
3
- import { DataTable, BaseButton, DeleteIcon, EditIcon, useDataTable, FormFooter, FormField, FormFieldMultiSelect } from "@tager/admin-ui";
3
+ import { DataTable, BaseButton, DeleteIcon, EditIcon, useDataTable, TabList, FormFooter, FormField, FormFieldMultiSelect } from "@tager/admin-ui";
4
+ import { universalFieldUtils, DynamicField } from "@tager/admin-dynamic-field";
4
5
  import { compile } from "path-to-regexp";
5
6
  import { Page } from "@tager/admin-layout";
6
7
  import { useRoute, useRouter } from "vue-router";
@@ -42,7 +43,11 @@ const EN = {
42
43
  adminForm: "Admin form",
43
44
  roleList: "Role List",
44
45
  roleForm: "Role form",
45
- andMorePrivilege: "and more {{count}} privilege..."
46
+ andMorePrivilege: "and more {{count}} privilege...",
47
+ tabs: {
48
+ general: "General",
49
+ params: "Template"
50
+ }
46
51
  };
47
52
  const RU = {
48
53
  home: "\u0413\u043B\u0430\u0432\u043D\u0430\u044F",
@@ -82,12 +87,19 @@ const RU = {
82
87
  adminForm: "\u0424\u043E\u0440\u043C\u0430 \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u0430",
83
88
  roleList: "\u0421\u043F\u0438\u0441\u043E\u043A \u0440\u043E\u043B\u0435\u0439",
84
89
  roleForm: "\u0424\u043E\u0440\u043C\u0430 \u0440\u043E\u043B\u0438",
85
- andMorePrivilege: "\u0438 \u0435\u0449\u0435 {{count}} \u043F\u0440\u0438\u0432\u0438\u043B\u0435\u0433\u0438\u0439..."
90
+ andMorePrivilege: "\u0438 \u0435\u0449\u0435 {{count}} \u043F\u0440\u0438\u0432\u0438\u043B\u0435\u0433\u0438\u0439...",
91
+ tabs: {
92
+ general: "\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0435",
93
+ params: "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B"
94
+ }
86
95
  };
87
96
  function applyTranslations() {
88
97
  i18n.addTranslations("en", "administrators", EN);
89
98
  i18n.addTranslations("ru", "administrators", RU);
90
99
  }
100
+ function getFieldList() {
101
+ return request.get({ path: "/admin/admins/fields" });
102
+ }
91
103
  function getRoleList() {
92
104
  return request.get({ path: "/admin/rbac/roles" });
93
105
  }
@@ -299,17 +311,21 @@ function convertAdminToFormValues(admin, roleOptionList) {
299
311
  roles: currentRoleOptionList
300
312
  };
301
313
  }
302
- function convertFormValuesToAdminUpdatePayload(values) {
314
+ function convertFormValuesToAdminUpdatePayload(values, paramsValues = []) {
303
315
  return {
304
316
  name: values.name,
305
317
  email: values.email,
306
318
  roles: values.roles.map((role) => role.value),
307
- password: values.password
319
+ password: values.password,
320
+ params: paramsValues.map((field) => ({
321
+ value: universalFieldUtils.getOutgoingValue(field),
322
+ name: field.config.name
323
+ }))
308
324
  };
309
325
  }
310
- function convertFormValuesToAdminCreationPayload(values) {
326
+ function convertFormValuesToAdminCreationPayload(values, paramsValues = []) {
311
327
  return {
312
- ...convertFormValuesToAdminUpdatePayload(values)
328
+ ...convertFormValuesToAdminUpdatePayload(values, paramsValues)
313
329
  };
314
330
  }
315
331
  function convertRoleListToOptions(roleList) {
@@ -320,7 +336,14 @@ function convertRoleListToOptions(roleList) {
320
336
  }
321
337
  const _sfc_main$2 = defineComponent({
322
338
  name: "AdminForm",
323
- components: { Page, FormFooter, FormField, FormFieldMultiSelect },
339
+ components: {
340
+ DynamicField,
341
+ TabList,
342
+ Page,
343
+ FormFooter,
344
+ FormField,
345
+ FormFieldMultiSelect
346
+ },
324
347
  setup() {
325
348
  const { t } = useI18n();
326
349
  const route = useRoute();
@@ -333,16 +356,20 @@ const _sfc_main$2 = defineComponent({
333
356
  initialValue: null,
334
357
  resourceName: "Admin"
335
358
  });
336
- const [
337
- fetchRoleList,
338
- { data: roleList, loading: isRoleListLoading }
339
- ] = useResource({
359
+ const [fetchRoleList, { data: roleList, loading: isRoleListLoading }] = useResource({
340
360
  fetchResource: getRoleList,
341
361
  initialValue: [],
342
- resourceName: "Role list"
362
+ resourceName: "Role List"
363
+ });
364
+ const [fetchFieldList, { data: fieldList, loading: isFieldListLoading }] = useResource({
365
+ fetchResource: getFieldList,
366
+ initialValue: [],
367
+ resourceName: "Field List"
343
368
  });
344
369
  onMounted(() => {
345
370
  fetchRoleList();
371
+ fetchFieldList();
372
+ updateTemplateValues();
346
373
  if (isCreation.value)
347
374
  return;
348
375
  fetchAdmin();
@@ -357,8 +384,8 @@ const _sfc_main$2 = defineComponent({
357
384
  function submitForm(event) {
358
385
  if (admin.value && admin.value.isSelf)
359
386
  return;
360
- const creationBody = convertFormValuesToAdminCreationPayload(values.value);
361
- const updateBody = convertFormValuesToAdminUpdatePayload(values.value);
387
+ const creationBody = convertFormValuesToAdminCreationPayload(values.value, templateValues.value);
388
+ const updateBody = convertFormValuesToAdminUpdatePayload(values.value, templateValues.value);
362
389
  const requestPromise = isCreation.value ? createAdmin(creationBody) : updateAdmin(adminId.value, updateBody);
363
390
  requestPromise.then(({ data }) => {
364
391
  errors.value = {};
@@ -391,7 +418,27 @@ const _sfc_main$2 = defineComponent({
391
418
  const pageTitle = computed(() => {
392
419
  return isCreation.value ? t("administrators:createAdmin") : `${t("administrators:updateAdmin")} "${values.value.name}"`;
393
420
  });
394
- const isContentLoading = computed(() => isAdminLoading.value || isRoleListLoading.value);
421
+ const isContentLoading = computed(() => isAdminLoading.value || isRoleListLoading.value || isFieldListLoading.value);
422
+ const shouldDisplayParamsTab = computed(() => fieldList.value.length > 0);
423
+ const tabList = computed(() => {
424
+ return [
425
+ { id: "general", label: t("administrators:tabs.general") },
426
+ shouldDisplayParamsTab.value ? { id: "params", label: t("administrators:tabs.params") } : null
427
+ ].filter(notEmpty);
428
+ });
429
+ const selectedTabId = ref(tabList.value[0].id);
430
+ const templateValues = ref([]);
431
+ function updateTemplateValues() {
432
+ var _a, _b;
433
+ const incomingFieldList = (_b = (_a = admin.value) == null ? void 0 : _a.params) != null ? _b : [];
434
+ templateValues.value = fieldList.value.map((fieldConfig, index) => {
435
+ var _a2;
436
+ return universalFieldUtils.createFormField(fieldConfig, (_a2 = incomingFieldList[index]) == null ? void 0 : _a2.value);
437
+ });
438
+ }
439
+ watch([admin, fieldList], () => {
440
+ updateTemplateValues();
441
+ });
395
442
  return {
396
443
  t,
397
444
  backButtonUrl: getAdminListUrl(),
@@ -403,13 +450,18 @@ const _sfc_main$2 = defineComponent({
403
450
  admin,
404
451
  pageTitle,
405
452
  isCreation,
406
- roleOptionList
453
+ roleOptionList,
454
+ tabList,
455
+ selectedTabId,
456
+ templateValues
407
457
  };
408
458
  }
409
459
  });
410
460
  function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
461
+ const _component_TabList = resolveComponent("TabList");
411
462
  const _component_FormField = resolveComponent("FormField");
412
463
  const _component_FormFieldMultiSelect = resolveComponent("FormFieldMultiSelect");
464
+ const _component_DynamicField = resolveComponent("DynamicField");
413
465
  const _component_FormFooter = resolveComponent("FormFooter");
414
466
  const _component_Page = resolveComponent("Page");
415
467
  return openBlock(), createBlock(_component_Page, {
@@ -419,47 +471,60 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
419
471
  footer: withCtx(() => [
420
472
  createVNode(_component_FormFooter, {
421
473
  "back-href": _ctx.backButtonUrl,
422
- onSubmit: _ctx.submitForm,
423
474
  "is-submitting": _ctx.isSubmitting,
424
475
  "is-creation": _ctx.isCreation,
425
- "can-create-another": _ctx.isCreation
426
- }, null, 8, ["back-href", "onSubmit", "is-submitting", "is-creation", "can-create-another"])
476
+ "can-create-another": _ctx.isCreation,
477
+ onSubmit: _ctx.submitForm
478
+ }, null, 8, ["back-href", "is-submitting", "is-creation", "can-create-another", "onSubmit"])
427
479
  ]),
428
480
  default: withCtx(() => [
429
481
  createElementVNode("form", {
430
482
  novalidate: "",
431
- onSubmit: _cache[4] || (_cache[4] = withModifiers(() => {
483
+ onSubmit: _cache[5] || (_cache[5] = withModifiers(() => {
432
484
  }, ["prevent"]))
433
485
  }, [
434
- createVNode(_component_FormField, {
435
- value: _ctx.values.name,
436
- "onUpdate:value": _cache[0] || (_cache[0] = ($event) => _ctx.values.name = $event),
437
- name: "name",
438
- error: _ctx.errors.name,
439
- label: _ctx.$i18n.t("administrators:name")
440
- }, null, 8, ["value", "error", "label"]),
441
- createVNode(_component_FormField, {
442
- value: _ctx.values.email,
443
- "onUpdate:value": _cache[1] || (_cache[1] = ($event) => _ctx.values.email = $event),
444
- name: "email",
445
- error: _ctx.errors.email,
446
- label: _ctx.$i18n.t("administrators:email")
447
- }, null, 8, ["value", "error", "label"]),
448
- createVNode(_component_FormFieldMultiSelect, {
449
- "selected-options": _ctx.values.roles,
450
- "onUpdate:selected-options": _cache[2] || (_cache[2] = ($event) => _ctx.values.roles = $event),
451
- name: "roles",
452
- label: _ctx.$i18n.t("administrators:roles"),
453
- options: _ctx.roleOptionList,
454
- error: _ctx.errors.roles
455
- }, null, 8, ["selected-options", "label", "options", "error"]),
456
- createVNode(_component_FormField, {
457
- value: _ctx.values.password,
458
- "onUpdate:value": _cache[3] || (_cache[3] = ($event) => _ctx.values.password = $event),
459
- name: "password",
460
- error: _ctx.errors.password,
461
- label: _ctx.isCreation ? _ctx.$i18n.t("administrators:password") : _ctx.$i18n.t("administrators:newPassword")
462
- }, null, 8, ["value", "error", "label"])
486
+ createVNode(_component_TabList, {
487
+ "tab-id": _ctx.selectedTabId,
488
+ "onUpdate:tab-id": _cache[0] || (_cache[0] = ($event) => _ctx.selectedTabId = $event),
489
+ "tab-list": _ctx.tabList
490
+ }, null, 8, ["tab-id", "tab-list"]),
491
+ _ctx.selectedTabId === "general" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
492
+ createVNode(_component_FormField, {
493
+ value: _ctx.values.name,
494
+ "onUpdate:value": _cache[1] || (_cache[1] = ($event) => _ctx.values.name = $event),
495
+ name: "name",
496
+ error: _ctx.errors.name,
497
+ label: _ctx.$i18n.t("administrators:name")
498
+ }, null, 8, ["value", "error", "label"]),
499
+ createVNode(_component_FormField, {
500
+ value: _ctx.values.email,
501
+ "onUpdate:value": _cache[2] || (_cache[2] = ($event) => _ctx.values.email = $event),
502
+ name: "email",
503
+ error: _ctx.errors.email,
504
+ label: _ctx.$i18n.t("administrators:email")
505
+ }, null, 8, ["value", "error", "label"]),
506
+ createVNode(_component_FormFieldMultiSelect, {
507
+ "selected-options": _ctx.values.roles,
508
+ "onUpdate:selected-options": _cache[3] || (_cache[3] = ($event) => _ctx.values.roles = $event),
509
+ name: "roles",
510
+ label: _ctx.$i18n.t("administrators:roles"),
511
+ options: _ctx.roleOptionList,
512
+ error: _ctx.errors.roles
513
+ }, null, 8, ["selected-options", "label", "options", "error"]),
514
+ createVNode(_component_FormField, {
515
+ value: _ctx.values.password,
516
+ "onUpdate:value": _cache[4] || (_cache[4] = ($event) => _ctx.values.password = $event),
517
+ name: "password",
518
+ error: _ctx.errors.password,
519
+ label: _ctx.isCreation ? _ctx.$i18n.t("administrators:password") : _ctx.$i18n.t("administrators:newPassword")
520
+ }, null, 8, ["value", "error", "label"])
521
+ ], 64)) : createCommentVNode("", true),
522
+ _ctx.selectedTabId === "params" ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.templateValues, (field) => {
523
+ return openBlock(), createBlock(_component_DynamicField, {
524
+ key: field.config.name,
525
+ field
526
+ }, null, 8, ["field"]);
527
+ }), 128)) : createCommentVNode("", true)
463
528
  ], 32)
464
529
  ]),
465
530
  _: 1
@@ -872,4 +937,4 @@ const ROLE_FORM_ROUTE = {
872
937
  }
873
938
  };
874
939
  applyTranslations();
875
- export { ADMIN_FORM_ROUTE, ADMIN_LIST_ROUTE, ROLE_FORM_ROUTE, ROLE_LIST_ROUTE, createAdmin, createRole, deleteAdmin, deleteRole, getAdmin, getAdminFormUrl, getAdminList, getAdminListUrl, getRole, getRoleFormUrl, getRoleList, getRoleListUrl, getScopes, updateAdmin, updateRole };
940
+ export { ADMIN_FORM_ROUTE, ADMIN_LIST_ROUTE, ROLE_FORM_ROUTE, ROLE_LIST_ROUTE, createAdmin, createRole, deleteAdmin, deleteRole, getAdmin, getAdminFormUrl, getAdminList, getAdminListUrl, getFieldList, getRole, getRoleFormUrl, getRoleList, getRoleListUrl, getScopes, updateAdmin, updateRole };
@@ -37,4 +37,8 @@ export declare const EN: {
37
37
  roleList: string;
38
38
  roleForm: string;
39
39
  andMorePrivilege: string;
40
+ tabs: {
41
+ general: string;
42
+ params: string;
43
+ };
40
44
  };
@@ -1,8 +1,11 @@
1
1
  import { ResponseBody } from '@tager/admin-services';
2
+ import { FieldConfigUnion, FieldShortType, OutgoingValueUnion } from '@tager/admin-dynamic-field';
2
3
  import { AdminType, RoleType, ScopeGroupsData } from '../typings/model';
3
4
  declare type SuccessData = {
4
5
  success: boolean;
5
6
  };
7
+ /** Fields */
8
+ export declare function getFieldList(): Promise<ResponseBody<Array<FieldConfigUnion>>>;
6
9
  /** Roles */
7
10
  export declare function getRoleList(): Promise<ResponseBody<Array<RoleType>>>;
8
11
  export declare function getRole(roleId: string | number): Promise<ResponseBody<RoleType>>;
@@ -24,6 +27,7 @@ export declare type AdminUpdatePayload = {
24
27
  email: string;
25
28
  roles: Array<number>;
26
29
  password: string;
30
+ params: Array<FieldShortType<OutgoingValueUnion>>;
27
31
  };
28
32
  export declare type AdminCreationPayload = AdminUpdatePayload;
29
33
  export declare function createAdmin(payload: AdminCreationPayload): Promise<ResponseBody<AdminType>>;
@@ -1,3 +1,4 @@
1
+ import { FieldShortType, IncomingValueUnion } from '@tager/admin-dynamic-field';
1
2
  export declare type ScopeType = {
2
3
  readonly value: string;
3
4
  readonly label: string;
@@ -22,4 +23,5 @@ export declare type AdminType = {
22
23
  readonly roles: Array<RoleType>;
23
24
  readonly isSelf: boolean;
24
25
  readonly isSuperAdmin: boolean;
26
+ readonly params: Array<FieldShortType<IncomingValueUnion>>;
25
27
  };
@@ -1,5 +1,6 @@
1
1
  import { Nullable } from '@tager/admin-services';
2
2
  import { OptionType } from '@tager/admin-ui';
3
+ import { FieldUnion } from '@tager/admin-dynamic-field';
3
4
  import { AdminType, RoleType } from '../../typings/model';
4
5
  import { AdminCreationPayload, AdminUpdatePayload } from '../../services/requests';
5
6
  export declare type FormValues = {
@@ -9,6 +10,6 @@ export declare type FormValues = {
9
10
  roles: Array<OptionType<number>>;
10
11
  };
11
12
  export declare function convertAdminToFormValues(admin: Nullable<AdminType>, roleOptionList: Array<OptionType<number>>): FormValues;
12
- export declare function convertFormValuesToAdminUpdatePayload(values: FormValues): AdminUpdatePayload;
13
- export declare function convertFormValuesToAdminCreationPayload(values: FormValues): AdminCreationPayload;
13
+ export declare function convertFormValuesToAdminUpdatePayload(values: FormValues, paramsValues?: Array<FieldUnion>): AdminUpdatePayload;
14
+ export declare function convertFormValuesToAdminCreationPayload(values: FormValues, paramsValues?: Array<FieldUnion>): AdminCreationPayload;
14
15
  export declare function convertRoleListToOptions(roleList: Array<RoleType>): Array<OptionType<number>>;