From f3d6e29e4eae16347280c4ad78deeb32c294947d Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 17 Dec 2020 17:01:06 +0100 Subject: [PATCH 1/6] Remove time from used invitations list Date is enough. --- app/views/invitations/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/invitations/index.html.erb b/app/views/invitations/index.html.erb index 5b461ce..c38b98d 100644 --- a/app/views/invitations/index.html.erb +++ b/app/views/invitations/index.html.erb @@ -29,7 +29,7 @@ URL - Used at + Accepted Invited user @@ -37,7 +37,7 @@ <% @invitations_used.each do |invitation| %> <%= invitation_url(invitation.token) %> - <%= invitation.used_at %> + <%= invitation.used_at.strftime("%Y-%m-%d") %> <%= User.find(invitation.invited_user_id).address %> <% end %> From 40f3e8327a9218c37d8443704269a8507c897356 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 17 Dec 2020 21:55:16 +0100 Subject: [PATCH 2/6] Basic donation records Adds donation model/table and basic manual management in the admin panel, as well as basic listing of users' own donations. --- app/assets/stylesheets/forms.scss | 4 - app/assets/stylesheets/layout.scss | 4 + app/controllers/admin/donations_controller.rb | 74 +++++++++++++++++++ app/controllers/donations_controller.rb | 9 +++ app/helpers/donations_helper.rb | 2 + app/models/donation.rb | 10 +++ app/models/user.rb | 1 + app/views/admin/dashboard/index.html.erb | 7 +- .../admin/donations/_donation.json.jbuilder | 2 + app/views/admin/donations/_form.html.erb | 53 +++++++++++++ app/views/admin/donations/edit.html.erb | 8 ++ app/views/admin/donations/index.html.erb | 39 ++++++++++ app/views/admin/donations/index.json.jbuilder | 1 + app/views/admin/donations/new.html.erb | 7 ++ app/views/admin/donations/show.html.erb | 29 ++++++++ app/views/admin/donations/show.json.jbuilder | 1 + app/views/donations/index.html.erb | 29 ++++++++ app/views/donations/index.json.jbuilder | 1 + config/routes.rb | 2 + .../20201130132533_create_invitations.rb | 1 + db/migrate/20201217161544_create_donations.rb | 15 ++++ db/schema.rb | 13 +++- spec/factories/donations.rb | 9 +++ spec/helpers/donations_helper_spec.rb | 15 ++++ spec/models/donation_spec.rb | 5 ++ 25 files changed, 333 insertions(+), 8 deletions(-) create mode 100644 app/controllers/admin/donations_controller.rb create mode 100644 app/controllers/donations_controller.rb create mode 100644 app/helpers/donations_helper.rb create mode 100644 app/models/donation.rb create mode 100644 app/views/admin/donations/_donation.json.jbuilder create mode 100644 app/views/admin/donations/_form.html.erb create mode 100644 app/views/admin/donations/edit.html.erb create mode 100644 app/views/admin/donations/index.html.erb create mode 100644 app/views/admin/donations/index.json.jbuilder create mode 100644 app/views/admin/donations/new.html.erb create mode 100644 app/views/admin/donations/show.html.erb create mode 100644 app/views/admin/donations/show.json.jbuilder create mode 100644 app/views/donations/index.html.erb create mode 100644 app/views/donations/index.json.jbuilder create mode 100644 db/migrate/20201217161544_create_donations.rb create mode 100644 spec/factories/donations.rb create mode 100644 spec/helpers/donations_helper_spec.rb create mode 100644 spec/models/donation_spec.rb diff --git a/app/assets/stylesheets/forms.scss b/app/assets/stylesheets/forms.scss index e8afb30..b994c05 100644 --- a/app/assets/stylesheets/forms.scss +++ b/app/assets/stylesheets/forms.scss @@ -22,10 +22,6 @@ form { color: #bc0101; } - .actions { - margin-top: 2rem; - } - .accept-terms { margin-top: 2rem; font-size: 0.85rem; diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index f57e8e5..c615505 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -143,6 +143,10 @@ main { margin-bottom: 3rem; } } + + .actions { + margin-top: 2rem; + } } .grid { diff --git a/app/controllers/admin/donations_controller.rb b/app/controllers/admin/donations_controller.rb new file mode 100644 index 0000000..6aa0b36 --- /dev/null +++ b/app/controllers/admin/donations_controller.rb @@ -0,0 +1,74 @@ +class Admin::DonationsController < Admin::BaseController + before_action :set_donation, only: [:show, :edit, :update, :destroy] + + # GET /donations + # GET /donations.json + def index + @donations = Donation.all + end + + # GET /donations/1 + # GET /donations/1.json + def show + end + + # GET /donations/new + def new + @donation = Donation.new + end + + # GET /donations/1/edit + def edit + end + + # POST /donations + # POST /donations.json + def create + @donation = Donation.new(donation_params) + + respond_to do |format| + if @donation.save + format.html { redirect_to admin_donation_url(@donation), notice: 'Donation was successfully created.' } + format.json { render :show, status: :created, location: @donation } + else + format.html { render :new } + format.json { render json: @donation.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /donations/1 + # PATCH/PUT /donations/1.json + def update + respond_to do |format| + if @donation.update(donation_params) + format.html { redirect_to admin_donation_url(@donation), notice: 'Donation was successfully updated.' } + format.json { render :show, status: :ok, location: @donation } + else + format.html { render :edit } + format.json { render json: @donation.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /donations/1 + # DELETE /donations/1.json + def destroy + @donation.destroy + respond_to do |format| + format.html { redirect_to admin_donations_url, notice: 'Donation was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_donation + @donation = Donation.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def donation_params + params.require(:donation).permit(:user_id, :amount_sats, :amount_eur, :amount_usd, :public_name) + end +end diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb new file mode 100644 index 0000000..d5d74bc --- /dev/null +++ b/app/controllers/donations_controller.rb @@ -0,0 +1,9 @@ +class DonationsController < ApplicationController + before_action :require_user_signed_in + + # GET /donations + # GET /donations.json + def index + @donations = current_user.donations + end +end diff --git a/app/helpers/donations_helper.rb b/app/helpers/donations_helper.rb new file mode 100644 index 0000000..d04dc2d --- /dev/null +++ b/app/helpers/donations_helper.rb @@ -0,0 +1,2 @@ +module DonationsHelper +end diff --git a/app/models/donation.rb b/app/models/donation.rb new file mode 100644 index 0000000..183e7fc --- /dev/null +++ b/app/models/donation.rb @@ -0,0 +1,10 @@ +class Donation < ApplicationRecord + # Relations + belongs_to :user + + # Validations + validates_presence_of :amount_sats + + # Hooks + # TODO before_create :store_fiat_value +end diff --git a/app/models/user.rb b/app/models/user.rb index 6987a0a..da3a01a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,6 +3,7 @@ class User < ApplicationRecord # Relations has_many :invitations, dependent: :destroy + has_many :donations validates_uniqueness_of :cn validates_length_of :cn, :minimum => 3 diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index d718467..34a898c 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -2,6 +2,7 @@

