Merge pull request #2864 from consul/backport_1543-budget_execution_list

Budget execution list
This commit is contained in:
Javier Martín
2018-11-07 15:44:57 +01:00
committed by GitHub
20 changed files with 537 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

View File

@@ -1680,6 +1680,59 @@
}
}
.budget-execution {
border: 1px solid $border;
overflow: hidden;
position: relative;
a {
color: $text;
display: block;
img {
height: $line-height * 9;
transition-duration: 0.3s;
transition-property: transform;
width: 100%;
}
&:hover {
text-decoration: none;
img {
transform: scale(1.05);
}
}
}
h5 {
font-size: $base-font-size;
margin-bottom: 0;
}
.budget-execution-info {
padding: $line-height / 2;
}
.author {
color: $text-medium;
font-size: $small-font-size;
}
.budget-execution-content {
min-height: $line-height * 3;
}
.price {
color: $budget;
font-size: rem-calc(24);
}
&:hover {
box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.2);
}
}
// 07. Proposals successful
// -------------------------

View File

@@ -0,0 +1,46 @@
module Budgets
class ExecutionsController < ApplicationController
before_action :load_budget
load_and_authorize_resource :budget
def show
authorize! :read_executions, @budget
@statuses = ::Budget::Investment::Status.all
if params[:status].present?
@investments_by_heading = @budget.investments.winners
.joins(:milestones).includes(:milestones)
.select { |i| i.milestones.published.with_status
.order_by_publication_date.last
.status_id == params[:status].to_i }
.uniq
.group_by(&:heading)
else
@investments_by_heading = @budget.investments.winners
.joins(:milestones).includes(:milestones)
.distinct.group_by(&:heading)
end
@investments_by_heading = reorder_alphabetically_with_city_heading_first.to_h
end
private
def load_budget
@budget = Budget.find_by(slug: params[:id]) || Budget.find_by(id: params[:id])
end
def reorder_alphabetically_with_city_heading_first
@investments_by_heading.sort do |a, b|
if a[0].name == 'Toda la ciudad'
-1
elsif b[0].name == 'Toda la ciudad'
1
else
a[0].name <=> b[0].name
end
end
end
end
end

View File

@@ -0,0 +1,9 @@
module BudgetExecutionsHelper
def filters_select_counts(status)
@budget.investments.winners.with_milestones.select { |i| i.milestones
.published.with_status.order_by_publication_date
.last.status_id == status rescue false }.count
end
end

View File

@@ -22,7 +22,7 @@ module Abilities
can [:read], Budget
can [:read], Budget::Group
can [:read, :print, :json_data], Budget::Investment
can :read_results, Budget, phase: "finished"
can [:read_results, :read_executions], Budget, phase: "finished"
can :new, DirectMessage
can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals], Legislation::Process, published: true
can [:read, :changes, :go_to_version], Legislation::DraftVersion

View File

@@ -84,6 +84,7 @@ class Budget
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
scope :with_milestones, -> { joins(:milestones).distinct }
scope :by_budget, ->(budget) { where(budget: budget) }
scope :by_group, ->(group_id) { where(group_id: group_id) }

View File

@@ -18,6 +18,8 @@ class Budget
validate :description_or_status_present?
scope :order_by_publication_date, -> { order(publication_date: :asc) }
scope :published, -> { where("publication_date <= ?", Date.current) }
scope :with_status, -> { where("status_id IS NOT NULL") }
def self.title_max_length
80

View File

@@ -4,7 +4,8 @@ class SiteCustomization::Image < ActiveRecord::Base
"logo_header" => [260, 80],
"social_media_icon" => [470, 246],
"social_media_icon_twitter" => [246, 246],
"apple-touch-icon-200" => [200, 200]
"apple-touch-icon-200" => [200, 200],
"budget_execution_no_image" => [800, 600]
}
has_attached_file :image

View File

