Skip to content

Commit

Permalink
WIP: Bulk upload facilities CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
vkrmis committed Jun 12, 2019
1 parent e99da6f commit 93d6ba9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/controllers/admin/facility_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def destroy
end
end

def upload
authorize FacilityGroup
if params[:facilities_csv]
redirect_to admin_facilities_url, notice: "File uploaded #{params[:facilities_csv].original_filename}"
else
render :upload
end
end

private

def set_organizations
Expand Down
4 changes: 4 additions & 0 deletions app/policies/facility_group_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def graphics?
show?
end

def upload?
user.owner? || user.organization_owner?
end

private

def destroyable?
Expand Down
10 changes: 7 additions & 3 deletions app/views/admin/facilities/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<% if policy(FacilityGroup).new? %>
<%= link_to '+ Facility group', new_admin_facility_group_path, class: "btn btn-sm btn-primary float-right" %>
<div class="page-header">
<h1 class="page-title"">All facilities</h1>
<nav class="page-nav">
<%= link_to '+ Facility group', new_admin_facility_group_path, class: "btn btn-sm btn-primary" %>
<%= link_to '+ Upload Facilities CSV', upload_admin_facility_groups_path, class: "btn btn-sm btn-primary" %>
</nav>
</div>
<% end %>

<h1 style="margin-bottom: 32px;">All facilities</h1>

<% @organizations.order(:name).each do |organization| %>
<% if @organizations.size > 1 %><h1><%= organization.name %></h1><% end %>

Expand Down
13 changes: 13 additions & 0 deletions app/views/admin/facility_groups/upload.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Upload Facilities</h1>

Upload a filled in csv file in this format to bulk create facilities
<script>$(document).on('ready turbolinks:load', function() {
$('.custom-file-input').change(function(){
$('.custom-file-label').text(this.value);
});
});
</script>
<%= bootstrap_form_tag(url: '/admin/facility_groups/upload' , multipart: true) do |f| %>
<%= f.file_field :facilities_csv %>
<%= f.primary 'Upload' %>
<% end %>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
resources :facilities, only: [:index]
resources :facility_groups do
resources :facilities
collection do
get 'upload'
post 'upload'
end
end

resources :protocols do
Expand Down

0 comments on commit 93d6ba9

Please sign in to comment.