Report generation. Download csv

This commit is contained in:
German Galia
2019-06-12 10:17:31 +02:00
parent 139b2720d8
commit 9d1ca3bfd4
63 changed files with 1528 additions and 40 deletions

View File

@@ -82,6 +82,7 @@
//= require managers
//= require globalize
//= require send_admin_notification_alert
//= require modal_download
//= require settings
var initialize_modules = function() {
@@ -130,6 +131,7 @@ var initialize_modules = function() {
App.Managers.initialize();
App.Globalize.initialize();
App.SendAdminNotificationAlert.initialize();
App.ModalDownload.initialize();
App.Settings.initialize();
};

View File

@@ -0,0 +1,9 @@
App.ModalDownload =
enableButton: ->
$("#js-download-modal-submit").attr("disabled", false)
$("#js-download-modal-submit").removeClass('disabled')
initialize: ->
$("#js-download-modal-submit").on "click", ->
setTimeout(App.ModalDownload.enableButton, 2000)

View File

@@ -1,6 +1,7 @@
class Admin::BudgetInvestmentsController < Admin::BaseController
include FeatureFlags
include CommentableActions
include DownloadSettingsHelper
feature_flag :budgets
@@ -18,7 +19,9 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
format.html
format.js
format.csv do
send_data Budget::Investment::Exporter.new(@investments).to_csv,
send_data to_csv(@investments, Budget::Investment),
type: "text/csv",
disposition: "attachment",
filename: "budget_investments.csv"
end
end

View File

@@ -0,0 +1,17 @@
class Admin::CommentsController < Admin::BaseController
include DownloadSettingsHelper
def index
@comments = Comment.sort_by_newest.page(params[:page])
respond_to do |format|
format.html
format.csv {send_data to_csv(Comment.sort_by_newest, Comment),
type: "text/csv",
disposition: "attachment",
filename: "comments.csv" }
end
end
end

View File

@@ -0,0 +1,20 @@
class Admin::DebatesController < Admin::BaseController
include FeatureFlags
include CommentableActions
include HasOrders
feature_flag :debates
has_orders %w[created_at]
def show
@debate = Debate.find(params[:id])
end
private
def resource_model
Debate
end
end

View File

@@ -0,0 +1,43 @@
class Admin::DownloadSettingsController < Admin::BaseController
include DownloadSettingsHelper
load_and_authorize_resource
def edit
permitted = downloadable_params
@download_settings = []
if permitted_models.include? permitted[:resource]
set_edit(permitted[:resource])
end
end
def update
permitted = downloadable_params
if permitted[:downloadable]
DownloadSetting.where(name_model: get_model(permitted[:resource]).to_s,
config: permitted[:config].to_i).each do |download_setting|
download_setting.update(downloadable: permitted[:downloadable]
.include?(download_setting.name_field))
end
end
set_edit(permitted[:resource])
render :edit, resource: permitted[:resource], config: permitted[:config]
end
private
def set_edit(resource)
@download_resource = {name: resource, config: get_config}
@download_settings = get_attrs(get_model(resource), get_config)
end
def permitted_models
["legislation_processes", "debates", "proposals", "budget_investments", "comments"]
end
def downloadable_params
params.permit(:resource,
:config,
downloadable: [])
end
end

View File

@@ -1,6 +1,7 @@
class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController
include Translatable
include ImageAttributes
include DownloadSettingsHelper
has_filters %w[active all], only: :index
@@ -9,6 +10,13 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
def index
@processes = ::Legislation::Process.send(@current_filter).order(start_date: :desc)
.page(params[:page])
respond_to do |format|
format.html
format.csv {send_data to_csv(process_for_download, Legislation::Process),
type: "text/csv",
disposition: "attachment",
filename: "legislation_processes.csv" }
end
end
def create
@@ -43,6 +51,10 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
private
def process_for_download
::Legislation::Process.send(@current_filter).order(start_date: :desc)
end
def process_params
params.require(:legislation_process).permit(allowed_params)
end

View File

@@ -3,6 +3,7 @@ class Admin::ProposalsController < Admin::BaseController
include CommentableActions
include FeatureFlags
feature_flag :proposals
helper DownloadSettingsHelper
has_orders %w[created_at]

View File

@@ -1,5 +1,6 @@
module Budgets
class ExecutionsController < ApplicationController
include DownloadSettingsHelper
before_action :load_budget
load_and_authorize_resource :budget
@@ -8,6 +9,19 @@ module Budgets
authorize! :read_executions, @budget
@statuses = Milestone::Status.all
@investments_by_heading = investments_by_heading_ordered_alphabetically.to_h
downloadables = []
investments_by_heading_ordered_alphabetically
.map { |heading| downloadables.concat heading[1] }
respond_to do |format|
format.html
format.csv { send_data to_csv(downloadables,
Budget::Investment,
1),
type: "text/csv",
disposition: "attachment",
filename: "budget_investment_milestones.csv" }
end
end
private

View File

@@ -2,6 +2,7 @@ module Budgets
class ResultsController < ApplicationController
before_action :load_budget
before_action :load_heading
include DownloadSettingsHelper
load_and_authorize_resource :budget
@@ -9,6 +10,14 @@ module Budgets
authorize! :read_results, @budget
@investments = Budget::Result.new(@budget, @heading).investments
@headings = @budget.headings.sort_by_name
respond_to do |format|
format.html
format.csv { send_data to_csv(@investments.compatible, Budget::Investment),
type: "text/csv",
disposition: "attachment",
filename: "budget_investment_results.csv" }
end
end
private

View File

@@ -2,6 +2,7 @@ module CommentableActions
extend ActiveSupport::Concern
include Polymorphic
include Search
include DownloadSettingsHelper
def index
@resources = resource_model.all
@@ -10,6 +11,7 @@ module CommentableActions
@resources = @resources.search(@search_terms) if @search_terms.present?
@resources = @advanced_search_terms.present? ? @resources.filter(@advanced_search_terms) : @resources
@resources = @resources.tagged_with(@tag_filter) if @tag_filter
resources_csv = @resources
@resources = @resources.page(params[:page]).send("sort_by_#{@current_order}")
@@ -21,6 +23,13 @@ module CommentableActions
set_resource_votes(@resources)
set_resources_instance
respond_to do |format|
format.html
format.csv {send_data to_csv(resources_csv, resource_model),
type: "text/csv",
disposition: "attachment",
filename: "#{get_resource(resource_model)}.csv" }
end
end
def show

View File

@@ -1,5 +1,6 @@
class Legislation::ProcessesController < Legislation::BaseController
include RandomSeed
include DownloadSettingsHelper
has_filters %w[open past], only: :index
has_filters %w[random winners], only: :proposals
@@ -12,6 +13,14 @@ class Legislation::ProcessesController < Legislation::BaseController
@current_filter ||= "open"
@processes = ::Legislation::Process.send(@current_filter).published
.not_in_draft.order(start_date: :desc).page(params[:page])
respond_to do |format|
format.html
format.csv { send_data to_csv(process_for_download, Legislation::Process),
type: "text/csv",
disposition: "attachment",
filename: "legislation_processes.csv" }
end
end
def show
@@ -122,6 +131,10 @@ class Legislation::ProcessesController < Legislation::BaseController
private
def process_for_download
Legislation::Process.send(@current_filter).order(start_date: :desc)
end
def member_method?
params[:id].present?
end

View File

@@ -0,0 +1,47 @@
module DownloadSettingsHelper
def get_model(resource_name)
case resource_name
when "legislation_processes"
Legislation::Process
when "budget_investments"
Budget::Investment
else
resource_name.singularize.classify.constantize
end
end
def get_attrs(model, config = 0)
download_settings = []
get_attr_names(model).each do |attr_name|
download_settings << DownloadSetting.initialize(model, attr_name, config)
end
download_settings
end
def get_attr_names(model)
model.attribute_names + model.get_association_attribute_names
end
def to_csv(resources_csv, resource_model, config = 0)
attribute_csv = resource_model.get_downloadables_names(config)
if admin_downloables?
attribute_csv = params[:downloadable]
end
resource_model.to_csv(resources_csv, attribute_csv)
end
def admin_downloables?
params[:downloadable].present? && !params[:downloadable].empty?
end
def get_resource(resource)
resource.to_s.pluralize.downcase
end
def get_config
params[:config].present? && !params[:config].nil? ? params[:config] : 0
end
end

View File

@@ -97,6 +97,8 @@ module Abilities
can [:deliver], Newsletter, hidden_at: nil
can [:manage], Dashboard::AdministratorTask
can [:edit, :update], DownloadSetting
end
end
end

View File

@@ -1,4 +1,5 @@
class Budget
require "csv"
class Investment < ApplicationRecord
SORTING_OPTIONS = {id: "id", title: "title", supports: "cached_votes_up"}.freeze
@@ -39,6 +40,9 @@ class Budget
has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: "Comment"
has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: "Comment"
extend DownloadSettings::BudgetInvestmentCsv
delegate :name, :email, to: :author, prefix: true
validates :title, presence: true
validates :author, presence: true
validates :description, presence: true

View File

@@ -1,8 +1,11 @@
require "csv"
class Comment < ApplicationRecord
include Flaggable
include HasPublicAuthor
include Graphqlable
include Notifiable
extend DownloadSettings::CommentCsv
COMMENTABLE_TYPES = %w[Debate Proposal Budget::Investment Poll Topic
Legislation::Question Legislation::Annotation

View File

@@ -0,0 +1,28 @@
module DownloadSettings
module BudgetInvestmentCsv
extend ActiveSupport::Concern
def get_association_attribute_names
["author_name", "author_email"]
end
def get_downloadables_names(config)
DownloadSetting.where(name_model: "Budget::Investment",
downloadable: true,
config: config).pluck(:name_field)
end
def to_csv(budgets, admin_attr, options = {})
attributes = admin_attr.nil? ? [] : admin_attr
CSV.generate(options) do |csv|
csv << attributes
budgets.each do |budget|
csv << attributes.map{ |attr| budget.send(attr)}
end
end
end
end
end

View File

@@ -0,0 +1,28 @@
module DownloadSettings
module CommentCsv
extend ActiveSupport::Concern
def get_association_attribute_names
["author_name", "author_email"]
end
def get_downloadables_names(config)
DownloadSetting.where(name_model: "Comment",
downloadable: true,
config: config).pluck(:name_field)
end
def to_csv(comments, admin_attr, options = {})
attributes = admin_attr.nil? ? [] : admin_attr
CSV.generate(options) do |csv|
csv << attributes
comments.each do |comment|
csv << attributes.map {|attr| comment.send(attr)}
end
end
end
end
end

View File

@@ -0,0 +1,28 @@
module DownloadSettings
module DebateCsv
extend ActiveSupport::Concern
def get_association_attribute_names
["author_name", "author_email"]
end
def get_downloadables_names(config)
DownloadSetting.where(name_model: "Debate",
downloadable: true,
config: config).pluck(:name_field)
end
def to_csv(debates, admin_attr, options = {})
attributes = admin_attr.nil? ? [] : admin_attr
CSV.generate(options) do |csv|
csv << attributes
debates.each do |debate|
csv << attributes.map{ |attr| debate.send(attr)}
end
end
end
end
end

View File

@@ -0,0 +1,28 @@
module DownloadSettings
module LegislationProcessCsv
extend ActiveSupport::Concern
def get_association_attribute_names
[]
end
def get_downloadables_names(config)
DownloadSetting.where(name_model: "Legislation::Process",
downloadable: true,
config: config).pluck(:name_field)
end
def to_csv(processes, admin_attr, options = {})
attributes = admin_attr.nil? ? [] : admin_attr
CSV.generate(options) do |csv|
csv << attributes
processes.each do |process|
csv << attributes.map{ |attr| process.send(attr)}
end
end
end
end
end

View File

@@ -0,0 +1,28 @@
module DownloadSettings
module ProposalCsv
extend ActiveSupport::Concern
def get_association_attribute_names
["author_name", "author_email"]
end
def get_downloadables_names(config)
DownloadSetting.where(name_model: "Proposal",
downloadable: true,
config: config).pluck(:name_field)
end
def to_csv(proposals, admin_attr, options = {})
attributes = admin_attr.nil? ? [] : admin_attr
CSV.generate(options) do |csv|
csv << attributes
proposals.each do |proposal|
csv << attributes.map {|attr| proposal.send(attr)}
end
end
end
end
end

View File

@@ -1,4 +1,6 @@
require "numeric"
require "csv"
class Debate < ApplicationRecord
include Rails.application.routes.url_helpers
include Flaggable
@@ -22,6 +24,9 @@ class Debate < ApplicationRecord
belongs_to :geozone
has_many :comments, as: :commentable
extend DownloadSettings::DebateCsv
delegate :name, :email, to: :author, prefix: true
validates :title, presence: true
validates :description, presence: true
validates :author, presence: true

View File

@@ -0,0 +1,18 @@
class DownloadSetting < ActiveRecord::Base
validates :name_model, presence: true
validates :name_field, presence: true
def self.initialize(model, field_name, config)
download_setting = DownloadSetting.find_by(name_model: model.name,
name_field: field_name,
config: config)
if download_setting.nil?
download_setting = DownloadSetting.create(downloadable: false,
name_model: model.name,
name_field: field_name,
config: config)
end
download_setting
end
end

View File

@@ -1,3 +1,5 @@
require "csv"
class Legislation::Process < ApplicationRecord
include ActsAsParanoidAliases
include Taggable
@@ -15,6 +17,7 @@ class Legislation::Process < ApplicationRecord
translates :milestones_summary, touch: true
translates :homepage, touch: true
include Globalizable
extend DownloadSettings::LegislationProcessCsv
PHASES_AND_PUBLICATIONS = %i[homepage_phase draft_phase debate_phase allegations_phase
proposals_phase people_proposals_phase draft_publication

View File

@@ -1,3 +1,5 @@
require "csv"
class Proposal < ApplicationRecord
include Rails.application.routes.url_helpers
include Flaggable
@@ -34,6 +36,12 @@ class Proposal < ApplicationRecord
has_many :dashboard_actions, through: :dashboard_executed_actions, class_name: "Dashboard::Action"
has_many :polls, as: :related
extend DownloadSettings::ProposalCsv
delegate :name, :email, to: :author, prefix: true
extend DownloadSettings::ProposalCsv
delegate :name, :email, to: :author, prefix: true
validates :title, presence: true
validates :summary, presence: true
validates :author, presence: true

View File

@@ -9,6 +9,22 @@
</li>
<% end %>
<% if feature?(:debates) %>
<li class="section-title <%= "is-active" if controller_name == "debates" %>">
<%= link_to admin_debates_path do %>
<span class="icon-debates"></span>
<strong><%= t("admin.menu.debates") %></strong>
<% end %>
</li>
<% end %>
<li class="section-title <%= "is-active" if controller_name == "comments" %>">
<%= link_to admin_comments_path do %>
<span class="icon-comments"></span>
<strong><%= t("admin.menu.comments") %></strong>
<% end %>
</li>
<% if feature?(:polls) %>
<li class="section-title <%= "is-active" if menu_polls? %>">
<%= link_to admin_polls_path do %>
@@ -212,6 +228,50 @@
<% end %>
</li>
<li class="section-title">
<a href="#">
<span class="icon-arrow-down"></span>
<strong><%= t("admin.menu.download_settings.title") %></strong>
</a>
<ul <%= "class=is-active" if controller_name == "download_settings" %>>
<% if feature?(:debates) %>
<li <%= "class=is-active" if !@download_resource.nil? && @download_resource == "debates" %>>
<%= link_to t("admin.menu.download_settings.debates"), admin_edit_download_settings_path(resource: "debates") %>
</li>
<% end %>
<% if feature?(:proposals) %>
<li <%= "class=is-active" if !@download_resource.nil? && @download_resource == "proposals" %>>
<%= link_to t("admin.menu.download_settings.proposals"), admin_edit_download_settings_path(resource: "proposals") %>
</li>
<% end %>
<% if feature?(:legislation) %>
<li <%= "class=is-active" if !@download_resource.nil? && @download_resource == "legislation_processes" %>>
<%= link_to t("admin.menu.download_settings.legislation_processes"), admin_edit_download_settings_path(resource: "legislation_processes") %>
</li>
<% end %>
<% if feature?(:budgets) %>
<li <%= "class=is-active" if !@download_resource.nil? && @download_resource == "budget_investments" %>>
<%= link_to t("admin.menu.download_settings.budget_investments"), admin_edit_download_settings_path(resource: "budget_investments") %>
</li>
<% end %>
<% if feature?(:budgets) %>
<li <%= "class=is-active" if !@download_resource.nil? && @download_resource == "budget_investments" %>>
<%= link_to t("admin.menu.download_settings.budget_investments_milestones"), admin_edit_download_settings_path(resource: "budget_investments", config: 1) %>
</li>
<% end %>
<li <%= "class=is-active" if !@download_resource.nil? && @download_resource == "comments" %>>
<%= link_to t("admin.menu.download_settings.comments"), admin_edit_download_settings_path(resource: "comments") %>
</li>
</ul>
</li>
<li class="section-title">
<a href="#">
<span class="icon-settings"></span>

View File

@@ -1,6 +1,4 @@
<%= link_to t("admin.budget_investments.index.download_current_selection"),
admin_budget_budget_investments_path(csv_params),
class: "float-right small clear" %>
<a class="small float-right clear" data-open="download-modal"><%= t("admin.budget_investments.index.download_current_selection") %></a>
<% if params[:advanced_filters].include?("winners") %>
@@ -62,3 +60,5 @@
<%= t("admin.budget_investments.index.no_budget_investments") %>
</div>
<% end %>
<%= render "admin/download_settings/modal", resource: { name: "budget_investments" } %>

View File

@@ -0,0 +1,49 @@
<% provide(:title) do %>
<%= t("admin.header.title") %> - <%= t("admin.comments.index.title") %>
<% end %>
<h2><%= t("admin.comments.index.title") %></h2>
<% if @comments.any? %>
<h3 class="inline-block"><%= page_entries_info @comments %></h3>
<a class="small float-right clear" data-open="download-modal"><%= t("admin.comments.index.link") %></a>
<table>
<thead>
<tr>
<th class="text-center"><%= t("admin.comments.index.id") %></th>
<th><%= t("admin.comments.index.content") %></th>
<th><%= t("admin.comments.index.author") %></th>
<th><%= t("admin.comments.index.commentable_type") %></th>
<th><%= t("admin.comments.index.table_link") %></th>
</tr>
</thead>
<tbody>
<% @comments.each do |comment| %>
<tr id="<%= dom_id(comment) %>" class="debates">
<td class="text-center"><%= comment.id %></td>
<td><%= comment.body %></td>
<td><%= comment.author.username %></td>
<td><%= comment.commentable_type.constantize.model_name.human %></td>
<td>
<% if comment.commentable.hidden? %>
(<%= t("admin.comments.index.hidden_#{comment.commentable_type.downcase}") %>: <%= comment.commentable.title %>)
<% else %>
<%= link_to comment.commentable.title, commentable_path(comment) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @comments %>
<% else %>
<div class="callout primary margin">
<%= t("admin.comments.index.no_comments") %>
</div>
<% end %>
<%= render "admin/download_settings/modal", resource: { name: "comments" } %>

View File

@@ -0,0 +1,38 @@
<% provide(:title) do %>
<%= t("admin.header.title") %> - <%= t("admin.debates.index.title") %>
<% end %>
<h2><%= t("admin.debates.index.title") %></h2>
<% if @debates.any? %>
<%= render "/admin/shared/debate_search", url: admin_debates_path %>
<h3 class="inline-block"><%= page_entries_info @debates %></h3>
<a class="small float-right clear" data-open="download-modal"><%= t("admin.debates.index.link") %></a>
<table>
<thead>
<th class="text-center"><%= t("admin.debates.index.id") %></th>
<th><%= t("admin.debates.index.title") %></th>
<th><%= t("admin.debates.index.author") %></th>
</thead>
<tbody>
<% @debates.each do |debate| %>
<tr id="<%= dom_id(debate) %>" class="debates">
<td class="text-center"><%= debate.id %></td>
<td><%= link_to debate.title, admin_debate_path(debate) %></td>
<td><%= debate.author.username %></td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @debates %>
<% else %>
<div class="callout primary margin">
<%= t("admin.debates.index.no_debates") %>
</div>
<% end %>
<%= render "admin/download_settings/modal", resource: { name: "debates" } %>

View File

@@ -0,0 +1,56 @@
<% provide :title do %>
<%= t("admin.header.title") %> - <%= t("admin.menu.debates") %> - <%= @debate.title %>
<% end %>
<div class="debate-show">
<h2><%= @debate.title %></h2>
<% if @debate.conflictive? %>
<div data-alert class="callout alert margin-top">
<strong><%= t("debates.show.flag") %></strong>
</div>
<% end %>
<div class="debate-info">
<%= render '/shared/author_info', resource: @debate %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l @debate.created_at.to_date %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="icon-comments"></span>&nbsp;
<%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="js-flag-actions">
<%= render 'debates/flag_actions', debate: @debate %>
</span>
</div>
<%= safe_html_with_links @debate.description %>
<h3><%= t("votes.supports") %></h3>
<span class="total-votes">
<%= t("debates.debate.votes", count: @debate.votes_score) %>
</span>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<div class="in-favor inline-block">
<span class="icon-like">
<span class="show-for-sr"><%= t('votes.agree') %></span>
</span>
<span class="percentage"><%= votes_percentage('likes', @debate) %></span>
</div>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<div class="against inline-block">
<span class="icon-unlike">
<span class="show-for-sr"><%= t('votes.disagree') %></span>
</span>
<span class="percentage"><%= votes_percentage('dislikes', @debate) %></span>
</div>
</div>
<%= render 'shared/tags', taggable: @debate %>

View File

@@ -0,0 +1,19 @@
<table>
<thead>
<tr>
<th><%= t("download.edit.fields") %></th>
<th><%= t("download.edit.description") %></th>
<th class="small"><%= t("download.edit.downloadable") %></th>
</tr>
</thead>
<tbody>
<% download_settings.each do |attr| %>
<tr>
<td><%= attr.name_field %></td>
<td><%= t("download.fielddescription.#{resource[:name]}.#{attr.name_field}", default: "") %></td>
<td class="text-center small"><%= check_box_tag "downloadable[]", attr.name_field, attr.downloadable, class: "js-download-settings-check" %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,30 @@
<% if params[:search].present? %>
<%= hidden_field_tag "search", params[:search] %>
<% end %>
<% if params[:commit].present? %>
<%= hidden_field_tag "commit", params[:commit] %>
<% end %>
<% if params[:filter].present? %>
<%= hidden_field_tag "filter", params[:filter] %>
<% end %>
<% if params[:page].present? %>
<%= hidden_field_tag "page", params[:page] %>
<% end %>
<% if params[:administrator_id].present? %>
<%= hidden_field_tag "administrator_id", params[:administrator_id] %>
<% end %>
<% if params[:valuator_or_group_id].present? %>
<%= hidden_field_tag "valuator_or_group_id", params[:valuator_or_group_id] %>
<% end %>
<% if params[:heading_id].present? %>
<%= hidden_field_tag "heading_id", params[:heading_id] %>
<% end %>
<% if params[:title_or_id].present? %>
<%= hidden_field_tag "title_or_id", params[:title_or_id] %>
<% end %>
<% if params[:tag_name].present? %>
<%= hidden_field_tag "tag_name", params[:tag_name] %>
<% end %>
<% if params[:min_total_supports].present? %>
<%= hidden_field_tag "min_total_supports", params[:min_total_supports] %>
<% end %>

View File

@@ -0,0 +1,13 @@
<div class="small reveal" id="download-modal" data-reveal>
<h1><%= t('download.modal.title') %></h1>
<%= form_tag current_path_with_query_params(format: :csv), method: :get do |f| %>
<%= render 'admin/download_settings/form_hidden_params' %>
<%= render 'admin/download_settings/form', resource: resource, download_settings: get_attrs(get_model(resource[:name])) %>
<div class="medium-5 column clear end">
<button type="submit" data-close id="js-download-modal-submit" class="button success expanded"><%= t("download.modal.submit") %></button>
</div>
<% end %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>

View File

@@ -0,0 +1,16 @@
<% unless @download_settings.empty? %>
<% provide(:title) do %>
<%= t("admin.header.title") %> - <%= t("download.edit.#{@download_resource[:name]}") %>
<% end %>
<h2><%= t("download.edit.#{@download_resource[:name]}") %> <%= t("download.edit.config.#{@download_resource[:config].to_s}") unless @download_resource[:config] == 0 %></h2>
<%= form_tag admin_update_download_settings_path(resource: @download_resource[:name], config: @download_resource[:config]), method: :put do %>
<%= render 'form', resource: @download_resource, download_settings: @download_settings %>
<div class="small-12 medium-3 column clear end">
<%= submit_tag t("download.edit.submit"), class: "button success expanded" %>
</div>
<% end %>
<% end %>

View File

@@ -9,8 +9,8 @@
<table>
<thead>
<th scope="col" class="small-8"><%= t("admin.shared.description") %></th>
<th scope="col"><%= t("admin.shared.actions") %></th>
<th scope="col" class="small-8"><%= t("admin.shared.description") %></th>
<th scope="col"><%= t("admin.shared.actions") %></th>
</thead>
<tbody>
<% @comments.each do |comment| %>
@@ -25,15 +25,15 @@
</td>
<td>
<%= link_to t("admin.actions.restore"),
restore_admin_hidden_comment_path(comment, request.query_parameters),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button hollow warning" %>
restore_admin_hidden_comment_path(comment, request.query_parameters),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button hollow warning" %>
<% unless comment.confirmed_hide? %>
<%= link_to t("admin.actions.confirm_hide"),
confirm_hide_admin_hidden_comment_path(comment, request.query_parameters),
method: :put,
class: "button" %>
confirm_hide_admin_hidden_comment_path(comment, request.query_parameters),
method: :put,
class: "button" %>
<% end %>
</td>
</tr>

View File

@@ -9,9 +9,9 @@
<table>
<thead>
<th scope="col"><%= t("admin.shared.title") %></th>
<th scope="col" class="small-6"><%= t("admin.shared.description") %></th>
<th scope="col" class="small-4"><%= t("admin.shared.actions") %></th>
<th scope="col"><%= t("admin.shared.title") %></th>
<th scope="col" class="small-6"><%= t("admin.shared.description") %></th>
<th scope="col" class="small-4"><%= t("admin.shared.actions") %></th>
</thead>
<tbody>
<% @debates.each do |debate| %>
@@ -26,15 +26,15 @@
</td>
<td class="align-top">
<%= link_to t("admin.actions.restore"),
restore_admin_hidden_debate_path(debate, request.query_parameters),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button hollow warning" %>
restore_admin_hidden_debate_path(debate, request.query_parameters),
method: :put,
data: { confirm: t("admin.actions.confirm") },
class: "button hollow warning" %>
<% unless debate.confirmed_hide? %>
<%= link_to t("admin.actions.confirm_hide"),
confirm_hide_admin_hidden_debate_path(debate, request.query_parameters),
method: :put,
class: "button" %>
confirm_hide_admin_hidden_debate_path(debate, request.query_parameters),
method: :put,
class: "button" %>
<% end %>
</td>
</tr>

View File

@@ -12,6 +12,8 @@
<% if @processes.any? %>
<h3><%= page_entries_info @processes %></h3>
<a class="small float-right clear" data-open="download-modal"><%= t("admin.legislation.processes.index.link") %></a>
<table class="stack">
<thead>
<tr>
@@ -50,3 +52,5 @@
<%= page_entries_info @processes %>
</div>
<% end %>
<%= render "admin/download_settings/modal", resource: { name: "legislation_processes" } %>

View File

@@ -7,7 +7,9 @@
<% if @proposals.any? %>
<%= render "/admin/shared/proposal_search", url: admin_proposals_path %>
<h3><%= page_entries_info @proposals %></h3>
<h3 class="inline-block"><%= page_entries_info @proposals %></h3>
<a class="small float-right clear" data-open="download-modal"><%= t("admin.proposals.index.link") %></a>
<table>
<thead>
@@ -39,3 +41,5 @@
<%= t("admin.proposals.index.no_proposals") %>
</div>
<% end %>
<%= render "admin/download_settings/modal", resource: { name: "proposals" } %>

View File

@@ -0,0 +1,10 @@
<%= form_for(Debate.new, url: url, as: :debate, method: :get) do |f| %>
<div class="small-12 medium-6">
<div class="input-group">
<%= text_field_tag :search, "", placeholder: t("admin.shared.debate_search.placeholder") %>
<div class="input-group-button">
<%= f.submit t("admin.shared.debate_search.button"), class: "button" %>
</div>
</div>
</div>
<% end %>

View File

@@ -42,6 +42,10 @@
</div>
<div class="small-12 medium-9 large-10 column">
<%= link_to t("shared.download.link.investments"), current_path_with_query_params(format: :csv),
class: "button hollow margin-bottom margin-right float-right-medium" %>
<%= form_tag(budget_executions_path(@budget), method: :get) do %>
<div class="small-12 medium-3 column">
<%= label_tag :milestone_tag, t("budgets.executions.filters.milestone_tag.label") %>

View File

@@ -48,6 +48,9 @@
data: {"toggle-selector" => ".js-discarded",
"toggle-text" => t("budgets.results.hide_discarded_link")} %>
<%= link_to t("shared.download.link.investments"), current_path_with_query_params(format: :csv),
class: "button hollow margin-bottom margin-right float-right-medium" %>
<%= render "results_table", results_type: :compatible,
title: @heading.name,
heading_price: @heading.price,

View File

@@ -98,6 +98,7 @@
<aside class="margin-bottom">
<%= link_to t("debates.index.start_debate"), new_debate_path, class: "button expanded" %>
<%= render "shared/tag_cloud", taggable: "debate" %>
<%= render "shared/download_links", downloadable: 'debate' %>
</aside>
</div>

View File

@@ -25,6 +25,14 @@
</p>
<p><%= t("legislation.processes.index.section_footer.description") %></p>
</div>
</div>
</div>
<div class="small-12 medium-3 column">
<aside class="margin-bottom">
<%= render "shared/download_links", downloadable: 'legislation_process' %>
</aside>
</div>
</div>

View File

@@ -139,6 +139,7 @@
<% end %>
<%= render "retired" %>
<%= render "proposals_lists" %>
<%= render "shared/download_links", downloadable: "proposal" %>
</aside>
</div>

View File

@@ -0,0 +1,4 @@
<div class="sidebar-divider"></div>
<h2 class="sidebar-title"><%= t("shared.download.title") %></h2>
<p><%= link_to t("shared.download.link.#{downloadable}"), current_path_with_query_params(format: :csv), class: "small" %></p>

View File

@@ -46,6 +46,7 @@ data:
- config/locales/%{locale}/i18n.yml
- config/locales/%{locale}/milestones.yml
- config/locales/%{locale}/stats.yml
- config/locales/%{locale}/download.yml
# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
@@ -189,6 +190,7 @@ ignore_unused:
- "legislation.processes.proposals.filters.*"
- "helpers.page_entries_info.*" # kaminari
- "views.pagination.*" # kaminari
- "shared.download.*"
- "shared.suggest.*"
- "invisible_captcha.*"
- "admin.site_customization.pages.page.status_*"

View File

@@ -357,6 +357,16 @@ en:
notice: "Progress bar updated successfully"
delete:
notice: "Progress bar deleted successfully"
comments:
index:
id: "ID"
content: "Content"
author: "Author"
commentable_type: "Type"
link: "Download comments"
title: Comments
no_comments: There is no comments.
table_link: "Link"
hidden_comments:
index:
filter: Filter
@@ -432,6 +442,13 @@ en:
request: Requested resource
update:
success: The task has been marked as solved.
debates:
index:
id: ID
author: Author
title: Debates
no_debates: There is no debates.
link: "Download debates"
hidden_debates:
index:
filter: Filter
@@ -522,6 +539,7 @@ en:
filters:
active: Active
all: All
link: "Download legislation process"
new:
back: Back
title: Create new collaborative legislation process
@@ -725,6 +743,16 @@ en:
dashboard: Proposals dashboard
administrator_tasks: Resources requested
dashboard_actions: Resources and actions
download_settings:
title: "Download settings"
debates: "Debates"
proposals: "Proposals"
legislation_processes: "Legislation process"
budget_investments: "Participatory budgeting"
comments: "Comments"
budget_investments_milestones: "Participatory budgeting (Milestones)"
debates: "Debates"
comments: "Comments"
administrators:
index:
title: Administrators
@@ -1240,6 +1268,7 @@ en:
selected: Selected
milestones: Milestones
no_proposals: There are no proposals.
link: "Download proposals"
show:
create_question: Add this proposal to a poll to be voted
form:
@@ -1309,6 +1338,9 @@ en:
proposal_search:
button: Search
placeholder: Search proposals by title, code, description or question
debate_search:
button: Search
placeholder: Search debates by title or description
user_search:
button: Search
placeholder: Search user by name or email

View File

@@ -0,0 +1,170 @@
en:
download:
edit:
fields: "Fields"
description: "Description"
downloadable: "Downloadable"
debates: "Debates"
proposals: "Proposals"
legislation_processes: "Legislation process"
budget_investments: "Participatory budgeting"
comments: "Comments"
submit: "Save changes"
config:
"0": ""
"1": "- Milestones"
fielddescription:
debates:
id: "Identification Number"
title: "Title"
description: "Description"
author_id: "Author Identification Number"
created_at: "Created at"
updated_at: "Updated at"
visit_id: "Visit id"
hidden_at: "Hidden at"
flags_count: "Flags count"
ignored_flag_at: "Ignored flag at"
cached_votes_total: "Cached votes total"
cached_votes_up: "Cached votes up"
cached_votes_down: "Cached votes down"
comments_count: "Comments count"
confirmed_hide_at: "Confirmed hide at"
cached_anonymous_votes_total: "Cached anonymous votes total"
cached_votes_score: "Cached votes score"
hot_score: "Hot score"
confidence_score: "Confidence score"
geozone_id: "Geozone id"
tsv: "Tsv"
featured_at: "Featured at"
author_name: "Author name"
author_email: "Author email"
proposals:
id: "Identification Number"
title: "Title"
description: "Description"
question: "Question"
external_url: "External Url"
author_id: "Author Identification Number"
hidden_at: "Hidden at"
flags_count: "Flags count"
ignored_flag_at: "Ignored flag at"
cached_votes_up: "Cached votes up"
comments_count: "Comments count"
confirmed_hide_at: "Confirmed hide at"
hot_score: "Hot Score"
confidence_score: "Confidence Score"
created_at: "Created at"
updated_at: "Updated at"
responsible_name: "Responsible name"
summary: "Summary"
video_url: "Video url"
tsv: "Tsv"
geozone_id: "Geozone id"
retired_at: "Retired at"
retired_reason: "Retired reason"
retired_explanation: "Retired Explanation"
community_id: "Community id"
author_name: "Author name"
author_email: "Author email"
legislation_processes:
id: "Identification Number"
title: "Title"
description: "Description"
additional_info: "Additional Info"
start_date: "Start date"
end_date: "End date"
debate_start_date: "Debate start date"
debate_end_date: "Debate end date"
draft_publication_date: "Draft publication date"
allegations_start_date: "Allegation start date"
allegations_end_date: "Allegation end date"
result_publication_date: "Result publication date"
hidden_at: "Hidden at"
created_at: "Created at"
updated_at: "Updated at"
summary: "Summary"
debate_phase_enabled: "Debate phase enabled"
allegations_phase_enabled: "Allegations phase enabled"
draft_publication_enabled: "Draft publication enabled"
result_publication_enabled: "Result publication enabled"
published: "Published"
proposals_phase_start_date: "Proposals phase start date"
proposals_phase_end_date: "Proposals phase end date"
proposals_phase_enabled: "Proposal phase enabled"
proposals_description: "Proposals description"
draft_start_date: "Draft start date"
draft_end_date: "Draft end date"
draft_phase_enabled: "Draft phase enabled"
homepage_enabled: "Homepage enabled"
background_color: "Background color"
font_color: "Font color"
budget_investments:
id: "Identification Number"
author_id: "Author id"
administrator_id: "Administrator id"
title: "Title"
description: "Description"
external_url: "External url"
price: "Price"
feasibility: "Feasibility"
price_explanation: "Price explanation"
unfeasibility_explanation: "Unfeasibility explanation"
valuation_finished: "Valuation finished"
valuator_assignments_count: "Valuator assignments count"
price_first_year: "Price first year"
duration: "Duration"
hidden_at: "Hidden at"
cached_votes_up: "Cached votes up"
comments_count: "Comments count"
confidence_score: "Confidence score"
physical_votes: "Physical votes"
tsv: "Tsv"
created_at: "Created at"
updated_at: "Updated at"
heading_id: "Heading id"
responsible_name: "Responsible name"
budget_id: "Budget id"
group_id: "Group id"
selected: "Selected"
location: "Location"
organization_name: "Organization name"
unfeasible_email_sent_at: "Unfeasible email sent at"
ballot_lines_count: "Ballot lines count"
previous_heading_id: "Previous heading id"
winner: "Winner"
incompatible: "Incompatible"
community_id: "Commmunity id"
visible_to_valuators: "Visible to valuators"
valuator_group_assignments_count: "Valuator group assignments count"
confirmed_hide_at: "Confirmed hide at"
ignored_flag_at: "Ignored flag at"
flags_count: "Flags count"
author_name: "Author name"
author_email: "Author email"
comments:
id: "Identification Number"
commentable_id: "Commentable id"
commentable_type: "Commentable type"
body: "Body"
subject: "Subject"
user_id: "User id"
created_at: "Created at"
updated_at: "Updated at"
hidden_at: "Hidden at"
flags_count: "Flags count"
ignored_flag_at: "Ignored flag at"
moderator_id: "Moderator id"
administrator_id: "Administrator id"
cached_votes_total: "Cached votes total"
cached_votes_up: "Cached votes up"
cached_votes_down: "Cached votes down"
confirmed_hide_at: "Confirmed hide at"
ancestry: "Ancestry"
confidence_score: "Confidance score"
valuation: "Valuation"
author_name: "Author name"
author_email: "Author email"
modal:
title: "Download"
submit: "Download"

View File

@@ -794,6 +794,14 @@ en:
title: Recommendations
see_more: See more recommendations
hide: Hide recommendations
download:
title: "Downloads"
link:
proposal: "Download proposals"
debate: "Download debates"
legislation_process: "Download legislation processes"
budget: "Download budgets"
investments: "Download projects"
social:
facebook: "%{org} Facebook"
twitter: "%{org} Twitter"

View File

@@ -357,6 +357,18 @@ es:
notice: "Barra de progreso actualizada"
delete:
notice: "Barra de progreso eliminada correctamente"
comments:
index:
id: "ID"
content: "Contenido"
author: "Autor"
commentable_type: "Tipo"
link: "Descargar comentarios"
title: Comentarios
no_comments: No hay comentarios.
hidden_debate: Debate oculto
hidden_proposal: Propuesta oculta
table_link: "Link"
hidden_comments:
index:
filter: Filtro
@@ -432,6 +444,13 @@ es:
request: Recurso solicitado
update:
success: La tarea ha sido marcada como resuelta
debates:
index:
id: ID
author: Autor
title: Debates
no_debates: No hay debates.
link: "Descargar debates"
hidden_debates:
index:
filter: Filtro
@@ -522,6 +541,7 @@ es:
filters:
active: Activos
all: Todos
link: "Descargar procesos legislativos"
new:
back: Volver
title: Crear nuevo proceso de legislación colaborativa
@@ -724,6 +744,16 @@ es:
dashboard: Panel de progreso de propuestas
administrator_tasks: Recursos solicitados
dashboard_actions: Recursos y acciones
download_settings:
title: "Configuración de descarga"
debates: "Debates"
proposals: "Propuestas"
legislation_processes: "Procesos legislativos"
budget_investments: "Pressupuestos participativos"
comments: "Comentarios"
budget_investments_milestones: "Pressupuestos participativos (Seguimiento)"
debates: "Debates"
comments: "Comentarios"
administrators:
index:
title: Administradores
@@ -1239,6 +1269,7 @@ es:
select: Seleccionar
selected: Seleccionada
no_proposals: No hay propuestas.
link: "Descargar propuestas"
show:
create_question: Añadir esta propuesta a una votación para ser votada
form:

View File

@@ -0,0 +1,170 @@
es:
download:
edit:
fields: "Campos"
description: "Descripción"
downloadable: "Descargable"
debates: "Debates"
proposals: "Propuestas"
legislation_processes: "Procesos legislativos"
budget_investments: "Pressupuestos participativos"
comments: "Comentarios"
submit: "Guardar cambios"
config:
"0": ""
"1": "- Seguimiento"
fielddescription:
debates:
id: "Número de Identificación"
title: "Título"
description: "Descripción"
author_id: "Número de Identificación del Autor"
created_at: "Creado el"
updated_at: "Actualizado el"
hidden_at: "Ocultado el"
visit_id: "Núm. Identificación de vísita"
flags_count: "Núm. de denúncias"
ignored_flag_at: "Denúncia ignorada el"
cached_votes_total: "Total de votos"
cached_votes_up: "Votos positivos"
cached_votes_down: "Votos negativos"
comments_count: "Núm. de comentarios"
confirmed_hide_at: "Confirmado ocultado el"
cached_anonymous_votes_total: "Total votos anónimos"
cached_votes_score: "Puntuación votos"
hot_score: "Hot score"
confidence_score: "Puntuación de confianza"
geozone_id: "Núm. Identificación de zona"
tsv: "Tsv"
featured_at: "Presentado el"
author_name: "Nombre del autor"
author_email: "Email del autor"
proposals:
id: "Número de Identificación"
title: "Título"
description: "Descripción"
question: "Pregunta"
external_url: "URL externa"
author_id: "Número de Identificación del Autor"
flags_count: "Núm. de denúncias"
ignored_flag_at: "Denúncia ignorada el"
cached_votes_up: "Votos positivos"
comments_count: "Núm. de comentarios"
confirmed_hide_at: "Confirmado ocultado el"
hot_score: "Hot Score"
confidence_score: "Puntuación de confianza"
created_at: "Creado el"
updated_at: "Actualizado el"
hidden_at: "Ocultado el"
responsible_name: "Nombre del responsable"
summary: "Resumen"
video_url: "URL del vídeo"
tsv: "Tsv"
geozone_id: "Núm. Identificación de zona"
retired_at: "Retirado el"
retired_reason: "Razón de retirada"
retired_explanation: "Explicación de retirada"
community_id: "Núm. Identificación de la comunidad"
author_name: "Nombre del autor"
author_email: "Email del autor"
legislation_processes:
id: "Número de Identificación"
title: "Título"
description: "Descripción"
additional_info: "Información adicional"
start_date: "Fecha de início"
end_date: "Fecha de finalización"
debate_start_date: "Fecha de inicio del debate"
debate_end_date: "Fecha de finalización del debate"
draft_publication_date: "Fecha de publicación del borrador"
allegations_start_date: "Fecha de inicio de las alegaciones"
allegations_end_date: "Fecha de finalización de las alegaciones"
result_publication_date: "Fecha de publicación de resultados"
created_at: "Creado el"
updated_at: "Actualizado el"
hidden_at: "Ocultado el"
summary: "Resumen"
debate_phase_enabled: "Fase de debate activa"
allegations_phase_enabled: "Fase de alegaciones activa"
draft_publication_enabled: "Publicación del borrador activa"
result_publication_enabled: "Publicación de los resltados activa"
published: "Publicado"
proposals_phase_start_date: "Fecha de inicio de la fase de propuestas"
proposals_phase_end_date: "Fecha de finalización de la fase de propuestas"
proposals_phase_enabled: "Fase de propuestas activa"
proposals_description: "Descripción de propuestas"
draft_start_date: "Fecha de inicio del borrador"
draft_end_date: "Fecha de finalización del borrador"
draft_phase_enabled: "Fase de borrador activa"
homepage_enabled: "Página principal activa"
background_color: "color de fondo"
font_color: "Color de fuente"
budget_investments:
id: "Número de Identificación"
author_id: "Núm. de identificación"
administrator_id: "Núm. de identificación del administrador"
title: "Título"
description: "Descripción"
external_url: "URL externa"
price: "Precio"
feasibility: "Factibilidad"
price_explanation: "Explicación del precio"
unfeasibility_explanation: "Explicación de la infactibilidad"
valuation_finished: "Evaluación finalizada"
valuator_assignments_count: "Núm. de asignaciones del evaluador"
price_first_year: "Precio primer año"
duration: "Duración"
hidden_at: "Ocultado el"
cached_votes_up: "Votos positivos"
comments_count: "Núm. de comentarios"
confidence_score: "Puntuación de confianza"
physical_votes: "Votos físicos"
tsv: "Tsv"
created_at: "Creado el"
updated_at: "Actualizado el"
heading_id: "Núm. de identificación de título"
responsible_name: "Nombre del responsable"
budget_id: "Núm. de identificación del presupuesto"
group_id: "Núm. de identificación del grupo"
selected: "Seleccionado"
location: "Localización"
organization_name: "Nombre de la organización"
unfeasible_email_sent_at: "Correo de infactibilidad enviado el"
ballot_lines_count: "Núm. de líneas de votación"
previous_heading_id: "Núm. de identificación del título anterior"
winner: "Ganador"
incompatible: "Incompatible"
community_id: "Núm. de identificación de la comunidad"
visible_to_valuators: "Visible a los evaluadores"
valuator_group_assignments_count: "Núm. de asignaciones al grupo de evaluación"
confirmed_hide_at: "Confirmado ocultado el"
flags_count: "Núm. de denúncias"
ignored_flag_at: "Denúncia ignorada el"
author_name: "Nombre del autor"
author_email: "Email del autor"
comments:
id: "Número de Identificación"
commentable_id: "Núm. identificación del comentable"
commentable_type: "Tipo del comentable"
body: "Body"
subject: "Tma"
user_id: "Núm. identificación del usuario"
created_at: "Creado el"
updated_at: "Actualizado el"
hidden_at: "Ocultado el"
flags_count: "Núm. de denúncias"
ignored_flag_at: "Denúncia ignorada el"
moderator_id: "Núm. identificación del moderador"
administrator_id: "Núm. identificación del administrador"
cached_votes_total: "Total de votos"
cached_votes_up: "Votos positivos"
cached_votes_down: "Votos negativos"
confirmed_hide_at: "Confirmado ocultado el"
ancestry: "Ascendencia"
confidence_score: "Puntuación de confianza"
valuation: "Evaluación"
author_name: "Nombre del autor"
author_email: "Email del autor"
modal:
title: "Descarga"
submit: "Descargar"

View File

@@ -792,6 +792,14 @@ es:
title: Recomendaciones
see_more: Ver más recomendaciones
hide: Ocultar recomendaciones
download:
title: "Descargas"
link:
proposal: "Descargar propuestas"
debate: "Descargar debates"
legislation_process: "Descargar procesos legislativos"
budget: "Descargar presupuestos"
investments: "Descargar proyectos"
social:
facebook: "Facebook de %{org}"
twitter: "Twitter de %{org}"

View File

@@ -29,6 +29,8 @@ namespace :admin do
end
end
resources :debates, only: [:index, :show]
resources :proposals, only: [:index, :show, :update] do
member { patch :toggle_selection }
resources :milestones, controller: "proposal_milestones"
@@ -82,6 +84,8 @@ namespace :admin do
end
end
resources :comments, only: :index
resources :tags, only: [:index, :create, :update, :destroy]
resources :officials, only: [:index, :edit, :update, :destroy] do
@@ -241,4 +245,6 @@ namespace :admin do
resources :actions, only: [:index, :new, :create, :edit, :update, :destroy]
resources :administrator_tasks, only: [:index, :edit, :update]
end
get 'download_settings/:resource', to: 'download_settings#edit', as: 'edit_download_settings'
put 'download_settings/:resource', to: 'download_settings#update', as: 'update_download_settings'
end

View File

@@ -0,0 +1,13 @@
class CreateDownloadSettings < ActiveRecord::Migration
def change
create_table :download_settings do |t|
t.string :name_model, null: false
t.string :name_field, null: false
t.boolean :downloadable, null: false, default: false
t.timestamps null: false
end
add_index :download_settings, [:name_model, :name_field], unique: true
end
end

View File

@@ -0,0 +1,8 @@
class AddConfigToDownloadSettings < ActiveRecord::Migration
def change
add_column :download_settings, :config, :integer, default: 0, null: false
remove_index :download_settings, name: "index_download_settings_on_name_model_and_name_field"
add_index :download_settings, [:name_model, :name_field, :config], unique: true
end
end

View File

@@ -512,6 +512,16 @@ ActiveRecord::Schema.define(version: 20190607160900) do
t.index ["user_id"], name: "index_documents_on_user_id", using: :btree
end
create_table "download_settings", force: :cascade do |t|
t.string "name_model", null: false
t.string "name_field", null: false
t.boolean "downloadable", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "config", default: 0, null: false
t.index ["name_model", "name_field", "config"], name: "index_download_settings_on_name_model_and_name_field_and_config", unique: true, using: :btree
end
create_table "failed_census_calls", force: :cascade do |t|
t.integer "user_id"
t.string "document_number"

View File

@@ -1708,20 +1708,11 @@ describe "Admin budget investments" do
visit admin_budget_budget_investments_path(budget)
click_link "Download current selection"
click_button "Download"
header = page.response_headers["Content-Disposition"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="budget_investments.csv"$/)
csv_contents = "ID,Title,Supports,Administrator,Valuator,Valuation Group,Scope of operation,"\
"Feasibility,Val. Fin.,Selected,Show to valuators,Author username\n"\
"#{first_investment.id},Le Investment,88,Admin,-,Valuator Group,"\
"Budget Heading,Feasible (€99),Yes,Yes,Yes,"\
"#{first_investment.author.username}\n#{second_investment.id},"\
"Alt Investment,66,No admin assigned,Valuator,-,Other Heading,"\
"Unfeasible,No,No,No,#{second_investment.author.username}\n"
expect(page.body).to eq(csv_contents)
end
scenario "Downloading CSV file with applied filter" do
@@ -1733,7 +1724,8 @@ describe "Admin budget investments" do
check "Valuation finished"
click_button "Filter"
click_link "Download current selection"
find(:css, "#downloadable_[value='title']").set(true)
click_button "Download"
expect(page).to have_content("Finished Investment")
expect(page).not_to have_content("Unfeasible one")

View File

@@ -17,6 +17,14 @@ describe "Admin debates" do
login_as(admin.user)
end
scenario "Show debate" do
debate = create(:debate)
visit admin_debate_path(debate)
expect(page).to have_content(debate.title)
expect(page).to have_content(debate.description)
end
scenario "Restore" do
debate = create(:debate, :hidden)
visit admin_hidden_debates_path

View File

@@ -0,0 +1,328 @@
require "rails_helper"
feature "Admin download settings" do
background do
admin = create(:administrator)
login_as(admin.user)
end
scenario "Edit download settings debates" do
visit admin_edit_download_settings_path(resource: "debates")
expect(page).to have_content("Debates")
end
scenario "Update download settings debates" do
visit admin_edit_download_settings_path(resource: "debates")
find(:css, "#downloadable_[value='id']").set(true)
find(:css, "#downloadable_[value='title']").set(true)
click_button "Save changes"
expect(DownloadSetting.find_by(name_model: "Debate",
name_field: "id").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Debate",
name_field: "title").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Debate",
name_field: "description").downloadable).to eq false
end
context "Download debates" do
background do
create(:debate)
end
scenario "admin csv" do
visit admin_debates_path
click_button "Download"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="debates.csv"$/)
expect(content_type).to match("text/csv")
end
scenario "public csv" do
visit debates_path
click_link "Download debates"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="debates.csv"$/)
expect(content_type).to match("text/csv")
end
end
scenario "Edit download settings proposals" do
visit admin_edit_download_settings_path(resource: "proposals")
expect(page).to have_content("Proposals")
end
scenario "Update download settings proposals" do
visit admin_edit_download_settings_path(resource: "proposals")
find(:css, "#downloadable_[value='id']").set(true)
find(:css, "#downloadable_[value='title']").set(true)
click_button "Save changes"
expect(DownloadSetting.find_by(name_model: "Proposal",
name_field: "id").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Proposal",
name_field: "title").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Proposal",
name_field: "description").downloadable).to eq false
end
context "Download proposals" do
background do
create(:proposal)
end
scenario "admin csv" do
visit admin_proposals_path
click_button "Download"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="proposals.csv"$/)
expect(content_type).to match("text/csv")
end
scenario "public csv" do
visit proposals_path
click_link "Download proposals"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="proposals.csv"$/)
expect(content_type).to match("text/csv")
end
end
scenario "Edit download settings comments" do
visit admin_edit_download_settings_path(resource: "comments")
expect(page).to have_content("Comments")
end
scenario "Update download settings comments" do
visit admin_edit_download_settings_path(resource: "comments")
find(:css, "#downloadable_[value='id']").set(true)
find(:css, "#downloadable_[value='body']").set(true)
click_button "Save changes"
expect(DownloadSetting.find_by(name_model: "Comment",
name_field: "id").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Comment",
name_field: "body").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Comment",
name_field: "subject").downloadable).to eq false
end
scenario "Download comments" do
create(:comment)
visit admin_comments_path
click_button "Download"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="comments.csv"$/)
expect(content_type).to match("text/csv")
end
scenario "Edit download settings legislation process" do
visit admin_edit_download_settings_path(resource: "legislation_processes")
expect(page).to have_content("Legislation process")
end
scenario "Update download settings legislation process" do
visit admin_edit_download_settings_path(resource: "legislation_processes")
find(:css, "#downloadable_[value='id']").set(true)
find(:css, "#downloadable_[value='title']").set(true)
click_button "Save changes"
expect(DownloadSetting.find_by(name_model: "Legislation::Process",
name_field: "id").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Legislation::Process",
name_field: "title").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Legislation::Process",
name_field: "description").downloadable).to eq false
end
context "Download legislation process" do
background do
create(:legislation_process, :open)
create(:legislation_process, :published)
end
scenario "admin csv" do
visit admin_legislation_processes_path
click_button "Download"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="legislation_processes.csv"$/)
expect(content_type).to match("text/csv")
end
scenario "public csv" do
visit legislation_processes_path
click_link "Download legislation processes"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="legislation_processes.csv"$/)
expect(content_type).to match("text/csv")
end
end
scenario "Edit download settings budget investment results" do
visit admin_edit_download_settings_path(resource: "budget_investments")
expect(page).to have_content("Participatory budgeting")
end
scenario "Update download settings budget investment results" do
visit admin_edit_download_settings_path(resource: "budget_investments")
find(:css, "#downloadable_[value='id']").set(true)
find(:css, "#downloadable_[value='title']").set(true)
click_button "Save changes"
expect(DownloadSetting.find_by(name_model: "Budget::Investment",
name_field: "id").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Budget::Investment",
name_field: "title").downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Budget::Investment",
name_field: "description").downloadable).to eq false
end
scenario "Edit download settings budget investment milestones" do
visit admin_edit_download_settings_path(resource: "budget_investments", config: 1)
expect(page).to have_content("Participatory budgeting - Milestones")
end
scenario "Update download settings budget investment milestones" do
visit admin_edit_download_settings_path(resource: "budget_investments", config: 1)
find(:css, "#downloadable_[value='id']").set(true)
find(:css, "#downloadable_[value='title']").set(true)
click_button "Save changes"
expect(DownloadSetting.find_by(name_model: "Budget::Investment",
name_field: "id",
config: 1).downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Budget::Investment",
name_field: "title",
config: 1).downloadable).to eq true
expect(DownloadSetting.find_by(name_model: "Budget::Investment",
name_field: "description",
config: 1).downloadable).to eq false
end
context "Download budgets" do
let(:budget_finished) { create(:budget, phase: "finished") }
let(:group) { create(:budget_group, budget: budget_finished) }
let(:heading) { create(:budget_heading, group: group, price: 1000) }
let(:investment1) { create(:budget_investment,
:selected,
heading: heading,
price: 200,
ballot_lines_count: 900) }
let(:investment2) { create(:budget_investment,
:selected,
heading: heading,
price: 300,
ballot_lines_count: 800) }
let(:investment3) { create(:budget_investment,
:incompatible,
heading: heading,
price: 500,
ballot_lines_count: 700) }
let(:investment4) { create(:budget_investment,
:selected,
heading: heading,
price: 600,
ballot_lines_count: 600) }
let(:budget) {create :budget}
background do
Budget::Result.new(budget_finished, heading).calculate_winners
end
scenario "admin results csv" do
visit admin_budget_budget_investments_path(budget_id: budget.id)
click_button "Download"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="budget_investments.csv"$/)
expect(content_type).to match("text/csv")
end
xscenario "public csv results" do
visit budget_results_path(budget_id: budget_finished.id)
save_page
click_link "Download projects"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="budget_investment_results.csv"$/)
expect(content_type).to match("text/csv")
end
scenario "public csv milestones" do
visit budget_executions_path(budget_id: budget_finished.id)
save_page
click_link "Download projects"
header = page.response_headers["Content-Disposition"]
content_type = page.response_headers["Content-Type"]
expect(header).to match(/^attachment/)
expect(header).to match(/filename="budget_investment_milestones.csv"$/)
expect(content_type).to match("text/csv")
end
end
end

