@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,34 +1,32 @@
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"
4
+ <FormField
5
+ v-model:value="values.name"
7
6
  name="name"
8
7
  :error="errors.name"
9
- :label="t('administrators:name')"
10
- />
11
- <form-field-multi-select
8
+ :label="$i18n.t('administrators:name')"
9
+ />
10
+ <FormFieldMultiSelect
12
11
  v-if="!values.isSuperAdmin"
13
- v-model="values.scopes"
12
+ v-model:selected-options="values.scopes"
14
13
  name="scopes"
15
- :label="t('administrators:privileges')"
14
+ :label="$i18n.t('administrators:privileges')"
16
15
  :options="scopeOptionList"
17
16
  :error="errors.scopes"
18
- />
19
- </template>
17
+ />
20
18
  </form>
21
19
 
22
- <template v-slot:footer>
20
+ <template #footer>
23
21
  <FormFooter
24
- :back-href="backButtonUrl"
25
- :on-submit="submitForm"
26
- :is-submitting="isSubmitting"
27
- :is-creation="isCreation"
28
- :can-create-another="isCreation"
22
+ :back-href="backButtonUrl"
23
+ @submit="submitForm"
24
+ :is-submitting="isSubmitting"
25
+ :is-creation="isCreation"
26
+ :can-create-another="isCreation"
29
27
  />
30
28
  </template>
31
- </page>
29
+ </Page>
32
30
  </template>
33
31
 
34
32
  <script lang="ts">
@@ -37,20 +35,24 @@ import {
37
35
  defineComponent,
38
36
  onMounted,
39
37
  ref,
40
- SetupContext,
41
38
  watch,
42
- } from '@vue/composition-api';
39
+ } from 'vue';
40
+
41
+ import {Page} from "@tager/admin-layout";
43
42
 
44
43
  import {
45
- convertRequestErrorToMap,
44
+ convertRequestErrorToMap, navigateBack,
46
45
  Nullable,
47
- useResource,
46
+ useResource, useToast,
48
47
  } from '@tager/admin-services';
48
+
49
+ import {useI18n} from "@tager/admin-services";
50
+
49
51
  import {
50
52
  OptionType,
51
53
  FormFooter,
52
54
  TagerFormSubmitEvent,
53
- useTranslation,
55
+ FormField, FormFieldMultiSelect
54
56
  } from '@tager/admin-ui';
55
57
 
