-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from goosys/wip/issue-10
feat: Add CSV import templates
- Loading branch information
Showing
7 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/views/administrate/application/_import_buttons.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% if accessible_action?(new_resource, :import_for_delete) %> | ||
<div class='import-link-button'> | ||
<% modal_target_import_for_delete = 'modal-import-for-delete-'.concat(page.resource_name) %> | ||
<span class="modal-link button btn-danger" data-modal-target="<%= modal_target_import_for_delete %>"> | ||
<%= t('administrate.actions.import_for_delete', name: page.resource_name.titleize.downcase) %> | ||
</span> | ||
</div> | ||
<%= render 'modal', modal_target: modal_target_import_for_delete do %> | ||
<%= render 'import_form_for_delete', page: page %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if accessible_action?(new_resource, :import) %> | ||
<div class='import-link-button'> | ||
<% modal_target_import = 'modal-import-'.concat(page.resource_name) %> | ||
<span class="modal-link button btn-info" data-modal-target="<%= modal_target_import %>"> | ||
<%= t('administrate.actions.import_resource', name: page.resource_name.titleize.downcase) %> | ||
</span> | ||
</div> | ||
<%= render 'modal', modal_target: modal_target_import do %> | ||
<%= render 'import_form', page: page %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= form_tag({ controller: page.resource_name.pluralize, action: :import }, method: :post, multipart: true) do %> | ||
<%= file_field_tag :csv_file, required: true %> | ||
<div class="import-form-buttons"> | ||
<%= submit_tag t('administrate.actions.import_button'), class: 'button btn-update', data: { disable_with: false } %> | ||
<%= link_to t('administrate.actions.download_csv_format'), | ||
{ controller: page.resource_name.pluralize, action: :download_csv_format }, | ||
format: :csv, | ||
class: 'button' | ||
%> | ||
</div> | ||
<% end %> |
11 changes: 11 additions & 0 deletions
11
app/views/administrate/application/_import_form_for_delete.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= form_tag({ controller: page.resource_name.pluralize, action: :import_for_delete }, method: :post, multipart: true) do %> | ||
<%= file_field_tag :csv_file, required: true %> | ||
<div class="import-form-buttons"> | ||
<%= submit_tag t('administrate.actions.import_for_delete_button'), class: 'button btn-danger', data: { disable_with: false } %> | ||
<%= link_to t('administrate.actions.download_invalid_resource'), | ||
{ controller: page.resource_name.pluralize, action: :download_invalid_resource }, | ||
format: :csv, | ||
class: 'button' | ||
%> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="modal <%= modal_target %>"> | ||
<div class="modal-inner"> | ||
<div class="modal-bg"></div> | ||
<div class="modal-contents"> | ||
<%= yield %> | ||
</div> | ||
</div> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
app/views/administrate/application/download_csv_format.csb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# vim: set ft=ruby: | ||
|
||
return '' if @csv_data.blank? | ||
|
||
csv.items = @csv_data | ||
csv.filename = "#{resource_class.name.tableize}_import_format.csv" | ||
|
||
@csv_header.each do |attr_name, header| | ||
csv.cols.add(header, attr_name) { |r| r[attr_name]} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters