@tager/admin-export 0.1.4 → 1.0.1

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 (54) hide show
  1. package/dist/constants/paths.d.ts +4 -4
  2. package/dist/constants/routes.d.ts +3 -3
  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 +512 -0
  8. package/dist/locales/apply.d.ts +1 -0
  9. package/dist/locales/en.d.ts +23 -25
  10. package/dist/locales/ru.d.ts +2 -3
  11. package/dist/main.d.ts +3 -3
  12. package/dist/services/requests.d.ts +8 -8
  13. package/dist/style.css +1 -0
  14. package/dist/typings/model.d.ts +26 -24
  15. package/dist/utils/common.d.ts +1 -1
  16. package/dist/utils/paths.d.ts +4 -4
  17. package/dist/views/ExportForm/ExportForm.helpers.d.ts +11 -9
  18. package/dist/views/ExportForm/ExportForm.types.d.ts +7 -0
  19. package/dist/views/ExportForm/ExportForm.vue.d.ts +2693 -74
  20. package/dist/views/ExportForm/index.d.ts +1 -1
  21. package/dist/views/ExportList/ExportList.vue.d.ts +16 -41
  22. package/dist/views/ExportList/components/CellHistory/CellHistory.helpers.d.ts +1 -0
  23. package/dist/views/ExportList/components/CellHistory/CellHistory.vue.d.ts +19 -0
  24. package/dist/views/ExportList/components/CellHistory/index.d.ts +1 -0
  25. package/dist/views/ExportList/index.d.ts +1 -1
  26. package/package.json +49 -47
  27. package/src/constants/routes.ts +10 -10
  28. package/src/dev/App.vue +38 -0
  29. package/src/dev/config.ts +23 -0
  30. package/src/dev/env.ts +17 -0
  31. package/src/dev/main.ts +36 -0
  32. package/src/locales/apply.ts +9 -0
  33. package/src/locales/en.ts +1 -4
  34. package/src/locales/ru.ts +2 -5
  35. package/src/main.ts +2 -6
  36. package/src/services/requests.ts +1 -1
  37. package/src/typings/model.ts +8 -1
  38. package/src/views/ExportForm/ExportForm.helpers.ts +31 -8
  39. package/src/views/ExportForm/ExportForm.types.ts +8 -0
  40. package/src/views/ExportForm/ExportForm.vue +143 -118
  41. package/src/views/ExportList/ExportList.vue +47 -63
  42. package/src/views/ExportList/components/CellHistory/CellHistory.helpers.ts +12 -0
  43. package/src/views/ExportList/components/CellHistory/CellHistory.vue +38 -0
  44. package/src/views/ExportList/components/CellHistory/index.ts +1 -0
  45. package/README.md +0 -0
  46. package/dist/dev.d.ts +0 -1
  47. package/dist/index.esm.js +0 -714
  48. package/dist/index.umd.js +0 -725
  49. package/src/config/config.json +0 -20
  50. package/src/dev.ts +0 -41
  51. package/src/typings/sfc.d.ts +0 -12
  52. package/src/typings/shims-tsx.d.ts +0 -13
  53. package/src/typings/shims-vue.d.ts +0 -11
  54. package/src/views/App.vue +0 -36
@@ -1,131 +1,131 @@
1
1
  <template>
2
- <page :title="$t('export:newExport')" :is-content-loading="isContentLoading">
2
+ <Page :title="$i18n.t('export:newExport')" :is-content-loading="isContentLoading">
3
3
  <form novalidate @submit.prevent>
4
- <template>
5
- <form-field-select
6
- v-model="values.strategy"
7
- :options="strategyOptionList"
8
- :error="errors.strategy"
9
- :label="$t('export:exportType')"
4
+ <FormFieldSelect
5
+ v-model:value="values.strategy"
10
6
  name="exportType"
11
- />
7
+ :error="errors.strategy"
8
+ :label="$i18n.t('export:exportType')"
9
+ :options="strategyOptionList"
10
+ />
12
11
 
13
- <div class="field">
14
- <form-field
15
- v-model="values.filename"
12
+ <div class="field">
13
+ <FormField
14
+ v-model:value="values.filename"
16
15
  :error="errors.filename"
17
- :label="$t('export:filename')"
16
+ :label="$i18n.t('export:filename')"
18
17
  name="filename"
19
- />
18
+ />
20
19
 
21
- <form-field-select
22
- v-model="values.format"
20
+ <FormFieldSelect
21
+ v-model:value="values.format"
23
22
  :options="formatOptionList"
24
23
  :error="errors.format"
25
- :label="$t('export:format')"
24
+ :label="$i18n.t('export:format')"
26
25
  name="format"
27
- />
28
-
29
- <div />
26
+ />
30
27
 
31
- <form-field-select
28
+ <FormFieldSelect
32
29
  v-if="shouldDisplayDelimiter"
33
- v-model="values.delimiter"
30
+ v-model:value="values.delimiter"
34
31
  :options="delimiterOptionList"
35
32
  :error="errors.delimiter"
36
- :label="$t('export:delimiter')"
33
+ :label="$i18n.t('export:delimiter')"
37
34
  name="delimiter"
38
- />
39
- </div>
40
- </template>
35
+ />
36
+ </div>
37
+ <DynamicField
38
+ v-for="field of templateValues"
39
+ :key="field.config.name"
40
+ :field="field"
41
+ />
41
42
  </form>
42
43
 
43
- <template v-slot:footer>
44
+ <template #footer>
44
45
  <FormFooter
45
- :back-href="getExportListUrl()"
46
- :on-submit="submitForm"
47
- :is-submitting="isSubmitting"
48
- :is-creation="true"
46
+ :back-href="getExportListUrl()"
47
+ @submit="submitForm"
48
+ :is-submitting="isSubmitting"
49
+ :is-creation="true"
49
50
  />
50
51
  </template>
51
- </page>
52
+ </Page>
52
53
  </template>
53
54
 
54
55
  <script lang="ts">
55
- import { defineComponent, watch } from '@vue/composition-api';
56
- import { computed, onMounted, ref } from '@vue/composition-api';
56
+ import {defineComponent, onMounted, watch, ref, computed} from "vue";
57
+ import {useRoute, useRouter} from "vue-router";
57
58
 
58
- import { convertRequestErrorToMap, useResource } from '@tager/admin-services';
59
+ import {useI18n, navigateBack, useToast} from '@tager/admin-services';
60
+ import {Page} from "@tager/admin-layout";
61
+
62
+ import {convertRequestErrorToMap, useResource} from '@tager/admin-services';
59
63
  import {
60
64
  OptionType,
61
65
  TagerFormSubmitEvent,
62
- FormFooter,
63
- useTranslation,
66
+ FormFooter, FormField, FormFieldSelect
64
67
  } from '@tager/admin-ui';
68
+ import {
69
+ DynamicField,
70
+ FieldConfigUnion,
71
+ FieldUnion,
72
+ universalFieldUtils,
73
+ } from '@tager/admin-dynamic-field';
65
74
 
66
- import { createExport, getStrategyList } from '../../services/requests';
67
- import { getExportListUrl } from '../../utils/paths';
68
- import { replaceFileExtension } from '../../utils/common';
75
+ import {createExport, getStrategies} from '../../services/requests';
76
+ import {getExportListUrl} from '../../utils/paths';
77
+ import {replaceFileExtension} from '../../utils/common';
69
78
 
70
79
  import {
71
80
  convertExportFormValuesToCreationPayload,
72
- FormValues,
81
+ convertStrategiesToStrategyOptionList,
82
+ formatOptionList,
83
+ isCSVFormat,
73
84
  } from './ExportForm.helpers';
85
+ import {FormValues} from './ExportForm.types';
86
+
74
87
 
