adds admin summary page for spending proposals
This commit is contained in:
@@ -28,6 +28,10 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def summary
|
||||
@spending_proposals = SpendingProposal.for_summary.group(:geozone).sum(:price)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def spending_proposal_params
|
||||
|
||||
@@ -13,4 +13,13 @@ module SpendingProposalsHelper
|
||||
spending_proposal_path(spending_proposal, options)
|
||||
end
|
||||
end
|
||||
|
||||
def spending_proposal_count_for_geozone(geozone)
|
||||
if geozone.present?
|
||||
geozone.spending_proposals.for_summary.count
|
||||
else
|
||||
SpendingProposal.where(geozone: nil).for_summary.count
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -37,7 +37,7 @@ module Abilities
|
||||
|
||||
can :manage, Annotation
|
||||
|
||||
can [:read, :update, :destroy], SpendingProposal
|
||||
can [:read, :update, :destroy, :summary], SpendingProposal
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
class Geozone < ActiveRecord::Base
|
||||
has_many :spending_proposals
|
||||
validates :name, presence: true
|
||||
|
||||
def self.names
|
||||
Geozone.pluck(:name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -134,4 +134,8 @@ class SpendingProposal < ActiveRecord::Base
|
||||
self.responsible_name = author.try(:document_number) if author.try(:document_number).present?
|
||||
end
|
||||
|
||||
def self.for_summary
|
||||
valuation_finished.feasible
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
</div>
|
||||
|
||||
<%= render 'shared/filter_subnav', i18n_namespace: "admin.spending_proposals.index" %>
|
||||
<%= link_to t("admin.spending_proposals.index.summary_link"),
|
||||
summary_admin_spending_proposals_path %>
|
||||
|
||||
<h3><%= page_entries_info @spending_proposals %></h3>
|
||||
|
||||
|
||||
15
app/views/admin/spending_proposals/summary.html.erb
Normal file
15
app/views/admin/spending_proposals/summary.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<h2><%= t("admin.spending_proposals.summary.title") %></h2>
|
||||
|
||||
<table id="spending_proposals">
|
||||
<th><%= t("admin.spending_proposals.summary.geozone_name") %></th>
|
||||
<th><%= t("admin.spending_proposals.summary.count_for_geozone") %></th>
|
||||
<th><%= t("admin.spending_proposals.summary.cost_for_geozone") %></th>
|
||||
|
||||
<% @spending_proposals.each do |geozone, price| %>
|
||||
<tr id="<%= geozone.present? ? dom_id(geozone) : 'geozone_all_city' %>">
|
||||
<td class="name"><%= geozone.present? ? geozone.name : t("geozones.none") %></td>
|
||||
<td class="proposals-count"><%= spending_proposal_count_for_geozone(geozone) %></td>
|
||||
<td class="total-price"><%= number_to_currency(price) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
@@ -135,6 +135,8 @@ Rails.application.routes.draw do
|
||||
patch :assign_admin
|
||||
patch :assign_valuators
|
||||
end
|
||||
|
||||
get :summary, on: :collection
|
||||
end
|
||||
|
||||
resources :comments, only: :index do
|
||||
|
||||
Reference in New Issue
Block a user