diff --git a/app/controllers/admin/facility_groups_controller.rb b/app/controllers/admin/facility_groups_controller.rb index 135a1f7412..aef8792624 100644 --- a/app/controllers/admin/facility_groups_controller.rb +++ b/app/controllers/admin/facility_groups_controller.rb @@ -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 diff --git a/app/policies/facility_group_policy.rb b/app/policies/facility_group_policy.rb index 6628f1fe5e..7a4b4d93c0 100644 --- a/app/policies/facility_group_policy.rb +++ b/app/policies/facility_group_policy.rb @@ -31,6 +31,10 @@ def graphics? show? end + def upload? + user.owner? || user.organization_owner? + end + private def destroyable? diff --git a/app/views/admin/facilities/index.html.erb b/app/views/admin/facilities/index.html.erb index 55d02d0a36..81ff0ece6a 100644 --- a/app/views/admin/facilities/index.html.erb +++ b/app/views/admin/facilities/index.html.erb @@ -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" %> + <% end %> -

All facilities

- <% @organizations.order(:name).each do |organization| %> <% if @organizations.size > 1 %>

<%= organization.name %>

<% end %> diff --git a/app/views/admin/facility_groups/upload.html.erb b/app/views/admin/facility_groups/upload.html.erb new file mode 100644 index 0000000000..e4a06b60a6 --- /dev/null +++ b/app/views/admin/facility_groups/upload.html.erb @@ -0,0 +1,13 @@ +

Upload Facilities

+ +Upload a filled in csv file in this format to bulk create facilities + +<%= bootstrap_form_tag(url: '/admin/facility_groups/upload' , multipart: true) do |f| %> + <%= f.file_field :facilities_csv %> + <%= f.primary 'Upload' %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index e8382589ca..a48aeed9b5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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