@tager/admin-administrators 0.2.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/constants/paths.d.ts +6 -6
  2. package/dist/constants/routes.d.ts +5 -5
  3. package/dist/dev/App.vue.d.ts +5 -0
  4. package/dist/dev/config.d.ts +2 -0
  5. package/dist/dev/env.d.ts +1 -0
  6. package/dist/dev/main.d.ts +3 -0
  7. package/dist/index.mjs +875 -0
  8. package/dist/locales/apply.d.ts +1 -0
  9. package/dist/locales/en.d.ts +40 -40
  10. package/dist/locales/ru.d.ts +2 -3
  11. package/dist/main.d.ts +3 -3
  12. package/dist/services/requests.d.ts +32 -32
  13. package/dist/style.css +1 -0
  14. package/dist/typings/model.d.ts +25 -25
  15. package/dist/utils/paths.d.ts +8 -8
  16. package/dist/views/AdminForm/AdminForm.helpers.d.ts +14 -14
  17. package/dist/views/AdminForm/AdminForm.vue.d.ts +26 -61
  18. package/dist/views/AdminForm/index.d.ts +1 -1
  19. package/dist/views/AdminList/AdminList.vue.d.ts +14 -33
  20. package/dist/views/AdminList/index.d.ts +1 -1
  21. package/dist/views/RoleForm/RoleForm.helpers.d.ts +13 -13
  22. package/dist/views/RoleForm/RoleForm.vue.d.ts +24 -59
  23. package/dist/views/RoleForm/index.d.ts +1 -1
  24. package/dist/views/RoleList/RoleList.vue.d.ts +20 -46
  25. package/dist/views/RoleList/index.d.ts +1 -1
  26. package/package.json +51 -50
  27. package/src/constants/routes.ts +19 -19
  28. package/src/dev/App.vue +57 -0
  29. package/src/dev/config.ts +23 -0
  30. package/src/dev/env.ts +17 -0
  31. package/src/dev/main.ts +46 -0
  32. package/src/locales/apply.ts +9 -0
  33. package/src/locales/en.ts +2 -3
  34. package/src/locales/ru.ts +40 -41
  35. package/src/main.ts +5 -9
  36. package/src/views/AdminForm/AdminForm.vue +99 -96
  37. package/src/views/AdminList/AdminList.vue +54 -49
  38. package/src/views/RoleForm/RoleForm.vue +86 -81
  39. package/src/views/RoleList/RoleList.vue +78 -64
  40. package/CHANGELOG.md +0 -0
  41. package/dist/dev.d.ts +0 -1
  42. package/dist/index.esm.js +0 -1334
  43. package/dist/index.umd.js +0 -1357
  44. package/src/config/config.json +0 -20
  45. package/src/dev.ts +0 -51
  46. package/src/typings/sfc.d.ts +0 -12
  47. package/src/typings/shims-tsx.d.ts +0 -13
  48. package/src/typings/shims-vue.d.ts +0 -11
  49. package/src/views/App.vue +0 -52
@@ -1,32 +1,32 @@
1
1
  <template>
2
- <page
3
- :title="pageTitle"
4
- :is-content-loading="isContentLoading"
5
- :footer="{
6
- backHref: backButtonUrl,
7
- onSubmit: submitForm,
8
- isSubmitting: isSubmitting,
9
- }"
10
- >
2
+ <Page :title="pageTitle" :is-content-loading="isContentLoading">
11
3
  <form novalidate @submit.prevent>
12
- <template>
13
- <form-field
14
- v-model="values.name"
4
+ <FormField
5
+ v-model:value="values.name"
15
6
  name="name"
16
7
  :error="errors.name"
17
- :label="t('administrators:name')"
18
- />
19
- <form-field-multi-select
8
+ :label="$i18n.t('administrators:name')"
9
+ />
10
+ <FormFieldMultiSelect
20
11
  v-if="!values.isSuperAdmin"
21
- v-model="values.scopes"
12
+ v-model:selected-options="values.scopes"
22
13
  name="scopes"
23
- :label="t('administrators:privileges')"
14
+ :label="$i18n.t('administrators:privileges')"
24
15
  :options="scopeOptionList"
25
16
  :error="errors.scopes"
26
- />
27
- </template>
17
+ />
28
18
  </form>
29
- </page>
19
+
20
+ <template #footer>
21
+ <FormFooter
22
+ :back-href="backButtonUrl"
23
+ @submit="submitForm"
24
+ :is-submitting="isSubmitting"
25
+ :is-creation="isCreation"
26
+ :can-create-another="isCreation"
27
+ />
28
+ </template>
29
+ </Page>
30
30
  </template>
31
31
 
32
32
  <script lang="ts">
@@ -35,20 +35,24 @@ import {
35
35
  defineComponent,
36
36
  onMounted,
37
37
  ref,
38
- SetupContext,
39
38
  watch,
40
- } from '@vue/composition-api';
39
+ } from 'vue';
40
+
41
+ import {Page} from "@tager/admin-layout";
41
42
 
42
43
  import {
43
- convertRequestErrorToMap,
44
+ convertRequestErrorToMap, navigateBack,
44
45
  Nullable,
45
- useResource,
46
+ useResource, useToast,
46
47
  } from '@tager/admin-services';