View File

@@ -16,7 +16,7 @@ describe "Admin proposals" do
create(:proposal, title: "Build a monument to honour CONSUL developers")
visit admin_root_path
within("#side_menu") { click_link "Proposals" }
within("#side_menu") { first(:link, "Proposals").click }
expect(page).to have_content "Make Pluto a planet again"
expect(page).to have_content "Build a monument"

View File

@@ -22,10 +22,10 @@ describe "Admin custom information texts" do
expect(page).to have_content "Help about collaborative legislation"
expect(page).to have_content "Help with participatory budgets"
click_link "Debates"
within("#information-texts-tabs") { click_link "Debates" }
expect(page).to have_content "Help about debates"
click_link "Community"
within("#information-texts-tabs") { click_link "Community" }
expect(page).to have_content "Access the community"
within("#information-texts-tabs") { click_link "Proposals" }

View File

@@ -83,7 +83,7 @@ describe "Results" do
end
scenario "Loads budget and heading by slug" do
visit budget_results_path(budget.slug, heading.slug)
visit budget_results_path(budget.slug, heading_id: heading.slug)
expect(page).to have_selector("a.is-active", text: heading.name)

View File

@@ -107,7 +107,7 @@ describe "Proposals" do
proposal_with_image = create(:proposal)
image = create(:image, imageable: proposal_with_image)
visit proposals_path(proposal)
visit proposals_path(id: proposal)
within("#proposal_#{proposal.id}") do
expect(page).not_to have_css("div.with-image")