From be6d7a1d39b8fcd8948263dd104325bd1bb97523 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 3 Jun 2016 18:50:49 +0200 Subject: [PATCH] Adds views and helpers for investments --- app/helpers/budget_helper.rb | 15 +++++ app/views/budgets/investments/_form.html.erb | 49 +++++++++++++++ .../budgets/investments/_header.html.erb | 56 +++++++++++++++++ .../budgets/investments/_investment.html.erb | 61 +++++++++++++++++++ .../investments/_progress_bar.html.erb | 0 .../budgets/investments/_sidebar.html.erb | 29 +++++++++ app/views/budgets/investments/index.html.erb | 49 +++++++++++++++ app/views/budgets/investments/show.html.erb | 4 ++ 8 files changed, 263 insertions(+) create mode 100644 app/views/budgets/investments/_form.html.erb create mode 100644 app/views/budgets/investments/_header.html.erb create mode 100644 app/views/budgets/investments/_investment.html.erb create mode 100644 app/views/budgets/investments/_progress_bar.html.erb create mode 100644 app/views/budgets/investments/_sidebar.html.erb create mode 100644 app/views/budgets/investments/index.html.erb create mode 100644 app/views/budgets/investments/show.html.erb diff --git a/app/helpers/budget_helper.rb b/app/helpers/budget_helper.rb index 47dbbca98..8c19516e8 100644 --- a/app/helpers/budget_helper.rb +++ b/app/helpers/budget_helper.rb @@ -5,4 +5,19 @@ module BudgetHelper locale: I18n.default_locale, unit: budget.currency_symbol) end + + def heading_name(heading) + heading.present? ? heading.name : t("budget.headings.none") + end + + def namespaced_budget_investment_path(investment, options={}) + @namespaced_budget_investment_path ||= namespace + options[:budget_id] ||= investment.budget.id + case @namespace_budget_investment_path + when "management" + management_budget_investment_path(investment, options) + else + budget_investment_path(investment, options) + end + end end diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb new file mode 100644 index 000000000..249637d40 --- /dev/null +++ b/app/views/budgets/investments/_form.html.erb @@ -0,0 +1,49 @@ +<%= form_for(@investment, url: form_url) do |f| %> + <%= render 'shared/errors', resource: @investment %> + +
+
+ <%= f.label :title, t("budget.investments.form.title") %> + <%= f.text_field :title, maxlength: SpendingProposal.title_max_length, placeholder: t("budget.investments.form.title"), label: false %> +
+ + <%= f.invisible_captcha :subtitle %> + +
+ <%= f.label :description, t("budget.investments.form.description") %> + <%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> +
+ +
+ <%= f.label :external_url, t("budget.investments.form.external_url") %> + <%= f.text_field :external_url, placeholder: t("budget.investments.form.external_url"), label: false %> +
+ +
+ <%= f.label :heading_id, t("budget.investments.form.heading") %> + <%= f.select :heading_id, heading_select_options, {include_blank: t("budget.headings.none"), label: false} %> +
+ +
+ <%= f.label :association_name, t("budget.investments.form.association_name_label") %> + <%= f.text_field :association_name, placeholder: t("budget.investments.form.association_name"), label: false %> +
+ +
+ <% if @investment.new_record? %> + <%= f.label :terms_of_service do %> + <%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %> + + <%= t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> + + <% end %> + <% end %> +
+ +
+ <%= f.submit(class: "button", value: t("budget.investments.form.submit_buttons.#{action_name}")) %> +
+
+<% end %> diff --git a/app/views/budgets/investments/_header.html.erb b/app/views/budgets/investments/_header.html.erb new file mode 100644 index 000000000..ae5dbd318 --- /dev/null +++ b/app/views/budgets/investments/_header.html.erb @@ -0,0 +1,56 @@ +<% if @filter_heading_name.present? %> +
+
+ +
+
+ <%= link_to @budget, class: "back" do %> + + <%= t("shared.back") %> + <% end %> + + <% if can? :show, @ballot %> + <%= link_to t("budget.investments.header.check_ballot"), ballot_path, class: "button float-right" %> + <% end %> +
+
+ +
+
+
+

<%= @filter_geozone_name %>

+ + <% if @heading.present? && @ballot.heading.present? && @ballot.heading != @heading %> +
+

+ <%= t("budget.investments.header.different_heading_active") %> + <%= link_to @ballot.heading.name, budget_investments_path(budget_id: budget.id, heading_id: @ballot.heading_id) %> +