Ohai there, admin human.

-

- <%= link_to 'LDAP users', admin_ldap_users_path %> -

+ diff --git a/app/views/admin/donations/_donation.json.jbuilder b/app/views/admin/donations/_donation.json.jbuilder new file mode 100644 index 0000000..51574aa --- /dev/null +++ b/app/views/admin/donations/_donation.json.jbuilder @@ -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) diff --git a/app/views/admin/donations/_form.html.erb b/app/views/admin/donations/_form.html.erb new file mode 100644 index 0000000..09f124c --- /dev/null +++ b/app/views/admin/donations/_form.html.erb @@ -0,0 +1,53 @@ +<%= form_with(url: url, model: donation, local: true) do |form| %> + <% if donation.errors.any? %> +
+

<%= pluralize(donation.errors.count, "error") %> prohibited this donation from being saved:

+
    + <% donation.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+

+ <%= form.label :user_id %> + <%= form.collection_select :user_id, User.where(ou: "kosmos.org").order(:cn), :id, :cn %> +

+
+ +
+

+ <%= form.label :amount_sats, "Amount BTC (sats)" %> + <%= form.number_field :amount_sats %> +

+
+ +
+

+ <%= form.label :amount_eur, "Amount EUR (cents)" %> + <%= form.number_field :amount_eur %> +

+
+ +
+

+ <%= form.label :amount_usd, "Amount USD (cents)"%> + <%= form.number_field :amount_usd %> +

+
+ +
+

+ <%= form.label :public_name %> + <%= form.text_field :public_name %> +

