@tager/admin-banners 0.3.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 (70) hide show
  1. package/dist/constants/paths.d.ts +5 -10
  2. package/dist/constants/routes.d.ts +4 -4
  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/hooks/index.d.ts +2 -2
  8. package/dist/hooks/useFetchBanner.d.ts +7 -8
  9. package/dist/hooks/useFetchBanners.d.ts +3 -6
  10. package/dist/hooks/useFetchZoneFields.d.ts +7 -8
  11. package/dist/hooks/useFetchZones.d.ts +3 -6
  12. package/dist/index.mjs +993 -0
  13. package/dist/locales/apply.d.ts +1 -0
  14. package/dist/locales/en.d.ts +41 -41
  15. package/dist/locales/ru.d.ts +2 -3
  16. package/dist/main.d.ts +3 -4
  17. package/dist/services/requests.d.ts +25 -25
  18. package/dist/style.css +1 -0
  19. package/dist/typings/banners.d.ts +47 -47
  20. package/dist/typings/common.d.ts +1 -1
  21. package/dist/typings/model.d.ts +104 -104
  22. package/dist/typings/zones.d.ts +9 -9
  23. package/dist/utils/common.d.ts +2 -2
  24. package/dist/utils/paths.d.ts +5 -0
  25. package/dist/views/Banners/BannerForm/BannerForm.helpers.d.ts +5 -5
  26. package/dist/views/Banners/BannerForm/BannerForm.vue.d.ts +2694 -9251
  27. package/dist/views/Banners/BannerForm/index.d.ts +1 -1
  28. package/dist/views/Banners/BannerList/BannerList.helpers.d.ts +6 -6
  29. package/dist/views/Banners/BannerList/BannerList.vue.d.ts +25 -55
  30. package/dist/views/Banners/BannerList/hooks/index.d.ts +1 -1
  31. package/dist/views/Banners/BannerList/hooks/useAdvancedSearch.d.ts +23 -21
  32. package/dist/views/Banners/BannerList/index.d.ts +1 -1
  33. package/dist/views/Zones/ZoneList/ZoneList.helpers.d.ts +5 -5
  34. package/dist/views/Zones/ZoneList/ZoneList.vue.d.ts +11 -28
  35. package/dist/views/Zones/ZoneList/index.d.ts +1 -1
  36. package/package.json +51 -49
  37. package/src/constants/paths.ts +1 -15
  38. package/src/constants/routes.ts +7 -7
  39. package/src/dev/App.vue +46 -0
  40. package/src/dev/config.ts +23 -0
  41. package/src/dev/env.ts +17 -0
  42. package/src/dev/main.ts +47 -0
  43. package/src/hooks/useFetchBanner.ts +3 -6
  44. package/src/hooks/useFetchBanners.ts +2 -5
  45. package/src/hooks/useFetchZoneFields.ts +1 -10
  46. package/src/hooks/useFetchZones.ts +2 -5
  47. package/src/locales/apply.ts +9 -0
  48. package/src/locales/en.ts +1 -1
  49. package/src/locales/ru.ts +40 -42
  50. package/src/main.ts +3 -8
  51. package/src/utils/paths.ts +15 -0
  52. package/src/views/Banners/BannerForm/BannerForm.vue +97 -80
  53. package/src/views/Banners/BannerList/BannerList.vue +60 -47
  54. package/src/views/Banners/BannerList/hooks/useAdvancedSearch.ts +14 -14
  55. package/src/views/Zones/ZoneList/ZoneList.helpers.ts +1 -1
  56. package/src/views/Zones/ZoneList/ZoneList.vue +18 -19
  57. package/CHANGELOG.md +0 -13
  58. package/dist/constants/menu.d.ts +0 -5
  59. package/dist/dev.d.ts +0 -1
  60. package/dist/index.esm.js +0 -3709
  61. package/dist/index.umd.js +0 -3728
  62. package/dist/router/index.d.ts +0 -4
  63. package/src/constants/menu.ts +0 -26
  64. package/src/dev.ts +0 -34
  65. package/src/router/index.ts +0 -38
  66. package/src/typings/sfc.d.ts +0 -12
  67. package/src/typings/shims-tsx.d.ts +0 -13
  68. package/src/typings/shims-vue.d.ts +0 -11
  69. package/src/views/App.vue +0 -22
  70. package/src/views/Home.vue +0 -37
