From 8ef3e81e03b03774cc4d8cee3ac03828d90e160f Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 13 Jun 2018 13:54:18 -0400 Subject: [PATCH] Adapt public views for flagging/unflagging investments --- app/controllers/stats_controller.rb | 1 + .../budgets/investments/_actions.html.erb | 10 + .../investments/_flag_actions.html.erb | 25 ++ .../investments/_investment_show.html.erb | 341 +++++++++--------- .../investments/_refresh_flag_actions.js.erb | 1 + 5 files changed, 215 insertions(+), 163 deletions(-) create mode 100644 app/views/budgets/investments/_actions.html.erb create mode 100644 app/views/budgets/investments/_flag_actions.html.erb create mode 100644 app/views/budgets/investments/_refresh_flag_actions.js.erb diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 7130e661d..7bb872257 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -14,6 +14,7 @@ class StatsController < ApplicationController @debate_votes = daily_cache('debate_votes') { Vote.where(votable_type: 'Debate').count } @proposal_votes = daily_cache('proposal_votes') { Vote.where(votable_type: 'Proposal').count } @comment_votes = daily_cache('comment_votes') { Vote.where(votable_type: 'Comment').count } + @investment_votes = daily_cache('budget_investment_votes') { Vote.where(votable_type: 'Budget::Investment').count } @votes = daily_cache('votes') { Vote.count } @verified_users = daily_cache('verified_users') { User.with_hidden.level_two_or_three_verified.count } diff --git a/app/views/budgets/investments/_actions.html.erb b/app/views/budgets/investments/_actions.html.erb new file mode 100644 index 000000000..a464d7495 --- /dev/null +++ b/app/views/budgets/investments/_actions.html.erb @@ -0,0 +1,10 @@ +<% if can? :hide, investment %> + <%= link_to t("admin.actions.hide").capitalize, hide_moderation_budget_investment_path(investment), + method: :put, remote: true, data: { confirm: t("admin.actions.confirm") } %> +<% end %> + +<% if can? :hide, investment.author %> +  |  + <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(investment.author_id), + method: :put, data: { confirm: t("admin.actions.confirm") } %> +<% end %> diff --git a/app/views/budgets/investments/_flag_actions.html.erb b/app/views/budgets/investments/_flag_actions.html.erb new file mode 100644 index 000000000..8627dfe94 --- /dev/null +++ b/app/views/budgets/investments/_flag_actions.html.erb @@ -0,0 +1,25 @@ + + <% if show_flag_action? investment %> + + + + + <%= link_to t('shared.flag'), flag_budget_investment_path(investment.budget, investment.id), + method: :put, + remote: true, + id: "flag-investment-#{ investment.id }" %> + + <% end %> + + <% if show_unflag_action? investment %> + + + + + <%= link_to t('shared.unflag'), unflag_budget_investment_path(investment.budget, investment.id), + method: :put, + remote: true, + id: "unflag-investment-#{ investment.id }" %> + + <% end %> + diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index acca21a80..2f3528653 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -7,180 +7,195 @@ og_image_url: (investment.image.present? ? investment.image_url(:thumb) : nil) %> <% end %> -
+<% cache [locale_and_user_status(investment), + investment, + investment.author, + Flag.flagged?(current_user, investment), + @investment_votes] do %> +
-
-
- <%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %> +
+
+ <%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %> -

<%= investment.title %>

-
- <%= render '/shared/author_info', resource: investment %> +

<%= investment.title %>

+
+ <%= render '/shared/author_info', resource: investment %> -  •  - <%= l investment.created_at.to_date %> -  •  - <%= investment.heading.name %> +  •  + <%= l investment.created_at.to_date %> +  •  + <%= investment.heading.name %> +  •  + + <%= render 'budgets/investments/flag_actions', investment: @investment %> + +
+ +
+ + <%= render_image(investment.image, :large, true) if investment.image.present? %> + +

+ <%= t("budgets.investments.show.code_html", code: investment.id) %> +

+ + <%= safe_html_with_links investment.description.html_safe %> + + <% if feature?(:map) && map_location_available?(@investment.map_location) %> +
+ <%= render_map(@investment.map_location, "budget_investment", false, nil) %> +
+ <% end %> + + <% if investment.location.present? %> +

+ <%= t("budgets.investments.show.location_html", location: investment.location) %> +

+ <% end %> + + <% if investment.organization_name.present? %> +

+ <%= t("budgets.investments.show.organization_name_html", name: investment.organization_name) %> +

+ <% end %> + + <% if feature?(:allow_attached_documents) %> + <%= render 'documents/documents', + documents: investment.documents, + max_documents_allowed: Budget::Investment.max_documents_allowed %> + <% end %> + + <%= render 'shared/tags', taggable: investment %> + + <% if investment.external_url.present? %> + + <% end %> + + <% if investment.should_show_unfeasibility_explanation? %> +

<%= t('budgets.investments.show.unfeasibility_explanation') %>

+

<%= investment.unfeasibility_explanation %>

+ <% end %> + + <% if investment.should_show_price_explanation? %> +

<%= t('budgets.investments.show.price_explanation') %>

+

<%= investment.price_explanation %>

+ <% end %> + + <%= render 'relationable/related_content', relationable: @investment %> + +
+ <%= render "budgets/investments/actions", investment: @investment %> +
-
+
- - -
-
+ + +
+<% end %> diff --git a/app/views/budgets/investments/_refresh_flag_actions.js.erb b/app/views/budgets/investments/_refresh_flag_actions.js.erb new file mode 100644 index 000000000..07cf8d30a --- /dev/null +++ b/app/views/budgets/investments/_refresh_flag_actions.js.erb @@ -0,0 +1 @@ +App.Flaggable.update("<%= dom_id(@investment) %>", "<%= j render("budgets/investments/flag_actions", investment: @investment) %>")