@tager/admin-export 0.1.3 → 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 (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 +506 -0
  8. package/dist/locales/apply.d.ts +1 -0
  9. package/dist/locales/en.d.ts +23 -22
  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 -23
  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 -8
  18. package/dist/views/ExportForm/ExportForm.types.d.ts +7 -0
  19. package/dist/views/ExportForm/ExportForm.vue.d.ts +2693 -60
  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 +4 -4
  34. package/src/locales/ru.ts +5 -5
  35. package/src/main.ts +2 -6
  36. package/src/services/requests.ts +1 -1
  37. package/src/typings/model.ts +9 -1
  38. package/src/views/ExportForm/ExportForm.helpers.ts +32 -7
  39. package/src/views/ExportForm/ExportForm.types.ts +8 -0
  40. package/src/views/ExportForm/ExportForm.vue +157 -94
  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 +0 -0
  46. package/dist/dev.d.ts +0 -1
  47. package/dist/index.esm.js +0 -668
  48. package/dist/index.umd.js +0 -679
  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,171 +1,231 @@
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
- </div>
29
- </template>
26
+ />
27
+
28
+ <FormFieldSelect
29
+ v-if="shouldDisplayDelimiter"
30
+ v-model:value="values.delimiter"
31
+ :options="delimiterOptionList"
32
+ :error="errors.delimiter"
33
+ :label="$i18n.t('export:delimiter')"
34
+ name="delimiter"
35
+ />
36
+ </div>
37
+ <DynamicField
38
+ v-for="field of templateValues"
39
+ :key="field.config.name"
40
+ :field="field"
41
+ />
30
42
  </form>
31
43
 
32
- <template v-slot:footer>
44
+ <template #footer>
33
45
  <FormFooter
34
- :back-href="getExportListUrl()"
35
- :on-submit="submitForm"
36
- :is-submitting="isSubmitting"
37
- :is-creation="true"
46
+ :back-href="getExportListUrl()"
47
+ @submit="submitForm"
48
+ :is-submitting="isSubmitting"
49
+ :is-creation="true"
38
50
  />
39
51
  </template>
40
- </page>
52
+ </Page>
41
53
  </template>
42
54
 
43
55
  <script lang="ts">
44
- import { defineComponent, watch } from '@vue/composition-api';
45
- import { computed, onMounted, ref } from '@vue/composition-api';
56
+ import {defineComponent, onMounted, watch, ref, computed} from "vue";
57
+ import {useRoute, useRouter} from "vue-router";
58
+
59
+ import {useI18n, navigateBack, useToast} from '@tager/admin-services';
60
+ import {Page} from "@tager/admin-layout";
46
61
 
47
- import { convertRequestErrorToMap, useResource } from '@tager/admin-services';
62
+ import {convertRequestErrorToMap, useResource} from '@tager/admin-services';
48
63
  import {
49
64
  OptionType,
50
65
  TagerFormSubmitEvent,
51
- FormFooter,
52
- useTranslation,
66
+ FormFooter, FormField, FormFieldSelect
53
67
  } from '@tager/admin-ui';
68
+ import {
69
+ DynamicField,
70
+ FieldConfigUnion,
71
+ FieldUnion,
72
+ universalFieldUtils,
73
+ } from '@tager/admin-dynamic-field';
54
74
 
55
- import { createExport, getStrategyList } from '../../services/requests';
56
- import { getExportListUrl } from '../../utils/paths';
57
- import { replaceFileExtension } from '../../utils/common';
75
+ import {createExport, getStrategies} from '../../services/requests';
76
+ import {getExportListUrl} from '../../utils/paths';
77
+ import {replaceFileExtension} from '../../utils/common';
58
78
 
59
79
  import {
60
80
  convertExportFormValuesToCreationPayload,
61
- FormValues,
81
+ convertStrategiesToStrategyOptionList,
82
+ formatOptionList,
83
+ isCSVFormat,
62
84
  } from './ExportForm.helpers';
85
+ import {FormValues} from './ExportForm.types';
86
+
63
87
 
64
88
  export default defineComponent({
65
89
  name: 'ExportForm',
66
- components: { FormFooter },
67
- setup(props, context) {
68
- 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();
69
99
 
70
100
  /** Strategies */
71
101
 
72
102
  const [
73
- fetchStrategyList,
74
- { data: strategyList, loading: isStrategyListLoading },
103
+ fetchStrategies,
104
+ {data: strategies, loading: isStrategiesLoading},
75
105
  ] = useResource({
76
- fetchResource: getStrategyList,
106
+ fetchResource: getStrategies,
77
107
  initialValue: [],
78
- context,
79
- resourceName: 'Strategy List',
108
+ resourceName: 'Strategies',
80
109
  });
81
110
 
82
111
  const strategyOptionList = computed<Array<OptionType>>(() =>
83
- strategyList.value.map<OptionType>((strategy) => ({
84
- value: strategy.id,
85
- label: strategy.name,
86
- }))
112
+ convertStrategiesToStrategyOptionList(strategies.value)
87
113
  );
88
114
 
89
115
  onMounted(() => {
90
- fetchStrategyList();
116
+ fetchStrategies();
91
117
  });
92
118
 
93
- /** Format **/
119
+ /** Delimiter **/
94
120
 
95
- const formatOptionList = computed<Array<OptionType>>(() => [
96
- { value: 'CSV', label: 'CSV' },
97
- { value: 'XLS', label: 'XLS' },
121
+ const delimiterOptionList = computed<Array<OptionType>>(() => [
122
+ {value: ',', label: t('export:comma')},
123
+ {value: ';', label: t('export:semicolon')},
98
124
  ]);
99
125
 
100
126
  /** Form state */
101
127
 
102
- const defaultExtension = formatOptionList.value[0];
128
+ const defaultExtension = formatOptionList[0];
129
+ const defaultDelimiter = delimiterOptionList.value[0];
103
130
 
104
131
  const errors = ref<Record<string, string>>({});
105
132
  const values = ref<FormValues>({
106
133
  strategy: null,
107
134
  filename: `export.${defaultExtension.value.toLowerCase()}`,
108
135
  format: defaultExtension,
136
+ delimiter: defaultDelimiter,
109
137
  });
110
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
+ }
111
153
 
112
154
  watch(
113
- () => values.value.format,
114
- () => {
115
- const newExtension = values.value.format?.value.toLowerCase();
116
-
117
- values.value.filename = replaceFileExtension(
118
- values.value.filename,
119
- newExtension || ''
120
- );
121
- }
155
+ () => values.value.strategy,
156
+ () => {
157
+ updateTemplateValues();
158
+ }
159
+ );
160
+
161
+ onMounted(() => {
162
+ updateTemplateValues();
163
+ });
164
+
165
+ const shouldDisplayDelimiter = ref<boolean>(
166
+ isCSVFormat(values.value.format?.value ?? '')
167
+ );
168
+
169
+ watch(
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
+ }
122
183
  );
123
184
 
124
185
  function submitForm(event: TagerFormSubmitEvent) {
125
186
  isSubmitting.value = true;
126
187
 
127
188
  const creationPayload = convertExportFormValuesToCreationPayload(
128
- values.value
189
+ values.value,
190
+ templateValues.value
129
191
  );
130
192
 
131
193
  createExport(creationPayload)
132
- .then(() => {
133
- errors.value = {};
134
-
135
- if (
136
- event.type === 'create' ||
137
- event.type === 'save' ||
138
- event.type === 'create_exit' ||
139
- event.type === 'save_exit'
140
- ) {
141
- context.root.$router.push(getExportListUrl());
142
- }
143
-
144
- context.root.$toast({
145
- variant: 'success',
146
- title: t('export:success'),
147
- body: t('export:createdSuccessMessage'),
148
- });
149
- })
150
- .catch((error) => {
151
- console.error(error);
152
- errors.value = convertRequestErrorToMap(error);
153
- context.root.$toast({
154
- variant: 'danger',
155
- title: t('export:error'),
156
- body: t('export:createdErrorMessage'),
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;
157
223
  });
158
- })
159
- .finally(() => {
160
- isSubmitting.value = false;
161
- });
162
224
  }
163
225
 
164
226
  /** Is content loading **/
165
227
 
166
- const isContentLoading = computed<boolean>(
167
- () => isStrategyListLoading.value
168
- );
228
+ const isContentLoading = computed<boolean>(() => isStrategiesLoading.value);
169
229
 
170
230
  return {
171
231
  values,
@@ -175,7 +235,10 @@ export default defineComponent({
175
235
  getExportListUrl,
176
236
  strategyOptionList,
177
237
  formatOptionList,
238
+ delimiterOptionList,
178
239
  isContentLoading,
240
+ shouldDisplayDelimiter,
241
+ templateValues,
179
242
  };
180
243
  },
181
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%'},
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 options = {
3
+ /*year: 'numeric',
4
+ month: 'numeric',
5
+ day: 'numeric',
6
+ hour: 'numeric',
7
+ minute: 'numeric',
8
+ second: 'numeric',*/
9
+ };
10
+ const date = new Date(value);
11
+ return new Intl.DateTimeFormat('ru-RU', options).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 DELETED
File without changes
package/dist/dev.d.ts DELETED
@@ -1 +0,0 @@
1
- import '@tager/admin-ui/dist/admin-ui.css';