ixport 0.3.0 → 0.3.2
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.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/models/ixport/import.rb +4 -0
- data/app/models/ixport/row_walk.rb +7 -1
- data/app/views/ixport/imports/show.html.erb +3 -1
- data/app/views/ixport/mappings/show.html.erb +8 -4
- data/lib/ixport/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03be028cedf3161974f8143be44d6f31d79cc669e0388d266bc787d12a9dcd9e
|
|
4
|
+
data.tar.gz: e7aec59ef0d4d8288a4062e713f0ef87eb7bc23f3bbda19db8e638eabc2872ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2afc07d8cba3ef5d3272d5e74d4981ffd882c4dafe969d70af85dd85947049acea43356b804b8afc7bc4f3a918027f3a6aecebe990c774686cef254420f3873f
|
|
7
|
+
data.tar.gz: eb1aba5fb3eecb5071f3ce89fd847eea67d0e79bf6270f639fc0d0c24bb92c3216e0ce8924a191622b07c07afae1af004312523db31dcf89436f527ba0897731
|
data/README.md
CHANGED
|
@@ -81,7 +81,7 @@ To match on several fields, name them all, for example `match_on :happened_on, :
|
|
|
81
81
|
|
|
82
82
|
From the engine's root page, a person picks a registered import and uploads a CSV for it. The upload is refused, with a message on the upload page, when the file is not UTF-8 text, when its quoting is broken (the message names the line where reading stopped), when it has no header row, or, in an app with no background runner, when it has more rows than `config.inline_row_limit`. A byte order mark at the start of the file is ignored, so the first column keeps its name.
|
|
83
83
|
|
|
84
|
-
After uploading, the person matches each column of the file's header row to one of the importer's fields, by its label, or skips it. Saving the mapping moves them on to the preview.
|
|
84
|
+
After uploading, the person matches each column of the file's header row to one of the importer's fields, by its label, or skips it. Saving the mapping moves them on to the preview, and going back to the mapping page shows the choices already made.
|
|
85
85
|
|
|
86
86
|
The preview shows how many rows will add a record, update one or be refused, before anything is saved. It lists each row that will update a record and each refused row, by its row number in the file, with the reason the record gives for a refusal. A row is refused when the record it builds is not valid. Viewing the preview saves nothing, and the person can go back from it to change the mapping.
|
|
87
87
|
|
|
@@ -89,7 +89,7 @@ The preview shows how many rows will add a record, update one or be refused, bef
|
|
|
89
89
|
|
|
90
90
|
The person runs the import from the preview. With no background runner configured, it runs inside the request. Each row that passes the record's validations is saved, updating the record it matches or adding a new one. Each row that fails them is refused and kept with its row number and reason, and the record it matched is left unchanged.
|
|
91
91
|
|
|
92
|
-
The import's result page then shows how many rows were added and how many updated, and lists each refused row. It shows the same thing on every later visit. A finished import offers no Run button, its preview leads to its result page, and running it again adds or changes nothing.
|
|
92
|
+
The import's result page then shows its status, how many rows the file had, how many were added and how many updated, and lists each refused row. It shows the same thing on every later visit. A finished import offers no Run button, its preview leads to its result page, and running it again adds or changes nothing.
|
|
93
93
|
|
|
94
94
|
An import belongs to the person and account that uploaded it, and anyone else gets not found when they open it.
|
|
95
95
|
|
data/app/models/ixport/import.rb
CHANGED
|
@@ -19,7 +19,7 @@ module Ixport
|
|
|
19
19
|
|
|
20
20
|
def row_for(cells, number)
|
|
21
21
|
values = values_of(cells)
|
|
22
|
-
existing = existing_records[match_key(values)]
|
|
22
|
+
existing = own_copy(existing_records[match_key(values)])
|
|
23
23
|
record = existing ? existing.tap { |found| found.assign_attributes(values) } : @importer.records.new(values)
|
|
24
24
|
return Row.new(number: number, record: record, outcome: :refused, reason: record.errors.full_messages.to_sentence) unless record.valid?
|
|
25
25
|
|
|
@@ -34,11 +34,17 @@ module Ixport
|
|
|
34
34
|
@import.mapping.to_h { |column, field| [ field.to_sym, cells[column.to_i] ] }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def own_copy(record)
|
|
38
|
+
record&.class&.instantiate(record.attributes_before_type_cast)
|
|
39
|
+
end
|
|
40
|
+
|
|
37
41
|
def match_fields
|
|
38
42
|
@importer.class.match_fields
|
|
39
43
|
end
|
|
40
44
|
|
|
41
45
|
def match_key(values)
|
|
46
|
+
return if match_fields.empty?
|
|
47
|
+
|
|
42
48
|
key = match_fields.map { |field| cast(field, values[field]) }
|
|
43
49
|
key unless key.any?(&:blank?)
|
|
44
50
|
end
|
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
<%= ui_alert(type: :error, message: tag.span(@import.error_message, data: { import_error: true })) %>
|
|
16
16
|
<p>Rows saved before it stopped stay saved.</p>
|
|
17
17
|
<% end %>
|
|
18
|
-
<%=
|
|
18
|
+
<%= ui_badge(label: tag.span(@import.status.humanize, data: { import_status: true }), variant: @import.failed? ? :danger : :success) %>
|
|
19
|
+
<%= ui_grid(cols: { default: 1, sm: 3 }) do %>
|
|
19
20
|
<%= ui_stat_card(label: "Added", value: tag.span(@import.added_count, data: { result_count: "added" })) %>
|
|
20
21
|
<%= ui_stat_card(label: "Updated", value: tag.span(@import.updated_count, data: { result_count: "updated" })) %>
|
|
22
|
+
<%= ui_stat_card(label: "Rows in file", value: tag.span(@import.row_count, data: { result_count: "total" })) %>
|
|
21
23
|
<% end %>
|
|
22
24
|
<% if @import.refusals.any? %>
|
|
23
25
|
<%= ui_section(title: "Refused") do %>
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
<%= ui_form_page(title: "Match columns", back_url: root_path) %>
|
|
2
2
|
<%= ui_page(max_width: :md) do %>
|
|
3
3
|
<%= ui_form(action: import_mapping_path(@import), method: :patch) do %>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<%= tag.
|
|
7
|
-
|
|
4
|
+
<%= ui_grid(cols: { default: 1 }, gap: :md) do %>
|
|
5
|
+
<% @import.headers.each_with_index do |header, index| %>
|
|
6
|
+
<%= tag.div(data: { column: true }) do %>
|
|
7
|
+
<%= ui_grid(cols: { default: 1, sm: 2 }, gap: :sm) do %>
|
|
8
|
+
<%= tag.span(header, data: { column_name: true }) %>
|
|
9
|
+
<%= ui_select(name: "mapping[#{index}]", options: @fields.map { |field| [field.label, field.key] }, selected: @import.mapping&.dig(index.to_s), include_blank: "Skip") %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<% end %>
|
|
8
12
|
<% end %>
|
|
9
13
|
<% end %>
|
|
10
14
|
<%= ui_button(label: "Save mapping") %>
|
data/lib/ixport/version.rb
CHANGED