56
58
  import {
@@ -59,8 +61,8 @@ import {
59
61
  getScopes,
60
62
  updateRole,
61
63
  } from '../../services/requests';
62
- import { RoleType, ScopeGroupsData } from '../../typings/model';
63
- import { getRoleFormUrl, getRoleListUrl } from '../../utils/paths';
64
+ import {RoleType, ScopeGroupsData} from '../../typings/model';
65
+ import {getRoleFormUrl, getRoleListUrl} from '../../utils/paths';
64
66
 
65
67
  import {
66
68
  convertFormValuesToRoleCreationPayload,
@@ -69,34 +71,35 @@ import {
69
71
  convertScopeDataToOptions,
70
72
  FormValues,
71
73
  } from './RoleForm.helpers';
74
+ import {useRoute, useRouter} from "vue-router";
72
75
 
73
76
  export default defineComponent({
74
77
  name: 'RoleForm',
75
- components: { FormFooter },
76
- setup(props, context: SetupContext) {
77
- const { t } = useTranslation(context);
78
+ components: {Page, FormFooter, FormField, FormFieldMultiSelect},
79
+ setup() {
80
+ const {t} = useI18n();
81
+
82
+ const route = useRoute();
83
+ const router = useRouter();
84
+ const toast = useToast();
78
85
 
79
- const roleId = computed<string>(() => context.root.$route.params.roleId);
86
+ const roleId = computed(() => route.params.roleId as string | number);
80
87
 
81
- const isCreation = computed<boolean>(() => roleId.value === 'create');
88
+ const isCreation = computed(() => roleId.value === "create");
82
89
 
83
- const [fetchRole, { data: role, loading: isRoleLoading }] = useResource<
84
- Nullable<RoleType>
85
- >({
90
+ const [fetchRole, {data: role, loading: isRoleLoading}] = useResource<Nullable<RoleType>>({
86
91
  fetchResource: () => getRole(roleId.value),
87
92
  initialValue: null,
88
- context,
89
93
  resourceName: 'Role',
90
94
  });
91
95
 
92
96
  /** Fetch scope list */
93
97
  const [
94
98
  fetchScopeData,
95
- { data: scopeData, loading: isScopeDataLoading },
99
+ {data: scopeData, loading: isScopeDataLoading},
96
100
  ] = useResource<Nullable<ScopeGroupsData>>({
97
101
  fetchResource: getScopes,
98
102
  initialValue: null,
99
- context,
100
103
  resourceName: 'Scope list',
101
104
  });
102
105
 
@@ -110,7 +113,7 @@ export default defineComponent({
110
113
 
111
114
  /** Scope Options */
112
115
  const scopeOptionList = computed<Array<OptionType>>(() =>
113
- convertScopeDataToOptions(scopeData.value)
116
+ convertScopeDataToOptions(scopeData.value)
114
117
  );
115
118
 
116
119
  const values = ref<FormValues>(convertRoleToFormValues(role.value));
@@ -128,61 +131,61 @@ export default defineComponent({
128
131
 
129
132
  const updateBody = convertFormValuesToRoleUpdatePayload(values.value);
130
133
  const requestPromise = isCreation.value
131
- ? createRole(creationBody)
132
- : updateRole(roleId.value, updateBody);
134
+ ? createRole(creationBody)
135
+ : updateRole(roleId.value, updateBody);
133
136
 
134
137
  requestPromise
135
- .then(({ data }) => {
136
- errors.value = {};
137
-
138
- if (event.type === 'create') {
139
- context.root.$router.push(getRoleFormUrl({ roleId: data.id }));
140
- }
141
-
142
- if (event.type === 'create_exit' || event.type === 'save_exit') {
143
- context.root.$router.push(getRoleListUrl());
144
- }
145
-
146
- if (event.type === 'create_create-another') {
147
- values.value = convertRoleToFormValues(null);
148
- }
149
-
150
- context.root.$toast({
151
- variant: 'success',
152
- title: t('administrators:success'),
153
- body: isCreation.value
154
- ? t('administrators:roleSuccessfullyCreated')
155
- : t('administrators:roleSuccessfullyUpdate'),
156
- });
157
- })
158
- .catch((error) => {
159
- console.error(error);
160
- errors.value = convertRequestErrorToMap(error);
161
- context.root.$toast({
162
- variant: 'danger',
163
- title: t('administrators:error'),
164
- body: isCreation.value
165
- ? t('administrators:roleCreationError')
166
- : t('administrators:roleUpdateError'),
138
+ .then(({data}) => {
139
+ errors.value = {};
140
+
141
+
142
+ if (event.type === "create") {
143
+ router.push(getRoleFormUrl({roleId: data.id}));
144
+ }
145
+
146
+ if (event.type === "create_exit" || event.type === "save_exit") {
147
+ navigateBack(router, getRoleListUrl());
148
+ }
149
+
150
+ if (event.type === 'create_create-another') {
151
+ values.value = convertRoleToFormValues(null);
152
+ }
153
+
154
+ toast.show({
155
+ variant: 'success',
156
+ title: t('administrators:success'),
157
+ body: isCreation.value
158
+ ? t('administrators:roleSuccessfullyCreated')
159
+ : t('administrators:roleSuccessfullyUpdate'),
160
+ });
161
+ })
162
+ .catch((error) => {
163
+ console.error(error);
164
+ errors.value = convertRequestErrorToMap(error);
165
+ toast.show({
166
+ variant: 'danger',
167
+ title: t('administrators:error'),
168
+ body: isCreation.value
169
+ ? t('administrators:roleCreationError')
170
+ : t('administrators:roleUpdateError'),
171
+ });
172
+ })
173
+ .finally(() => {
174
+ isSubmitting.value = false;
167
175
  });
168
- })
169
- .finally(() => {
170
- isSubmitting.value = false;
171
- });
172
176
  }
173
177
 
174
178
  const pageTitle = computed<string>(() => {
175
179
  return isCreation.value
176
- ? t('administrators:createRole')
177
- : `${t('administrators:updateRole')} "${values.value.name}"`;
180
+ ? t('administrators:createRole')
181
+ : `${t('administrators:updateRole')} "${values.value.name}"`;
178
182
  });
179
183
 
180
184
  const isContentLoading = computed<boolean>(
181
- () => isRoleLoading.value || isScopeDataLoading.value
185
+ () => isRoleLoading.value || isScopeDataLoading.value
182
186
  );
183
187
 
184
188
  return {
185
- t,
186
189
  backButtonUrl: getRoleListUrl(),
187
190
  values,
188
191
  errors,
@@ -1,104 +1,120 @@
1
1
  <template>
2
- <page
3
- :title="t('administrators:listOfRoles')"
4
- :header-buttons="[
2
+ <Page
3
+ :title="$i18n.t('administrators:listOfRoles')"
4
+ :header-buttons="[
5
5
  {
6
- text: t('administrators:addRole'),
6
+ text: $i18n.t('administrators:addRole'),
7
7
  href: getRoleFormUrl({ roleId: '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(scope)="{ row }">
16
+ >
17
+ <template #cell(scope)="{ row }">
19
18
  <span v-if="row.scopes.length === 0" class="no-scopes">
20
- {{ t('administrators:noPrivileges') }}
19
+ {{ $i18n.t('administrators:noPrivileges') }}
21
20
  </span>
22
- <span v-if="row.isSuperAdmin">{{ t('administrators:all') }}</span>
23
- <div
21
+ <span v-if="row.isSuperAdmin">{{ $i18n.t('administrators:all') }}</span>
22
+ <div
24
23
  v-for="scopeGroup in getScopeGroupList(row.scopes)"
25
24
  v-else
26
25
  :key="scopeGroup.module"
27
26
  class="scope-group"
28
- >
27
+ >
29
28
  <span class="module-name">
30
29
  {{ scopeGroup.module }}
31
30
  </span>
32
- <ul class="scope-list">
33
- <li
31
+ <ul class="scope-list">
32
+ <li
34
33
  v-for="scope of scopeGroup.scopes.slice(
35
34
  0,
36
35
  scopesPerModuleCount
37
36
  )"
38
37
  :key="scope.value"
39
- >
40
- <span>— {{ scope.label }}</span>
41
- </li>
42
- </ul>
43
- <span
38
+ >
39
+ <span>— {{ scope.label }}</span>
40
+ </li>
41
+ </ul>
42
+ <span
44
43
  v-if="scopeGroup.scopes.length > scopesPerModuleCount"
45
44
  class="rest-scopes-text"
46
- >
45
+ >
47
46
  {{
48
- getRestScopesText(
47
+ getRestScopesText(
49
48
  scopeGroup.scopes.length - scopesPerModuleCount
50
- )
51
- }}
49
+ )
50
+ }}
52
51
  </span>
53
- </div>
54
- </template>
55
- <template v-slot:cell(actions)="{ row }">
56
- <base-button
52
+ </div>
53
+ </template>
54
+ <template #cell(actions)="{ row }">
55
+ <BaseButton
57
56
  variant="icon"
58
- :title="t('administrators:edit')"
57
+ :title="$i18n.t('administrators:edit')"
59
58
  :disabled="isBusy(row.id)"
60
59
  :href="getRoleFormUrl({ roleId: row.id })"
61
- >
62
- <svg-icon name="edit"></svg-icon>
63
- </base-button>
64
- <base-button
60
+ >
61
+ <EditIcon/>
62
+ </BaseButton>
63
+ <BaseButton
65
64
  v-if="!row.isSuperAdmin"
66
65
  variant="icon"
67
- :title="t('administrators:delete')"
66
+ :title="$i18n.t('administrators:delete')"
68
67
  :disabled="isBusy(row.id)"
69
68
  @click="handleRoleDelete(row.id)"
70
- >
71
- <svg-icon name="delete"></svg-icon>
72
- </base-button>
73
- </template>
74
- </base-table>
75
- </template>
76
- </page>
69
+ >
70
+ <DeleteIcon/>
71
+ </BaseButton>
72
+ </template>
73
+ </DataTable>
74
+ </Page>
77
75
  </template>
78
76
 
79
77
  <script lang="ts">
80
- import { defineComponent, onMounted, SetupContext } from '@vue/composition-api';
78
+ import {defineComponent, onMounted} from "vue";
81
79
 
82
- import { useResource, useResourceDelete } from '@tager/admin-services';
83
- import { ColumnDefinition, useTranslation } from '@tager/admin-ui';
80
+ import {useResourceDelete, useI18n} from '@tager/admin-services';
81
+ import {Page} from "@tager/admin-layout";
84
82
 
85
- import { RoleType, ScopeType } from '../../typings/model';
86
- import { deleteRole, getRoleList } from '../../services/requests';
87
- import { getRoleFormUrl } from '../../utils/paths';
83
+ import {
84
+ BaseButton,
85
+ type ColumnDefinition,
86
+ DataTable,
87
+ DeleteIcon,
88
+ EditIcon,
89
+ useDataTable,
90
+ } from "@tager/admin-ui";
91
+
92
+ import {RoleType, ScopeType} from '../../typings/model';
93
+ import {deleteRole, getRoleList} from '../../services/requests';
94
+ import {getRoleFormUrl} from '../../utils/paths';
88
95
 
89
96
  export default defineComponent({
90
97
  name: 'RoleList',
91
- setup(props, context: SetupContext) {
92
- const { t } = useTranslation(context);
93
-
94
- const [
95
- fetchRoleList,
96
- { data: roleList, loading: isRoleLoading, error },
97
- ] = useResource<Array<RoleType>>({
98
- fetchResource: getRoleList,
98
+ components: {
99
+ Page,
100
+ DeleteIcon,
101
+ EditIcon,
102
+ DataTable,
103
+ BaseButton,
104
+ },
105
+ setup() {
106
+ const {t} = useI18n();
107
+
108
+ const {
109
+ fetchEntityList: fetchRoleList,
110
+ isLoading: isRoleListLoading,
111
+ rowData: roleList,
112
+ errorMessage: error,
113
+ } = useDataTable<RoleType>({
114
+ fetchEntityList: (params) => getRoleList(),
99
115
  initialValue: [],
100
- context,
101
- resourceName: 'Role list',
116
+ resourceName: "Role list",
117
+ pageSize: 100,
102
118
  });
103
119
 
104
120
  onMounted(() => {
@@ -112,15 +128,14 @@ export default defineComponent({
112
128
  deleteResource: deleteRole,
113
129
  resourceName: 'Role',
114
130
  onSuccess: fetchRoleList,
115
- context,
116
131
  });
117
132
 
118
133
  function isBusy(roleId: number): boolean {
119
- return isDeleting(roleId) || isRoleLoading.value;
134
+ return isDeleting(roleId) || isRoleListLoading.value;
120
135
  }
121
136
 
122
137
  function getScopeGroupList(
123
- scopes: Array<ScopeType>
138
+ scopes: Array<ScopeType>
124
139
  ): Array<{ module: string; scopes: ScopeType }> {
125
140
  const map = new Map();
126
141
  scopes.forEach((scope) => {
@@ -137,7 +152,7 @@ export default defineComponent({
137
152
 
138
153
  function getRestScopesText(restPrivilegesCount: number): string {
139
154
  if (restPrivilegesCount === 1) {
140
- return t('administrators:andMorePrivilege', { count: 1 });
155
+ return t('administrators:andMorePrivilege', {count: 1});
141
156
  }
142
157
 
143
158
  if (restPrivilegesCount > 1) {
@@ -164,16 +179,15 @@ export default defineComponent({
164
179
  id: 3,
165
180
  name: t('administrators:actions'),
166
181
  field: 'actions',
167
- style: { width: '180px', textAlign: 'center', whiteSpace: 'nowrap' },
168
- headStyle: { width: '180px', textAlign: 'center' },
182
+ style: {width: '180px', textAlign: 'center', whiteSpace: 'nowrap'},
183
+ headStyle: {width: '180px', textAlign: 'center'},
169
184
  },
170
185
  ];
171
186
 
172
187
  return {
173
- t,
174
188
  columnDefs,
175
189
  rowData: roleList,
176
- isRowDataLoading: isRoleLoading,
190
+ isRowDataLoading: isRoleListLoading,
177
191
  errorMessage: error,
178
192
  isBusy,
179
193
  handleRoleDelete,
package/CHANGELOG.md DELETED
File without changes
package/dist/dev.d.ts DELETED
@@ -1 +0,0 @@
1
- import '@tager/admin-ui/dist/admin-ui.css';