Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
 - reset btn
 - detect date casting type
  • Loading branch information
eLFuvo committed Nov 27, 2020
1 parent 7421a54 commit f74cf79
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/MapAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions src/assets/dist/import-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/messages/ru/import-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
'Items deleted' => 'Добавлено элементов',
'Ignored lines' => 'Добавлено элементов',
'Errors' => 'Ошибки',
'Reset' => 'Сбросить настройки',
];
7 changes: 7 additions & 0 deletions src/views/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@
Yii::t('import-wizard', 'Start import'),
['class' => 'btn btn-success']
); ?>
<?= Html::button(
Yii::t('import-wizard', 'Reset'),
[
'type'=>'reset',
'class' => 'btn btn-default'
]
); ?>
</div>

<?php
Expand Down

0 comments on commit f74cf79

Please sign in to comment.