@@ -1,17 +1,14 @@
1
- import { onMounted, SetupContext } from '@vue/composition-api';
1
+ import { onMounted } from 'vue';
2
2
 
3
3
  import { ResourceRef, useResource } from '@tager/admin-services';
4
4
 
5
5
  import { getZones } from '../services/requests';
6
6
  import { Zone } from '../typings/zones';
7
7
 
8
- export function useFetchZones(params: {
9
- context: SetupContext;
10
- }): ResourceRef<Zone[]> {
8
+ export function useFetchZones(): ResourceRef<Zone[]> {
11
9
  const [fetchZones, resource] = useResource<Zone[]>({
12
10
  fetchResource: getZones,
13
11
  initialValue: [],
14
- context: params.context,
15
12
  resourceName: 'Banner zones',
16
13
  });
17
14
 
@@ -0,0 +1,9 @@
1
+ import { i18n } from '@tager/admin-services';
2
+
3
+ import { EN } from './en';
4
+ import { RU } from './ru';
5
+
6
+ export function applyTranslations() {
7
+ i18n.addTranslations('en', 'banners', EN);
8
+ i18n.addTranslations('ru', 'banners', RU);
9
+ }
package/src/locales/en.ts CHANGED
@@ -1,4 +1,4 @@
1
- const EN = {
1
+ export const EN = {
2
2
  home: 'Home',
3
3
  zone: 'Banner zone',
4
4
  zones: 'Banner zones',
package/src/locales/ru.ts CHANGED
@@ -1,47 +1,45 @@
1
- import EN from './en';
1
+ import {EN} from './en';
2
2
 
3
- const RU: typeof EN = {
4
- home: 'Главная',
5
- zone: 'Баннерная зона',
6
- zones: 'Баннерные зоны',
7
- banners: 'Баннеры',
8
- bannerForm: 'Форма баннера',
9
- createBanner: 'Добавить баннер',
10
- updateBanner: 'Редактировать баннер',
11
- link: 'Ссылка',
12
- image: 'Картинка',
13
- openNewTab: 'Открывать в новой вкладке',
14
- period: 'Срок действия',
15
- from: 'От',
16
- to: 'До',
17
- disabled: 'Выключен',
18
- comment: 'Комментарий',
19
- status: 'Статус',
20
- bannerZoneIsDeleted: 'Баннерная зона удалена',
21
- newTab: 'Новая вкладка',
22
- yes: 'Да',
23
- no: 'Нет',
24
- edit: 'Редактировать',
25
- remove: 'Удалить',
26
- actions: 'Действия',
27
- date: 'Дата',
28
- name: 'Название',
29
- priority: 'Приоритет',
3
+ export const RU: typeof EN = {
4
+ home: 'Главная',
5
+ zone: 'Баннерная зона',
6
+ zones: 'Баннерные зоны',
7
+ banners: 'Баннеры',
8
+ bannerForm: 'Форма баннера',
9
+ createBanner: 'Добавить баннер',
10
+ updateBanner: 'Редактировать баннер',
11
+ link: 'Ссылка',
12
+ image: 'Картинка',
13
+ openNewTab: 'Открывать в новой вкладке',
14
+ period: 'Срок действия',
15
+ from: 'От',
16
+ to: 'До',
17
+ disabled: 'Выключен',
18
+ comment: 'Комментарий',
19
+ status: 'Статус',
20
+ bannerZoneIsDeleted: 'Баннерная зона удалена',
21
+ newTab: 'Новая вкладка',
22
+ yes: 'Да',
23
+ no: 'Нет',
24
+ edit: 'Редактировать',
25
+ remove: 'Удалить',
26
+ actions: 'Действия',
27
+ date: 'Дата',
28
+ name: 'Название',
29
+ priority: 'Приоритет',
30
30
 
31
- success: 'Успех',
32
- error: 'Ошибка',
31
+ success: 'Успех',
32
+ error: 'Ошибка',
33
33
 
34
- statuses: {
35
- waiting: 'В ожидании',
36
- archived: 'Архивный',
37
- active: 'Активный',
38
- disabled: 'Отключен',
39
- },
34
+ statuses: {
35
+ waiting: 'В ожидании',
36
+ archived: 'Архивный',
37
+ active: 'Активный',
38
+ disabled: 'Отключен',
39
+ },
40
40
 
41
- bannerWasSuccessfullyCreated: 'Баннер успешно создан',
42
- bannerWasSuccessfullyUpdated: 'Баннер успешно обновлен',
43
- bannerCreationWasFailed: 'Не удалось создать баннер',
44
- bannerUpdateWasFailed: 'Не удалось обновить баннер',
41
+ bannerWasSuccessfullyCreated: 'Баннер успешно создан',
42
+ bannerWasSuccessfullyUpdated: 'Баннер успешно обновлен',
43
+ bannerCreationWasFailed: 'Не удалось создать баннер',
44
+ bannerUpdateWasFailed: 'Не удалось обновить баннер',
45
45
  };
46
-
47
- export default RU;
package/src/main.ts CHANGED
@@ -1,12 +1,7 @@
1
- import { i18n } from '@tager/admin-services';
1
+ import { applyTranslations } from './locales/apply';
2
2
 
3
- import EN from './locales/en';
4
- import RU from './locales/ru';
5
-
6
- i18n.addTranslations('en', 'banners', EN);
7
- i18n.addTranslations('ru', 'banners', RU);
3
+ applyTranslations();
8
4
 
9
5
  export * from './constants/routes';
10
- export * from './constants/menu';
11
- export * from './constants/paths';
6
+ export * from './utils/paths';
12
7
  export * from './services/requests';
@@ -0,0 +1,15 @@
1
+ import {compile} from 'path-to-regexp';
2
+
3
+ import {BANNERS_ROUTE_PATHS} from '../constants/paths';
4
+
5
+ export function getBannersZoneListUrl() {
6
+ return BANNERS_ROUTE_PATHS.ZONE_LIST;
7
+ }
8
+
9
+ export function getBannersBannerListUrl() {
10
+ return BANNERS_ROUTE_PATHS.BANNER_LIST;
11
+ }
12
+
13
+ export function getBannersBannerFormUrl(params: { bannerId: number | string }) {
14
+ return compile(BANNERS_ROUTE_PATHS.BANNER_FORM)(params);
15
+ }
@@ -1,77 +1,79 @@
1
1
  <template>
2
- <page
2
+ <Page
3
3
  :title="
4
- isCreation ? $t('banners:createBanner') : $t('banners:updateBanner')
4
+ isCreation
5
+ ? $i18n.t('banners:createBanner')
6
+ : $i18n.t('banners:updateBanner')
5
7
  "
6
8
  :is-content-loading="isContentLoading"
7
9
  >
8
- <template v-slot:content>
10
+ <template #content>
9
11
  <form novalidate @submit.prevent="submitForm">
10
12
  <div class="zone">
11
- <form-field-select
12
- v-model="values.bannerZone"
13
+ <FormFieldSelect
14
+ v-model:value="values.bannerZone"
13
15
  name="bannerZone"
14
- :label="$t('banners:zone')"
16
+ :label="$i18n.t('banners:zone')"
15
17
  :options="zonesOptionList"
16
18
  :error="errors.bannerZone"
17
19
  />
18
20
 
19
- <form-field
20
- v-model="values.priority"
21
+ <FormField
22
+ v-model:value="values.priority"
21
23
  name="priority"
22
- :label="$t('banners:priority')"
24
+ :label="$i18n.t('banners:priority')"
23
25
  :error="errors.priority"
24
26
  />
25
27
  </div>
26
28
 
27
- <input-label>{{ $t('banners:period') }}</input-label>
29
+ <InputLabel>{{ $i18n.t('banners:period') }}</InputLabel>
28
30
 
29
31
  <div class="date">
30
- <form-field
31
- v-model="values.dateStart"
32
- :label="$t('banners:from')"
32
+ <FormField
33
+ v-model:value="values.dateStart"
34
+ :label="$i18n.t('banners:from')"
33
35
  name="dateStart"
34
36
  type="date"
35
37
  :max="values.dateEnd"
36
38
  />
37
39
 
38
- <form-field
39
- v-model="values.dateEnd"
40
- :label="$t('banners:to')"
40
+ <FormField
41
+ v-model:value="values.dateEnd"
42
+ :label="$i18n.t('banners:to')"
41
43
  name="dateEnd"
42
44
  type="date"
43
45
  :min="values.dateStart"
44
46
  />
45
47
  </div>
46
48
 
47
- <form-field-checkbox
48
- v-model="values.disabled"
49
+ <FormFieldCheckbox
50
+ v-model:checked="values.disabled"
49
51
  name="disabled"
50
- :label="$t('banners:disabled')"
52
+ :label="$i18n.t('banners:disabled')"
51
53
  :error="errors.disabled"
52
54
  />
53
55
 
54
56
  <div class="link">
55
- <form-field
56
- v-model="values.link"
57
+ <FormField
58
+ v-model:value="values.link"
57
59
  name="link"
58
- :label="$t('banners:link')"
60
+ :label="$i18n.t('banners:link')"
59
61
  :error="errors.name"
60
62
  />
61
63
 
62
- <form-field-checkbox
63
- v-model="values.openNewTab"
64
+ <FormFieldCheckbox
65
+ v-model:checked="values.openNewTab"
64
66
  name="openNewTab"
65
- :label="$t('banners:openNewTab')"
67
+ :label="$i18n.t('banners:openNewTab')"
66
68
  :error="errors.openNewTab"
67
69
  />
68
70
  </div>
69
71
 
70
- <form-field-file-input
71
- v-model="values.image"
72
+ <FormFieldFileInput
73
+ v-model:value="values.image"
72
74
  name="image"
73
75
  file-type="image"
74
- :label="$t('banners:image')"
76
+ :label="$i18n.t('banners:image')"
75
77
  :error="errors.file"
76
78
  />
77
79
 
@@ -81,40 +83,50 @@
81
83
  :field="field"
82
84
  />
83
85
 
84
- <form-field
85
- v-model="values.comment"
86
+ <FormField
87
+ v-model:value="values.comment"
86
88
  name="comment"
87
89
  type="textarea"
88
- :label="$t('banners:comment')"
90
+ :label="$i18n.t('banners:comment')"
89
91
  :error="errors.comment"
90
92
  />
91
93
  </form>
92
94
  </template>
93
95
 
94
- <template v-slot:footer>
96
+ <template #footer>
95
97
  <FormFooter
96
98
  :back-href="bannerListUrl"
97
- :on-submit="submitForm"
98
99
  :is-submitting="isSubmitting"
99
100
  :is-creation="isCreation"
100
101
  :can-create-another="isCreation"
102
+ @submit="submitForm"
101
103
  />
102
104
  </template>
103
- </page>
105
+ </Page>
104
106
  </template>
105
107
 
106
108
  <script lang="ts">
109
+ import { computed, defineComponent, ref, SetupContext, watch } from 'vue';
110
+ import { useRoute, useRouter } from 'vue-router';
111
+
107
112
  import {
108
- computed,
109
- defineComponent,
110
- ref,
111
- SetupContext,
112
- watch,
113
- } from '@vue/composition-api';
114
-
115
- import { FormFooter, OptionType, TagerFormSubmitEvent } from '@tager/admin-ui';
113
+ FormField,
114
+ FormFieldCheckbox,
115
+ FormFieldFileInput,
116
+ FormFieldSelect,
117
+ FormFooter,
118
+ InputLabel,
119
+ OptionType,
120
+ TagerFormSubmitEvent,
121
+ } from '@tager/admin-ui';
116
122
  import { DynamicField, universalFieldUtils } from '@tager/admin-dynamic-field';
117
- import { convertRequestErrorToMap } from '@tager/admin-services';
123
+ import {
124
+ convertRequestErrorToMap,
125
+ navigateBack,
126
+ useI18n,
127
+ useToast,
128
+ } from '@tager/admin-services';
129
+ import { Page } from '@tager/admin-layout';
118
130
 
119
131
  import { useFetchZones } from '../../../hooks';
120
132
  import { BannerFormValues } from '../../../typings/banners';
@@ -122,7 +134,7 @@ import { useFetchBanner } from '../../../hooks/useFetchBanner';
122
134
  import {
123
135
  getBannersBannerFormUrl,
124
136
  getBannersBannerListUrl,
125
- } from '../../../constants/paths';
137
+ } from '../../../utils/paths';
126
138
  import { createBanner, updateBanner } from '../../../services/requests';
127
139
  import { useFetchZoneFields } from '../../../hooks/useFetchZoneFields';
128
140
 
@@ -133,16 +145,28 @@ import {
133
145
 
134
146
  export default defineComponent({
135
147
  name: 'BannerForm',
136
- components: { FormFooter, DynamicField },
137
- setup(props, context: SetupContext) {
138
- const bannerId = computed<string>(
139
- () => context.root.$route.params.bannerId
140
- );
148
+ components: {
149
+ FormFieldFileInput,
150
+ FormFieldCheckbox,
151
+ InputLabel,
152
+ FormField,
153
+ FormFieldSelect,
154
+ Page,
155
+ FormFooter,
156
+ DynamicField,
157
+ },
158
+ setup() {
159
+ const route = useRoute();
160
+ const router = useRouter();
161
+ const toast = useToast();
162
+ const { t } = useI18n();
163
+
164
+ const bannerId = computed<string>(() => route.params.bannerId as string);
141
165
  const isCreation = computed<boolean>(() => bannerId.value === 'create');
142
166
 
143
167
  /** Zones **/
144
168
 
145
- const { data: zones, loading: isZonesLoading } = useFetchZones({ context });
169
+ const { data: zones, loading: isZonesLoading } = useFetchZones();
146
170
 
147
171
  const zonesOptionList = computed<OptionType[]>(() =>
148
172
  zones.value.map<OptionType>((zone) => ({
@@ -154,7 +178,6 @@ export default defineComponent({
154
178
  /** Banner **/
155
179
 
156
180
  const { data: banner, loading: isBannerLoading } = useFetchBanner({
157
- context,
158
181
  bannerId,
159
182
  isCreation,
160
183
  });
@@ -176,19 +199,16 @@ export default defineComponent({
176
199
 
177
200
  /** Zone Fields **/
178
201
 
179
- const {
180
- loading: isZoneFieldsLoading,
181
- data: zoneFields,
182
- } = useFetchZoneFields({ context, values });
202
+ const { loading: isZoneFieldsLoading, data: zoneFields } =
203
+ useFetchZoneFields({ values });
183
204
 
184
205
  watch(zoneFields, () => {
185
- values.value.fields = (
186
- zoneFields.value?.fields ?? []
187
- ).map((fieldConfig, index) =>
188
- universalFieldUtils.createFormField(
189
- fieldConfig,
190
- banner.value ? banner.value.fields[index].value ?? null : null
191
- )
206
+ values.value.fields = (zoneFields.value?.fields ?? []).map(
207
+ (fieldConfig, index) =>
208
+ universalFieldUtils.createFormField(
209
+ fieldConfig,
210
+ banner.value ? banner.value.fields[index].value ?? null : null
211
+ )
192
212
  );
193
213
  });
194
214
 
@@ -206,39 +226,36 @@ export default defineComponent({
206
226
  errors.value = {};
207
227
 
208
228
  if (event.type === 'create') {
209
- context.root.$router.push(
210
- getBannersBannerFormUrl({ bannerId: String(data.id) })
211
- );
212
- }
213
-
214
- if (event.type === 'create_exit' || event.type === 'save_exit') {
215
- context.root.$router.push(getBannersBannerListUrl());
216
- }
217
-
218
- if (event.type === 'create_create-another') {
229
+ router.push(getBannersBannerFormUrl({ bannerId: String(data.id) }));
230
+ } else if (
231
+ event.type === 'create_exit' ||
232
+ event.type === 'save_exit'
233
+ ) {
234
+ navigateBack(router, getBannersBannerListUrl());
235
+ } else if (event.type === 'create_create-another') {
219
236
  values.value = convertBannerToFormValues(
220
237
  null,
221
238
  zonesOptionList.value
222
239
  );
223
240
  }
224
241
 
225
- context.root.$toast({
242
+ toast.show({
226
243
  variant: 'success',
227
- title: context.root.$t('banners:success'),
244
+ title: t('banners:success'),
228
245
  body: isCreation.value
229
- ? context.root.$t('banners:bannerWasSuccessfullyCreated')
230
- : context.root.$t('banners:bannerWasSuccessfullyUpdated'),
246
+ ? t('banners:bannerWasSuccessfullyCreated')
247
+ : t('banners:bannerWasSuccessfullyUpdated'),
231
248
  });
232
249
  })
233
250
  .catch((error) => {
234
251
  console.error(error);
235
252
  errors.value = convertRequestErrorToMap(error);
236
- context.root.$toast({
253
+ toast.show({
237
254
  variant: 'danger',
238
- title: context.root.$t('banners:error'),
255
+ title: t('banners:error'),
239
256
  body: isCreation.value
240
- ? context.root.$t('banners:bannerCreationWasFailed')
241
- : context.root.$t('banners:bannerUpdateWasFailed'),
257
+ ? t('banners:bannerCreationWasFailed')
258
+ : t('banners:bannerUpdateWasFailed'),
242
259
  });
243
260
  })
244
261
  .finally(() => {