@tager/admin-banners 0.3.2 → 0.3.6
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.
- package/dist/index.esm.js +131 -81
- package/dist/index.umd.js +131 -81
- package/dist/locales/en.d.ts +2 -0
- package/dist/typings/banners.d.ts +5 -2
- package/dist/views/Banners/BannerForm/BannerForm.vue.d.ts +2 -0
- package/dist/views/Banners/BannerList/BannerList.helpers.d.ts +2 -1
- package/package.json +3 -3
- package/src/locales/en.ts +2 -0
- package/src/locales/ru.ts +2 -0
- package/src/main.ts +2 -2
- package/src/typings/banners.ts +5 -2
- package/src/views/Banners/BannerForm/BannerForm.helpers.ts +4 -0
- package/src/views/Banners/BannerForm/BannerForm.vue +154 -115
- package/src/views/Banners/BannerList/BannerList.helpers.ts +28 -7
- package/src/views/Banners/BannerList/BannerList.vue +1 -1
- package/src/views/Banners/BannerList/hooks/useAdvancedSearch.ts +1 -1
|
@@ -1,86 +1,97 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<page
|
|
3
|
-
|
|
3
|
+
:title="
|
|
4
4
|
isCreation ? $t('banners:createBanner') : $t('banners:updateBanner')
|
|
5
5
|
"
|
|
6
|
-
|
|
6
|
+
:is-content-loading="isContentLoading"
|
|
7
7
|
>
|
|
8
8
|
<template v-slot:content>
|
|
9
9
|
<form novalidate @submit.prevent="submitForm">
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<form-field-file-input
|
|
19
|
-
v-model="values.image"
|
|
20
|
-
name="image"
|
|
21
|
-
file-type="image"
|
|
22
|
-
:label="$t('banners:image')"
|
|
23
|
-
:error="errors.file"
|
|
24
|
-
/>
|
|
25
|
-
|
|
26
|
-
<form-field
|
|
27
|
-
v-model="values.link"
|
|
28
|
-
name="link"
|
|
29
|
-
:label="$t('banners:link')"
|
|
30
|
-
:error="errors.name"
|
|
31
|
-
/>
|
|
10
|
+
<div class="zone">
|
|
11
|
+
<form-field-select
|
|
12
|
+
v-model="values.bannerZone"
|
|
13
|
+
name="bannerZone"
|
|
14
|
+
:label="$t('banners:zone')"
|
|
15
|
+
:options="zonesOptionList"
|
|
16
|
+
:error="errors.bannerZone"
|
|
17
|
+
/>
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
<form-field
|
|
20
|
+
v-model="values.priority"
|
|
21
|
+
name="priority"
|
|
22
|
+
:label="$t('banners:priority')"
|
|
23
|
+
:error="errors.priority"
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
39
26
|
|
|
40
27
|
<input-label>{{ $t('banners:period') }}</input-label>
|
|
41
28
|
|
|
42
29
|
<div class="date">
|
|
43
30
|
<form-field
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
v-model="values.dateStart"
|
|
32
|
+
:label="$t('banners:from')"
|
|
33
|
+
name="dateStart"
|
|
34
|
+
type="date"
|
|
35
|
+
:max="values.dateEnd"
|
|
49
36
|
/>
|
|
50
37
|
|
|
51
38
|
<form-field
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
v-model="values.dateEnd"
|
|
40
|
+
:label="$t('banners:to')"
|
|
41
|
+
name="dateEnd"
|
|
42
|
+
type="date"
|
|
43
|
+
:min="values.dateStart"
|
|
57
44
|
/>
|
|
58
45
|
</div>
|
|
59
46
|
|
|
60
47
|
<form-field-checkbox
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
v-model="values.disabled"
|
|
49
|
+
name="disabled"
|
|
50
|
+
:label="$t('banners:disabled')"
|
|
51
|
+
:error="errors.disabled"
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
<div class="link">
|
|
55
|
+
<form-field
|
|
56
|
+
v-model="values.link"
|
|
57
|
+
name="link"
|
|
58
|
+
:label="$t('banners:link')"
|
|
59
|
+
:error="errors.name"
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
<form-field-checkbox
|
|
63
|
+
v-model="values.openNewTab"
|
|
64
|
+
name="openNewTab"
|
|
65
|
+
:label="$t('banners:openNewTab')"
|
|
66
|
+
:error="errors.openNewTab"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<form-field-file-input
|
|
71
|
+
v-model="values.image"
|
|
72
|
+
name="image"
|
|
73
|
+
file-type="image"
|
|
74
|
+
:label="$t('banners:image')"
|
|
75
|
+
:error="errors.file"
|
|
65
76
|
/>
|
|
66
77
|
|
|
67
78
|
<form-field
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
v-model="values.comment"
|
|
80
|
+
name="comment"
|
|
81
|
+
type="textarea"
|
|
82
|
+
:label="$t('banners:comment')"
|
|
83
|
+
:error="errors.comment"
|
|
73
84
|
/>
|
|
74
85
|
</form>
|
|
75
86
|
</template>
|
|
76
87
|
|
|
77
88
|
<template v-slot:footer>
|
|
78
89
|
<FormFooter
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
:back-href="bannerListUrl"
|
|
91
|
+
:on-submit="submitForm"
|
|
92
|
+
:is-submitting="isSubmitting"
|
|
93
|
+
:is-creation="isCreation"
|
|
94
|
+
:can-create-another="isCreation"
|
|
84
95
|
/>
|
|
85
96
|
</template>
|
|
86
97
|
</page>
|
|
@@ -95,17 +106,17 @@ import {
|
|
|
95
106
|
watch,
|
|
96
107
|
} from '@vue/composition-api';
|
|
97
108
|
|
|
98
|
-
import {
|
|
99
|
-
import {
|
|
109
|
+
import {FormFooter, OptionType, TagerFormSubmitEvent} from '@tager/admin-ui';
|
|
110
|
+
import {convertRequestErrorToMap} from '@tager/admin-services';
|
|
100
111
|
|
|
101
|
-
import {
|
|
102
|
-
import {
|
|
103
|
-
import {
|
|
112
|
+
import {useFetchZones} from '../../../hooks';
|
|
113
|
+
import {BannerFormValues} from '../../../typings/banners';
|
|
114
|
+
import {useFetchBanner} from '../../../hooks/useFetchBanner';
|
|
104
115
|
import {
|
|
105
116
|
getBannersBannerFormUrl,
|
|
106
117
|
getBannersBannerListUrl,
|
|
107
118
|
} from '../../../constants/paths';
|
|
108
|
-
import {
|
|
119
|
+
import {createBanner, updateBanner} from '../../../services/requests';
|
|
109
120
|
|
|
110
121
|
import {
|
|
111
122
|
convertBannerFormValuesToPayload,
|
|
@@ -114,27 +125,27 @@ import {
|
|
|
114
125
|
|
|
115
126
|
export default defineComponent({
|
|
116
127
|
name: 'BannerForm',
|
|
117
|
-
components: {
|
|
128
|
+
components: {FormFooter},
|
|
118
129
|
setup(props, context: SetupContext) {
|
|
119
130
|
const bannerId = computed<string>(
|
|
120
|
-
|
|
131
|
+
() => context.root.$route.params.bannerId
|
|
121
132
|
);
|
|
122
133
|
const isCreation = computed<boolean>(() => bannerId.value === 'create');
|
|
123
134
|
|
|
124
135
|
/** Zones **/
|
|
125
136
|
|
|
126
|
-
const {
|
|
137
|
+
const {data: zones, loading: isZonesLoading} = useFetchZones({context});
|
|
127
138
|
|
|
128
139
|
const zonesOptionList = computed<OptionType[]>(() =>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
140
|
+
zones.value.map<OptionType>((zone) => ({
|
|
141
|
+
value: zone.id,
|
|
142
|
+
label: zone.name,
|
|
143
|
+
}))
|
|
133
144
|
);
|
|
134
145
|
|
|
135
146
|
/** Banner **/
|
|
136
147
|
|
|
137
|
-
const {
|
|
148
|
+
const {data: banner, loading: isBannerLoading} = useFetchBanner({
|
|
138
149
|
context,
|
|
139
150
|
bannerId,
|
|
140
151
|
isCreation,
|
|
@@ -144,14 +155,14 @@ export default defineComponent({
|
|
|
144
155
|
|
|
145
156
|
const isSubmitting = ref<boolean>(false);
|
|
146
157
|
const values = ref<BannerFormValues>(
|
|
147
|
-
|
|
158
|
+
convertBannerToFormValues(banner.value, zonesOptionList.value)
|
|
148
159
|
);
|
|
149
160
|
const errors = ref<Record<string, string>>({});
|
|
150
161
|
|
|
151
162
|
watch([banner, zones], () => {
|
|
152
163
|
values.value = convertBannerToFormValues(
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
banner.value,
|
|
165
|
+
zonesOptionList.value
|
|
155
166
|
);
|
|
156
167
|
});
|
|
157
168
|
|
|
@@ -161,56 +172,56 @@ export default defineComponent({
|
|
|
161
172
|
const body = convertBannerFormValuesToPayload(values.value);
|
|
162
173
|
|
|
163
174
|
const requestPromise = isCreation.value
|
|
164
|
-
|
|
165
|
-
|
|
175
|
+
? createBanner(body)
|
|
176
|
+
: updateBanner(bannerId.value, body);
|
|
166
177
|
|
|
167
178
|
requestPromise
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
179
|
+
.then(({data}) => {
|
|
180
|
+
errors.value = {};
|
|
181
|
+
|
|
182
|
+
if (event.type === 'create') {
|
|
183
|
+
context.root.$router.push(
|
|
184
|
+
getBannersBannerFormUrl({bannerId: String(data.id)})
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (event.type === 'create_exit' || event.type === 'save_exit') {
|
|
189
|
+
context.root.$router.push(getBannersBannerListUrl());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (event.type === 'create_create-another') {
|
|
193
|
+
values.value = convertBannerToFormValues(
|
|
194
|
+
null,
|
|
195
|
+
zonesOptionList.value
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
context.root.$toast({
|
|
200
|
+
variant: 'success',
|
|
201
|
+
title: context.root.$t('banners:success'),
|
|
202
|
+
body: isCreation.value
|
|
203
|
+
? context.root.$t('banners:bannerWasSuccessfullyCreated')
|
|
204
|
+
: context.root.$t('banners:bannerWasSuccessfullyUpdated'),
|
|
205
|
+
});
|
|
206
|
+
})
|
|
207
|
+
.catch((error) => {
|
|
208
|
+
console.error(error);
|
|
209
|
+
errors.value = convertRequestErrorToMap(error);
|
|
210
|
+
context.root.$toast({
|
|
211
|
+
variant: 'danger',
|
|
212
|
+
title: context.root.$t('banners:error'),
|
|
213
|
+
body: isCreation.value
|
|
214
|
+
? context.root.$t('banners:bannerCreationWasFailed')
|
|
215
|
+
: context.root.$t('banners:bannerUpdateWasFailed'),
|
|
216
|
+
});
|
|
217
|
+
})
|
|
218
|
+
.finally(() => {
|
|
219
|
+
isSubmitting.value = false;
|
|
194
220
|
});
|
|
195
|
-
})
|
|
196
|
-
.catch((error) => {
|
|
197
|
-
console.error(error);
|
|
198
|
-
errors.value = convertRequestErrorToMap(error);
|
|
199
|
-
context.root.$toast({
|
|
200
|
-
variant: 'danger',
|
|
201
|
-
title: context.root.$t('banners:error'),
|
|
202
|
-
body: isCreation.value
|
|
203
|
-
? context.root.$t('banners:bannerCreationWasFailed')
|
|
204
|
-
: context.root.$t('banners:bannerUpdateWasFailed'),
|
|
205
|
-
});
|
|
206
|
-
})
|
|
207
|
-
.finally(() => {
|
|
208
|
-
isSubmitting.value = false;
|
|
209
|
-
});
|
|
210
221
|
};
|
|
211
222
|
|
|
212
223
|
const isContentLoading = computed<boolean>(
|
|
213
|
-
|
|
224
|
+
() => isBannerLoading.value || isZonesLoading.value
|
|
214
225
|
);
|
|
215
226
|
|
|
216
227
|
return {
|
|
@@ -233,4 +244,32 @@ export default defineComponent({
|
|
|
233
244
|
grid-template-columns: repeat(2, 1fr);
|
|
234
245
|
column-gap: 10px;
|
|
235
246
|
}
|
|
247
|
+
|
|
248
|
+
.zone {
|
|
249
|
+
display: flex;
|
|
250
|
+
|
|
251
|
+
> *:first-child {
|
|
252
|
+
flex: 1 1 1px;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
> *:last-child {
|
|
256
|
+
flex-basis: 30%;
|
|
257
|
+
margin-left: 20px;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.link {
|
|
262
|
+
display: flex;
|
|
263
|
+
align-items: flex-end;
|
|
264
|
+
|
|
265
|
+
> *:first-child {
|
|
266
|
+
flex: 1 1 1px;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
> *:last-child {
|
|
270
|
+
flex-basis: 30%;
|
|
271
|
+
margin-left: 20px;
|
|
272
|
+
padding-bottom: 8px;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
236
275
|
</style>
|
|
@@ -3,6 +3,7 @@ import { TFunction } from 'i18next';
|
|
|
3
3
|
import { ColumnDefinition } from '@tager/admin-ui';
|
|
4
4
|
|
|
5
5
|
import { Banner, Status } from '../../../typings/banners';
|
|
6
|
+
import { Zone } from '../../../typings/zones';
|
|
6
7
|
|
|
7
8
|
export function getStatus(type: Status, t: TFunction) {
|
|
8
9
|
switch (type) {
|
|
@@ -20,12 +21,16 @@ export function getStatus(type: Status, t: TFunction) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export function getColumnDefs(
|
|
24
|
+
export function getColumnDefs(
|
|
25
|
+
zoneList: Zone[],
|
|
26
|
+
t: TFunction
|
|
27
|
+
): ColumnDefinition<Banner>[] {
|
|
24
28
|
return [
|
|
25
29
|
{
|
|
26
30
|
id: 0,
|
|
27
31
|
name: '#',
|
|
28
32
|
field: 'id',
|
|
33
|
+
format: ({ rowIndex }) => String(rowIndex + 1),
|
|
29
34
|
style: { width: '50px', textAlign: 'center' },
|
|
30
35
|
headStyle: { width: '50px', textAlign: 'center' },
|
|
31
36
|
},
|
|
@@ -33,8 +38,14 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
|
|
|
33
38
|
id: 1,
|
|
34
39
|
name: t('banners:zone'),
|
|
35
40
|
field: 'bannerZone',
|
|
36
|
-
format: ({ row }) =>
|
|
37
|
-
|
|
41
|
+
format: ({ row }) => {
|
|
42
|
+
const foundBannerZone = zoneList.find(
|
|
43
|
+
(zone) => zone.id === row.bannerZone
|
|
44
|
+
);
|
|
45
|
+
return foundBannerZone
|
|
46
|
+
? foundBannerZone.name
|
|
47
|
+
: t('banners:bannerZoneIsDeleted');
|
|
48
|
+
},
|
|
38
49
|
},
|
|
39
50
|
{
|
|
40
51
|
id: 2,
|
|
@@ -46,6 +57,13 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
|
|
|
46
57
|
},
|
|
47
58
|
{
|
|
48
59
|
id: 3,
|
|
60
|
+
name: t('banners:priority'),
|
|
61
|
+
field: 'priority',
|
|
62
|
+
style: { width: '100px', textAlign: 'center' },
|
|
63
|
+
headStyle: { width: '100px', textAlign: 'center' },
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 4,
|
|
49
67
|
name: t('banners:period'),
|
|
50
68
|
field: 'dateStart',
|
|
51
69
|
format: ({ row }) =>
|
|
@@ -54,13 +72,13 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
|
|
|
54
72
|
}`,
|
|
55
73
|
},
|
|
56
74
|
{
|
|
57
|
-
id:
|
|
75
|
+
id: 5,
|
|
58
76
|
name: t('banners:image'),
|
|
59
77
|
field: 'image',
|
|
60
78
|
type: 'image',
|
|
61
79
|
},
|
|
62
80
|
{
|
|
63
|
-
id:
|
|
81
|
+
id: 6,
|
|
64
82
|
name: t('banners:link'),
|
|
65
83
|
field: 'link',
|
|
66
84
|
type: 'name',
|
|
@@ -76,14 +94,17 @@ export function getColumnDefs(t: TFunction): ColumnDefinition<Banner>[] {
|
|
|
76
94
|
},
|
|
77
95
|
],
|
|
78
96
|
}),
|
|
97
|
+
options: {
|
|
98
|
+
shouldOpenNewTab: true,
|
|
99
|
+
},
|
|
79
100
|
},
|
|
80
101
|
{
|
|
81
|
-
id:
|
|
102
|
+
id: 7,
|
|
82
103
|
name: t('banners:comment'),
|
|
83
104
|
field: 'comment',
|
|
84
105
|
},
|
|
85
106
|
{
|
|
86
|
-
id:
|
|
107
|
+
id: 8,
|
|
87
108
|
name: t('banners:actions'),
|
|
88
109
|
field: 'actions',
|
|
89
110
|
style: { whiteSpace: 'nowrap', width: '100px' },
|
|
@@ -181,7 +181,7 @@ export default defineComponent({
|
|
|
181
181
|
};
|
|
182
182
|
|
|
183
183
|
const columnDefs = computed<ColumnDefinition<Banner>[]>(() =>
|
|
184
|
-
getColumnDefs(context.root.$t)
|
|
184
|
+
getColumnDefs(zoneList.value, context.root.$t)
|
|
185
185
|
);
|
|
186
186
|
|
|
187
187
|
const isRowDataLoading = computed<boolean>(
|
|
@@ -112,7 +112,7 @@ export function useAdvancedSearch({ context, t, zoneList }: Params): State {
|
|
|
112
112
|
const filterParams = computed(() =>
|
|
113
113
|
getFilterParams({
|
|
114
114
|
[FilterTypes.Zone]: zoneFilter.value.map(({ value }) => value),
|
|
115
|
-
[FilterTypes.Date]: dateFilter.value,
|
|
115
|
+
[FilterTypes.Date]: dateFilter.value || [],
|
|
116
116
|
[FilterTypes.Status]: statusFilter.value.map(({ value }) => value),
|
|
117
117
|
})
|
|
118
118
|
);
|