Implements graph for dashboard

Implements graph secion for dashboard.

Dashboard related actions have been agrupated inside a menu in the admin
section.

Minor bugfixes.
This commit is contained in:
Juan Salvador Pérez García
2018-06-22 11:57:58 +02:00
parent c1a9f1d138
commit f9a085a400
19 changed files with 67 additions and 262 deletions

View File

@@ -1,3 +0,0 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@@ -73,51 +73,3 @@
}); });
}); });
})(); })();
// function drawProposalGraph(data) {
// var xColumnValues = [ 'x' ],
// progressColumnValues = [ 'Progreso' ]; // [ '<%= t('.progress') %>' ],
// key;
//
// for (key in data) {
// if (data.hasOwnProperty(key)) {
// xColumnValues.push(key);
// progressColumnValues.push(data[key]);
// }
// }
//
// c3.generate({
// bindto: '#proposal-graph',
// data: {
// x: 'x',
// columns: [
// xColumnValues,
// progressColumnValues
// ]
// },
// axis: {
// y: {
// label: {
// text: 'Apoyos', // '<%= t '.supports' %> ',
// position: 'outer-middle'
// }
// },
// x: {
// type: 'category'
// }
// }
// });
// }
//
// $(document).ready(function () {
// $.ajax({
// url: '<%= supports_proposal_dashboard_index_path(proposal, format: :json) %>',
// cache: false,
// success: function (data) {
// drawProposalGraph(data);
// },
// data: {
// group_by: '<%= params[:group_by] %>'
// }
// });
// });

View File

@@ -1,3 +0,0 @@
// Place all the styles related to the Admin::ProposalDashboardActions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@@ -38,8 +38,13 @@ class Admin::ProposalDashboardActionsController < Admin::BaseController
end end
def destroy def destroy
proposal_dashboard_action.destroy if proposal_dashboard_action.destroy
redirect_to admin_proposal_dashboard_actions_path, notice: t('admin.proposal_dashboard_actions.delete.success') flash[:notice] = t('admin.proposal_dashboard_actions.delete.success')
else
flash[:error] = proposal_dashboard_action.errors.full_messages.join(',')
end
redirect_to admin_proposal_dashboard_actions_path
end end
private private

View File

@@ -1,27 +0,0 @@
# frozen_string_literal: true
class Moderation::AdministratorTasksController < Moderation::BaseController
helper_method :administrator_task
def index
authorize! :index, AdministratorTask
@administrator_tasks = AdministratorTask.pending
end
def edit
authorize! :edit, administrator_task
end
def update
authorize! :update, administrator_task
administrator_task.update(user: current_user, executed_at: Time.now)
redirect_to moderation_administrator_tasks_path, { flash: { notice: t('.success') } }
end
private
def administrator_task
@administrator_task ||= AdministratorTask.find(params[:id])
end
end

View File

@@ -44,6 +44,10 @@ module AdminHelper
["homepage", "cards"].include?(controller_name) ["homepage", "cards"].include?(controller_name)
end end
def menu_proposals_dashboard?
["proposal_dashboard_actions", "administrator_tasks"].include?(controller_name)
end
def official_level_options def official_level_options
options = [["", 0]] options = [["", 0]]
(1..5).each do |i| (1..5).each do |i|

View File

@@ -223,10 +223,6 @@
<%= link_to t("admin.menu.geozones"), admin_geozones_path %> <%= link_to t("admin.menu.geozones"), admin_geozones_path %>
</li> </li>
<li <%= 'class=is_active' if controller_name == 'proposal_dashboard_actions' %>>
<%= link_to ProposalDashboardAction.model_name.human(count: 2), admin_proposal_dashboard_actions_path %>
</li>
<li <%= "class=is-active" if controller_name == "images" && <li <%= "class=is-active" if controller_name == "images" &&
controller.class.parent != Admin::Poll::Questions::Answers %>> controller.class.parent != Admin::Poll::Questions::Answers %>>
<%= link_to t("admin.menu.site_customization.images"), admin_site_customization_images_path %> <%= link_to t("admin.menu.site_customization.images"), admin_site_customization_images_path %>
@@ -238,5 +234,21 @@
</ul> </ul>
</li> </li>
<li class="section-title">
<a href="#">
<span class="icon-check"></span>
<strong><%= t("admin.menu.proposals_dashboard") %></strong>
</a>
<ul <%= "class=is-active" if menu_proposals_dashboard? %>>
<li <%= "class=is-active" if controller_name == "proposal_dashboard_actions" %>>
<%= link_to ProposalDashboardAction.model_name.human(count: 2), admin_proposal_dashboard_actions_path %>
</li>
<li <%= "class=is-active" if controller_name == "administrator_tasks" %>>
<%= link_to admin_administrator_tasks_path do %>
<%= t("admin.menu.administrator_tasks") %>
<% end %>
</li>
</ul> </ul>
</li>
</div> </div>

View File

@@ -42,12 +42,5 @@
<%= t("moderation.menu.users") %> <%= t("moderation.menu.users") %>
<% end %> <% end %>
</li> </li>
<li <%= 'class=is-active' if controller_name == 'administrator_tasks' %>>
<%= link_to moderation_administrator_tasks_path do %>
<span class="icon-check"></span>
<%= t 'moderation.menu.administrator_tasks' %>
<% end %>
</li>
</ul> </ul>
</nav> </nav>

View File

@@ -1,15 +0,0 @@
<%= form_for [:moderation, administrator_task] do |f| %>
<div class="callout">
<h5><%=t '.proposal', title: administrator_task.source.proposal.title %></h5>
<p><%=t '.request', title: administrator_task.source.proposal_dashboard_action.title %></p>
<%== administrator_task.source.comments unless administrator_task.source.comments.blank? %>
<%= link_to t('.check_details'), proposal_path(administrator_task.source.proposal), target: '_blank' %>
</div>
<div class="row">
<div class="actions small-12 large-3 medium-3 column">
<%= f.submit(class: 'button expanded', value: t('.solve')) %>
</div>
</div>
<% end %>

View File

@@ -1,9 +0,0 @@
<div class="row">
<div class="small-12 column">
<%= back_link_to moderation_administrator_tasks_path, t('.back') %>
<h1><%= t('.solving') %></h1>
<%= render 'form' %>
</div>
</div>

View File

@@ -1,34 +0,0 @@
<h2 class="inline-block">
<%= AdministratorTask.model_name.human(count: 2) %>
</h2>
<table>
<thead>
<tr>
<th><%= AdministratorTask.human_attribute_name(:source) %></th>
<th></th>
</tr>
</thead>
<tbody>
<% if @administrator_tasks.empty? %>
<tr>
<td colspan="100%"><%= t '.no_records' %></td>
</tr>
<% end %>
<% @administrator_tasks.each do |task| %>
<tr id="<%= dom_id(task) %>">
<td>
<%= task.source.proposal.title %>:
<%= task.source.proposal_dashboard_action.title %>
</td>
<td style="text-align: right">
<%= link_to t('.solve'),
edit_moderation_administrator_task_path(task),
class: 'edit-banner button hollow' %>
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -545,6 +545,8 @@ en:
title_booths: Voting booths title_booths: Voting booths
legislation: Collaborative Legislation legislation: Collaborative Legislation
users: Users users: Users
proposals_dashboard: Proposals dashboard
administrator_tasks: Pending tasks
administrators: administrators:
index: index:
title: Administrators title: Administrators
@@ -1318,3 +1320,17 @@ en:
submit_header: Save header submit_header: Save header
card_title: Edit card card_title: Edit card
submit_card: Save card submit_card: Save card
administrator_tasks:
index:
solve: Solve
no_records: There are no pending tasks
edit:
back: Back to pending tasks list
solving: Solve pending task
form:
solve: Mark as solved
proposal: "The proposal: %{title}"
request: "Has requested: %{title}"
check_details: Check the proposal details
update:
success: The task has been marked as solved.

View File

@@ -49,7 +49,6 @@ en:
proposals: Proposals proposals: Proposals
proposal_notifications: Proposals notifications proposal_notifications: Proposals notifications
users: Block users users: Block users
administrator_tasks: Pending tasks
proposals: proposals:
index: index:
block_authors: Block authors block_authors: Block authors
@@ -96,17 +95,3 @@ en:
search_placeholder: email or name of user search_placeholder: email or name of user
title: Block users title: Block users
notice_hide: User blocked. All of this user's debates and comments have been hidden. notice_hide: User blocked. All of this user's debates and comments have been hidden.
administrator_tasks:
index:
solve: Solve
no_records: There are no pending tasks
edit:
back: Back to pending tasks list
solving: Solve pending task
form:
solve: Mark as solved
proposal: "The proposal: %{title}"
request: "Has requested: %{title}"
check_details: Check the proposal details
update:
success: The task has been marked as solved.

View File

@@ -545,6 +545,8 @@ es:
title_booths: Urnas de votación title_booths: Urnas de votación
legislation: Legislación colaborativa legislation: Legislación colaborativa
users: Usuarios users: Usuarios
proposals_dashboard: Panel de control de propuestas
administrator_tasks: Tareas pendientes
administrators: administrators:
index: index:
title: Administradores title: Administradores
@@ -1319,3 +1321,17 @@ es:
submit_header: Guardar encabezado submit_header: Guardar encabezado
card_title: Editar tarjeta card_title: Editar tarjeta
submit_card: Guardar tarjeta submit_card: Guardar tarjeta
administrator_tasks:
index:
solve: Resolver
no_records: No hay tareas pendientes
edit:
back: Volver a la lista de tareas pendientes
solving: Resolver tarea pendiente
form:
solve: Marcar como resuelta
proposal: "La propuesta: %{title}"
request: "Ha solicitado: %{title}"
check_details: Ver los detalles de la propuesta
update:
success: La tarea ha sido marcada como resuelta

View File