+
+ +
+

+ <%= form.submit %> +

+
+<% end %> diff --git a/app/views/admin/donations/edit.html.erb b/app/views/admin/donations/edit.html.erb new file mode 100644 index 0000000..f3bffd3 --- /dev/null +++ b/app/views/admin/donations/edit.html.erb @@ -0,0 +1,8 @@ +

Editing Donation

+ +<%= render 'form', donation: @donation, url: admin_donation_path(@donation) %> + +

+ <%= link_to 'Show', admin_donation_path(@donation) %> | + <%= link_to 'Back', admin_donations_path %> +

diff --git a/app/views/admin/donations/index.html.erb b/app/views/admin/donations/index.html.erb new file mode 100644 index 0000000..ef69627 --- /dev/null +++ b/app/views/admin/donations/index.html.erb @@ -0,0 +1,39 @@ +

Donations

+ +<% if @donations.any? %> + + + + + + + + + + + + + + <% @donations.each do |donation| %> + + + + + + + + + + + <% end %> + +
UserAmount BTC (sats)in EURin USDPublic name
<%= donation.user.cn %><%= donation.amount_sats %><%= donation.amount_eur %><%= donation.amount_usd %><%= donation.public_name %><%= link_to 'Show', admin_donation_path(donation) %><%= link_to 'Edit', edit_admin_donation_path(donation) %><%= link_to 'Destroy', admin_donation_path(donation), method: :delete, data: { confirm: 'Are you sure?' } %>
+<% else %> +

+ No donations yet. +

+<% end %> + +

+ <%= link_to 'Record an out-of-system donation', new_admin_donation_path %> +

diff --git a/app/views/admin/donations/index.json.jbuilder b/app/views/admin/donations/index.json.jbuilder new file mode 100644 index 0000000..9df428c --- /dev/null +++ b/app/views/admin/donations/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @donations, partial: "donations/donation", as: :donation diff --git a/app/views/admin/donations/new.html.erb b/app/views/admin/donations/new.html.erb new file mode 100644 index 0000000..4fd44bf --- /dev/null +++ b/app/views/admin/donations/new.html.erb @@ -0,0 +1,7 @@ +

New Donation

+ +<%= render 'form', donation: @donation, url: admin_donations_path %> + +

+ <%= link_to 'Back', admin_donations_path %> +

diff --git a/app/views/admin/donations/show.html.erb b/app/views/admin/donations/show.html.erb new file mode 100644 index 0000000..b6bc85a --- /dev/null +++ b/app/views/admin/donations/show.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

+ User: + <%= @donation.user_id %> +

+ +

+ Amount sats: + <%= @donation.amount_sats %> +

+ +

+ Amount eur: + <%= @donation.amount_eur %> +

+ +

+ Amount usd: + <%= @donation.amount_usd %> +

+ +

+ Public name: + <%= @donation.public_name %> +

+ +<%= link_to 'Edit', edit_admin_donation_path(@donation) %> | +<%= link_to 'Back', admin_donations_path %> diff --git a/app/views/admin/donations/show.json.jbuilder b/app/views/admin/donations/show.json.jbuilder new file mode 100644 index 0000000..a152e38 --- /dev/null +++ b/app/views/admin/donations/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "donations/donation", donation: @donation diff --git a/app/views/donations/index.html.erb b/app/views/donations/index.html.erb new file mode 100644 index 0000000..67c2fe2 --- /dev/null +++ b/app/views/donations/index.html.erb @@ -0,0 +1,29 @@ +

Donations

+ +<% if @donations.any? %> + + + + + + + + + + + + <% @donations.each do |donation| %> + + + + + + + <% end %> + +
Amount BTC (sats)in EURin USDPublic name
<%= donation.amount_sats %><%= donation.amount_eur %><%= donation.amount_usd %><%= donation.public_name %>
+<% else %> +

+ No donations to show. +

