Merge branch 'suggest_before_creating'
Conflicts: app/assets/javascripts/application.js app/controllers/debates_controller.rb app/controllers/proposals_controller.rb config/locales/es.yml config/routes.rb db/schema.rb spec/features/debates_spec.rb spec/features/proposals_spec.rb
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
//= require annotatable
|
||||
//= require advanced_search
|
||||
//= require registration_form
|
||||
//= require show_results
|
||||
|
||||
var initialize_modules = function() {
|
||||
App.Comments.initialize();
|
||||
@@ -53,6 +54,7 @@ var initialize_modules = function() {
|
||||
App.Annotatable.initialize();
|
||||
App.AdvancedSearch.initialize();
|
||||
App.RegistrationForm.initialize();
|
||||
App.ShowResults.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
15
app/assets/javascripts/show_results.js.coffee
Normal file
15
app/assets/javascripts/show_results.js.coffee
Normal file
@@ -0,0 +1,15 @@
|
||||
App.ShowResults =
|
||||
show: (ajax_show, ajax_url, query) ->
|
||||
$.ajax
|
||||
url: ajax_url,
|
||||
data: {search: query},
|
||||
type: 'GET',
|
||||
dataType: 'html'
|
||||
success: (stHtml) ->
|
||||
$(ajax_show).html(stHtml)
|
||||
error: (xhr, status) ->
|
||||
complete: (xhr, status) ->
|
||||
|
||||
initialize: ->
|
||||
$('[data-ajax-target]').on('blur',(event) ->
|
||||
App.ShowResults.show($(this).data('ajax-show'), $(this).data('ajax-url'), $(this).val()) )
|
||||
@@ -29,6 +29,12 @@ module CommentableActions
|
||||
set_resource_instance
|
||||
end
|
||||
|
||||
def suggest
|
||||
@resources = @search_terms.present? ? resource_model.search(@search_terms).sort_by_confidence_score: nil
|
||||
set_resources_instance
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def create
|
||||
@resource = resource_model.new(strong_params)
|
||||
@resource.author = current_user
|
||||
|
||||
@@ -3,7 +3,7 @@ class DebatesController < ApplicationController
|
||||
include CommentableActions
|
||||
include FlagActions
|
||||
|
||||
before_action :parse_search_terms, only: :index
|
||||
before_action :parse_search_terms, only: [:index, :suggest]
|
||||
before_action :parse_advanced_search_terms, only: :index
|
||||
before_action :parse_tag_filter, only: :index
|
||||
before_action :set_search_order, only: :index
|
||||
|
||||
@@ -2,7 +2,7 @@ class ProposalsController < ApplicationController
|
||||
include CommentableActions
|
||||
include FlagActions
|
||||
|
||||
before_action :parse_search_terms, only: :index
|
||||
before_action :parse_search_terms, only: [:index, :suggest]
|
||||
before_action :parse_advanced_search_terms, only: :index
|
||||
before_action :parse_tag_filter, only: :index
|
||||
before_action :set_search_order, only: :index
|
||||
|
||||
@@ -23,6 +23,9 @@ module Abilities
|
||||
can :create, Debate
|
||||
can :create, Proposal
|
||||
|
||||
can :suggest, Debate
|
||||
can :suggest, Proposal
|
||||
|
||||
can [:flag, :unflag], Comment
|
||||
cannot [:flag, :unflag], Comment, user_id: user.id
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<%= form_for(@debate) do |f| %>
|
||||
<%= render 'shared/errors', resource: @debate %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<%= f.label :title, t("debates.form.debate_title") %>
|
||||
<%= f.text_field :title, maxlength: Debate.title_max_length, placeholder: t("debates.form.debate_title"), label: false %>
|
||||
<%= f.text_field :title, maxlength: Debate.title_max_length, placeholder: t("debates.form.debate_title"), label: false, data: {ajax_target: "ajax_suggest", ajax_show: "#ajax_suggest_show", ajax_url: suggest_debates_path}%>
|
||||
</div>
|
||||
|
||||
<div id="ajax_suggest_show"></div>
|
||||
<div class="ckeditor small-12 column">
|
||||
<%= f.label :description, t("debates.form.debate_text") %>
|
||||
<%= f.cktext_area :description, maxlength: Debate.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
|
||||
@@ -41,4 +40,4 @@
|
||||
<%= f.submit(class: "button radius", value: t("debates.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
25
app/views/debates/suggest.html.erb
Normal file
25
app/views/debates/suggest.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<div class="small-12 column" >
|
||||
<% if @search_terms && @debates.count >0 %>
|
||||
<% debates_count = @debates.count %>
|
||||
<% query = @search_terms %>
|
||||
<% limit = 5 %>
|
||||
<div class="alert-box radius warning">
|
||||
<p class="note-marked">
|
||||
<%= t("debates.new.suggestions.found", count: debates_count, query: query)%>
|
||||
</p>
|
||||
<ul>
|
||||
<% @debates.take(limit).each do |debate| %>
|
||||
<li> <%= link_to debate.title, debate %> </li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if debates_count > limit %>
|
||||
<p class="note-marked">
|
||||
<%= t("debates.new.suggestions.message", count: debates_count,
|
||||
query: query,
|
||||
limit: limit)%>
|
||||
<%= link_to t("debates.new.suggestions.see_all"), debates_path(:search => query)%>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -4,8 +4,9 @@
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<%= f.label :title, t("proposals.form.proposal_title") %>
|
||||
<%= f.text_field :title, maxlength: Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false %>
|
||||
<%= f.text_field :title, maxlength: Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {ajax_target: "ajax_suggest", ajax_show: "#ajax_suggest_show", ajax_url: suggest_proposals_path}%>
|
||||
</div>
|
||||
<div id="ajax_suggest_show"></div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :question, t("proposals.form.proposal_question") %>
|
||||
|
||||
25
app/views/proposals/suggest.html.erb
Normal file
25
app/views/proposals/suggest.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<div class="small-12 column" >
|
||||
<% if @search_terms && @proposals.count >0 %>
|
||||
<% proposals_count = @proposals.count %>
|
||||
<% query = @search_terms %>
|
||||
<% limit = 5 %>
|
||||
<div class="alert-box radius warning">
|
||||
<p class="note-marked">
|
||||
<%= t("proposals.new.suggestions.found", count: proposals_count, query: query)%>
|
||||
</p>
|
||||
<ul>
|
||||
<% @proposals.take(limit).each do |proposal| %>
|
||||
<li> <%= link_to proposal.title, proposal %> </li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if proposals_count > limit %>
|
||||
<p class="note-marked">
|
||||
<%= t("proposals.new.suggestions.message", count: proposals_count,
|
||||
query: query,
|
||||
limit: limit)%>
|
||||
<%= link_to t("proposals.new.suggestions.see_all"), proposals_path(:search => query)%>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -121,6 +121,12 @@ en:
|
||||
recommendation_two: Any debate or comment suggesting illegal action will be deleted, as well as those intending to sabotage the debate spaces. Anything else is allowed.
|
||||
recommendations_title: Recommendations for creating a debate
|
||||
start_new: Start a debate
|
||||
suggestions:
|
||||
found:
|
||||
one: "There is a debate with the term '%{query}', you can participate in it instead of opening a new one."
|
||||
other: "There are debates with the term '%{query}', you can participate in them instead of opening a new one."
|
||||
message: "You are seeing %{limit} of %{count} debates containing the term %{query}"
|
||||
see_all: "See all"
|
||||
show:
|
||||
author_deleted: User deleted
|
||||
back_link: Go back
|
||||
@@ -300,6 +306,12 @@ en:
|
||||
recommendation_two: Any proposal or comment suggesting illegal action will be deleted, as well as those intending to sabotage the debate spaces. Anything else is allowed.
|
||||
recommendations_title: Recommendations for creating a proposal
|
||||
start_new: Create new proposal
|
||||
suggestions:
|
||||
found:
|
||||
one: "There is a proposal by the term '%{query}', you can contribute to it instead of creating a new"
|
||||
other: "There are proposals by the term '%{query}', you can contribute to them instead of creating a new"
|
||||
message: "You are seeing %{limit} of %{count} proposals containing the term %{query}"
|
||||
see_all: "See all"
|
||||
proposal:
|
||||
already_supported: You have already supported this proposal. Share it!
|
||||
comments:
|
||||
|
||||
15
config/locales/es.yml
Normal file → Executable file
15
config/locales/es.yml
Normal file → Executable file
@@ -26,7 +26,8 @@ es:
|
||||
user_permission_votes: Participar en las votaciones finales*
|
||||
username_label: Nombre de usuario
|
||||
verified_account: Cuenta verificada
|
||||
verify_my_account: Verificar mi cuenta
|
||||
verify_my_account: Verificar mi cuentaquer
|
||||
|
||||
application:
|
||||
close: Cerrar
|
||||
menu: Menú
|
||||
@@ -121,6 +122,12 @@ es:
|
||||
recommendation_two: Cualquier debate o comentario que implique una acción ilegal será eliminado, también los que tengan la intención de sabotear los espacios de debate, todo lo demás está permitido.
|
||||
recommendations_title: Recomendaciones para crear un debate
|
||||
start_new: Empezar un debate
|
||||
suggestions:
|
||||
found:
|
||||
one: "Existe un debate con el término '%{query}', puedes participar en él en vez de abrir uno nuevo."
|
||||
other: "Existen debates con el término '%{query}', puedes participar en ellos en vez de abrir uno nuevo."
|
||||
message: "Estás viendo %{limit} de %{count} debates que contienen el término %{query}"
|
||||
see_all: "Ver todos"
|
||||
show:
|
||||
author_deleted: Usuario eliminado
|
||||
back_link: Volver
|
||||
@@ -300,6 +307,12 @@ es:
|
||||
recommendation_two: Cualquier propuesta o comentario que implique una acción ilegal será eliminada, también las que tengan la intención de sabotear los espacios de propuesta, todo lo demás está permitido.
|
||||
recommendations_title: Recomendaciones para crear una propuesta
|
||||
start_new: Crear una propuesta
|
||||
suggestions:
|
||||
found:
|
||||
one: "Existe un debate con el término '%{query}', puedes participar en él en vez de abrir uno nuevo."
|
||||
other: "Existen debates con el término '%{query}', puedes participar en ellos en vez de abrir uno nuevo."
|
||||
message: "Estás viendo %{limit} de %{count} debates que contienen el término %{query}"
|
||||
see_all: "Ver todos"
|
||||
proposal:
|
||||
already_supported: "¡Ya has apoyado esta propuesta, compártela!"
|
||||
comments:
|
||||
|
||||
@@ -38,9 +38,9 @@ Rails.application.routes.draw do
|
||||
put :flag
|
||||
put :unflag
|
||||
end
|
||||
|
||||
collection do
|
||||
get :map
|
||||
get :suggest
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,9 +51,9 @@ Rails.application.routes.draw do
|
||||
put :flag
|
||||
put :unflag
|
||||
end
|
||||
|
||||
collection do
|
||||
get :map
|
||||
get :suggest
|
||||
end
|
||||
end
|
||||
|
||||
@@ -242,4 +242,4 @@ Rails.application.routes.draw do
|
||||
# static pages
|
||||
get '/blog' => redirect("http://diario.madrid.es/participa/")
|
||||
resources :pages, path: '/', only: [:show]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,16 +103,16 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
t.string "title", limit: 80
|
||||
t.text "description"
|
||||
t.integer "author_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "visit_id"
|
||||
t.datetime "hidden_at"
|
||||
t.integer "flags_count", default: 0
|
||||
t.integer "flags_count", default: 0
|
||||
t.integer "cached_votes_total", default: 0
|
||||
t.integer "cached_votes_up", default: 0
|
||||
t.integer "cached_votes_down", default: 0
|
||||
t.datetime "ignored_flag_at"
|
||||
t.integer "cached_votes_total", default: 0
|
||||
t.integer "cached_votes_up", default: 0
|
||||
t.integer "cached_votes_down", default: 0
|
||||
t.integer "comments_count", default: 0
|
||||
t.integer "comments_count", default: 0
|
||||
t.datetime "confirmed_hide_at"
|
||||
t.integer "cached_anonymous_votes_total", default: 0
|
||||
t.integer "cached_votes_score", default: 0
|
||||
@@ -865,6 +865,7 @@ feature 'Debates' do
|
||||
expect(page).to have_content('User deleted')
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
context "Filter" do
|
||||
|
||||
pending "By category" do
|
||||
@@ -947,4 +948,43 @@ feature 'Debates' do
|
||||
end
|
||||
end
|
||||
|
||||
context 'Suggesting debates' do
|
||||
|
||||
scenario 'Shows up to 5 suggestions per debate', :js do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
debate1 = create(:debate, title: "1 - El Quijote: En un lugar de la Mancha", cached_votes_up: 1)
|
||||
debate2 = create(:debate, title: "2 - El Quijote: de cuyo nombre no quiero acordarme", cached_votes_up: 2)
|
||||
debate3 = create(:debate, title: "3 - El Quijote: no ha mucho tiempo que vivía ", cached_votes_up: 3)
|
||||
debate4 = create(:debate, title: "4 - un hidalgo de los de lanza en astillero", description: "El Quijote un hidalgo de los de lanza en astillero", cached_votes_up: 4)
|
||||
debate5 = create(:debate, title: "5 - El Quijote: adarga antigua, rocín flaco y galgo corredor", cached_votes_up: 5)
|
||||
debate6 = create(:debate, title: "6 - Una olla de algo más vaca que carnero", description: 'El Quijote', cached_votes_up: 6)
|
||||
debate7 = create(:debate, title: "7 - No se sugiere", cached_votes_up: 7)
|
||||
|
||||
visit new_debate_path
|
||||
fill_in 'debate_title', with: 'Quijote'
|
||||
page.find("body").click
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to have_content ("You are seeing 5 of 6 debates containing the term Quijote")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'No found suggestions for debate', :js do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
debate1 = create(:debate, title: "El Quijote: En un lugar de la Mancha", cached_votes_up: 10)
|
||||
debate2 = create(:debate, title: "El Quijote: de cuyo nombre no quiero acordarme")
|
||||
|
||||
visit new_debate_path
|
||||
fill_in 'debate_title', with: 'La Celestina'
|
||||
page.find("body").click
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to_not have_content ('You are seeing')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1023,6 +1023,7 @@ feature 'Proposals' do
|
||||
expect(page).to have_content('User deleted')
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
context "Filter" do
|
||||
|
||||
scenario "By category" do
|
||||
@@ -1105,4 +1106,42 @@ feature 'Proposals' do
|
||||
end
|
||||
end
|
||||
|
||||
context 'Suggesting proposals' do
|
||||
|
||||
scenario 'Shows up to 5 suggestions per proposal', :js do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
create(:proposal, title: 'First proposal').update_column(:confidence_score, 10)
|
||||
create(:proposal, title: 'Second proposal').update_column(:confidence_score, 8)
|
||||
create(:proposal, title: 'Third proposal').update_column(:confidence_score, 6)
|
||||
create(:proposal, title: 'Fourth proposal').update_column(:confidence_score, 4)
|
||||
create(:proposal, title: 'Fifth proposal').update_column(:confidence_score, 3)
|
||||
create(:proposal, title: 'Sixth proposal').update_column(:confidence_score, 1)
|
||||
|
||||
visit new_proposal_path
|
||||
fill_in 'proposal_title', with: 'proposal'
|
||||
page.find("body").click
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to have_content ("You are seeing 5 of 6 proposals containing the term proposal")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'No found suggestions for debate', :js do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
create(:proposal, title: 'First proposal').update_column(:confidence_score, 10)
|
||||
create(:proposal, title: 'Second proposal').update_column(:confidence_score, 8)
|
||||
|
||||
visit new_proposal_path
|
||||
fill_in 'proposal_title', with: 'debate'
|
||||
page.find("body").click
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to_not have_content ('You are seeing')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user