Adds contributions list page

This commit is contained in:
Hugo Peixoto 2023-03-19 15:15:56 +00:00
parent a106bc0357
commit cd43a5c382
6 changed files with 42 additions and 7 deletions

View File

@ -3,16 +3,22 @@ class ContributionsController < ApplicationController
before_action :set_member, only: %i[ new create ] before_action :set_member, only: %i[ new create ]
before_action :set_contribution, only: %i[ edit update delete destroy ] 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 def new
@contribution = Contribution.new @contribution = Contribution.new
end end
# GET /members/1/edit # GET /contributions/1/edit
def edit def edit
end end
# POST /members # POST /contributions
def create def create
@contribution = @member.contributions.build(contribution_params) @contribution = @member.contributions.build(contribution_params)
@ -29,7 +35,7 @@ class ContributionsController < ApplicationController
end end
end end
# PATCH/PUT /members/1 # PATCH/PUT /contributions/1
def update def update
if @contribution.update(contribution_params) if @contribution.update(contribution_params)
redirect_to @contribution.member, notice: "Contribution was successfully updated." redirect_to @contribution.member, notice: "Contribution was successfully updated."
@ -38,11 +44,11 @@ class ContributionsController < ApplicationController
end end
end end
# #
# GET /members/1/delete # GET /contributions/1/delete
def delete def delete
end end
# DELETE /members/1 # DELETE /contributions/1
def destroy def destroy
@member = @contribution.member @member = @contribution.member
@contribution.destroy @contribution.destroy

View File

@ -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>

View File

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

View File

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

View File

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

View File

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