Skip to content

Commit

Permalink
use current_tenant to get scoped fund and use for urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Hicks committed Mar 16, 2023
1 parent ea98081 commit 4e5370d
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 208 deletions.
27 changes: 15 additions & 12 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
class FundsController < ApplicationController
before_action :confirm_admin_user
before_action :confirm_data_access, only: [:edit, :update]
before_action :set_fund, only: %i[show edit update destroy]
rescue_from ActiveRecord::RecordNotFound, with: -> { head :bad_request }

# GET /funds
def index
@funds = Fund.all.sort_by { |f| [f.name] }
end
# def index
# @funds = Fund.all.sort_by { |f| [f.name] }
# end

# GET /funds/1
# GET /fund
def show
@fund
set_fund
end

# GET /funds/edit
def edit; end
# def edit
# set_fund
# end

# PATCH/PUT /funds/1
# PATCH /fund
def update
set_fund
if @fund.update(fund_params)
redirect_to @fund, notice: 'Fund was successfully updated.'
else
render :edit, status: :unprocessable_entity
end
end

def destroy; end

private
# Use callbacks to share common setup or constraints between actions.
def set_fund
@fund = Fund.find(params[:id])
@fund = current_tenant
end

# Only allow a list of trusted parameters through.
def fund_params
params.fetch(:fund, {})
params.require(:fund)
.permit(:full_name, :site_domain, :phone)
end
end
2 changes: 0 additions & 2 deletions app/helpers/funds_helper.rb

This file was deleted.

13 changes: 3 additions & 10 deletions app/views/funds/_fund_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@
</ul>
</div>
<% end %>

<div>
<%= form.submit %>
</div>
<% end %>

<%= bootstrap_form_with model: @fund, local: true do |f| %>
<div class="row">
<div class="info-form-left col">
<%= f.text_field :name, autocomplete: 'off' %>
<%= f.text_field :subdomain, autocomplete: 'off' %>
<%= f.text_field :full_name, autocomplete: 'off' %>
<%= f.text_field :site_domain, autocomplete: 'off' %>
<%= f.text_field :full_name %>
<%= f.text_field :site_domain %>
<%= f.text_field :phone,
autocomplete: 'off',
pattern: "[0-9]{10}|[0-9]{3}\.[0-9]{3}\.[0-9]{4}|[0-9]{3}[-][0-9]{3}[-][0-9]{4}" %>
<%= f.submit label, class: 'btn btn-primary btn-lg' %>
</div>

<%= f.submit label, class: 'btn btn-primary btn-lg' %>
<% end %>
7 changes: 2 additions & 5 deletions app/views/funds/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<p style="text-align:right;"><strong><%= link_to "Back", fund_url(current_tenant) %></strong></p>
<h1>
<%= t 'funds.edit.title' %>
</h1>

<%= render 'funds/fund_form',
fund: @fund,
fund: current_tenant,
label: t('funds.form.save_changes') %>

<div>
<%= link_to "Show this fund", @fund %> |
<%= link_to "Back to funds", funds_path %>
</div>
27 changes: 27 additions & 0 deletions app/views/funds/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h1><%= current_tenant.name %></h1>

<div class="fund-list">
<table class="table border-side table-hover top-spacer" id="funds_table">
<thead>
<tr class="funds-table-header">
<th><%= t 'activerecord.attributes.fund.subdomain' %></th>
<th><%= t 'activerecord.attributes.fund.domain' %></th>
<th><%= t 'activerecord.attributes.fund.full_name' %></th>
<th><%= t 'activerecord.attributes.fund.site_domain' %></th>
<th><%= t 'activerecord.attributes.fund.phone' %></th>
<th><!-- spacer --></th>
</tr>
</thead>

<tbody>
<tr class="funds-table-row">
<td><%= current_tenant.subdomain %></td>
<td><%= current_tenant.domain %></td>
<td><%= current_tenant.full_name %></td>
<td><%= current_tenant.site_domain %></td>
<td><%= current_tenant.phone %></td>
<td><%= link_to "Edit", edit_fund_path(current_tenant) %></td>
</tr>
</tbody>
</table>
</div>
7 changes: 6 additions & 1 deletion app/views/layouts/_navigation_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
<%= link_to t('navigation.admin_tools.user_management'), users_path, class: 'dropdown-item' %>
<%= link_to t('navigation.admin_tools.clinic_management'), clinics_path, class: 'dropdown-item' %>
<%= link_to t('navigation.admin_tools.config_management'), configs_path, class: 'dropdown-item' %>
<%= link_to t('navigation.admin_tools.fund_management'), configs_path, class: 'dropdown-item' %>
<%
=begin%>
TODO: set @fund
<%
=end%>
<%= link_to t('navigation.admin_tools.fund_management'), fund_url(current_tenant), class: 'dropdown-item' %>
<% end %>
<%= link_to t('navigation.admin_tools.accounting'), accountants_path, class: 'dropdown-item' %>
<%= link_to t('navigation.admin_tools.export'), patients_path(format: :csv), class: 'dropdown-item' %>
Expand Down
Loading

0 comments on commit 4e5370d

Please sign in to comment.