-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
567c568
commit 8ede7d7
Showing
44 changed files
with
1,354 additions
and
525 deletions.
There are no files selected for viewing
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
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,31 @@ | ||
class Avo::Actions::ExportCsv < Avo::BaseAction | ||
self.name = "Export csv" | ||
self.no_confirmation = false | ||
self.may_download_file = true | ||
|
||
def handle(**args) | ||
records, resource = args.values_at(:records, :resource) | ||
|
||
return error "No record selected" if records.blank? | ||
|
||
attributes = get_attributes records.first | ||
|
||
file = CSV.generate(headers: true) do |csv| | ||
csv << attributes | ||
|
||
records.each do |record| | ||
csv << attributes.map do |attr| | ||
record.send(attr) | ||
end | ||
end | ||
end | ||
|
||
download file, "#{resource.plural_name}.csv" | ||
end | ||
|
||
def get_attributes(record) | ||
# return ["id", "created_at"] # uncomment this and fill in for custom model properties | ||
|
||
record.class.columns_hash.keys | ||
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
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
Oops, something went wrong.