@tager/admin-administrators 0.2.7 → 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 -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 +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 +1 -3
  34. package/src/locales/ru.ts +40 -42
  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 +82 -79
  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 -1350
  43. package/dist/index.umd.js +0 -1373
  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
@@ -1,49 +1,47 @@
1
1
  <template>
2
- <page :title="pageTitle" :is-content-loading="isContentLoading">
2
+ <Page :title="pageTitle" :is-content-loading="isContentLoading">
3
3
  <form novalidate @submit.prevent>
4
- <template>
5
- <form-field
6
- v-model="values.name"
7
- name="name"
8
- :error="errors.name"
9
- :label="t('administrators:name')"
4
+ <FormField
5
+ v-model:value="values.name"
6
+ name="name"
7
+ :error="errors.name"
8
+ :label="$i18n.t('administrators:name')"
10
9
  />
11
- <form-field
12
- v-model="values.email"
13
- name="email"
14
- :error="errors.email"
15
- :label="t('administrators:email')"
10
+ <FormField
11
+ v-model:value="values.email"
12
+ name="email"
13
+ :error="errors.email"
14
+ :label="$i18n.t('administrators:email')"
16
15
  />
17
- <form-field-multi-select
18
- v-model="values.roles"
19
- name="roles"
20
- :label="t('administrators:roles')"
21
- :options="roleOptionList"
22
- :error="errors.roles"
16
+ <FormFieldMultiSelect
17
+ v-model:selected-options="values.roles"
18
+ name="roles"
19
+ :label="$i18n.t('administrators:roles')"
20
+ :options="roleOptionList"
21
+ :error="errors.roles"
23
22
  />
24
- <form-field
25
- v-model="values.password"
26
- name="password"
27
- :error="errors.password"
28
- :label="
23
+ <FormField
24
+ v-model:value="values.password"
25
+ name="password"
26
+ :error="errors.password"
27
+ :label="
29
28
  isCreation
30
- ? t('administrators:password')
31
- : t('administrators:newPassword')
29
+ ? $i18n.t('administrators:password')
30
+ : $i18n.t('administrators:newPassword')
32
31
  "
33
32
  />
34
- </template>
35
33
  </form>
36
34
 
37
- <template v-slot:footer>
35
+ <template #footer>
38
36
  <FormFooter
39
- :back-href="backButtonUrl"
40
- :on-submit="submitForm"
41
- :is-submitting="isSubmitting"
42
- :is-creation="isCreation"
43
- :can-create-another="isCreation"
37
+ :back-href="backButtonUrl"
38
+ @submit="submitForm"
39
+ :is-submitting="isSubmitting"
40
+ :is-creation="isCreation"
41
+ :can-create-another="isCreation"
44
42
  />
45
43
  </template>
46
- </page>
44
+ </Page>
47
45
  </template>
48
46
 
49
47
  <script lang="ts">
@@ -54,23 +52,27 @@ import {
54
52
  ref,
55
53
  SetupContext,
56
54
  watch,
57
- } from '@vue/composition-api';
55
+ } from 'vue';
56
+
57
+ import {Page} from "@tager/admin-layout";
58
58
 
59
59
  import {
60
- convertRequestErrorToMap,
60
+ convertRequestErrorToMap, navigateBack,
61
61
  Nullable,
62
- useResource,
62
+ useResource, useToast,
63
63
  } from '@tager/admin-services';
64
- import { OptionType, FormFooter, TagerFormSubmitEvent, useTranslation } from '@tager/admin-ui';
64
+ import {OptionType, FormFooter, TagerFormSubmitEvent, FormField, FormFieldMultiSelect} from '@tager/admin-ui';
65
+
66
+ import {useI18n} from "@tager/admin-services";
65
67
 
66
- import { AdminType, RoleType } from '../../typings/model';
68
+ import {AdminType, RoleType} from '../../typings/model';
67
69
  import {
68
70
  createAdmin,
69
71
  getAdmin,
70
72
  getRoleList,
71
73
  updateAdmin,
72
74
  } from '../../services/requests';
73
- import { getAdminFormUrl, getAdminListUrl } from '../../utils/paths';
75
+ import {getAdminFormUrl, getAdminListUrl, getRoleFormUrl, getRoleListUrl} from '../../utils/paths';
74
76
 
75
77
  import {
76
78
  convertFormValuesToAdminCreationPayload,
@@ -79,23 +81,25 @@ import {
79
81
  convertRoleListToOptions,
80
82
  FormValues,
81
83
  } from './AdminForm.helpers';
84
+ import {useRoute, useRouter} from "vue-router";
82
85
 
83
86
  export default defineComponent({
84
87
  name: 'AdminForm',
85
- components: { FormFooter },
86
- setup(props, context: SetupContext) {
87
- const { t } = useTranslation(context);
88
+ components: {Page, FormFooter, FormField, FormFieldMultiSelect},
89
+ setup() {
90
+ const {t} = useI18n();
88
91
 
89
- const adminId = computed<string>(() => context.root.$route.params.adminId);
92
+ const route = useRoute();
93
+ const router = useRouter();
94
+ const toast = useToast();
90
95
 
91
- const isCreation = computed<boolean>(() => adminId.value === 'create');
96
+ const adminId = computed(() => route.params.adminId as string | number);
92
97
 
93
- const [fetchAdmin, { data: admin, loading: isAdminLoading }] = useResource<
94
- Nullable<AdminType>
95
- >({
98
+ const isCreation = computed(() => adminId.value === "create");
99
+
100
+ const [fetchAdmin, {data: admin, loading: isAdminLoading}] = useResource<Nullable<AdminType>>({
96
101
  fetchResource: () => getAdmin(adminId.value),
97
102
  initialValue: null,
98
- context,
99
103
  resourceName: 'Admin',
100
104
  });
101
105
 
@@ -103,11 +107,10 @@ export default defineComponent({
103
107
 
104
108
  const [
105
109
  fetchRoleList,
106
- { data: roleList, loading: isRoleListLoading },
110
+ {data: roleList, loading: isRoleListLoading},
107
111
  ] = useResource<Array<RoleType>>({
108
112
  fetchResource: getRoleList,
109
113
  initialValue: [],
110
- context,
111
114
  resourceName: 'Role list',
112
115
  });
113
116
 
@@ -120,11 +123,11 @@ export default defineComponent({
120
123
 
121
124
  /** Role Options */
122
125
  const roleOptionList = computed<Array<OptionType<number>>>(() =>
123
- convertRoleListToOptions(roleList.value)
126
+ convertRoleListToOptions(roleList.value)
124
127
  );
125
128
 
126
129
  const values = ref<FormValues>(
127
- convertAdminToFormValues(admin.value, roleOptionList.value)
130
+ convertAdminToFormValues(admin.value, roleOptionList.value)
128
131
  );
129
132
 
130
133
  const errors = ref<Record<string, string>>({});
@@ -132,8 +135,8 @@ export default defineComponent({
132
135
 
133
136
  watch([admin, roleOptionList], () => {
134
137
  values.value = convertAdminToFormValues(
135
- admin.value,
136
- roleOptionList.value
138
+ admin.value,
139
+ roleOptionList.value
137
140
  );
138
141
  });
139
142
 
@@ -143,63 +146,63 @@ export default defineComponent({
143
146
  if (admin.value && admin.value.isSelf) return;
144
147
 
145
148
  const creationBody = convertFormValuesToAdminCreationPayload(
146
- values.value
149
+ values.value
147
150
  );
148
151
 
149
152
  const updateBody = convertFormValuesToAdminUpdatePayload(values.value);
150
153
 
151
154
  const requestPromise = isCreation.value
152
- ? createAdmin(creationBody)
153
- : updateAdmin(adminId.value, updateBody);
155
+ ? createAdmin(creationBody)
156
+ : updateAdmin(adminId.value, updateBody);
154
157
 
155
158
  requestPromise
156
- .then(({ data }) => {
157
- errors.value = {};
158
-
159
- if (event.type === 'create') {
160
- context.root.$router.push(getAdminFormUrl({ adminId: data.id }));
161
- }
162
-
163
- if (event.type === 'create_exit' || event.type === 'save_exit') {
164
- context.root.$router.push(getAdminListUrl());
165
- }
166
-
167
- if (event.type === 'create_create-another') {
168
- values.value = convertAdminToFormValues(null, roleOptionList.value);
169
- }
170
-
171
- context.root.$toast({
172
- variant: 'success',
173
- title: t('administrators:success'),
174
- body: isCreation.value
175
- ? t('administrators:adminSuccessfullyCreated')
176
- : t('administrators:adminSuccessfullyUpdated'),
177
- });
178
- })
179
- .catch((error) => {
180
- console.error(error);
181
- errors.value = convertRequestErrorToMap(error);
182
- context.root.$toast({
183
- variant: 'danger',
184
- title: t('administrators:error'),
185
- body: isCreation.value
186
- ? t('administrators:adminCreationError')
187
- : t('administrators:adminUpdateError'),
159
+ .then(({data}) => {
160
+ errors.value = {};
161
+
162
+ if (event.type === "create") {
163
+ router.push(getAdminFormUrl({adminId: data.id}));
164
+ }
165
+
166
+ if (event.type === "create_exit" || event.type === "save_exit") {
167
+ navigateBack(router, getAdminListUrl());
168
+ }
169
+
170
+ if (event.type === 'create_create-another') {
171
+ values.value = convertAdminToFormValues(null, roleOptionList.value);
172
+ }
173
+
174
+ toast.show({
175
+ variant: 'success',
176
+ title: t('administrators:success'),
177
+ body: isCreation.value
178
+ ? t('administrators:adminSuccessfullyCreated')
179
+ : t('administrators:adminSuccessfullyUpdated'),
180
+ });
181
+ })
182
+ .catch((error) => {
183
+ console.error(error);
184
+ errors.value = convertRequestErrorToMap(error);
185
+ toast.show({
186
+ variant: 'danger',
187
+ title: t('administrators:error'),
188
+ body: isCreation.value
189
+ ? t('administrators:adminCreationError')
190
+ : t('administrators:adminUpdateError'),
191
+ });
192
+ })
193
+ .finally(() => {
194
+ isSubmitting.value = false;
188
195
  });
189
- })
190
- .finally(() => {
191
- isSubmitting.value = false;
192
- });
193
196
  }
194
197
 
195
198
  const pageTitle = computed<string>(() => {
196
199
  return isCreation.value
197
- ? t('administrators:createAdmin')
198
- : `${t('administrators:updateAdmin')} "${values.value.name}"`;
200
+ ? t('administrators:createAdmin')
201
+ : `${t('administrators:updateAdmin')} "${values.value.name}"`;
199
202
  });
200
203
 
201
204
  const isContentLoading = computed<boolean>(
202
- () => isAdminLoading.value || isRoleListLoading.value
205
+ () => isAdminLoading.value || isRoleListLoading.value
203
206
  );
204
207
 
205
208
  return {
@@ -1,75 +1,81 @@
1
1
  <template>
2
- <page
3
- :title="t('administrators:administrators')"
4
- :header-buttons="[
2
+ <Page
3
+ :title="$i18n.t('administrators:administrators')"
4
+ :header-buttons="[
5
5
  {
6
- text: t('administrators:createAdministrator'),
6
+ text: $i18n.t('administrators:createAdministrator'),
7
7
  href: getAdminFormUrl({ adminId: 'create' }),
8
8
  },
9
9
  ]"
10
10
  >
11
- <template v-slot:content>
12
- <base-table
11
+ <DataTable
13
12
  :column-defs="columnDefs"
14
13
  :row-data="rowData"
15
14
  :loading="isRowDataLoading"
16
15
  :error-message="errorMessage"
17
- >
18
- <template v-slot:cell(roles)="{ row }">
19
- <ul>
20
- <li v-for="role of row.roles" :key="role.id">
21
- {{ role.name }}
22
- </li>
23
- </ul>
24
- </template>
25
- <template v-slot:cell(actions)="{ row }">
26
- <base-button
16
+ >
17
+ <template v-slot:cell(roles)="{ row }">
18
+ <ul>
19
+ <li v-for="role of row.roles" :key="role.id">
20
+ {{ role.name }}
21
+ </li>
22
+ </ul>
23
+ </template>
24
+ <template #cell(actions)="{ row }">
25
+ <BaseButton
27
26
  v-if="!row.isSelf"
28
27
  variant="icon"
29
- :title="t('administrators:edit')"
28
+ :title="$i18n.t('administrators:edit')"
30
29
  :disabled="isBusy(row.id)"
31
30
  :href="getAdminFormUrl({ adminId: row.id })"
32
- >
33
- <svg-icon name="edit"></svg-icon>
34
- </base-button>
35
- <base-button
31
+ >
32
+ <EditIcon/>
33
+ </BaseButton>
34
+ <BaseButton
36
35
  v-if="!row.isSuperAdmin || !row.isSelf"
37
36
  variant="icon"
38
- :title="t('administrators:delete')"
37
+ :title="$i18n.t('administrators:delete')"
39
38
  :disabled="isBusy(row.id)"
40
39
  @click="handleAdminDelete(row.id)"
41
- >
42
- <svg-icon name="delete"></svg-icon>
43
- </base-button>
44
- </template>
45
- </base-table>
46
- </template>
47
- </page>
40
+ >
41
+ <DeleteIcon/>
42
+ </BaseButton>
43
+ </template>
44
+ </DataTable>
45
+ </Page>
48
46
  </template>
49
47
 
50
48
  <script lang="ts">
51
- import { defineComponent, onMounted, SetupContext } from '@vue/composition-api';
49
+ import {defineComponent, onMounted} from 'vue';
52
50
 
53
- import { useResource, useResourceDelete } from '@tager/admin-services';
54
- import { ColumnDefinition, useTranslation } from '@tager/admin-ui';
51
+ import {useResourceDelete} from '@tager/admin-services';
52
+ import {ColumnDefinition, DataTable, BaseButton, DeleteIcon, EditIcon, useDataTable} from '@tager/admin-ui';
53
+ import {useI18n} from "@tager/admin-services";
55
54
 
56
- import { AdminType } from '../../typings/model';
57
- import { deleteAdmin, getAdminList } from '../../services/requests';
58
- import { getAdminFormUrl } from '../../utils/paths';
55
+ import {AdminType} from '../../typings/model';
56
+ import {deleteAdmin, getAdminList} from '../../services/requests';
57
+ import {getAdminFormUrl} from '../../utils/paths';
58
+
59
+ import {Page} from "@tager/admin-layout";
59
60
 
60
61
  export default defineComponent({
61
62
  name: 'AdminList',
62
- setup(props, context: SetupContext) {
63
- const { t } = useTranslation(context);
63
+ components: {
64
+ Page, DataTable, BaseButton, DeleteIcon, EditIcon
65
+ },
66
+ setup() {
67
+ const {t} = useI18n();
64
68
 
65
- const [
66
- fetchAdminList,
67
- { data: adminList, loading: isAdminLoading, error },
68
- ] = useResource<Array<AdminType>>({
69
- fetchResource: getAdminList,
69
+ const {
70
+ fetchEntityList: fetchAdminList,
71
+ isLoading: isAdminListLoading,
72
+ rowData: adminList,
73
+ errorMessage: error,
74
+ } = useDataTable<AdminType>({
75
+ fetchEntityList: () => getAdminList(),
70
76
  initialValue: [],
71
- context,
72
- resourceName: 'Admin list',
77
+ resourceName: "Admin list",
78
+ pageSize: 100,
73
79
  });
74
80
 
75
81
  onMounted(() => {
@@ -83,11 +89,10 @@ export default defineComponent({
83
89
  deleteResource: deleteAdmin,
84
90
  resourceName: 'Admin',
85
91
  onSuccess: fetchAdminList,
86
- context,
87
92
  });
88
93
 
89
94
  function isBusy(adminId: number): boolean {
90
- return isDeleting(adminId) || isAdminLoading.value;
95
+ return isDeleting(adminId) || isAdminListLoading.value;
91
96
  }
92
97
 
93
98
  const columnDefs: Array<ColumnDefinition<AdminType>> = [
@@ -110,8 +115,8 @@ export default defineComponent({
110
115
  id: 4,
111
116
  name: t('administrators:actions'),
112
117
  field: 'actions',
113
- style: { width: '180px', textAlign: 'center', whiteSpace: 'nowrap' },
114
- headStyle: { width: '180px', textAlign: 'center' },
118
+ style: {width: '180px', textAlign: 'center', whiteSpace: 'nowrap'},
119
+ headStyle: {width: '180px', textAlign: 'center'},
115
120
  },
116
121
  ];
117
122
 
@@ -119,7 +124,7 @@ export default defineComponent({
119
124
  t,
120
125
  columnDefs,
121
126
  rowData: adminList,
122
- isRowDataLoading: isAdminLoading,
127
+ isRowDataLoading: isAdminListLoading,
123
128
  errorMessage: error,
124
129
  isBusy,
125
130
  handleAdminDelete,