@@ -49,7 +49,6 @@ es:
proposals: Propuestas proposals: Propuestas
proposal_notifications: Notificaciones de propuestas proposal_notifications: Notificaciones de propuestas
users: Bloquear usuarios users: Bloquear usuarios
administrator_tasks: Tareas pendientes
proposals: proposals:
index: index:
block_authors: Bloquear autores block_authors: Bloquear autores
@@ -96,17 +95,3 @@ es:
search_placeholder: email o nombre de usuario search_placeholder: email o nombre de usuario
title: Bloquear usuarios title: Bloquear usuarios
notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios. notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios.
administrator_tasks:
index:
solve: Resolver
no_records: No hay tareas pendientes
edit:
back: Volver a la lista de tareas pendientes
solving: Resolver tarea pendiente
form:
solve: Marcar como resuelta
proposal: "La propuesta: %{title}"
request: "Ha solicitado: %{title}"
check_details: Ver los detalles de la propuesta
update:
success: La tarea ha sido marcada como resuelta

View File

@@ -196,5 +196,6 @@ namespace :admin do
resources :feeds, only: [:update] resources :feeds, only: [:update]
end end
resources :proposal_dashboard_actions, only: %i[index new create edit update destroy] resources :proposal_dashboard_actions, only: [:index, :new, :create, :edit, :update, :destroy]
resources :administrator_tasks, only: [:index, :edit, :update]
end end

View File

@@ -1,74 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Administrator tasks moderation' do
let(:moderator) { create(:moderator) }
before do
login_as moderator.user
end
context 'when accessing the pending task list' do
context 'and no pending task' do
before do
visit moderation_administrator_tasks_path
end
it 'informs that there are no pending tasks' do
expect(page).to have_content('There are no pending tasks')
end
end
context 'and there are pending tasks' do
let!(:task) { create :administrator_task, :pending }
before do
visit moderation_administrator_tasks_path
end
it 'shows the related proposal title' do
expect(page).to have_content(task.source.proposal.title)
end
it 'shows the requested action title' do
expect(page).to have_content(task.source.proposal_dashboard_action.title)
end
it 'has a link that allows solving the request' do
expect(page).to have_link('Solve')
end
end
end
context 'when solving a pending task' do
let!(:task) { create :administrator_task, :pending }
before do
visit moderation_administrator_tasks_path
click_link 'Solve'
end
it 'contains a link to the proposal' do
expect(page).to have_link('Check the proposal details')
end
it 'contains a button that solves the request' do
expect(page).to have_button('Mark as solved')
end
it 'shows the comments added by the user during the request' do
expect(page).to have_content(task.source.comments)
end
context 'and the Mark as solved button is pressed' do
before do
click_button 'Mark as solved'
end
it 'The proposal dissapears from the list' do
expect(page).not_to have_content(task.source.proposal.title)
end
end
end
end

View File

@@ -28,6 +28,8 @@ describe Abilities::Administrator do
let(:hidden_comment) { create(:comment, :hidden) } let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_proposal) { create(:proposal, :hidden) } let(:hidden_proposal) { create(:proposal, :hidden) }
let(:administrator_task) { create(:administrator_task) }
it { should be_able_to(:index, Debate) } it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) } it { should be_able_to(:show, debate) }
it { should be_able_to(:vote, debate) } it { should be_able_to(:vote, debate) }
@@ -88,4 +90,7 @@ describe Abilities::Administrator do
it { should_not be_able_to(:destroy, budget_investment_image) } it { should_not be_able_to(:destroy, budget_investment_image) }
it { should_not be_able_to(:destroy, budget_investment_document) } it { should_not be_able_to(:destroy, budget_investment_document) }
it { should be_able_to(:manage, ProposalDashboardAction) } it { should be_able_to(:manage, ProposalDashboardAction) }
it { is_expected.to be_able_to :manage, AdministratorTask }
it { is_expected.to be_able_to :manage, administrator_task }
end end

View File

@@ -21,7 +21,6 @@ describe Abilities::Moderator do
let(:hidden_debate) { create(:debate, :hidden) } let(:hidden_debate) { create(:debate, :hidden) }
let(:hidden_comment) { create(:comment, :hidden) } let(:hidden_comment) { create(:comment, :hidden) }
let(:hidden_proposal) { create(:proposal, :hidden) } let(:hidden_proposal) { create(:proposal, :hidden) }
let(:administrator_task) { create(:administrator_task) }
it { should be_able_to(:index, Debate) } it { should be_able_to(:index, Debate) }
it { should be_able_to(:show, debate) } it { should be_able_to(:show, debate) }
@@ -32,9 +31,6 @@ describe Abilities::Moderator do
it { should be_able_to(:read, Organization) } it { should be_able_to(:read, Organization) }
it { is_expected.to be_able_to :manage, AdministratorTask }
it { is_expected.to be_able_to :manage, administrator_task }
describe "organizations" do describe "organizations" do
let(:pending_organization) { create(:organization) } let(:pending_organization) { create(:organization) }
let(:rejected_organization) { create(:organization, :rejected) } let(:rejected_organization) { create(:organization, :rejected) }