From f74cf79fcfdb114f65826243d5f6fed64e69d9e7 Mon Sep 17 00:00:00 2001 From: elfuvo Date: Fri, 27 Nov 2020 11:28:22 +0500 Subject: [PATCH] fixes and improvements - reset btn - detect date casting type --- src/MapAttribute.php | 4 ++++ src/assets/dist/import-setup.js | 17 +++++++++++++++-- src/messages/ru/import-wizard.php | 1 + src/views/setup.php | 7 +++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/MapAttribute.php b/src/MapAttribute.php index cacd19d..0e7c155 100644 --- a/src/MapAttribute.php +++ b/src/MapAttribute.php @@ -192,6 +192,10 @@ public static function detectCasting(Model $model, $attribute) if ($validator instanceof $allowedValidator) { if ($validator instanceof NumberValidator && $validator->integerOnly) { return self::TYPE_INTEGER; + } elseif ($validator instanceof DateValidator + && strlen($validator->format) <= 10 // YYYY-MM-dd, dd/MM/YYYY + && preg_match('#Y#i', $validator->format)) { + return self::TYPE_DATE; } return $castType; diff --git a/src/assets/dist/import-setup.js b/src/assets/dist/import-setup.js index 82bd343..c203d43 100644 --- a/src/assets/dist/import-setup.js +++ b/src/assets/dist/import-setup.js @@ -43,10 +43,13 @@ } $setupForm.find('.map-attribute').on('change', function () { const attribute = $(this).val(), - castTo = $(this).find('option:selected').data('type'), id = $(this).closest('td').data('id'), $selectCastTo = $setupForm.find('.type[data-id="' + id + '"] select'); - if (castTo && $selectCastTo.length) { + let castTo = $(this).find('option:selected').data('type'); + if (castTo <= '') { + castTo = 'string'; + } + if ($selectCastTo.length) { $selectCastTo.val(castTo).trigger('change'); } mapAttribute[id] = { @@ -66,6 +69,16 @@ }); window.localStorage.setItem('identity-' + model, JSON.stringify(columns)); }); + $setupForm.find('button[type="reset"]').on('click', function () { + $setupForm.find('.map-attribute').val('').trigger('change'); + // $setupForm.find('select.type').val('string').trigger('change'); + $setupForm.find('input.identity').prop('checked', false).trigger('change'); + $setupForm.find('input.start-row-index').val(2); + + window.localStorage.removeItem('import-' + model); + window.localStorage.removeItem('startRow-' + model); + window.localStorage.removeItem('identity-' + model); + }); if ($importProgressContainer.length) { $(window).on('import.stat.reload', function () { $importProgressContainer.load($importProgressContainer.data('url'), function (content) { diff --git a/src/messages/ru/import-wizard.php b/src/messages/ru/import-wizard.php index 863f4f4..cc51aef 100644 --- a/src/messages/ru/import-wizard.php +++ b/src/messages/ru/import-wizard.php @@ -28,4 +28,5 @@ 'Items deleted' => 'Добавлено элементов', 'Ignored lines' => 'Добавлено элементов', 'Errors' => 'Ошибки', + 'Reset' => 'Сбросить настройки', ]; diff --git a/src/views/setup.php b/src/views/setup.php index 61d83fd..a180fc8 100644 --- a/src/views/setup.php +++ b/src/views/setup.php @@ -143,6 +143,13 @@ Yii::t('import-wizard', 'Start import'), ['class' => 'btn btn-success'] ); ?> + 'reset', + 'class' => 'btn btn-default' + ] + ); ?>