Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2410: Round out the Fund model with UI #2824

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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]
rescue_from ActiveRecord::RecordNotFound, with: -> { head :bad_request }

# GET /funds/id
def show
set_fund
end

# GET /funds/edit
def edit; end

# PATCH /funds/id
def update
set_fund

if @fund.update(fund_params)
flash[:notice] = t('flash.fund_details_updated')
redirect_to @fund
else
flash[:alert] = t('flash.error_saving_fund_details', error: @fund.errors.full_messages.to_sentence)
render :edit, status: :unprocessable_entity
end
end

private
def set_fund
@fund = current_tenant
end

def fund_params
params.require(:fund)
.permit(:full_name, :site_domain, :phone)
end
end
25 changes: 25 additions & 0 deletions app/views/funds/_fund_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_with(model: fund) do |form| %>
<% if fund.errors.any? %>
<div style="color: red">
<h2><%= pluralize(fund.errors.count, "error") %> prohibited this fund from being saved:</h2>

<ul>
<% fund.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
<% end %>

<%= bootstrap_form_with model: @fund, local: true do |f| %>
<div class="row">
<div class="info-form-left col">
<%= f.text_field :full_name %>
<%= f.text_field :site_domain %>
<%= f.text_field :phone,
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>

<% end %>
9 changes: 9 additions & 0 deletions app/views/funds/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p><strong><%= link_to "Back", fund_url(current_tenant) %></strong></p>
<h1>
<%= t 'funds.edit.title', fund: current_tenant.name %>
</h1>

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

31 changes: 31 additions & 0 deletions app/views/funds/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<h1><%= t 'funds.index.title' %></h1>

<div class="fund-list">
<table class="table border-side table-hover top-spacer" id="funds_table">
<thead>
<tr class="funds-table-header">
<th><!-- spacer --></th>
<th><%= t 'activerecord.attributes.fund.name' %></th>
<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>
</tr>
</thead>

<tbody>
<% @funds.each do |fund| %>
<tr class="funds-table-row">
<td><!-- spacer --></td>
<td><%= link_to fund.name, edit_fund_path(fund) %></td>
<td><%= fund.subdomain %></td>
<td><%= fund.domain %></td>
<td><%= fund.full_name %></td>
<td><%= fund.site_domain %></td>
<td><%= fund.phone %></td>
</tr>
<% end %>
</tbody>
</table>
</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>
3 changes: 2 additions & 1 deletion app/views/layouts/_navigation_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
<% if current_user.admin? || current_user.data_volunteer? %>
<div class="dropdown">
<button href="#" data-toggle="dropdown" class="btn dropdown-toggle navbar-text" id="admin-dropdown" aria-haspopup="true" aria-expanded="false">
<%= t('navigation.admin_tools.label') %>
<%= t('navigation.admin_tools.label') %>
</button>

<div class="dropdown-menu" aria-labelledby="admin-dropdown">
<% if current_user.admin? %>
<%= 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'), 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
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ en:
demote_own_account_warn: For safety reasons, you are not allowed to change your role from an admin to a not-admin. Ask another admin to demote you.
error_saving_clinic: Errors prevented this clinic from being saved - %{error}
error_saving_clinic_details: Error saving clinic details - %{error}
error_saving_fund_details: Error saving fund details - %{error}
fetch_pledge_error: Errors prevented this pledge from generating. Please check that you've filled out any form inputs, and reach out to the DARIA team if the problem persists.
fund_details_updated: Successfully updated fund details.
locked: Locked
new_patient_error: Errors prevented this patient from being saved - %{error}
new_patient_save: A new patient has been successfully saved
Expand All @@ -293,6 +295,11 @@ en:
user_created: User created!
user_update_error: Error saving user details - %{error}
user_update_success: Successfully updated user details
funds:
edit:
title: Edit %{fund}
form:
save_changes: Save changes
lines:
new:
start: Get started
Expand Down
Loading
Loading