diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 1cc6e87c9..cafbb52be 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -887,6 +887,13 @@ } } +.legislation-proposals { + + .votes { + min-height: $line-height * 8; + } +} + .proposal-show .votes, .debate-show .votes { border: 0; diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index 7f4441bce..44a1dd192 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -1,7 +1,16 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseController + + has_orders %w[id title supports], only: :index + load_and_authorize_resource :process, class: "Legislation::Process" load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process def index + @proposals = @proposals.send("sort_by_#{@current_order}").page(params[:page]) + end + + def toggle_selection + @proposal.toggle :selected + @proposal.save! end end diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index f30b9d894..f05d2fdda 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,5 +1,7 @@ class Legislation::ProcessesController < Legislation::BaseController - has_filters %w{open next past}, only: :index + has_filters %w[open next past], only: :index + has_filters %w[random winners], only: :proposals + load_and_authorize_resource before_action :set_random_seed, only: :proposals @@ -91,7 +93,9 @@ class Legislation::ProcessesController < Legislation::BaseController @proposals = ::Legislation::Proposal.where(process: @process) @proposals = @proposals.search(params[:search]) if params[:search].present? - @proposals = @proposals.order('random()').page(params[:page]) + + @current_filter = "winners" if params[:filter].blank? && @proposals.winners.any? + @proposals = @proposals.send(@current_filter).page(params[:page]) if @process.proposals_phase.started? || (current_user && current_user.administrator?) legislation_proposal_votes(@proposals) diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index d8dc77f87..a737824ab 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -10,4 +10,20 @@ module LegislationHelper def new_legislation_proposal_link_text(process) t("proposals.index.start_proposal") end + + def link_to_toggle_legislation_proposal_selection(proposal) + if proposal.selected? + button_text = t("admin.legislation.proposals.index.selected") + html_class = 'button expanded' + else + button_text = t("admin.legislation.proposals.index.select") + html_class = 'button hollow expanded' + end + + link_to button_text, + toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal), + remote: true, + method: :patch, + class: html_class + end end diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index a345a5904..43a5cf1e8 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -45,9 +45,15 @@ class Legislation::Proposal < ActiveRecord::Base scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) } scope :sort_by_created_at, -> { reorder(created_at: :desc) } scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } + scope :sort_by_title, -> { reorder(title: :asc) } + scope :sort_by_id, -> { reorder(id: :asc) } + scope :sort_by_supports, -> { reorder(cached_votes_up: :desc) } scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} + scope :selected, -> { where(selected: true) } + scope :random, -> { sort_by_random } + scope :winners, -> { selected.sort_by_confidence_score } def to_param "#{id}-#{title}".parameterize diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb new file mode 100644 index 000000000..2f75b4223 --- /dev/null +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -0,0 +1,29 @@ +<% if proposals.any? %> +
| <%= t("admin.legislation.proposals.index.id") %> | +<%= t("admin.legislation.proposals.index.title") %> | +<%= t("admin.legislation.proposals.index.supports") %> | +<%= t("admin.legislation.proposals.index.selected") %> | +
|---|---|---|---|
| <%= proposal.id %> | +<%= proposal.title %> | +<%= proposal.cached_votes_up %> | +<%= render "select_proposal", proposal: proposal %> | +
<%= t("legislation.processes.proposals.empty_proposals") %>
diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index 8452bed9f..d88cf96d2 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -39,8 +39,6 @@<%= t("legislation.proposals.closed") %>
<% end %> diff --git a/app/views/shared/_wide_order_selector.html.erb b/app/views/shared/_wide_order_selector.html.erb index d5b1405eb..0594f4301 100644 --- a/app/views/shared/_wide_order_selector.html.erb +++ b/app/views/shared/_wide_order_selector.html.erb @@ -2,6 +2,7 @@ # # i18n_namespace: for example "moderation.debates.index" %> + <% if @valid_orders.present? && @valid_orders.count > 1 %>