+<% end %> diff --git a/app/views/donations/index.json.jbuilder b/app/views/donations/index.json.jbuilder new file mode 100644 index 0000000..9df428c --- /dev/null +++ b/app/views/donations/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @donations, partial: "donations/donation", as: :donation diff --git a/config/routes.rb b/config/routes.rb index bdefef0..5873f71 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :donations devise_for :users get 'welcome', to: 'welcome#index' @@ -16,6 +17,7 @@ Rails.application.routes.draw do namespace :admin do root to: 'dashboard#index' get 'ldap_users', to: 'ldap_users#index' + resources :donations end # Letter Opener (open "sent" emails in dev and staging) diff --git a/db/migrate/20201130132533_create_invitations.rb b/db/migrate/20201130132533_create_invitations.rb index 0b53910..aea9997 100644 --- a/db/migrate/20201130132533_create_invitations.rb +++ b/db/migrate/20201130132533_create_invitations.rb @@ -8,6 +8,7 @@ class CreateInvitations < ActiveRecord::Migration[6.0] t.timestamps end + add_index :invitations, :user_id add_index :invitations, :invited_user_id end diff --git a/db/migrate/20201217161544_create_donations.rb b/db/migrate/20201217161544_create_donations.rb new file mode 100644 index 0000000..8043a37 --- /dev/null +++ b/db/migrate/20201217161544_create_donations.rb @@ -0,0 +1,15 @@ +class CreateDonations < ActiveRecord::Migration[6.0] + def change + create_table :donations do |t| + t.integer :user_id + t.integer :amount_sats + t.integer :amount_eur + t.integer :amount_usd + t.string :public_name + + t.timestamps + end + + add_index :donations, :user_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d99780..49ae73a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,18 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_11_30_132533) do +ActiveRecord::Schema.define(version: 2020_12_17_161544) do + + create_table "donations", force: :cascade do |t| + t.integer "user_id" + t.integer "amount_sats" + t.integer "amount_eur" + t.integer "amount_usd" + t.string "public_name" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["user_id"], name: "index_donations_on_user_id" + end create_table "invitations", force: :cascade do |t| t.string "token" diff --git a/spec/factories/donations.rb b/spec/factories/donations.rb new file mode 100644 index 0000000..cb45fd6 --- /dev/null +++ b/spec/factories/donations.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :donation do + user_id { 1 } + amount_sats { 100000 } + amount_eur { 10 } + amount_usd { 13 } + public_name { nil } + end +end diff --git a/spec/helpers/donations_helper_spec.rb b/spec/helpers/donations_helper_spec.rb new file mode 100644 index 0000000..1834826 --- /dev/null +++ b/spec/helpers/donations_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the DonationsHelper. For example: +# +# describe DonationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe DonationsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/donation_spec.rb b/spec/models/donation_spec.rb new file mode 100644 index 0000000..b23ee4e --- /dev/null +++ b/spec/models/donation_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Donation, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 2f70bae5230518078b5c7ccdcdd1287fb81683d5 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 19 Dec 2020 13:16:04 +0100 Subject: [PATCH 3/6] Format and style user donations --- app/assets/stylesheets/donations.scss | 40 ++++++++++++++++ app/helpers/application_helper.rb | 3 ++ app/views/donations/index.html.erb | 63 ++++++++++++++----------- spec/helpers/application_helper_spec.rb | 9 ++++ 4 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 app/assets/stylesheets/donations.scss create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/app/assets/stylesheets/donations.scss b/app/assets/stylesheets/donations.scss new file mode 100644 index 0000000..ef401ab --- /dev/null +++ b/app/assets/stylesheets/donations.scss @@ -0,0 +1,40 @@ +ul.donations { + list-style: none; + + li { + margin-bottom: 2rem; + display: grid; + grid-row-gap: 0.5rem; + grid-column-gap: 2rem; + grid-template-columns: 1fr 1fr; + grid-template-areas: + "date amount-btc" + "public-name amounts-fiat"; + + h3 { + grid-area: "date"; + margin-bottom: 0; + } + + p { + margin-bottom: 0; + + &.amount-btc { + grid-area: amount-btc; + text-align: right; + font-family: monospace; + font-size: 1.25rem; + } + &.amounts-fiat { + grid-area: amounts-fiat; + text-align: right; + font-family: monospace; + font-size: 0.85rem; + color: #888; + } + &.public-name { + grid-area: public-name; + } + } + } +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..e2ff699 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def sats_to_btc(sats) + sats.to_f / 100000000 + end end diff --git a/app/views/donations/index.html.erb b/app/views/donations/index.html.erb index 67c2fe2..f2a3e8d 100644 --- a/app/views/donations/index.html.erb +++ b/app/views/donations/index.html.erb @@ -1,29 +1,38 @@ -

