@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
package/dist/index.esm.js DELETED
@@ -1,714 +0,0 @@
1
- import { request, useResource, convertRequestErrorToMap, i18n } from '@tager/admin-services';
2
- import { defineComponent, onMounted, computed, ref, watch } from '@vue/composition-api';
3
- import { useTranslation, useDataTable, FormFooter } from '@tager/admin-ui';
4
- import { compile } from 'path-to-regexp';
5
-
6
- const EN = {
7
- home: 'Home',
8
- exportAndImport: 'Export / Import',
9
- export: 'Export',
10
- exportList: 'Export List',
11
- exportForm: 'Export Form',
12
- type: 'Type',
13
- exportType: 'Export type',
14
- status: 'status',
15
- message: 'Message',
16
- log: 'Log',
17
- file: 'file',
18
- newExport: 'New export',
19
- exportCreation: 'Export creation',
20
- success: 'Success',
21
- error: 'Error',
22
- createdSuccessMessage: 'Export has been successfully created',
23
- createdErrorMessage: 'Export creation has been failed',
24
- filename: 'File name',
25
- format: 'Format',
26
- delimiter: 'Delimiter',
27
- comma: 'Comma',
28
- semicolon: 'Semicolon',
29
- };
30
-
31
- const RU = {
32
- home: 'Главная',
33
- exportAndImport: 'Экспорт / Импорт',
34
- export: 'Экспорт',
35
- exportList: 'Список экспортов',
36
- exportForm: 'Форма экспорта',
37
- type: 'Тип',
38
- exportType: 'Тип экспорта',
39
- status: 'Статус',
40
- message: 'Сообщение',
41
- log: 'Лог',
42
- file: 'Файл',
43
- newExport: 'Новый экспорт',
44
- exportCreation: 'Создание экспорта',
45
- success: 'Успех',
46
- error: 'Ошибка',
47
- createdSuccessMessage: 'Экспорт была успешно создан',
48
- createdErrorMessage: 'Создание экспорта не удалось',
49
- filename: 'Имя файла',
50
- format: 'Формат',
51
- delimiter: 'Разделитель',
52
- comma: 'Запятая',
53
- semicolon: 'Точка с запятой',
54
- };
55
-
56
- function getExportList(params) {
57
- return request.get({ path: '/admin/tager/export', params });
58
- }
59
- function getStrategyList() {
60
- return request.get({ path: '/admin/tager/export/strategies' });
61
- }
62
- function createExport(payload) {
63
- return request.post({ path: '/admin/tager/export', body: payload });
64
- }
65
-
66
- const EXPORT_ROUTE_PATHS = {
67
- EXPORT_LIST: '/export',
68
- EXPORT_FORM: '/export/:exportId',
69
- };
70
-
71
- function getExportListUrl() {
72
- return EXPORT_ROUTE_PATHS.EXPORT_LIST;
73
- }
74
- function getExportFormUrl(params) {
75
- return compile(EXPORT_ROUTE_PATHS.EXPORT_FORM)(params);
76
- }
77
-
78
- var script = defineComponent({
79
- name: 'ExportList',
80
- setup(props, context) {
81
- const { t } = useTranslation(context);
82
- const { fetchEntityList: fetchExportList, isLoading: isExportListLoading, rowData: exportList, errorMessage, searchQuery, handleChange, pageSize, pageCount, pageNumber, } = useDataTable({
83
- fetchEntityList: (params) => getExportList({
84
- pageNumber: params.pageNumber,
85
- pageSize: params.pageSize,
86
- }),
87
- initialValue: [],
88
- context,
89
- resourceName: 'Export list',
90
- pageSize: 100,
91
- });
92
- onMounted(() => {
93
- fetchExportList();
94
- });
95
- const columnDefs = [
96
- {
97
- id: 1,
98
- name: 'ID',
99
- field: 'id',
100
- style: { width: '50px', textAlign: 'center' },
101
- headStyle: { width: '50px', textAlign: 'center' },
102
- },
103
- {
104
- id: 2,
105
- name: t('export:type'),
106
- field: 'strategy',
107
- style: { width: '15%' },
108
- headStyle: { width: '15%' },
109
- },
110
- {
111
- id: 3,
112
- name: t('export:status'),
113
- field: 'status',
114
- style: { width: '15%' },
115
- headStyle: { width: '15%' },
116
- },
117
- {
118
- id: 4,
119
- name: t('export:message'),
120
- field: 'message',
121
- },
122
- {
123
- id: 5,
124
- name: t('export:log'),
125
- field: 'history',
126
- style: { width: '25%' },
127
- headStyle: { width: '25%' },
128
- },
129
- {
130
- id: 6,
131
- name: t('export:file'),
132
- field: 'file',
133
- type: 'file',
134
- style: { width: '150px', textAlign: 'center' },
135
- headStyle: { width: '150px', textAlign: 'center' },
136
- },
137
- ];
138
- function dateTimeFormat(value) {
139
- const options = {
140
- year: 'numeric',
141
- month: 'numeric',
142
- day: 'numeric',
143
- hour: 'numeric',
144
- minute: 'numeric',
145
- second: 'numeric',
146
- };
147
- const date = new Date(value);
148
- return new Intl.DateTimeFormat('ru-RU', options).format(date);
149
- }
150
- return {
151
- columnDefs,
152
- getExportFormUrl,
153
- rowData: exportList,
154
- isRowDataLoading: isExportListLoading,
155
- errorMessage: errorMessage,
156
- searchQuery,
157
- handleChange,
158
- pageSize,
159
- pageCount,
160
- pageNumber,
161
- t,
162
- dateTimeFormat,
163
- };
164
- },
165
- });
166
-
167
- function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
168
- if (typeof shadowMode !== 'boolean') {
169
- createInjectorSSR = createInjector;
170
- createInjector = shadowMode;
171
- shadowMode = false;
172
- }
173
- // Vue.extend constructor export interop.
174
- const options = typeof script === 'function' ? script.options : script;
175
- // render functions
176
- if (template && template.render) {
177
- options.render = template.render;
178
- options.staticRenderFns = template.staticRenderFns;
179
- options._compiled = true;
180
- // functional template
181
- if (isFunctionalTemplate) {
182
- options.functional = true;
183
- }
184
- }
185
- // scopedId
186
- if (scopeId) {
187
- options._scopeId = scopeId;
188
- }
189
- let hook;
190
- if (moduleIdentifier) {
191
- // server build
192
- hook = function (context) {
193
- // 2.3 injection
194
- context =
195
- context || // cached call
196
- (this.$vnode && this.$vnode.ssrContext) || // stateful
197
- (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
198
- // 2.2 with runInNewContext: true
199
- if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
200
- context = __VUE_SSR_CONTEXT__;
201
- }
202
- // inject component styles
203
- if (style) {
204
- style.call(this, createInjectorSSR(context));
205
- }
206
- // register component module identifier for async chunk inference
207
- if (context && context._registeredComponents) {
208
- context._registeredComponents.add(moduleIdentifier);
209
- }
210
- };
211
- // used by ssr in case component is cached and beforeCreate
212
- // never gets called
213
- options._ssrRegister = hook;
214
- }
215
- else if (style) {
216
- hook = shadowMode
217
- ? function (context) {
218
- style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
219
- }
220
- : function (context) {
221
- style.call(this, createInjector(context));
222
- };
223
- }
224
- if (hook) {
225
- if (options.functional) {
226
- // register for functional component in vue file
227
- const originalRender = options.render;
228
- options.render = function renderWithStyleInjection(h, context) {
229
- hook.call(context);
230
- return originalRender(h, context);
231
- };
232
- }
233
- else {
234
- // inject component registration as beforeCreate hook
235
- const existing = options.beforeCreate;
236
- options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
237
- }
238
- }
239
- return script;
240
- }
241
-
242
- /* script */
243
- const __vue_script__ = script;
244
-
245
- /* template */
246
- var __vue_render__ = function () {
247
- var _vm = this;
248
- var _h = _vm.$createElement;
249
- var _c = _vm._self._c || _h;
250
- return _c(
251
- "page",
252
- {
253
- attrs: {
254
- title: _vm.t("export:export"),
255
- "header-buttons": [
256
- {
257
- text: _vm.t("export:newExport"),
258
- href: _vm.getExportFormUrl({ exportId: "create" }),
259
- },
260
- ],
261
- },
262
- },
263
- [
264
- _c("data-table", {
265
- attrs: {
266
- "column-defs": _vm.columnDefs,
267
- "row-data": _vm.rowData,
268
- loading: _vm.isRowDataLoading,
269
- "error-message": _vm.errorMessage,
270
- pagination: {
271
- pageSize: _vm.pageSize,
272
- pageCount: _vm.pageCount,
273
- pageNumber: _vm.pageNumber,
274
- disabled: _vm.isRowDataLoading,
275
- },
276
- "use-search": false,
277
- },
278
- on: { change: _vm.handleChange },
279
- scopedSlots: _vm._u([
280
- {
281
- key: "cell(history)",
282
- fn: function (ref) {
283
- var row = ref.row;
284
- return [
285
- row.history
286
- ? _c(
287
- "ul",
288
- _vm._l(row.history, function (history, index) {
289
- return _c("li", { key: index }, [
290
- _c(
291
- "span",
292
- {
293
- style: {
294
- width: "100px",
295
- display: "inline-block",
296
- },
297
- },
298
- [_vm._v(_vm._s(history.status))]
299
- ),
300
- _vm._v(
301
- "\n " +
302
- _vm._s(_vm.dateTimeFormat(history.datetime)) +
303
- "\n "
304
- ),
305
- ])
306
- }),
307
- 0
308
- )
309
- : _vm._e(),
310
- ]
311
- },
312
- },
313
- ]),
314
- }),
315
- ],
316
- 1
317
- )
318
- };
319
- var __vue_staticRenderFns__ = [];
320
- __vue_render__._withStripped = true;
321
-
322
- /* style */
323
- const __vue_inject_styles__ = undefined;
324
- /* scoped */
325
- const __vue_scope_id__ = undefined;
326
- /* module identifier */
327
- const __vue_module_identifier__ = undefined;
328
- /* functional template */
329
- const __vue_is_functional_template__ = false;
330
- /* style inject */
331
-
332
- /* style inject SSR */
333
-
334
- /* style inject shadow dom */
335
-
336
-
337
-
338
- const __vue_component__ = /*#__PURE__*/normalizeComponent(
339
- { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
340
- __vue_inject_styles__,
341
- __vue_script__,
342
- __vue_scope_id__,
343
- __vue_is_functional_template__,
344
- __vue_module_identifier__,
345
- false,
346
- undefined,
347
- undefined,
348
- undefined
349
- );
350
-
351
- function replaceFileExtension(fileName, newExtension) {
352
- const dotIndex = fileName.lastIndexOf('.');
353
- const fileNameWithoutExtension = fileName.slice(0, dotIndex);
354
- if (newExtension) {
355
- return `${fileNameWithoutExtension}.${newExtension}`;
356
- }
357
- return fileNameWithoutExtension;
358
- }
359
-
360
- function convertExportFormValuesToCreationPayload(values) {
361
- var _a, _b, _c, _d, _e, _f;
362
- return {
363
- strategy: (_b = (_a = values.strategy) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '',
364
- filename: values.filename,
365
- format: (_d = (_c = values.format) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '',
366
- delimiter: (_f = (_e = values.delimiter) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : '',
367
- };
368
- }
369
-
370
- var script$1 = defineComponent({
371
- name: 'ExportForm',
372
- components: { FormFooter },
373
- setup(props, context) {
374
- var _a, _b;
375
- const { t } = useTranslation(context);
376
- /** Strategies */
377
- const [fetchStrategyList, { data: strategyList, loading: isStrategyListLoading },] = useResource({
378
- fetchResource: getStrategyList,
379
- initialValue: [],
380
- context,
381
- resourceName: 'Strategy List',
382
- });
383
- const strategyOptionList = computed(() => strategyList.value.map((strategy) => ({
384
- value: strategy.id,
385
- label: strategy.name,
386
- })));
387
- onMounted(() => {
388
- fetchStrategyList();
389
- });
390
- /** Format **/
391
- const formatOptionList = computed(() => [
392
- { value: 'CSV', label: 'CSV' },
393
- { value: 'XLS', label: 'XLS' },
394
- { value: 'XML', label: 'XML' },
395
- { value: 'YAML', label: 'YAML' },
396
- { value: 'JSON', label: 'JSON' },
397
- { value: 'TXT', label: 'TXT' },
398
- ]);
399
- function isCSVFormat(format) {
400
- return format === 'CSV';
401
- }
402
- /** Delimiter **/
403
- const delimiterOptionList = computed(() => [
404
- { value: ',', label: t('export:comma') },
405
- { value: ';', label: t('export:semicolon') },
406
- ]);
407
- /** Form state */
408
- const defaultExtension = formatOptionList.value[0];
409
- const defaultDelimiter = delimiterOptionList.value[0];
410
- const errors = ref({});
411
- const values = ref({
412
- strategy: null,
413
- filename: `export.${defaultExtension.value.toLowerCase()}`,
414
- format: defaultExtension,
415
- delimiter: defaultDelimiter,
416
- });
417
- const isSubmitting = ref(false);
418
- const shouldDisplayDelimiter = ref(isCSVFormat((_b = (_a = values.value.format) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''));
419
- watch(() => values.value.format, () => {
420
- var _a, _b, _c;
421
- const newExtension = (_a = values.value.format) === null || _a === void 0 ? void 0 : _a.value.toLowerCase();
422
- values.value.filename = replaceFileExtension(values.value.filename, newExtension || '');
423
- shouldDisplayDelimiter.value = isCSVFormat((_c = (_b = values.value.format) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '');
424
- });
425
- function submitForm(event) {
426
- isSubmitting.value = true;
427
- const creationPayload = convertExportFormValuesToCreationPayload(values.value);
428
- createExport(creationPayload)
429
- .then(() => {
430
- errors.value = {};
431
- if (event.type === 'create' ||
432
- event.type === 'save' ||
433
- event.type === 'create_exit' ||
434
- event.type === 'save_exit') {
435
- context.root.$router.push(getExportListUrl());
436
- }
437
- context.root.$toast({
438
- variant: 'success',
439
- title: t('export:success'),
440
- body: t('export:createdSuccessMessage'),
441
- });
442
- })
443
- .catch((error) => {
444
- console.error(error);
445
- errors.value = convertRequestErrorToMap(error);
446
- context.root.$toast({
447
- variant: 'danger',
448
- title: t('export:error'),
449
- body: t('export:createdErrorMessage'),
450
- });
451
- })
452
- .finally(() => {
453
- isSubmitting.value = false;
454
- });
455
- }
456
- /** Is content loading **/
457
- const isContentLoading = computed(() => isStrategyListLoading.value);
458
- return {
459
- values,
460
- errors,
461
- isSubmitting,
462
- submitForm,
463
- getExportListUrl,
464
- strategyOptionList,
465
- formatOptionList,
466
- delimiterOptionList,
467
- isContentLoading,
468
- shouldDisplayDelimiter,
469
- };
470
- },
471
- });
472
-
473
- const isOldIE = typeof navigator !== 'undefined' &&
474
- /msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());
475
- function createInjector(context) {
476
- return (id, style) => addStyle(id, style);
477
- }
478
- let HEAD;
479
- const styles = {};
480
- function addStyle(id, css) {
481
- const group = isOldIE ? css.media || 'default' : id;
482
- const style = styles[group] || (styles[group] = { ids: new Set(), styles: [] });
483
- if (!style.ids.has(id)) {
484
- style.ids.add(id);
485
- let code = css.source;
486
- if (css.map) {
487
- // https://developer.chrome.com/devtools/docs/javascript-debugging
488
- // this makes source maps inside style tags work properly in Chrome
489
- code += '\n/*# sourceURL=' + css.map.sources[0] + ' */';
490
- // http://stackoverflow.com/a/26603875
491
- code +=
492
- '\n/*# sourceMappingURL=data:application/json;base64,' +
493
- btoa(unescape(encodeURIComponent(JSON.stringify(css.map)))) +
494
- ' */';
495
- }
496
- if (!style.element) {
497
- style.element = document.createElement('style');
498
- style.element.type = 'text/css';
499
- if (css.media)
500
- style.element.setAttribute('media', css.media);
501
- if (HEAD === undefined) {
502
- HEAD = document.head || document.getElementsByTagName('head')[0];
503
- }
504
- HEAD.appendChild(style.element);
505
- }
506
- if ('styleSheet' in style.element) {
507
- style.styles.push(code);
508
- style.element.styleSheet.cssText = style.styles
509
- .filter(Boolean)
510
- .join('\n');
511
- }
512
- else {
513
- const index = style.ids.size - 1;
514
- const textNode = document.createTextNode(code);
515
- const nodes = style.element.childNodes;
516
- if (nodes[index])
517
- style.element.removeChild(nodes[index]);
518
- if (nodes.length)
519
- style.element.insertBefore(textNode, nodes[index]);
520
- else
521
- style.element.appendChild(textNode);
522
- }
523
- }
524
- }
525
-
526
- /* script */
527
- const __vue_script__$1 = script$1;
528
-
529
- /* template */
530
- var __vue_render__$1 = function () {
531
- var _vm = this;
532
- var _h = _vm.$createElement;
533
- var _c = _vm._self._c || _h;
534
- return _c(
535
- "page",
536
- {
537
- attrs: {
538
- title: _vm.$t("export:newExport"),
539
- "is-content-loading": _vm.isContentLoading,
540
- },
541
- scopedSlots: _vm._u([
542
- {
543
- key: "footer",
544
- fn: function () {
545
- return [
546
- _c("FormFooter", {
547
- attrs: {
548
- "back-href": _vm.getExportListUrl(),
549
- "on-submit": _vm.submitForm,
550
- "is-submitting": _vm.isSubmitting,
551
- "is-creation": true,
552
- },
553
- }),
554
- ]
555
- },
556
- proxy: true,
557
- },
558
- ]),
559
- },
560
- [
561
- _c(
562
- "form",
563
- {
564
- attrs: { novalidate: "" },
565
- on: {
566
- submit: function ($event) {
567
- $event.preventDefault();
568
- },
569
- },
570
- },
571
- [
572
- [
573
- _c("form-field-select", {
574
- attrs: {
575
- options: _vm.strategyOptionList,
576
- error: _vm.errors.strategy,
577
- label: _vm.$t("export:exportType"),
578
- name: "exportType",
579
- },
580
- model: {
581
- value: _vm.values.strategy,
582
- callback: function ($$v) {
583
- _vm.$set(_vm.values, "strategy", $$v);
584
- },
585
- expression: "values.strategy",
586
- },
587
- }),
588
- _vm._v(" "),
589
- _c(
590
- "div",
591
- { staticClass: "field" },
592
- [
593
- _c("form-field", {
594
- attrs: {
595
- error: _vm.errors.filename,
596
- label: _vm.$t("export:filename"),
597
- name: "filename",
598
- },
599
- model: {
600
- value: _vm.values.filename,
601
- callback: function ($$v) {
602
- _vm.$set(_vm.values, "filename", $$v);
603
- },
604
- expression: "values.filename",
605
- },
606
- }),
607
- _vm._v(" "),
608
- _c("form-field-select", {
609
- attrs: {
610
- options: _vm.formatOptionList,
611
- error: _vm.errors.format,
612
- label: _vm.$t("export:format"),
613
- name: "format",
614
- },
615
- model: {
616
- value: _vm.values.format,
617
- callback: function ($$v) {
618
- _vm.$set(_vm.values, "format", $$v);
619
- },
620
- expression: "values.format",
621
- },
622
- }),
623
- _vm._v(" "),
624
- _c("div"),
625
- _vm._v(" "),
626
- _vm.shouldDisplayDelimiter
627
- ? _c("form-field-select", {
628
- attrs: {
629
- options: _vm.delimiterOptionList,
630
- error: _vm.errors.delimiter,
631
- label: _vm.$t("export:delimiter"),
632
- name: "delimiter",
633
- },
634
- model: {
635
- value: _vm.values.delimiter,
636
- callback: function ($$v) {
637
- _vm.$set(_vm.values, "delimiter", $$v);
638
- },
639
- expression: "values.delimiter",
640
- },
641
- })
642
- : _vm._e(),
643
- ],
644
- 1
645
- ),
646
- ],
647
- ],
648
- 2
649
- ),
650
- ]
651
- )
652
- };
653
- var __vue_staticRenderFns__$1 = [];
654
- __vue_render__$1._withStripped = true;
655
-
656
- /* style */
657
- const __vue_inject_styles__$1 = function (inject) {
658
- if (!inject) return
659
- inject("data-v-1d7bcab0_0", { source: ".field[data-v-1d7bcab0] {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n column-gap: 20px;\n}\n\n/*# sourceMappingURL=ExportForm.vue.map */", map: {"version":3,"sources":["/home/runner/work/tager-admin-export/tager-admin-export/src/views/ExportForm/ExportForm.vue","ExportForm.vue"],"names":[],"mappings":"AA8NA;EACA,aAAA;EACA,qCAAA;EACA,gBAAA;AC7NA;;AAEA,yCAAyC","file":"ExportForm.vue","sourcesContent":["<template>\n <page :title=\"$t('export:newExport')\" :is-content-loading=\"isContentLoading\">\n <form novalidate @submit.prevent>\n <template>\n <form-field-select\n v-model=\"values.strategy\"\n :options=\"strategyOptionList\"\n :error=\"errors.strategy\"\n :label=\"$t('export:exportType')\"\n name=\"exportType\"\n />\n\n <div class=\"field\">\n <form-field\n v-model=\"values.filename\"\n :error=\"errors.filename\"\n :label=\"$t('export:filename')\"\n name=\"filename\"\n />\n\n <form-field-select\n v-model=\"values.format\"\n :options=\"formatOptionList\"\n :error=\"errors.format\"\n :label=\"$t('export:format')\"\n name=\"format\"\n />\n\n <div />\n\n <form-field-select\n v-if=\"shouldDisplayDelimiter\"\n v-model=\"values.delimiter\"\n :options=\"delimiterOptionList\"\n :error=\"errors.delimiter\"\n :label=\"$t('export:delimiter')\"\n name=\"delimiter\"\n />\n </div>\n </template>\n </form>\n\n <template v-slot:footer>\n <FormFooter\n :back-href=\"getExportListUrl()\"\n :on-submit=\"submitForm\"\n :is-submitting=\"isSubmitting\"\n :is-creation=\"true\"\n />\n </template>\n </page>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent, watch } from '@vue/composition-api';\nimport { computed, onMounted, ref } from '@vue/composition-api';\n\nimport { convertRequestErrorToMap, useResource } from '@tager/admin-services';\nimport {\n OptionType,\n TagerFormSubmitEvent,\n FormFooter,\n useTranslation,\n} from '@tager/admin-ui';\n\nimport { createExport, getStrategyList } from '../../services/requests';\nimport { getExportListUrl } from '../../utils/paths';\nimport { replaceFileExtension } from '../../utils/common';\n\nimport {\n convertExportFormValuesToCreationPayload,\n FormValues,\n} from './ExportForm.helpers';\n\nexport default defineComponent({\n name: 'ExportForm',\n components: { FormFooter },\n setup(props, context) {\n const { t } = useTranslation(context);\n\n /** Strategies */\n\n const [\n fetchStrategyList,\n { data: strategyList, loading: isStrategyListLoading },\n ] = useResource({\n fetchResource: getStrategyList,\n initialValue: [],\n context,\n resourceName: 'Strategy List',\n });\n\n const strategyOptionList = computed<Array<OptionType>>(() =>\n strategyList.value.map<OptionType>((strategy) => ({\n value: strategy.id,\n label: strategy.name,\n }))\n );\n\n onMounted(() => {\n fetchStrategyList();\n });\n\n /** Format **/\n\n const formatOptionList = computed<Array<OptionType>>(() => [\n { value: 'CSV', label: 'CSV' },\n { value: 'XLS', label: 'XLS' },\n { value: 'XML', label: 'XML' },\n { value: 'YAML', label: 'YAML' },\n { value: 'JSON', label: 'JSON' },\n { value: 'TXT', label: 'TXT' },\n ]);\n\n function isCSVFormat(format: string): boolean {\n return format === 'CSV';\n }\n\n /** Delimiter **/\n\n const delimiterOptionList = computed<Array<OptionType>>(() => [\n { value: ',', label: t('export:comma') },\n { value: ';', label: t('export:semicolon') },\n ]);\n\n /** Form state */\n\n const defaultExtension = formatOptionList.value[0];\n const defaultDelimiter = delimiterOptionList.value[0];\n\n const errors = ref<Record<string, string>>({});\n const values = ref<FormValues>({\n strategy: null,\n filename: `export.${defaultExtension.value.toLowerCase()}`,\n format: defaultExtension,\n delimiter: defaultDelimiter,\n });\n const isSubmitting = ref<boolean>(false);\n\n const shouldDisplayDelimiter = ref<boolean>(\n isCSVFormat(values.value.format?.value ?? '')\n );\n\n watch(\n () => values.value.format,\n () => {\n const newExtension = values.value.format?.value.toLowerCase();\n\n values.value.filename = replaceFileExtension(\n values.value.filename,\n newExtension || ''\n );\n\n shouldDisplayDelimiter.value = isCSVFormat(\n values.value.format?.value ?? ''\n );\n }\n );\n\n function submitForm(event: TagerFormSubmitEvent) {\n isSubmitting.value = true;\n\n const creationPayload = convertExportFormValuesToCreationPayload(\n values.value\n );\n\n createExport(creationPayload)\n .then(() => {\n errors.value = {};\n\n if (\n event.type === 'create' ||\n event.type === 'save' ||\n event.type === 'create_exit' ||\n event.type === 'save_exit'\n ) {\n context.root.$router.push(getExportListUrl());\n }\n\n context.root.$toast({\n variant: 'success',\n title: t('export:success'),\n body: t('export:createdSuccessMessage'),\n });\n })\n .catch((error) => {\n console.error(error);\n errors.value = convertRequestErrorToMap(error);\n context.root.$toast({\n variant: 'danger',\n title: t('export:error'),\n body: t('export:createdErrorMessage'),\n });\n })\n .finally(() => {\n isSubmitting.value = false;\n });\n }\n\n /** Is content loading **/\n\n const isContentLoading = computed<boolean>(\n () => isStrategyListLoading.value\n );\n\n return {\n values,\n errors,\n isSubmitting,\n submitForm,\n getExportListUrl,\n strategyOptionList,\n formatOptionList,\n delimiterOptionList,\n isContentLoading,\n shouldDisplayDelimiter,\n };\n },\n});\n</script>\n\n<style lang=\"scss\" scoped>\n.field {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n column-gap: 20px;\n}\n</style>\n",".field {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n column-gap: 20px;\n}\n\n/*# sourceMappingURL=ExportForm.vue.map */"]}, media: undefined });
660
-
661
- };
662
- /* scoped */
663
- const __vue_scope_id__$1 = "data-v-1d7bcab0";
664
- /* module identifier */
665
- const __vue_module_identifier__$1 = undefined;
666
- /* functional template */
667
- const __vue_is_functional_template__$1 = false;
668
- /* style inject SSR */
669
-
670
- /* style inject shadow dom */
671
-
672
-
673
-
674
- const __vue_component__$1 = /*#__PURE__*/normalizeComponent(
675
- { render: __vue_render__$1, staticRenderFns: __vue_staticRenderFns__$1 },
676
- __vue_inject_styles__$1,
677
- __vue_script__$1,
678
- __vue_scope_id__$1,
679
- __vue_is_functional_template__$1,
680
- __vue_module_identifier__$1,
681
- false,
682
- createInjector,
683
- undefined,
684
- undefined
685
- );
686
-
687
- const EXPORT_LIST_ROUTE = {
688
- path: EXPORT_ROUTE_PATHS.EXPORT_LIST,
689
- component: __vue_component__,
690
- name: 'Export List',
691
- meta: {
692
- getBreadcrumbs: (route, t) => [
693
- { url: '/', text: t('export:home') },
694
- { url: route.path, text: t('export:export') },
695
- ],
696
- },
697
- };
698
- const EXPORT_FORM_ROUTE = {
699
- path: EXPORT_ROUTE_PATHS.EXPORT_FORM,
700
- component: __vue_component__$1,
701
- name: 'Export Form',
702
- meta: {
703
- getBreadcrumbs: (route, t) => [
704
- { url: '/', text: t('export:home') },
705
- { url: EXPORT_LIST_ROUTE.path, text: t('export:export') },
706
- { url: route.path, text: t('export:newExport') },
707
- ],
708
- },
709
- };
710
-
711
- i18n.addTranslations('en', 'export', EN);
712
- i18n.addTranslations('ru', 'export', RU);
713
-
714
- export { EXPORT_FORM_ROUTE, EXPORT_LIST_ROUTE, createExport, getExportFormUrl, getExportList, getExportListUrl, getStrategyList };