From cd43a5c382301e672a83379848f7687612ef98cf Mon Sep 17 00:00:00 2001 From: Hugo Peixoto Date: Sun, 19 Mar 2023 15:15:56 +0000 Subject: [PATCH] Adds contributions list page --- app/controllers/contributions_controller.rb | 18 ++++++++++------ app/views/contributions/index.html.erb | 24 +++++++++++++++++++++ app/views/layouts/application.html.erb | 1 + config/locales/en.yml | 3 +++ config/locales/pt.yml | 1 + config/routes.rb | 2 +- 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 app/views/contributions/index.html.erb diff --git a/app/controllers/contributions_controller.rb b/app/controllers/contributions_controller.rb index c09b932..272ceb2 100644 --- a/app/controllers/contributions_controller.rb +++ b/app/controllers/contributions_controller.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 diff --git a/app/views/contributions/index.html.erb b/app/views/contributions/index.html.erb new file mode 100644 index 0000000..5e6db90 --- /dev/null +++ b/app/views/contributions/index.html.erb @@ -0,0 +1,24 @@ +

<%= notice %>

+ +

<%= t 'contributions.index.title' %>

+ + + + + + + + + + <% @contributions.each do |contribution| %> + + + + + + + + <% end %> +
<%= t('contributions.attributes.payment_on') %><%= t('members.attributes.display_name') %><%= t('contributions.attributes.amount') %><%= t('contributions.attributes.payment_method') %><%= t('members.index.actions.title') %>
<%= contribution.payment_on %><%= contribution.member.number %>. <%= contribution.member.display_name %><%= contribution.eurocents %><%= contribution.payment_method %> + <%= link_to t('members.index.actions.show'), contribution.member %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4636d6a..3e16bba 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,6 +17,7 @@
  • <%= link_to t('navigation.members'), members_path %>
  • <%= link_to t('navigation.board'), edit_board_path %>
  • <%= link_to t('navigation.notifications'), notifications_path %>
  • +
  • <%= link_to t('navigation.contributions'), contributions_path %>
  • <%= button_to sign_out_path, method: :delete do %> Sign out of <%= current_user.email %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d357e1..3eee3fb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,9 @@ en: navigation: members: "Member list" + board: "Board" + notifications: "Notificações" + contributions: "Contributions" members: index: title: "Members" diff --git a/config/locales/pt.yml b/config/locales/pt.yml index b76d419..c8138cb 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -6,6 +6,7 @@ pt: members: "Lista de membros" board: "Direcção" notifications: "Notificações" + contributions: "Contribuições" members: delete: confirmation_message: | diff --git a/config/routes.rb b/config/routes.rb index 96882fd..cb367c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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