Donations

- -<% if @donations.any? %> - - - - - - - - - - - - <% @donations.each do |donation| %> - - - - - - - <% end %> - -
Amount BTC (sats)in EURin USDPublic name
<%= donation.amount_sats %><%= donation.amount_eur %><%= donation.amount_usd %><%= donation.public_name %>
-<% else %> +
+

Donations

- No donations to show. + Your financial contributions to the development and + upkeep of Kosmos software and services.

-<% end %> +
+ +
+ <% if @donations.any? %> +
    + <% @donations.each do |donation| %> +
  • +

    + <%= donation.created_at.strftime("%B %d, %Y") %> +

    +

    + <%= sats_to_btc donation.amount_sats %> BTC +

    +

    + (~ <%= number_to_currency donation.amount_eur / 100 %> EUR) +

    +

    + <% if donation.public_name.present? %> + Public name: <%= donation.public_name %> + <% else %> + Anonymous + <% end %> +

    +
  • + <% end %> +
+ <% else %> +

+ No donations to show. +

+ <% end %> +
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..92f8de4 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +describe ApplicationHelper do + describe "sats_to_btc" do + it "converts satoshis to BTC" do + expect(helper.sats_to_btc(120000000)).to eq(1.2) + end + end +end From 5e2d5c3b28f795b318be4563b5bda03fba2f4a71 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 19 Dec 2020 13:28:47 +0100 Subject: [PATCH 4/6] Add paid_at date to donations --- app/controllers/admin/donations_controller.rb | 2 +- app/controllers/donations_controller.rb | 2 +- app/models/donation.rb | 3 +++ app/views/admin/donations/_form.html.erb | 7 +++++++ app/views/admin/donations/index.html.erb | 2 ++ app/views/admin/donations/show.html.erb | 5 +++++ app/views/donations/index.html.erb | 2 +- db/migrate/20201219121808_add_paid_at_to_donations.rb | 5 +++++ db/schema.rb | 3 ++- 9 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20201219121808_add_paid_at_to_donations.rb diff --git a/app/controllers/admin/donations_controller.rb b/app/controllers/admin/donations_controller.rb index 6aa0b36..7b00bac 100644 --- a/app/controllers/admin/donations_controller.rb +++ b/app/controllers/admin/donations_controller.rb @@ -69,6 +69,6 @@ class Admin::DonationsController < Admin::BaseController # Only allow a list of trusted parameters through. def donation_params - params.require(:donation).permit(:user_id, :amount_sats, :amount_eur, :amount_usd, :public_name) + params.require(:donation).permit(:user_id, :amount_sats, :amount_eur, :amount_usd, :public_name, :paid_at) end end diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb index d5d74bc..74ee81c 100644 --- a/app/controllers/donations_controller.rb +++ b/app/controllers/donations_controller.rb @@ -4,6 +4,6 @@ class DonationsController < ApplicationController # GET /donations # GET /donations.json def index - @donations = current_user.donations + @donations = current_user.donations.completed end end diff --git a/app/models/donation.rb b/app/models/donation.rb index 183e7fc..30f13a0 100644 --- a/app/models/donation.rb +++ b/app/models/donation.rb @@ -7,4 +7,7 @@ class Donation < ApplicationRecord # Hooks # TODO before_create :store_fiat_value + + #Scopes + scope :completed, -> { where.not(paid_at: nil) } end diff --git a/app/views/admin/donations/_form.html.erb b/app/views/admin/donations/_form.html.erb index 09f124c..038d129 100644 --- a/app/views/admin/donations/_form.html.erb +++ b/app/views/admin/donations/_form.html.erb @@ -45,6 +45,13 @@

+
+

+ <%= form.label :paid_at %> + <%= form.text_field :paid_at %> +

+
+

<%= form.submit %> diff --git a/app/views/admin/donations/index.html.erb b/app/views/admin/donations/index.html.erb index ef69627..6f4c674 100644 --- a/app/views/admin/donations/index.html.erb +++ b/app/views/admin/donations/index.html.erb @@ -9,6 +9,7 @@ in EUR in USD Public name + Date @@ -21,6 +22,7 @@ <%= donation.amount_eur %> <%= donation.amount_usd %> <%= donation.public_name %> + <%= donation.paid_at ? donation.paid_at.strftime("%Y-%m-%d") : "" %> <%= link_to 'Show', admin_donation_path(donation) %> <%= link_to 'Edit', edit_admin_donation_path(donation) %> <%= link_to 'Destroy', admin_donation_path(donation), method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/app/views/admin/donations/show.html.erb b/app/views/admin/donations/show.html.erb index b6bc85a..12bc37e 100644 --- a/app/views/admin/donations/show.html.erb +++ b/app/views/admin/donations/show.html.erb @@ -25,5 +25,10 @@ <%= @donation.public_name %>

+

+ Date: + <%= @donation.paid_at %> +

+ <%= link_to 'Edit', edit_admin_donation_path(@donation) %> | <%= link_to 'Back', admin_donations_path %> diff --git a/app/views/donations/index.html.erb b/app/views/donations/index.html.erb index f2a3e8d..0dadba5 100644 --- a/app/views/donations/index.html.erb +++ b/app/views/donations/index.html.erb @@ -12,7 +12,7 @@ <% @donations.each do |donation| %>
  • - <%= donation.created_at.strftime("%B %d, %Y") %> + <%= donation.paid_at.strftime("%B %d, %Y") %>

    <%= sats_to_btc donation.amount_sats %> BTC diff --git a/db/migrate/20201219121808_add_paid_at_to_donations.rb b/db/migrate/20201219121808_add_paid_at_to_donations.rb new file mode 100644 index 0000000..ce690c5 --- /dev/null +++ b/db/migrate/20201219121808_add_paid_at_to_donations.rb @@ -0,0 +1,5 @@ +class AddPaidAtToDonations < ActiveRecord::Migration[6.0] + def change + add_column :donations, :paid_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 49ae73a..db024da 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_12_17_161544) do +ActiveRecord::Schema.define(version: 2020_12_19_121808) do create_table "donations", force: :cascade do |t| t.integer "user_id" @@ -20,6 +20,7 @@ ActiveRecord::Schema.define(version: 2020_12_17_161544) do t.string "public_name" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.datetime "paid_at" t.index ["user_id"], name: "index_donations_on_user_id" end From 4a655739347395a694d20dea497c656811df9ec3 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sat, 19 Dec 2020 14:59:16 +0100 Subject: [PATCH 5/6] Format numbers on admin donations page And fix the wrong unit display in the user donations list. --- app/views/admin/donations/index.html.erb | 8 ++++---- app/views/donations/index.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/admin/donations/index.html.erb b/app/views/admin/donations/index.html.erb index 6f4c674..e0d38ce 100644 --- a/app/views/admin/donations/index.html.erb +++ b/app/views/admin/donations/index.html.erb @@ -5,7 +5,7 @@ User - Amount BTC (sats) + Amount BTC in EUR in USD Public name @@ -18,9 +18,9 @@ <% @donations.each do |donation| %> <%= donation.user.cn %> - <%= donation.amount_sats %> - <%= donation.amount_eur %> - <%= donation.amount_usd %> + <%= sats_to_btc donation.amount_sats %> BTC + <%= number_to_currency donation.amount_eur / 100, unit: "" %> + <%= number_to_currency donation.amount_usd / 100, unit: "" %> <%= donation.public_name %> <%= donation.paid_at ? donation.paid_at.strftime("%Y-%m-%d") : "" %> <%= link_to 'Show', admin_donation_path(donation) %> diff --git a/app/views/donations/index.html.erb b/app/views/donations/index.html.erb index 0dadba5..7c504de 100644 --- a/app/views/donations/index.html.erb +++ b/app/views/donations/index.html.erb @@ -18,7 +18,7 @@ <%= sats_to_btc donation.amount_sats %> BTC

    - (~ <%= number_to_currency donation.amount_eur / 100 %> EUR) + (~ <%= number_to_currency donation.amount_eur / 100, unit: "" %> EUR)

    <% if donation.public_name.present? %> From 26c6c5a3b25d7bcc608854d00cfcf02f5dd803bd Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Mon, 21 Dec 2020 13:59:46 +0100 Subject: [PATCH 6/6] Nullify donation owners when related record destroyed --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index da3a01a..046b948 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ class User < ApplicationRecord # Relations has_many :invitations, dependent: :destroy - has_many :donations + has_many :donations, dependent: :nullify validates_uniqueness_of :cn validates_length_of :cn, :minimum => 3