Basic donation records

Adds donation model/table and basic manual management in the admin
panel, as well as basic listing of users' own donations.
This commit is contained in:
2020-12-17 21:55:16 +01:00
parent f3d6e29e4e
commit 40f3e8327a
25 changed files with 333 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
<p>
Ohai there, admin human.
</p>
<p>
<%= link_to 'LDAP users', admin_ldap_users_path %>
</p>
<ul>
<li><%= link_to 'LDAP users', admin_ldap_users_path %></li>
<li><%= link_to 'Donations', admin_donations_path %></li>
</ul>

View File

@@ -0,0 +1,2 @@
json.extract! donation, :id, :user_id, :amount_sats, :amount_eur, :amount_usd, :public_name, :created_at, :updated_at
json.url donation_url(donation, format: :json)

View File

@@ -0,0 +1,53 @@
<%= form_with(url: url, model: donation, local: true) do |form| %>
<% if donation.errors.any? %>
<div id="error_explanation">
<h3><%= pluralize(donation.errors.count, "error") %> prohibited this donation from being saved:</h3>
<ul>
<% donation.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<p>
<%= form.label :user_id %>
<%= form.collection_select :user_id, User.where(ou: "kosmos.org").order(:cn), :id, :cn %>
</p>
</div>
<div class="field">
<p>
<%= form.label :amount_sats, "Amount BTC (sats)" %>
<%= form.number_field :amount_sats %>
</p>
</div>
<div class="field">
<p>
<%= form.label :amount_eur, "Amount EUR (cents)" %>
<%= form.number_field :amount_eur %>
</p>
</div>
<div class="field">
<p>
<%= form.label :amount_usd, "Amount USD (cents)"%>
<%= form.number_field :amount_usd %>
</p>
</div>
<div class="field">
<p>
<%= form.label :public_name %>
<%= form.text_field :public_name %>
</p>
</div>
<div class="actions">
<p>
<%= form.submit %>
</p>
</div>
<% end %>

View File

@@ -0,0 +1,8 @@
<h2>Editing Donation</h2>
<%= render 'form', donation: @donation, url: admin_donation_path(@donation) %>
<p class="actions">
<%= link_to 'Show', admin_donation_path(@donation) %> |
<%= link_to 'Back', admin_donations_path %>
<p>

View File

@@ -0,0 +1,39 @@
<h2>Donations</h2>
<% if @donations.any? %>
<table>
<thead>
<tr>
<th>User</th>
<th>Amount BTC (sats)</th>
<th>in EUR</th>
<th>in USD</th>
<th>Public name</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @donations.each do |donation| %>
<tr>
<td><%= donation.user.cn %></td>
<td><%= donation.amount_sats %></td>
<td><%= donation.amount_eur %></td>
<td><%= donation.amount_usd %></td>
<td><%= donation.public_name %></td>
<td><%= link_to 'Show', admin_donation_path(donation) %></td>
<td><%= link_to 'Edit', edit_admin_donation_path(donation) %></td>
<td><%= link_to 'Destroy', admin_donation_path(donation), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p>
No donations yet.
</p>
<% end %>
<p class="actions">
<%= link_to 'Record an out-of-system donation', new_admin_donation_path %>
</p>

View File

@@ -0,0 +1 @@
json.array! @donations, partial: "donations/donation", as: :donation

View File

@@ -0,0 +1,7 @@
<h2>New Donation</h2>
<%= render 'form', donation: @donation, url: admin_donations_path %>
<p class="actions">
<%= link_to 'Back', admin_donations_path %>
</p>

View File

@@ -0,0 +1,29 @@
<p id="notice"><%= notice %></p>
<p>
<strong>User:</strong>
<%= @donation.user_id %>
</p>
<p>
<strong>Amount sats:</strong>
<%= @donation.amount_sats %>
</p>
<p>
<strong>Amount eur:</strong>
<%= @donation.amount_eur %>
</p>
<p>
<strong>Amount usd:</strong>
<%= @donation.amount_usd %>
</p>
<p>
<strong>Public name:</strong>
<%= @donation.public_name %>
</p>
<%= link_to 'Edit', edit_admin_donation_path(@donation) %> |
<%= link_to 'Back', admin_donations_path %>

View File

@@ -0,0 +1 @@
json.partial! "donations/donation", donation: @donation