+ <% else %> +
+ <%= render 'progress_bar' %> +
+ <% end %> +
+
+
+
+
+<% else %> +
+
+
+ <%= link_to budget_path(@budget), class: "back" do %> + + <%= t("shared.back") %> + <% end %> + +

<%= t('budget.investments.index.title') %>

+
+
+
+<% end %> diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb new file mode 100644 index 000000000..3432bed49 --- /dev/null +++ b/app/views/budgets/investments/_investment.html.erb @@ -0,0 +1,61 @@ +
+
+
+ +
+
+ + <% cache [locale_and_user_status(investment), 'index', investment, investment.author] do %> + <%= t("budget.investments.investment.title") %> + +

<%= link_to investment.title, namespaced_budget_investment_path(investment) %>

+

+ + <%= l investment.created_at.to_date %> + + <% if investment.author.hidden? || investment.author.erased? %> +  •  + + <%= t("budget.investments.show.author_deleted") %> + + <% else %> +  •  + + <%= investment.author.name %> + + <% if investment.author.official? %> +  •  + + <%= investment.author.official_position %> + + <% end %> + <% end %> + +  •  + <%= heading_name(investment.heading) %> +

+
+

<%= link_to investment.description, namespaced_budget_investment_path(investment) %>

+
+
+ <% end %> +
+
+ + <% unless investment.unfeasible? %> + <% if feature?("investment_features.phase2") %> +
+ <%= render 'votes', + { investment: investment, vote_url: vote_investment_path(investment, value: 'yes') } %> +
+ <% elsif feature?("investment_features.phase3") %> +
+ <%= render 'ballot', investment: investment %> +
+ <% end %> + <% end %> +
+
+
diff --git a/app/views/budgets/investments/_progress_bar.html.erb b/app/views/budgets/investments/_progress_bar.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/budgets/investments/_sidebar.html.erb b/app/views/budgets/investments/_sidebar.html.erb new file mode 100644 index 000000000..53c5e98bc --- /dev/null +++ b/app/views/budgets/investments/_sidebar.html.erb @@ -0,0 +1,29 @@ +<%= link_to @budget, class: "back" do %> + + <%= t("spending_proposals.index.sidebar.back") %> +<% end %> + +
+ + + + +<% if @ballot.investments.by_heading(@heading).count > 0 %> +

+ + <%= t("budget.investments.index.sidebar.voted_html", + count: @ballot.investments.by_heading(@heading.id).count, + amount_spent: format_price(@ballot.amount_spent(@heading))) %> + +

+<% else %> +

<%= t("budget.investments.index.sidebar.zero") %>

+<% end %> + + + +

<%= t("budget.investments.index.sidebar.voted_info") %>

diff --git a/app/views/budgets/investments/index.html.erb b/app/views/budgets/investments/index.html.erb new file mode 100644 index 000000000..1f587c5ca --- /dev/null +++ b/app/views/budgets/investments/index.html.erb @@ -0,0 +1,49 @@ +<% provide :title do %><%= t('budget.investments.index.title') %><% end %> +<% content_for :header_addon do %> + <%= render "shared/search_form", + search_path: budget_investments_path(budget_id: @budget.id, page: 1), + i18n_namespace: "budget.investments.index.search_form" %> +<% end %> + +
+ + <%= render 'header' %> + +
+
+ +
+ + <% if params[:unfeasible].present? %> +

<%= t("budget.investments.index.unfeasible") %>

+

+ <%= t("budget.investments.index.unfeasible_text", + definitions: link_to(t("budget.investments.index.unfeasible_text_definitions"), "https://decide.madrid.es/participatory_budget_info#20")).html_safe %> +

+ <% end %> + + <%= content_tag(:h2, t("budget.investments.index.by_heading", heading: @filter_heading_name)) if @filter_heading_name.present? %> + <% if params[:search].present? %> +

+ <%= page_entries_info @investments %> + <%= t("budget.investments.index.search_results", count: @investments.size, search_term: params[:search]) %> +

+ <% end %> +
+ + <%= render('shared/order_links', i18n_namespace: "budget.investments.index") unless params[:unfeasible].present? %> + + <%= render partial: 'investment', collection: @investments %> + <%= paginate @investments %> +
+ +
+ +
+ +
+
diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb new file mode 100644 index 000000000..55cd12a6f --- /dev/null +++ b/app/views/budgets/investments/show.html.erb @@ -0,0 +1,4 @@ +

<%= @investment.title %>

+ +

<%= @investment.author.username %> + <%= @investment.price %>