Merge branch 'master' into dashboard

This commit is contained in:
decabeza
2019-03-26 16:45:48 +01:00
2476 changed files with 62613 additions and 84405 deletions

View File

@@ -2,6 +2,7 @@ class ProposalsController < ApplicationController
include FeatureFlags
include CommentableActions
include FlagActions
include ImageAttributes
before_action :parse_tag_filter, only: :index
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
@@ -35,7 +36,7 @@ class ProposalsController < ApplicationController
@proposal = Proposal.new(proposal_params.merge(author: current_user))
if @proposal.save
redirect_to created_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal')
redirect_to created_proposal_path(@proposal), notice: I18n.t("flash.actions.create.proposal")
else
render :new
end
@@ -47,18 +48,17 @@ class ProposalsController < ApplicationController
discard_draft
discard_archived
load_retired
load_successful_proposals
load_featured unless @proposal_successful_exists
load_featured
end
def vote
@proposal.register_vote(current_user, 'yes')
@proposal.register_vote(current_user, "yes")
set_proposal_votes(@proposal)
end
def retire
if valid_retired_params? && @proposal.update(retired_params.merge(retired_at: Time.current))
redirect_to proposal_path(@proposal), notice: t('proposals.notice.retired')
redirect_to proposal_path(@proposal), notice: t("proposals.notice.retired")
else
render action: :retire_form
end
@@ -67,14 +67,8 @@ class ProposalsController < ApplicationController
def retire_form
end
def share
if Setting['proposal_improvement_path'].present?
@proposal_improvement_path = Setting['proposal_improvement_path']
end
end
def vote_featured
@proposal.register_vote(current_user, 'yes')
@proposal.register_vote(current_user, "yes")
set_featured_proposal_votes(@proposal)
end
@@ -85,9 +79,9 @@ class ProposalsController < ApplicationController
def disable_recommendations
if current_user.update(recommended_proposals: false)
redirect_to proposals_path, notice: t('proposals.index.recommendations.actions.success')
redirect_to proposals_path, notice: t("proposals.index.recommendations.actions.success")
else
redirect_to proposals_path, error: t('proposals.index.recommendations.actions.error')
redirect_to proposals_path, error: t("proposals.index.recommendations.actions.error")
end
end
@@ -101,7 +95,7 @@ class ProposalsController < ApplicationController
def proposal_params
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url,
:responsible_name, :tag_list, :terms_of_service, :geozone_id, :skip_map,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom])
end
@@ -111,8 +105,8 @@ class ProposalsController < ApplicationController
end
def valid_retired_params?
@proposal.errors.add(:retired_reason, I18n.t('errors.messages.blank')) if params[:proposal][:retired_reason].blank?
@proposal.errors.add(:retired_explanation, I18n.t('errors.messages.blank')) if params[:proposal][:retired_explanation].blank?
@proposal.errors.add(:retired_reason, I18n.t("errors.messages.blank")) if params[:proposal][:retired_reason].blank?
@proposal.errors.add(:retired_explanation, I18n.t("errors.messages.blank")) if params[:proposal][:retired_explanation].blank?
@proposal.errors.empty?
end
@@ -143,10 +137,13 @@ class ProposalsController < ApplicationController
def load_featured
return unless !@advanced_search_terms && @search_terms.blank? && @tag_filter.blank? && params[:retired].blank? && @current_order != "recommendations"
@featured_proposals = Proposal.not_archived.sort_by_confidence_score.limit(3)
if @featured_proposals.present?
set_featured_proposal_votes(@featured_proposals)
@resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id))
if Setting["feature.featured_proposals"]
@featured_proposals = Proposal.not_archived.unsuccessful
.sort_by_confidence_score.limit(Setting["featured_proposals_number"])
if @featured_proposals.present?
set_featured_proposal_votes(@featured_proposals)
@resources = @resources.where("proposals.id NOT IN (?)", @featured_proposals.map(&:id))
end
end
end
@@ -154,10 +151,6 @@ class ProposalsController < ApplicationController
@view = (params[:view] == "minimal") ? "minimal" : "default"
end
def load_successful_proposals
@proposal_successful_exists = Proposal.successful.exists?
end
def destroy_map_location_association
map_location = params[:proposal][:map_location_attributes]
if map_location && (map_location[:longitude] && map_location[:latitude]).blank? && !map_location[:id].blank?
@@ -166,7 +159,7 @@ class ProposalsController < ApplicationController
end
def proposals_recommendations
if Setting['feature.user.recommendations_on_proposals'] && current_user.recommended_proposals
if Setting["feature.user.recommendations_on_proposals"] && current_user.recommended_proposals
@recommended_proposals = Proposal.recommendations(current_user).sort_by_random.limit(3)
end
end