@tager/admin-import 0.1.1 → 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 +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 +439 -0
  8. package/dist/locales/apply.d.ts +1 -0
  9. package/dist/locales/en.d.ts +19 -20
  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 +33 -26
  15. package/dist/utils/paths.d.ts +4 -4
  16. package/dist/views/ImportForm/ImportForm.helpers.d.ts +9 -7
  17. package/dist/views/ImportForm/ImportForm.vue.d.ts +2688 -70
  18. package/dist/views/ImportForm/index.d.ts +1 -1
  19. package/dist/views/ImportList/ImportList.vue.d.ts +16 -41
  20. package/dist/views/ImportList/components/CellHistory/CellHistory.helpers.d.ts +1 -0
  21. package/dist/views/ImportList/components/CellHistory/CellHistory.vue.d.ts +19 -0
  22. package/dist/views/ImportList/components/CellHistory/index.d.ts +1 -0
  23. package/dist/views/ImportList/index.d.ts +1 -1
  24. package/package.json +49 -47
  25. package/src/constants/routes.ts +10 -10
  26. package/src/dev/App.vue +38 -0
  27. package/src/dev/config.ts +23 -0
  28. package/src/dev/env.ts +17 -0
  29. package/src/dev/main.ts +36 -0
  30. package/src/locales/apply.ts +9 -0
  31. package/src/locales/en.ts +2 -4
  32. package/src/locales/ru.ts +19 -21
  33. package/src/main.ts +2 -6
  34. package/src/typings/model.ts +14 -1
  35. package/src/views/ImportForm/ImportForm.helpers.ts +17 -2
  36. package/src/views/ImportForm/ImportForm.vue +109 -69
  37. package/src/views/ImportList/ImportList.vue +60 -63
  38. package/src/views/ImportList/components/CellHistory/CellHistory.helpers.ts +13 -0
  39. package/src/views/ImportList/components/CellHistory/CellHistory.vue +38 -0
  40. package/src/views/ImportList/components/CellHistory/index.ts +1 -0
  41. package/README.md +0 -1
  42. package/dist/dev.d.ts +0 -1
  43. package/dist/index.esm.js +0 -618
  44. package/dist/index.umd.js +0 -629
  45. package/src/dev.ts +0 -41
  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 -36
@@ -1,87 +1,100 @@
1
1
  <template>
2
- <page
3
- :title="$t('import:importCreation')"
4
- :is-content-loading="isContentLoading"
2
+ <Page
3
+ :title="$i18n.t('import:importCreation')"
4
+ :is-content-loading="isContentLoading"
5
5
  >
6
6
  <form novalidate @submit.prevent>
7
- <template>
8
- <form-field-select
9
- v-model="values.strategy"
7
+ <FormFieldSelect
8
+ v-model:value="values.strategy"
10
9
  :options="strategyOptionList"
11
10
  :error="errors.strategy"
12
11
  name="importType"
13
- :label="$t('import:importType')"
14
- />
12
+ :label="$i18n.t('import:importType')"
13
+ />
15
14
 
16
- <form-field-file-input
17
- v-model="values.file"
15
+ <FormFieldFileInput
16
+ v-model:value="values.file"
18
17
  :error="errors.file"
19
- :label="$t('import:file')"
18
+ :label="$i18n.t('import:file')"
20
19
  name="file"
21
20
  :scenario="strategyFileScenario"
22
- />
23
- </template>
21
+ />
22
+
23
+ <DynamicField
24
+ v-for="field of templateValues"
25
+ :key="field.config.name"
26
+ :field="field"
27
+ />
24
28
  </form>
25
29
 
26
- <template v-slot:footer>
30
+ <template #footer>
27
31
  <FormFooter
28
- :back-href="getImportListUrl()"
29
- :on-submit="submitForm"
30
- :is-submitting="isSubmitting"
31
- :is-creation="true"
32
+ :back-href="getImportListUrl()"
33
+ @submit="submitForm"
34
+ :is-submitting="isSubmitting"
35
+ :is-creation="true"
32
36
  />
33
37
  </template>
34
- </page>
38
+ </Page>
35
39
  </template>
36
40
 
37
41
  <script lang="ts">
38
- import { defineComponent } from '@vue/composition-api';
39
- import { computed, onMounted, ref } from '@vue/composition-api';
42
+ import {defineComponent, watch, computed, onMounted, ref} from 'vue';
40
43
 
41
- import { convertRequestErrorToMap, useResource } from '@tager/admin-services';
44
+ import {convertRequestErrorToMap, navigateBack, useI18n, useResource, useToast} from '@tager/admin-services';
42
45
  import {
43
46
  OptionType,
44
47
  TagerFormSubmitEvent,
45
48
  FormFooter,
46
- useTranslation,
49
+ FormFieldFileInput, FormFieldSelect
47
50
  } from '@tager/admin-ui';
51
+ import {
52
+ DynamicField,
53
+ FieldConfigUnion,
54
+ FieldUnion,
55
+ universalFieldUtils,
56
+ } from '@tager/admin-dynamic-field';
48
57
 
49
- import { createImport, getModuleInfo } from '../../services/requests';
50
- import { getImportListUrl } from '../../utils/paths';
58
+ import {createImport, getModuleInfo} from '../../services/requests';
59
+ import {getImportListUrl} from '../../utils/paths';
51
60
 
52
61
  import {
53
62
  convertImportFormValuesToCreationPayload,
63
+ convertStrategiesToStrategyOptionList,
54
64
  FormValues,
55
65
  } from './ImportForm.helpers';
66
+ import {useRouter} from "vue-router";
67
+ import {Page} from "@tager/admin-layout";
56
68
 
