Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

[1337] Add user and equipment CSV export #1340

Merged
merged 1 commit into from
Feb 11, 2016
Merged

[1337] Add user and equipment CSV export #1340

merged 1 commit into from
Feb 11, 2016

Conversation

esoterik
Copy link
Collaborator

@esoterik esoterik commented Nov 3, 2015

Resolves #1337

  • adds the module CsvExport to handle exporting CSV files
  • also supports exporting multiple CSVs at once in a zip file

@orenyk orenyk changed the title Add user and equipment CSV export [1337] Add user and equipment CSV export Nov 4, 2015
@@ -9,7 +9,8 @@
<%= link_to "View All Equipment Models", equipment_models_path, :class => 'btn btn-default' %>
<% else %>
<%= link_to "New Equipment Model", new_equipment_model_path, :class => "btn btn-primary" %>
<%= link_to "Import Equipment Models", equip_import_page_path, :class => "btn btn-default" %>
<%= link_to "Import Equipment Models", equip_import_page_path, :class => "btn btn-default" %>
<%= link_to "Export Equipment Data", categories_path(format: 'zip'), :class => "btn btn-default" %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this link to the equipment items index as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

@orenyk
Copy link
Contributor

orenyk commented Nov 8, 2015

This looks really good! I want to take another look at the module when it's not this late at night but overall this seems to really solve the issue. I was able to export equipment and (after tweaking the names to avoid duplicates) import new data based on the exported files. The same was true for user export/import.

A few notes:

  1. While the idea of exporting a .zip archive with all three models is great behavior, we should allow users to select which equipment types they want to export. We could either make this a JS popup on the pages where they can hit the export button, or have all the export buttons take them to a page where they can select which data to export (the columns for each model being predetermined) and then we generate a .zip archive with whatever data they wanted (or simply return a single csv if they only want one model). Basically, I'm suggesting a data export portal vs having a route for each resource.
  2. The naming of the files is different - equipment files are named with camel case (e.g. EquipmentModel... whereas the user model is not capitalized and I'm guessing would be snake case if necessary. We should just be consistent (I prefer snake case, personally, but either is fine).
  3. Finally, I think we should use a simple numeric timestamp including the time to avoid file duplication issues (as unlikely as they will be). It would just be a matter of calling Time.zone.now.to_s(:number) instead.

Again, great work! Why don't you start working on the above and I'll re-review the module tomorrow to see if anything other than what I already commented on jumps out at me. Thanks!

columns = data.size == 1 ? objects.first.attributes.keys : data[1]

# we never need to export ids
columns.delete('id')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, any thoughts on also removing any password / authentication stuff if it's there? We could set up an array of columns to delete and simply call something like PROTECTED_COLS.each { |col| columns.delete(col) }. I don't love it since that array is coupled to the schema of our users table, but there's no specific harm in calling Hash#delete with a key that doesn't exist. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds good

@orenyk
Copy link
Contributor

orenyk commented Nov 8, 2015

Ok, second read-through complete, ready for updates!

@esoterik esoterik force-pushed the 1337_csv_export branch 2 times, most recently from 95a5c5f to 95d6c09 Compare January 31, 2016 03:10
@orenyk
Copy link
Contributor

orenyk commented Jan 31, 2016

Replied to some of your comments, not sure if you're done (rubocop error / any other changes) so we can do a complete review once you give the go-ahead.

@orenyk
Copy link
Contributor

orenyk commented Feb 2, 2016

Looks like we have some merge conflicts following tonight's PR mergings - can you rebase onto master?

@esoterik
Copy link
Collaborator Author

esoterik commented Feb 5, 2016

done!

@@ -28,6 +28,9 @@ gem 'net-ldap', '~> 0.13.0'
# attachments
gem 'paperclip', '~> 4.3.2'

# for exporting multiple files
gem 'rubyzip'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify a version here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make sure to use the latest version, thanks 😄

@orenyk
Copy link
Contributor

orenyk commented Feb 7, 2016

Don't have time for full review, will get to it tomorrow.

end

# downloads a csv of the given model table
# expects table to be an array with the following format:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that these comments are outdated / unnecessary.

@orenyk
Copy link
Contributor

orenyk commented Feb 9, 2016

A few small comments but this is really close. Let me know what you think about the ActionController dependency thing and once we've wrapped up the other stuff we can merge this in. Nice work!

Resolves #1337
 - adds the module CsvExport to handle exporting CSV files
 - also supports exporting multiple CSVs at once in a zip file
orenyk added a commit that referenced this pull request Feb 11, 2016
[1337] Add user and equipment CSV export
@orenyk orenyk merged commit ff807f5 into master Feb 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants