Adds contributions list page

main
Hugo Peixoto 3 months ago
parent a106bc0357
commit cd43a5c382
  1. 18
      app/controllers/contributions_controller.rb
  2. 24
      app/views/contributions/index.html.erb
  3. 1
      app/views/layouts/application.html.erb
  4. 3
      config/locales/en.yml
  5. 1
      config/locales/pt.yml
  6. 2
      config/routes.rb

@ -3,16 +3,22 @@ class ContributionsController < ApplicationController
before_action :set_member, only: %i[ new create ]
before_action :set_contribution, only: %i[ edit update delete destroy ]
# GET /members/new
# GET /contributions
def index
@contributions = Contribution.all.order(payment_on: 'DESC')
@contributions = @contributions.select {|c| c.payment_on.year == params[:year].to_i } if params[:year]
end
# GET /contributions/new
def new
@contribution = Contribution.new
end
# GET /members/1/edit
# GET /contributions/1/edit
def edit
end
# POST /members
# POST /contributions
def create
@contribution = @member.contributions.build(contribution_params)
@ -29,7 +35,7 @@ class ContributionsController < ApplicationController
end
end
# PATCH/PUT /members/1
# PATCH/PUT /contributions/1
def update
if @contribution.update(contribution_params)
redirect_to @contribution.member, notice: "Contribution was successfully updated."
@ -38,11 +44,11 @@ class ContributionsController < ApplicationController
end
end
#
# GET /members/1/delete
# GET /contributions/1/delete
def delete
end
# DELETE /members/1
# DELETE /contributions/1
def destroy
@member = @contribution.member
@contribution.destroy

@ -0,0 +1,24 @@
<p style="color: green"><%= notice %></p>
<h1><%= t 'contributions.index.title' %></h1>
<table class='zebra'>
<tr>
<th><%= t('contributions.attributes.payment_on') %></th>
<th><%= t('members.attributes.display_name') %></th>
<th><%= t('contributions.attributes.amount') %></th>
<th><%= t('contributions.attributes.payment_method') %></th>
<th><%= t('members.index.actions.title') %></th>
</tr>
<% @contributions.each do |contribution| %>
<tr id="<%= dom_id contribution %>">
<td><%= contribution.payment_on %></td>
<td><%= contribution.member.number %>. <%= contribution.member.display_name %></td>
<td><%= contribution.eurocents %></td>
<td><%= contribution.payment_method %></td>
<td>
<%= link_to t('members.index.actions.show'), contribution.member %>
</td>
</tr>
<% end %>
</table>

@ -17,6 +17,7 @@
<li><%= link_to t('navigation.members'), members_path %></li>
<li><%= link_to t('navigation.board'), edit_board_path %></li>
<li><%= link_to t('navigation.notifications'), notifications_path %></li>
<li><%= link_to t('navigation.contributions'), contributions_path %></li>
<li>
<%= button_to sign_out_path, method: :delete do %>
Sign out of <%= current_user.email %>

@ -1,6 +1,9 @@
en:
navigation:
members: "Member list"
board: "Board"
notifications: "Notificações"
contributions: "Contributions"
members:
index:
title: "Members"

@ -6,6 +6,7 @@ pt:
members: "Lista de membros"
board: "Direcção"
notifications: "Notificações"
contributions: "Contribuições"
members:
delete:
confirmation_message: |

@ -13,7 +13,7 @@ Rails.application.routes.draw do
resources :contributions, only: [:new, :create]
end
resources :contributions, only: [:edit, :update, :destroy] do
resources :contributions, only: [:index, :edit, :update, :destroy] do
member do
get :delete
end

Loading…
Cancel
Save