57
69
  export default defineComponent({
58
70
  name: 'ImportForm',
59
- components: { FormFooter },
60
- setup(props, context) {
61
- const { t } = useTranslation(context);
71
+ components: {Page, FormFieldFileInput, DynamicField, FormFooter, FormFieldSelect},
72
+ setup() {
73
+ const {t} = useI18n();
74
+
75
+ const toast = useToast();
76
+ const router = useRouter();
62
77
 
63
78
  /** Strategies */
64
79
 
65
80
  const [
66
81
  fetchModuleInfo,
67
- { data: moduleInfo, loading: isModuleInfoLoading },
82
+ {data: moduleInfo, loading: isModuleInfoLoading},
68
83
  ] = useResource({
69
84
  fetchResource: getModuleInfo,
70
- initialValue: null,
71
- context,
85
+ initialValue: {
86
+ fileScenario: '',
87
+ strategies: [],
88
+ },
72
89
  resourceName: 'Module info',
73
90
  });
74
91
 
75
92
  const strategyFileScenario = computed<string>(
76
- () => moduleInfo.value?.fileScenario ?? ''
93
+ () => moduleInfo.value.fileScenario
77
94
  );
78
95
 
79
- const strategyOptionList = computed<Array<OptionType>>(
80
- () =>
81
- moduleInfo.value?.strategies.map<OptionType>((strategy) => ({
82
- value: strategy.id,
83
- label: strategy.name,
84
- })) ?? []
96
+ const strategyOptionList = computed<Array<OptionType>>(() =>
97
+ convertStrategiesToStrategyOptionList(moduleInfo.value.strategies)
85
98
  );
86
99
 
87
100
  onMounted(() => {
@@ -91,47 +104,73 @@ export default defineComponent({
91
104
  /** Form state */
92
105
 
93
106
  const errors = ref<Record<string, string>>({});
94
- const values = ref<FormValues>({ strategy: null, file: null });
107
+ const values = ref<FormValues>({strategy: null, file: null});
95
108
  const isSubmitting = ref<boolean>(false);
109
+ const templateValues = ref<Array<FieldUnion>>([]);
110
+
111
+ function updateTemplateValues() {
112
+ const selectedStrategy = moduleInfo.value.strategies.find(
113
+ (strategy) => strategy.id === values.value.strategy?.value
114
+ );
115
+
116
+ const fieldTemplateList: Array<FieldConfigUnion> =
117
+ selectedStrategy?.fields ?? [];
118
+
119
+ templateValues.value = fieldTemplateList.map((fieldConfig) =>
120
+ universalFieldUtils.createFormField(fieldConfig, null)
121
+ );
122
+ }
123
+
124
+ watch(
125
+ () => values.value.strategy,
126
+ () => {
127
+ updateTemplateValues();
128
+ }
129
+ );
130
+
131
+ onMounted(() => {
132
+ updateTemplateValues();
133
+ });
96
134
 
97
135
  function submitForm(event: TagerFormSubmitEvent) {
98
136
  isSubmitting.value = true;
99
137
 
100
138
  const creationPayload = convertImportFormValuesToCreationPayload(
101
- values.value
139
+ values.value,
140
+ templateValues.value
102
141
  );
103
142
 
104
143
  createImport(creationPayload)
105
- .then(() => {
106
- errors.value = {};
107
-
108
- if (
109
- event.type === 'create' ||
110
- event.type === 'save' ||
111
- event.type === 'create_exit' ||
112
- event.type === 'save_exit'
113
- ) {
114
- context.root.$router.push(getImportListUrl());
115
- }
116
-
117
- context.root.$toast({
118
- variant: 'success',
119
- title: t('import:success'),
120
- body: t('import:createdSuccessMessage'),
121
- });
122
- })
123
- .catch((error) => {
124
- console.error(error);
125
- errors.value = convertRequestErrorToMap(error);
126
- context.root.$toast({
127
- variant: 'danger',
128
- title: t('import:error'),
129
- body: t('import:createdErrorMessage'),
144
+ .then(() => {
145
+ errors.value = {};
146
+
147
+ if (
148
+ event.type === 'create' ||
149
+ event.type === 'save' ||
150
+ event.type === 'create_exit' ||
151
+ event.type === 'save_exit'
152
+ ) {
153
+ navigateBack(router, getImportListUrl());
154
+ }
155
+
156
+ toast.show({
157
+ variant: 'success',
158
+ title: t('import:success'),
159
+ body: t('import:createdSuccessMessage'),
160
+ });
161
+ })
162
+ .catch((error) => {
163
+ console.error(error);
164
+ errors.value = convertRequestErrorToMap(error);
165
+ toast.show({
166
+ variant: 'danger',
167
+ title: t('import:error'),
168
+ body: t('import:createdErrorMessage'),
169
+ });
170
+ })
171
+ .finally(() => {
172
+ isSubmitting.value = false;
130
173
  });
131
- })
132
- .finally(() => {
133
- isSubmitting.value = false;
134
- });
135
174
  }
136
175
 
137
176
  /** Is content loading **/
@@ -147,6 +186,7 @@ export default defineComponent({
147
186
  strategyOptionList,
148
187
  strategyFileScenario,
149
188
  isContentLoading,
189
+ templateValues,
150
190
  };
151
191
  },
152
192
  });
@@ -1,58 +1,59 @@
1
1
  <template>
2
- <page
3
- :title="t('import:import')"
4
- :header-buttons="[
2
+ <Page
3
+ :title="$i18n.t('import:import')"
4
+ :header-buttons="[
5
5
  {
6
- text: t('import:newImport'),
6
+ text: $i18n.t('import:newImport'),
7
7
  href: getImportFormUrl({ importId: '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';
33
+ import {defineComponent, onMounted} from 'vue';
41
34
 
42
35
  import {
43
36
  ColumnDefinition,
44
37
  useDataTable,
45
- useTranslation,
38
+ DataTable
46
39
  } from '@tager/admin-ui';
47
40
 
48
- import { getImportList } from '../../services/requests';
49
- import { ImportType } from '../../typings/model';
50
- import { getImportFormUrl } from '../../utils/paths';
41
+ import {
42
+ Page
43
+ } from '@tager/admin-layout';
44
+ import {useI18n} from "@tager/admin-services";
45
+
46
+ import {getImportList} from '../../services/requests';
47
+ import {ImportType} from '../../typings/model';
48
+ import {getImportFormUrl} from '../../utils/paths';
49
+
50
+ import {CellHistory} from './components/CellHistory';
51
51
 
52
52
  export default defineComponent({
53
53
  name: 'ImportList',
54
- setup(props, context) {
55
- const { t } = useTranslation(context);
54
+ components: {CellHistory, DataTable, Page},
55
+ setup() {
56
+ const {t} = useI18n();
56
57
 
57
58
  const {
58
59
  fetchEntityList: fetchImportList,
@@ -66,12 +67,11 @@ export default defineComponent({
66
67
  pageNumber,
67
68
  } = useDataTable<ImportType>({
68
69
  fetchEntityList: (params) =>
69
- getImportList({
70
- pageNumber: params.pageNumber,
71
- pageSize: params.pageSize,
72
- }),
70
+ getImportList({
71
+ pageNumber: params.pageNumber,
72
+ pageSize: params.pageSize,
73
+ }),
73
74
  initialValue: [],
74
- context,
75
75
  resourceName: 'Import list',
76
76
  pageSize: 100,
77
77
  });
@@ -85,59 +85,58 @@ export default defineComponent({
85
85
  id: 1,
86
86
  name: 'ID',
87
87
  field: 'id',
88
- style: { width: '50px', textAlign: 'center' },
89
- headStyle: { width: '50px', textAlign: 'center' },
88
+ style: {width: '50px', textAlign: 'center'},
89
+ headStyle: {width: '50px', textAlign: 'center'},
90
90
  },
91
91
  {
92
92
  id: 2,
93
93
  name: t('import:type'),
94
94
  field: 'strategy',
95
- style: { width: '15%' },
96
- headStyle: { width: '15%' },
95
+ style: {width: '150px'},
96
+ headStyle: {width: '150px'},
97
97
  },
98
98
  {
99
99
  id: 3,
100
+ name: t('import:params'),
101
+ field: 'params',
102
+ type: 'key-value',
103
+ format: ({row}) => row.params ? row.params.map((param) => {
104
+ return {
105
+ key: param.label,
106
+ value: param.value
107
+ };
108
+ }) : null
109
+ },
110
+ {
111
+ id: 4,
100
112
  name: t('import:status'),
101
113
  field: 'status',
102
- style: { width: '15%' },
103
- headStyle: { width: '15%' },
114
+ style: {width: '120px'},
115
+ headStyle: {width: '120px'},
104
116
  },
105
117
  {
106
- id: 4,
118
+ id: 5,
107
119
  name: t('import:message'),
108
120
  field: 'message',
109
121
  },
110
122
 
111
123
  {
112
- id: 5,
124
+ id: 6,
113
125
  name: t('import:log'),
114
126
  field: 'history',
115
- style: { width: '25%' },
116
- headStyle: { width: '25%' },
127
+ style: {width: '270px', whiteSpace: 'nowrap'},
128
+ headStyle: {width: '270px'},
117
129
  },
118
130
  {
119
- id: 6,
131
+ id: 7,
120
132
  name: t('import:file'),
121
133
  field: 'file',
122
134
  type: 'file',
123
- style: { width: '150px', textAlign: 'center' },
124
- headStyle: { width: '150px', textAlign: 'center' },
135
+ style: {width: '150px', textAlign: 'center'},
136
+ headStyle: {width: '150px', textAlign: 'center'},
125
137
  },
126
138
  ];
127
139
 
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
140
  return {
142
141
  columnDefs,
143
142
  getImportFormUrl,
@@ -149,8 +148,6 @@ export default defineComponent({
149
148
  pageSize,
150
149
  pageCount,
151
150
  pageNumber,
152
- t,
153
- dateTimeFormat,
154
151
  };
155
152
  },
156
153
  });
@@ -0,0 +1,13 @@
1
+ export function dateTimeFormat(value: number | string | Date): string {
2
+
3
+ const date = new Date(value);
4
+
5
+ return new Intl.DateTimeFormat('ru-RU', {
6
+ "year": "numeric",
7
+ month: 'numeric',
8
+ day: 'numeric',
9
+ hour: 'numeric',
10
+ minute: 'numeric',
11
+ second: 'numeric',
12
+ }).format(date);
13
+ }
@@ -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
@@ -1 +0,0 @@
1
- # tager-admin-import
package/dist/dev.d.ts DELETED
@@ -1 +0,0 @@
1
- import '@tager/admin-ui/dist/admin-ui.css';