48
+
49
+ import {useI18n} from "@tager/admin-services";
50
+
47
51
  import {
48
52
  OptionType,
49
53
  FormFooter,
50
54
  TagerFormSubmitEvent,
51
- useTranslation,
55
+ FormField, FormFieldMultiSelect
52
56
  } from '@tager/admin-ui';
53
57
 
54
58
  import {
@@ -57,8 +61,8 @@ import {
57
61
  getScopes,
58
62
  updateRole,
59
63
  } from '../../services/requests';
60
- import { RoleType, ScopeGroupsData } from '../../typings/model';
61
- import { getRoleFormUrl, getRoleListUrl } from '../../utils/paths';
64
+ import {RoleType, ScopeGroupsData} from '../../typings/model';
65
+ import {getRoleFormUrl, getRoleListUrl} from '../../utils/paths';
62
66
 
63
67
  import {
64
68
  convertFormValuesToRoleCreationPayload,
@@ -67,34 +71,35 @@ import {
67
71
  convertScopeDataToOptions,
68
72
  FormValues,
69
73
  } from './RoleForm.helpers';
74
+ import {useRoute, useRouter} from "vue-router";
70
75
 
71
76
  export default defineComponent({
72
77
  name: 'RoleForm',
73
- components: { FormFooter },
74
- setup(props, context: SetupContext) {
75
- 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();
76
85
 
77
- const roleId = computed<string>(() => context.root.$route.params.roleId);
86
+ const roleId = computed(() => route.params.roleId as string | number);
78
87
 
79
- const isCreation = computed<boolean>(() => roleId.value === 'create');
88
+ const isCreation = computed(() => roleId.value === "create");
80
89
 
81
- const [fetchRole, { data: role, loading: isRoleLoading }] = useResource<
82
- Nullable<RoleType>
83
- >({
90
+ const [fetchRole, {data: role, loading: isRoleLoading}] = useResource<Nullable<RoleType>>({
84
91
  fetchResource: () => getRole(roleId.value),
85
92
  initialValue: null,
86
- context,
87
93
  resourceName: 'Role',
88
94
  });
89
95
 
90
96
  /** Fetch scope list */
91
97
  const [
92
98
  fetchScopeData,
93
- { data: scopeData, loading: isScopeDataLoading },
99
+ {data: scopeData, loading: isScopeDataLoading},
94
100
  ] = useResource<Nullable<ScopeGroupsData>>({
95
101
  fetchResource: getScopes,
96
102
  initialValue: null,
97
- context,
98
103
  resourceName: 'Scope list',
99
104
  });
100
105
 
@@ -108,7 +113,7 @@ export default defineComponent({
108
113
 
109
114
  /** Scope Options */
110
115
  const scopeOptionList = computed<Array<OptionType>>(() =>
111
- convertScopeDataToOptions(scopeData.value)
116
+ convertScopeDataToOptions(scopeData.value)
112
117
  );
113
118
 
114
119
  const values = ref<FormValues>(convertRoleToFormValues(role.value));
@@ -126,61 +131,61 @@ export default defineComponent({
126
131
 
127
132
  const updateBody = convertFormValuesToRoleUpdatePayload(values.value);
128
133
  const requestPromise = isCreation.value
129
- ? createRole(creationBody)
130
- : updateRole(roleId.value, updateBody);
134
+ ? createRole(creationBody)
135
+ : updateRole(roleId.value, updateBody);
131
136
 
132
137
  requestPromise
133
- .then(({ data }) => {
134
- errors.value = {};
135
-
136
- if (event.type === 'create') {
137
- context.root.$router.push(getRoleFormUrl({ roleId: data.id }));
138
- }
139
-
140
- if (event.type === 'create_exit' || event.type === 'save_exit') {
141
- context.root.$router.push(getRoleListUrl());
142
- }
143
-
144
- if (event.type === 'create_create-another') {
145
- values.value = convertRoleToFormValues(null);
146
- }
147
-
148
- context.root.$toast({
149
- variant: 'success',
150
- title: t('administrators:success'),
151
- body: isCreation.value
152
- ? t('administrators:roleSuccessfullyCreated')
153
- : t('administrators:roleSuccessfullyUpdate'),
154
- });
155
- })
156
- .catch((error) => {
157
- console.error(error);
158
- errors.value = convertRequestErrorToMap(error);
159
- context.root.$toast({
160
- variant: 'danger',
161
- title: t('administrators:error'),
162
- body: isCreation.value
163
- ? t('administrators:roleCreationError')
164
- : 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;
165
175
  });
166
- })
167
- .finally(() => {
168
- isSubmitting.value = false;
169
- });
170
176
  }
171
177
 
172
178
  const pageTitle = computed<string>(() => {
173
179
  return isCreation.value
174
- ? t('administrators:createRole')
175
- : `${t('administrators:updateRole')} "${values.value.name}"`;
180
+ ? t('administrators:createRole')
181
+ : `${t('administrators:updateRole')} "${values.value.name}"`;
176
182
  });
177
183
 
178
184
  const isContentLoading = computed<boolean>(
179
- () => isRoleLoading.value || isScopeDataLoading.value
185
+ () => isRoleLoading.value || isScopeDataLoading.value
180
186
  );
181
187
 
182
188
  return {
183
- t,
184
189
  backButtonUrl: getRoleListUrl(),
185
190
  values,
186
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';