Add select to Legislation::Proposals
Add admin interface for mark any proposal as selected Add filter to public interface for selected proposals
This commit is contained in:
committed by
Javi Martín
parent
429fbc5ed5
commit
05340e423c
@@ -1,7 +1,23 @@
|
|||||||
class Admin::Legislation::ProposalsController < Admin::Legislation::BaseController
|
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 :process, class: "Legislation::Process"
|
||||||
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process
|
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@proposals = @proposals.send("sort_by_#{@current_order}").page(params[:page])
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def update
|
||||||
|
@proposal.selected = !@proposal.selected
|
||||||
|
|
||||||
|
if @proposal.save
|
||||||
|
notice = t('admin.legislation.proposals.update.notice')
|
||||||
|
else
|
||||||
|
notice = t('admin.legislation.proposals.update.error')
|
||||||
|
end
|
||||||
|
redirect_to admin_legislation_process_proposals_path, notice: notice
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
class Legislation::ProcessesController < Legislation::BaseController
|
class Legislation::ProcessesController < Legislation::BaseController
|
||||||
has_filters %w{open next past}, only: :index
|
has_filters %w{open next past}, only: :index
|
||||||
|
has_filters %w{all selected}, only: :proposals
|
||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
before_action :set_random_seed, only: :proposals
|
before_action :set_random_seed, only: :proposals
|
||||||
@@ -91,7 +93,9 @@ class Legislation::ProcessesController < Legislation::BaseController
|
|||||||
|
|
||||||
@proposals = ::Legislation::Proposal.where(process: @process)
|
@proposals = ::Legislation::Proposal.where(process: @process)
|
||||||
@proposals = @proposals.search(params[:search]) if params[:search].present?
|
@proposals = @proposals.search(params[:search]) if params[:search].present?
|
||||||
@proposals = @proposals.order('random()').page(params[:page])
|
@proposals = @proposals.send(@current_filter).order('random()').page(params[:page])
|
||||||
|
|
||||||
|
@valid_filters = [] unless @proposals.map(&:selected).include? true
|
||||||
|
|
||||||
if @process.proposals_phase.started? || (current_user && current_user.administrator?)
|
if @process.proposals_phase.started? || (current_user && current_user.administrator?)
|
||||||
legislation_proposal_votes(@proposals)
|
legislation_proposal_votes(@proposals)
|
||||||
|
|||||||
@@ -45,9 +45,13 @@ class Legislation::Proposal < ActiveRecord::Base
|
|||||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
||||||
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
|
||||||
scope :sort_by_most_commented, -> { reorder(comments_count: :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: :asc) }
|
||||||
scope :sort_by_random, -> { reorder("RANDOM()") }
|
scope :sort_by_random, -> { reorder("RANDOM()") }
|
||||||
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
|
||||||
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
|
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
|
||||||
|
scope :selected, -> { where(selected: true) }
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
"#{id}-#{title}".parameterize
|
"#{id}-#{title}".parameterize
|
||||||
|
|||||||
@@ -11,4 +11,44 @@
|
|||||||
<%= render 'admin/legislation/processes/subnav', process: @process, active: 'proposals' %>
|
<%= render 'admin/legislation/processes/subnav', process: @process, active: 'proposals' %>
|
||||||
|
|
||||||
<%= render 'form' %>
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<% if @proposals.any? %>
|
||||||
|
<h3><%= page_entries_info @proposals %></h3>
|
||||||
|
|
||||||
|
<%= render 'shared/wide_order_selector', i18n_namespace: "admin.legislation.processes.proposals" %>
|
||||||
|
|
||||||
|
<table class="stack" id="proposals_table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="text-center"><%= t("admin.legislation.proposals.index.id") %></th>
|
||||||
|
<th><%= t("admin.legislation.proposals.index.title") %></th>
|
||||||
|
<th class="text-center"><%= t("admin.legislation.proposals.index.supports") %></th>
|
||||||
|
<th><%= t("admin.legislation.proposals.index.selected") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<% @proposals.each do |proposal| %>
|
||||||
|
<tr id="<%= dom_id(proposal) %>">
|
||||||
|
<td class="text-center"><%= proposal.id %></td>
|
||||||
|
<td><%= proposal.title %></td>
|
||||||
|
<td class="text-center"><%= proposal.cached_votes_up %></td>
|
||||||
|
<td>
|
||||||
|
<% if proposal.selected?
|
||||||
|
button_text = t("admin.legislation.proposals.index.selected")
|
||||||
|
clas = 'button expanded'
|
||||||
|
else
|
||||||
|
button_text = t("admin.legislation.proposals.index.select")
|
||||||
|
clas = 'button hollow expanded'
|
||||||
|
end %>
|
||||||
|
<%= link_to button_text, admin_legislation_process_proposal_path(@process, proposal), method: 'PUT', class: clas %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @proposals %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<p><%= t("legislation.processes.proposals.empty_proposals") %></p>
|
<p><%= t("legislation.processes.proposals.empty_proposals") %></p>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
<%= render 'shared/filter_subnav', i18n_namespace: "legislation.processes.proposals" %>
|
||||||
<%= render proposals %>
|
<%= render proposals %>
|
||||||
<%= paginate proposals %>
|
<%= paginate proposals %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#
|
#
|
||||||
# i18n_namespace: for example "moderation.debates.index"
|
# i18n_namespace: for example "moderation.debates.index"
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<% if @valid_orders.present? && @valid_orders.count > 1 %>
|
<% if @valid_orders.present? && @valid_orders.count > 1 %>
|
||||||
<div class="wide-order-selector small-12 medium-8">
|
<div class="wide-order-selector small-12 medium-8">
|
||||||
<form>
|
<form>
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ en:
|
|||||||
legislation/process:
|
legislation/process:
|
||||||
one: "Process"
|
one: "Process"
|
||||||
other: "Processes"
|
other: "Processes"
|
||||||
|
legislation/proposal:
|
||||||
|
one: "Proposal"
|
||||||
|
other: "Proposals"
|
||||||
legislation/draft_versions:
|
legislation/draft_versions:
|
||||||
one: "Draft version"
|
one: "Draft version"
|
||||||
other: "Draft versions"
|
other: "Draft versions"
|
||||||
|
|||||||
@@ -394,6 +394,12 @@ en:
|
|||||||
back: Back
|
back: Back
|
||||||
title: Create new collaborative legislation process
|
title: Create new collaborative legislation process
|
||||||
submit_button: Create process
|
submit_button: Create process
|
||||||
|
proposals:
|
||||||
|
select_order: Sort by
|
||||||
|
orders:
|
||||||
|
id: Id
|
||||||
|
title: Title
|
||||||
|
supports: Supports
|
||||||
process:
|
process:
|
||||||
title: Process
|
title: Process
|
||||||
comments: Comments
|
comments: Comments
|
||||||
@@ -411,6 +417,14 @@ en:
|
|||||||
index:
|
index:
|
||||||
title: Proposals
|
title: Proposals
|
||||||
back: Back
|
back: Back
|
||||||
|
id: Id
|
||||||
|
title: Title
|
||||||
|
supports: Supports
|
||||||
|
select: Select
|
||||||
|
selected: Selected
|
||||||
|
update:
|
||||||
|
notice: 'Proposal updated successfully'
|
||||||
|
error: Proposal couldn't be updated
|
||||||
form:
|
form:
|
||||||
custom_categories: Categories
|
custom_categories: Categories
|
||||||
custom_categories_description: Categories that users can select creating the proposal.
|
custom_categories_description: Categories that users can select creating the proposal.
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ en:
|
|||||||
more_info: More information and context
|
more_info: More information and context
|
||||||
proposals:
|
proposals:
|
||||||
empty_proposals: There are no proposals
|
empty_proposals: There are no proposals
|
||||||
|
filters:
|
||||||
|
all: All
|
||||||
|
selected: Selected
|
||||||
debate:
|
debate:
|
||||||
empty_questions: There aren't any questions
|
empty_questions: There aren't any questions
|
||||||
participate: Participate in the debate
|
participate: Participate in the debate
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ es:
|
|||||||
legislation/process:
|
legislation/process:
|
||||||
one: "Proceso"
|
one: "Proceso"
|
||||||
other: "Procesos"
|
other: "Procesos"
|
||||||
|
legislation/proposal:
|
||||||
|
one: "Propuesta"
|
||||||
|
other: "Propuestas"
|
||||||
legislation/draft_versions:
|
legislation/draft_versions:
|
||||||
one: "Versión borrador"
|
one: "Versión borrador"
|
||||||
other: "Versiones borrador"
|
other: "Versiones borrador"
|
||||||
|
|||||||
@@ -395,6 +395,12 @@ es:
|
|||||||
back: Volver
|
back: Volver
|
||||||
title: Crear nuevo proceso de legislación colaborativa
|
title: Crear nuevo proceso de legislación colaborativa
|
||||||
submit_button: Crear proceso
|
submit_button: Crear proceso
|
||||||
|
proposals:
|
||||||
|
select_order: Ordenar por
|
||||||
|
orders:
|
||||||
|
id: Id
|
||||||
|
title: Título
|
||||||
|
supports: Apoyos
|
||||||
process:
|
process:
|
||||||
title: Proceso
|
title: Proceso
|
||||||
comments: Comentarios
|
comments: Comentarios
|
||||||
@@ -412,6 +418,14 @@ es:
|
|||||||
index:
|
index:
|
||||||
title: Propuestas
|
title: Propuestas
|
||||||
back: Volver
|
back: Volver
|
||||||
|
id: Id
|
||||||
|
title: Título
|
||||||
|
supports: Apoyos
|
||||||
|
select: Seleccionar
|
||||||
|
selected: Seleccionado
|
||||||
|
update:
|
||||||
|
notice: Propuesta actualizada correctamente.
|
||||||
|
error: No se ha podido actualizar la propuesta
|
||||||
form:
|
form:
|
||||||
custom_categories: Categorías
|
custom_categories: Categorías
|
||||||
custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta.
|
custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta.
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ es:
|
|||||||
more_info: Más información y contexto
|
more_info: Más información y contexto
|
||||||
proposals:
|
proposals:
|
||||||
empty_proposals: No hay propuestas
|
empty_proposals: No hay propuestas
|
||||||
|
filters:
|
||||||
|
all: Todos
|
||||||
|
selected: Seleccionados
|
||||||
debate:
|
debate:
|
||||||
empty_questions: No hay preguntas
|
empty_questions: No hay preguntas
|
||||||
participate: Realiza tus aportaciones al debate previo participando en los siguientes temas.
|
participate: Realiza tus aportaciones al debate previo participando en los siguientes temas.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSelectedToLegislationProposals < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :legislation_proposals, :selected, :boolean
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -687,6 +687,7 @@ ActiveRecord::Schema.define(version: 20180924071722) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "cached_votes_total", default: 0
|
t.integer "cached_votes_total", default: 0
|
||||||
t.integer "cached_votes_down", default: 0
|
t.integer "cached_votes_down", default: 0
|
||||||
|
t.boolean "selected"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree
|
add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree
|
||||||
|
|||||||
Reference in New Issue
Block a user