diff --git a/modules/backend/behaviors/ImportExportController.php b/modules/backend/behaviors/ImportExportController.php index ec1a01f9a..ce3d67d3d 100644 --- a/modules/backend/behaviors/ImportExportController.php +++ b/modules/backend/behaviors/ImportExportController.php @@ -1,7 +1,8 @@ vars['importUploadFormWidget'] = $this->importUploadFormWidget; - $this->vars['importColumns'] = $this->getImportDbColumns(); + $this->vars['importDbColumns'] = $this->getImportDbColumns(); + $this->vars['importFileColumns'] = $this->getImportFileColumns(); // Make these variables to widgets $this->controller->vars += $this->vars; @@ -119,7 +121,20 @@ class ImportExportController extends ControllerBehavior protected function getImportFileColumns() { + if (!$path = $this->getImportFilePath()) { + return null; + } + $reader = CsvReader::createFromPath($path); + $firstRow = $reader->fetchOne(0); + + if (!post('first_row_titles')) { + array_walk($firstRow, function(&$value, $key) { + $value = 'Column #'.($key + 1); + }); + } + + return $firstRow; } protected function makeImportUploadFormWidget() @@ -139,6 +154,21 @@ class ImportExportController extends ControllerBehavior return $widget; } + protected function getImportFilePath() + { + $model = $this->importGetModel(); + $file = $model + ->import_file() + ->withDeferred($this->importUploadFormWidget->getSessionKey()) + ->first(); + + if (!$file) { + return null; + } + + return $file->getLocalPath(); + } + // // Exporting // diff --git a/modules/backend/behaviors/importexportcontroller/assets/css/importexport.css b/modules/backend/behaviors/importexportcontroller/assets/css/importexport.css index d6a657d9e..55df73949 100644 --- a/modules/backend/behaviors/importexportcontroller/assets/css/importexport.css +++ b/modules/backend/behaviors/importexportcontroller/assets/css/importexport.css @@ -18,6 +18,7 @@ height: 400px; background: #f0f0f0; padding: 5px; + overflow: auto; } .import-behavior .import-file-columns .upload-prompt { display: block; @@ -61,6 +62,11 @@ float: left; width: 45%; } +.import-behavior .import-file-columns > ul div.import-column-name > span { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} .import-behavior .import-file-columns > ul .import-column-bindings > ul { float: right; width: 55%; diff --git a/modules/backend/behaviors/importexportcontroller/assets/less/importexport.less b/modules/backend/behaviors/importexportcontroller/assets/less/importexport.less index 5448d4631..67c0d678b 100644 --- a/modules/backend/behaviors/importexportcontroller/assets/less/importexport.less +++ b/modules/backend/behaviors/importexportcontroller/assets/less/importexport.less @@ -30,6 +30,7 @@ height: 400px; background: #f0f0f0; padding: 5px; + overflow: auto; } .import-file-columns { .upload-prompt { @@ -71,6 +72,12 @@ div.import-column-name { float: left; width: 45%; + + > span { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } } .import-column-bindings > ul { diff --git a/modules/backend/behaviors/importexportcontroller/partials/_import_columns.htm b/modules/backend/behaviors/importexportcontroller/partials/_import_columns.htm deleted file mode 100644 index 19b8370a9..000000000 --- a/modules/backend/behaviors/importexportcontroller/partials/_import_columns.htm +++ /dev/null @@ -1,51 +0,0 @@ -
-
- File Columns - -
-

- Please upload a valid CSV file. -

- -
    -
  • -
    - Name -
    -
    -
      -
      -
    • -
    • -
      - URL Name -
      -
      -
        -
        -
      • -
      -
      -
      -
      - Record Columns - -
      -
        - $label): ?> -
      • - - -
      • - -
      -
      -
      -
      - - \ No newline at end of file diff --git a/modules/backend/behaviors/importexportcontroller/partials/_import_db_columns.htm b/modules/backend/behaviors/importexportcontroller/partials/_import_db_columns.htm new file mode 100644 index 000000000..7fd26c656 --- /dev/null +++ b/modules/backend/behaviors/importexportcontroller/partials/_import_db_columns.htm @@ -0,0 +1,17 @@ +
      + +
      + + \ No newline at end of file diff --git a/modules/backend/behaviors/importexportcontroller/partials/_import_file_columns.htm b/modules/backend/behaviors/importexportcontroller/partials/_import_file_columns.htm new file mode 100644 index 000000000..1f2723847 --- /dev/null +++ b/modules/backend/behaviors/importexportcontroller/partials/_import_file_columns.htm @@ -0,0 +1,20 @@ +
      + + + +

      + Please upload a valid CSV file. +

      + +
      \ No newline at end of file diff --git a/modules/backend/behaviors/importexportcontroller/partials/fields_import.yaml b/modules/backend/behaviors/importexportcontroller/partials/fields_import.yaml index ee9820d93..bd785d6ac 100644 --- a/modules/backend/behaviors/importexportcontroller/partials/fields_import.yaml +++ b/modules/backend/behaviors/importexportcontroller/partials/fields_import.yaml @@ -25,10 +25,18 @@ fields: label: 2. Match fields to the CSV columns type: section - import_columns: + import_file_columns: + label: File columns type: partial - path: ~/modules/backend/behaviors/importexportcontroller/partials/_import_columns.htm + path: ~/modules/backend/behaviors/importexportcontroller/partials/_import_file_columns.htm dependsOn: import_file + span: left + + import_db_columns: + label: Record columns + type: partial + path: ~/modules/backend/behaviors/importexportcontroller/partials/_import_db_columns.htm + span: right step3_section: label: 3. Set import options