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