Skip to content

Commit 1684d03

Browse files
authored
Merge pull request #33 from grrr-amsterdam/interface-improvements
Interface improvements
2 parents 78b5198 + 2b5de01 commit 1684d03

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

dist/js/tool.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/Main.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
<heading class="mb-6">CSV Import</heading>
44

55
<card class="flex flex-col items-center justify-center" style="min-height: 300px">
6-
<input type="file" name="file" ref="file" @change="handleFile">
7-
<button type="submit" class="btn btn-default btn-primary" @click="upload">Import</button>
6+
<input type="file" name="file" ref="file" @change="handleFile" class="mb-3">
7+
<button type="submit" class="btn btn-default btn-primary" v-bind:disabled="!file" @click="upload">Import</button>
88
</card>
99
</div>
1010
</template>
1111

1212
<script>
1313
export default {
14+
metaInfo() {
15+
return {
16+
title: "Import data",
17+
};
18+
},
1419
mounted() {
1520
//
1621
},

resources/js/components/Preview.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555

5656
<script>
5757
export default {
58+
metaInfo() {
59+
return {
60+
title: "Preview your imported data",
61+
};
62+
},
5863
mounted() {
5964
const self = this;
6065

resources/js/components/Review.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
<script>
1414
export default {
15+
metaInfo() {
16+
return {
17+
title: "All your data was successfully imported",
18+
};
19+
},
1520
mounted() {
1621
1722
},

src/Http/Controllers/ImportController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function getAvailableFieldsForImport(String $resource, $request)
5454
$novaResource = new $resource(new $resource::$model);
5555
$fieldsCollection = collect($novaResource->creationFields($request));
5656

57-
if (method_exists($novaResource, 'excludeAttributesFromImport')) {
58-
$fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) {
57+
if (method_exists($novaResource, 'excludeAttributesFromImport')) {
58+
$fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) {
5959
return !in_array($field->attribute, $novaResource::excludeAttributesFromImport($request));
6060
});
6161
}
@@ -67,7 +67,9 @@ public function getAvailableFieldsForImport(String $resource, $request)
6767
];
6868
});
6969

70-
return [$novaResource->uriKey() => $fields];
70+
// Note: ->values() is used here to avoid this array being turned into an object due to
71+
// non-sequential keys (which might happen due to the filtering above.
72+
return [$novaResource->uriKey() => $fields->values()];
7173
}
7274

7375
public function getAvailableResourcesForImport(NovaRequest $request) {

src/Importer.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
use Maatwebsite\Excel\Concerns\WithValidation;
1414
use Maatwebsite\Excel\Concerns\WithBatchInserts;
1515
use Maatwebsite\Excel\Concerns\WithChunkReading;
16+
use Maatwebsite\Excel\Concerns\WithMapping;
1617

17-
class Importer implements ToModel, WithValidation, WithHeadingRow, WithBatchInserts, WithChunkReading, SkipsOnFailure, SkipsOnError
18+
class Importer implements ToModel, WithValidation, WithHeadingRow, WithMapping, WithBatchInserts, WithChunkReading, SkipsOnFailure, SkipsOnError
1819
{
1920
use Importable, SkipsFailures, SkipsErrors;
2021

@@ -25,12 +26,14 @@ class Importer implements ToModel, WithValidation, WithHeadingRow, WithBatchInse
2526
protected $rules;
2627
protected $model_class;
2728

29+
public function map($row): array {
30+
return $this->mapRowDataToAttributes($row);
31+
}
32+
2833
public function model(array $row)
2934
{
30-
[$model, $callbacks] = $this->resource::fill(
31-
new ImportRequest($this->mapRowDataToAttributes($row)),
32-
$this->resource::newModel()
33-
);
35+
$model = $this->resource::newModel();
36+
$model->fill($row);
3437

3538
return $model;
3639
}

0 commit comments

Comments
 (0)