@@ -0,0 +1,33 @@
<% @investments_by_heading.each do |heading, investments| %>
<h4 id="<%= heading.name.parameterize %>">
<%= heading.name %> (<%= investments.count %>)
</h4>
<div class="row" data-equalizer-on="medium" data-equalizer>
<% investments.each do |investment| %>
<div class="small-12 medium-6 large-4 column end margin-bottom">
<div class="budget-execution">
<%= link_to budget_investment_path(@budget, investment, anchor: "tab-milestones"), data: { 'equalizer-watch': true } do %>
<% investment.milestones.order(publication_date: :desc).limit(1).each do |milestone| %>
<% if milestone.image.present? %>
<%= image_tag milestone.image_url(:large), alt: milestone.image.title %>
<% elsif investment.image.present? %>
<%= image_tag investment.image_url(:thumb), alt: investment.image.title %>
<% else %>
<%= image_tag "budget_execution_no_image.jpg", alt: investment.title %>
<% end %>
<% end %>
<div class="budget-execution-info">
<div class="budget-execution-content">
<h5><%= investment.title %></h5>
<span class="author"><%= investment.author.name %></span>
</div>
<p class="price margin-top text-center">
<strong><%= investment.formatted_price %></strong>
</p>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
<% end %>

View File

@@ -0,0 +1,77 @@
<% provide :title, t("budgets.executions.page_title", budget: @budget.name) %>
<% content_for :meta_description do %><%= @budget.description_for_phase('finished') %><% end %>
<% provide :social_media_meta_tags do %>
<%= render 'shared/social_media_meta_tags',
social_url: budget_executions_url(@budget),
social_title: @budget.name,
social_description: @budget.description_for_phase('finished') %>
<% end %>
<% content_for :canonical do %>
<%= render 'shared/canonical', href: budget_executions_url(@budget) %>
<% end %>
<div class="budgets-stats">
<div class="expanded no-margin-top padding header">
<div class="row">
<div class="small-12 column">
<%= back_link_to budgets_path %>
<h2 class="margin-top">
<%= t("budgets.executions.heading") %><br>
<span><%= @budget.name %></span>
</h2>
</div>
</div>
</div>
</div>
<div class="row margin-top">
<div class="small-12 column">
<ul class="tabs">
<li class="tabs-title">
<%= link_to t("budgets.results.link"), budget_results_path(@budget) %>
</li>
<li class="tabs-title is-active">
<%= link_to t("budgets.executions.link"), budget_executions_path(@budget), class: 'is-active' %>
</li>
</ul>
</div>
</div>
<div class="row">
<div class="small-12 medium-3 large-2 column">
<h3 class="margin-bottom">
<%= t("budgets.executions.heading_selection_title") %>
</h3>
<ul class="menu vertical no-margin-top no-padding-top">
<% @investments_by_heading.each_pair do |heading, investments| %>
<li>
<%= link_to heading.name, "#" + heading.name.parameterize %>
</li>
<% end %>
</ul>
</div>
<div class="small-12 medium-9 large-10 column">
<%= form_tag(budget_executions_path(@budget), method: :get) do %>
<div class="small-12 medium-3 column">
<%= label_tag t("budgets.executions.filters.label") %>
<%= select_tag :status,
options_from_collection_for_select(@statuses,
:id, lambda { |s| "#{s.name} (#{filters_select_counts(s.id)})" },
params[:status]),
class: "js-submit-on-change",
prompt: t("budgets.executions.filters.all",
count: @budget.investments.winners.with_milestones.count) %>
</div>
<% end %>
<% if @investments_by_heading.any? %>
<%= render 'budgets/executions/investments' %>
<% else %>
<div class="callout primary clear">
<%= t("budgets.executions.no_winner_investments") %>
</div>
<% end %>
</div>
</div>

View File

@@ -33,7 +33,7 @@
<% if current_user %>
<% if current_user.level_two_or_three_verified? %>
<%= link_to t("budgets.investments.index.sidebar.create"),
new_budget_investment_path(@budget),
new_budget_investment_path(current_budget),
class: "button margin-top expanded" %>
<% else %>
<div class="callout warning margin-top">

View File

@@ -29,10 +29,10 @@
<ul class="tabs">
<li class="tabs-title is-active">
<span class="show-for-sr"><%= t("shared.you_are_in") %></span>
<%= link_to t("budgets.results.link"), budget_results_path(@budget), class: "is-active" %>
<%= link_to t("budgets.results.link"), budget_results_path(@budget), class: "is-active" %>
</li>
<li class="tabs-title">
<%# link_to t("budgets.stats.link"), budget_stats_path(@budget)%>
<%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %>
</li>
</ul>
</div>