75
88
  export default defineComponent({
76
89
  name: 'ExportForm',
77
- components: { FormFooter },
78
- setup(props, context) {
79
- const { t } = useTranslation(context);
90
+ components: {
91
+ DynamicField, FormFooter,
92
+ Page, FormField, FormFieldSelect
93
+ },
94
+ setup() {
95
+ const {t} = useI18n();
96
+ const route = useRoute();
97
+ const router = useRouter();
98
+ const toast = useToast();
80
99
 
81
100
  /** Strategies */
82
101
 
83
102
  const [
84
- fetchStrategyList,
85
- { data: strategyList, loading: isStrategyListLoading },
103
+ fetchStrategies,
104
+ {data: strategies, loading: isStrategiesLoading},
86
105
  ] = useResource({
87
- fetchResource: getStrategyList,
106
+ fetchResource: getStrategies,
88
107
  initialValue: [],
89
- context,
90
- resourceName: 'Strategy List',
108
+ resourceName: 'Strategies',
91
109
  });
92
110
 
93
111
  const strategyOptionList = computed<Array<OptionType>>(() =>
94
- strategyList.value.map<OptionType>((strategy) => ({
95
- value: strategy.id,
96
- label: strategy.name,
97
- }))
112
+ convertStrategiesToStrategyOptionList(strategies.value)
98
113
  );
99
114
 
100
115
  onMounted(() => {
101
- fetchStrategyList();
116
+ fetchStrategies();
102
117
  });
103
118
 
104
- /** Format **/
105
-
106
- const formatOptionList = computed<Array<OptionType>>(() => [
107
- { value: 'CSV', label: 'CSV' },
108
- { value: 'XLS', label: 'XLS' },
109
- { value: 'XML', label: 'XML' },
110
- { value: 'YAML', label: 'YAML' },
111
- { value: 'JSON', label: 'JSON' },
112
- { value: 'TXT', label: 'TXT' },
113
- ]);
114
-
115
- function isCSVFormat(format: string): boolean {
116
- return format === 'CSV';
117
- }
118
-
119
119
  /** Delimiter **/
120
120
 
121
121
  const delimiterOptionList = computed<Array<OptionType>>(() => [
122
- { value: ',', label: t('export:comma') },
123
- { value: ';', label: t('export:semicolon') },
122
+ {value: ',', label: t('export:comma')},
123
+ {value: ';', label: t('export:semicolon')},
124
124
  ]);
125
125
 
126
126
  /** Form state */
127
127
 
128
- const defaultExtension = formatOptionList.value[0];
128
+ const defaultExtension = formatOptionList[0];
129
129
  const defaultDelimiter = delimiterOptionList.value[0];
130
130
 
131
131
  const errors = ref<Record<string, string>>({});
@@ -136,72 +136,96 @@ export default defineComponent({
136
136
  delimiter: defaultDelimiter,
137
137
  });
138
138
  const isSubmitting = ref<boolean>(false);
139
+ const templateValues = ref<Array<FieldUnion>>([]);
140
+
141
+ function updateTemplateValues() {
142
+ const selectedStrategy = strategies.value.find(
143
+ (strategy) => strategy.id === values.value.strategy?.value
144
+ );
145
+
146
+ const fieldTemplateList: Array<FieldConfigUnion> =
147
+ selectedStrategy?.fields ?? [];
148
+
149
+ templateValues.value = fieldTemplateList.map((fieldConfig) =>
150
+ universalFieldUtils.createFormField(fieldConfig, null)
151
+ );
152
+ }
153
+
154
+ watch(
155
+ () => values.value.strategy,
156
+ () => {
157
+ updateTemplateValues();
158
+ }
159
+ );
160
+
161
+ onMounted(() => {
162
+ updateTemplateValues();
163
+ });
139
164
 
140
165
  const shouldDisplayDelimiter = ref<boolean>(
141
- isCSVFormat(values.value.format?.value ?? '')
166
+ isCSVFormat(values.value.format?.value ?? '')
142
167
  );
143
168
 
144
169
  watch(
145
- () => values.value.format,
146
- () => {
147
- const newExtension = values.value.format?.value.toLowerCase();
148
-
149
- values.value.filename = replaceFileExtension(
150
- values.value.filename,
151
- newExtension || ''
152
- );
153
-
154
- shouldDisplayDelimiter.value = isCSVFormat(
155
- values.value.format?.value ?? ''
156
- );
157
- }
170
+ () => values.value.format,
171
+ () => {
172
+ const newExtension = values.value.format?.value.toLowerCase();
173
+
174
+ values.value.filename = replaceFileExtension(
175
+ values.value.filename,
176
+ newExtension || ''
177
+ );
178
+
179
+ shouldDisplayDelimiter.value = isCSVFormat(
180
+ values.value.format?.value ?? ''
181
+ );
182
+ }
158
183
  );
159
184
 
160
185
  function submitForm(event: TagerFormSubmitEvent) {
161
186
  isSubmitting.value = true;
162
187
 
163
188
  const creationPayload = convertExportFormValuesToCreationPayload(
164
- values.value
189
+ values.value,
190
+ templateValues.value
165
191
  );
166
192
 
167
193
  createExport(creationPayload)
168
- .then(() => {
169
- errors.value = {};
170
-
171
- if (
172
- event.type === 'create' ||
173
- event.type === 'save' ||
174
- event.type === 'create_exit' ||
175
- event.type === 'save_exit'
176
- ) {
177
- context.root.$router.push(getExportListUrl());
178
- }
179
-
180
- context.root.$toast({
181
- variant: 'success',
182
- title: t('export:success'),
183
- body: t('export:createdSuccessMessage'),
194
+ .then(() => {
195
+ errors.value = {};
196
+
197
+ if (
198
+ event.type === 'create' ||
199
+ event.type === 'save' ||
200
+ event.type === 'create_exit' ||
201
+ event.type === 'save_exit'
202
+ ) {
203
+ navigateBack(router, getExportListUrl());
204
+ }
205
+
206
+ toast.show({
207
+ variant: 'success',
208
+ title: t('export:success'),
209
+ body: t('export:createdSuccessMessage'),
210
+ });
211
+ })
212
+ .catch((error) => {
213
+ console.error(error);
214
+ errors.value = convertRequestErrorToMap(error);
215
+ toast.show({
216
+ variant: 'danger',
217
+ title: t('export:error'),
218
+ body: t('export:createdErrorMessage'),
219
+ });
220
+ })
221
+ .finally(() => {
222
+ isSubmitting.value = false;
184
223
  });
185
- })
186
- .catch((error) => {
187
- console.error(error);
188
- errors.value = convertRequestErrorToMap(error);
189
- context.root.$toast({
190
- variant: 'danger',
191
- title: t('export:error'),
192
- body: t('export:createdErrorMessage'),
193
- });
194
- })
195
- .finally(() => {
196
- isSubmitting.value = false;
197
- });
198
224
  }
199
225
 
200
226
  /** Is content loading **/
201
227
 
202
- const isContentLoading = computed<boolean>(
203
- () => isStrategyListLoading.value
204
- );
228
+ const isContentLoading = computed<boolean>(() => isStrategiesLoading.value);
205
229
 
206
230
  return {
207
231
  values,
@@ -214,6 +238,7 @@ export default defineComponent({
214
238
  delimiterOptionList,
215
239
  isContentLoading,
216
240
  shouldDisplayDelimiter,
241
+ templateValues,
217
242
  };
218
243
  },
219
244
  });
@@ -1,58 +1,58 @@
1
1
  <template>
2
- <page
3
- :title="t('export:export')"
4
- :header-buttons="[
2
+ <Page
3
+ :title="$i18n.t('export:export')"
4
+ :header-buttons="[
5
5
  {
6
- text: t('export:newExport'),
6
+ text: $i18n.t('export:newExport'),
7
7
  href: getExportFormUrl({ exportId: 'create' }),
8
8
  },
9
9
  ]"
10
10
  >
11
- <data-table
12
- :column-defs="columnDefs"
13
- :row-data="rowData"
14
- :loading="isRowDataLoading"
15
- :error-message="errorMessage"
16
- :pagination="{
11
+ <DataTable
12
+ :column-defs="columnDefs"
13
+ :row-data="rowData"
14
+ :loading="isRowDataLoading"
15
+ :error-message="errorMessage"
16
+ :pagination="{
17
17
  pageSize,
18
18
  pageCount,
19
19
  pageNumber,
20
20
  disabled: isRowDataLoading,
21
21
  }"
22
- :use-search="false"
23
- @change="handleChange"
22
+ :use-search="false"
23
+ @change="handleChange"
24
24
  >
25
- <template v-slot:cell(history)="{ row }">
26
- <ul v-if="row.history">
27
- <li v-for="(history, index) of row.history" :key="index">
28
- <span :style="{ width: '100px', display: 'inline-block' }">{{
29
- history.status
30
- }}</span>
31
- {{ dateTimeFormat(history.datetime) }}
32
- </li>
33
- </ul>
25
+ <template #cell(history)="{ row }">
26
+ <CellHistory :history="row.history"/>
34
27
  </template>
35
- </data-table>
36
- </page>
28
+ </DataTable>
29
+ </Page>
37
30
  </template>
38
31
 
39
32
  <script lang="ts">
40
- import { defineComponent, onMounted } from '@vue/composition-api';
41
-
33
+ import {defineComponent, onMounted} from "vue";
34
+ import {useI18n} from '@tager/admin-services';
35
+ import {Page} from "@tager/admin-layout";
42
36
  import {
43
- ColumnDefinition,
37
+ type ColumnDefinition,
38
+ DataTable,
44
39
  useDataTable,
45
- useTranslation,
46
- } from '@tager/admin-ui';
40
+ } from "@tager/admin-ui";
41
+
42
+ import {getExportList} from '../../services/requests';
43
+ import {ExportType} from '../../typings/model';
44
+ import {getExportFormUrl} from '../../utils/paths';
47
45
 
48
- import { getExportList } from '../../services/requests';
49
- import { ExportType } from '../../typings/model';
50
- import { getExportFormUrl } from '../../utils/paths';
46
+ import {CellHistory} from './components/CellHistory';
51
47
 
52
48
  export default defineComponent({
53
49
  name: 'ExportList',
54
- setup(props, context) {
55
- const { t } = useTranslation(context);
50
+ components: {
51
+ Page, CellHistory,
52
+ DataTable,
53
+ },
54
+ setup() {
55
+ const {t} = useI18n();
56
56
 
57
57
  const {
58
58
  fetchEntityList: fetchExportList,
@@ -66,12 +66,11 @@ export default defineComponent({
66
66
  pageNumber,
67
67
  } = useDataTable<ExportType>({
68
68
  fetchEntityList: (params) =>
69
- getExportList({
70
- pageNumber: params.pageNumber,
71
- pageSize: params.pageSize,
72
- }),
69
+ getExportList({
70
+ pageNumber: params.pageNumber,
71
+ pageSize: params.pageSize,
72
+ }),
73
73
  initialValue: [],
74
- context,
75
74
  resourceName: 'Export list',
76
75
  pageSize: 100,
77
76
  });
@@ -85,22 +84,22 @@ export default defineComponent({
85
84
  id: 1,
86
85
  name: 'ID',
87
86
  field: 'id',
88
- style: { width: '50px', textAlign: 'center' },
89
- headStyle: { width: '50px', textAlign: 'center' },
87
+ style: {width: '50px', textAlign: 'center'},
88
+ headStyle: {width: '50px', textAlign: 'center'},
90
89
  },
91
90
  {
92
91
  id: 2,
93
92
  name: t('export:type'),
94
93
  field: 'strategy',
95
- style: { width: '15%' },
96
- headStyle: { width: '15%' },
94
+ style: {width: '15%'},
95
+ headStyle: {width: '15%'},
97
96
  },
98
97
  {
99
98
  id: 3,
100
99
  name: t('export:status'),
101
100
  field: 'status',
102
- style: { width: '15%' },
103
- headStyle: { width: '15%' },
101
+ style: {width: '15%'},
102
+ headStyle: {width: '15%'},
104
103
  },
105
104
  {
106
105
  id: 4,
@@ -112,32 +111,19 @@ export default defineComponent({
112
111
  id: 5,
113
112
  name: t('export:log'),
114
113
  field: 'history',
115
- style: { width: '25%' },
116
- headStyle: { width: '25%' },
114
+ style: {width: '25%', whiteSpace: 'nowrap'},
115
+ headStyle: {width: '25%'},
117
116
  },
118
117
  {
119
118
  id: 6,
120
119
  name: t('export:file'),
121
120
  field: 'file',
122
121
  type: 'file',
123
- style: { width: '150px', textAlign: 'center' },
124
- headStyle: { width: '150px', textAlign: 'center' },
122
+ style: {width: '150px', textAlign: 'center'},
123
+ headStyle: {width: '150px', textAlign: 'center'},
125
124
  },
126
125
  ];
127
126
 
128
- function dateTimeFormat(value: number | string | Date): string {
129
- const options = {
130
- year: 'numeric',
131
- month: 'numeric',
132
- day: 'numeric',
133
- hour: 'numeric',
134
- minute: 'numeric',
135
- second: 'numeric',
136
- };
137
- const date = new Date(value);
138
- return new Intl.DateTimeFormat('ru-RU', options).format(date);
139
- }
140
-
141
127
  return {
142
128
  columnDefs,
143
129
  getExportFormUrl,
@@ -149,8 +135,6 @@ export default defineComponent({
149
135
  pageSize,
150
136
  pageCount,
151
137
  pageNumber,
152
- t,
153
- dateTimeFormat,
154
138
  };
155
139
  },
156
140
  });
@@ -0,0 +1,12 @@
1
+ export function dateTimeFormat(value: number | string | Date): string {
2
+ const date = new Date(value);
3
+
4
+ return new Intl.DateTimeFormat('ru-RU', {
5
+ year: 'numeric',
6
+ month: 'numeric',
7
+ day: 'numeric',
8
+ hour: 'numeric',
9
+ minute: 'numeric',
10
+ second: 'numeric',
11
+ }).format(date);
12
+ }
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <ul v-if="history.length > 0">
3
+ <li v-for="(history, index) of history" :key="index">
4
+ <span class="name">
5
+ {{ history.status }}
6
+ </span>
7
+ {{ dateTimeFormat(history.datetime) }}
8
+ </li>
9
+ </ul>
10
+ </template>
11
+
12
+ <script lang="ts">
13
+ import {defineComponent, PropType} from "vue";
14
+ import {dateTimeFormat} from './CellHistory.helpers';
15
+ import {HistoryType} from "../../../../typings/model";
16
+
17
+ export default defineComponent({
18
+ name: 'CellHistory',
19
+ props: {
20
+ history: {
21
+ type: Array as PropType<HistoryType[]>,
22
+ default: () => [],
23
+ },
24
+ },
25
+ setup() {
26
+ return {
27
+ dateTimeFormat,
28
+ };
29
+ },
30
+ });
31
+ </script>
32
+
33
+ <style lang="scss" scoped>
34
+ .name {
35
+ display: inline-block;
36
+ width: 100px;
37
+ }
38
+ </style>
@@ -0,0 +1 @@
1
+ export { default as CellHistory } from './CellHistory.vue';
package/README.md DELETED
File without changes
package/dist/dev.d.ts DELETED
@@ -1 +0,0 @@
1
- import '@tager/admin-ui/dist/admin-ui.css';