corrections about coding style
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
//= require annotatable
|
||||
//= require advanced_search
|
||||
//= require registration_form
|
||||
//= require show_results
|
||||
//= require suggest
|
||||
|
||||
var initialize_modules = function() {
|
||||
App.Comments.initialize();
|
||||
@@ -54,7 +54,7 @@ var initialize_modules = function() {
|
||||
App.Annotatable.initialize();
|
||||
App.AdvancedSearch.initialize();
|
||||
App.RegistrationForm.initialize();
|
||||
App.ShowResults.initialize();
|
||||
App.Suggest.initialize();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
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()) )
|
||||
16
app/assets/javascripts/suggest.js.coffee
Normal file
16
app/assets/javascripts/suggest.js.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
App.Suggest =
|
||||
|
||||
initialize: ->
|
||||
$('[data-js-suggest-result]').on('blur',(event) ->
|
||||
|
||||
js_suggest = $(this).data('js-suggest')
|
||||
|
||||
$.ajax
|
||||
url: $(this).data('js-url')
|
||||
data: {search: $(this).val()},
|
||||
type: 'GET',
|
||||
dataType: 'html'
|
||||
success: (stHtml) ->
|
||||
$(js_suggest).html(stHtml)
|
||||
error: (xhr, status) ->
|
||||
complete: (xhr, status) ->)
|
||||
@@ -32,7 +32,11 @@ module CommentableActions
|
||||
def suggest
|
||||
@resources = @search_terms.present? ? resource_model.search(@search_terms).sort_by_confidence_score: nil
|
||||
set_resources_instance
|
||||
render :layout => false
|
||||
if @resources then
|
||||
@resources_count = @resources.count
|
||||
@reg_show = 5
|
||||
render layout: false
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<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, data: {ajax_target: "ajax_suggest", ajax_show: "#ajax_suggest_show", ajax_url: suggest_debates_path}%>
|
||||
<%= f.text_field :title, maxlength: Debate.title_max_length, placeholder: t("debates.form.debate_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_debates_path}%>
|
||||
</div>
|
||||
<div id="ajax_suggest_show"></div>
|
||||
<div id="js-suggest"></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 %>
|
||||
|
||||
22
app/views/debates/_suggest.html.erb
Normal file
22
app/views/debates/_suggest.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<div class="small-12 column" >
|
||||
<% if @search_terms && @resources_count > 0 %>
|
||||
<div class="alert-box radius warning">
|
||||
<p class="note-marked">
|
||||
<%= t("debates.new.suggestions.found", count: @resources_count, query: @search_terms)%>
|
||||
</p>
|
||||
<ul>
|
||||
<% @debates.take(@reg_show).each do |debate| %>
|
||||
<li> <%= link_to debate.title, debate %> </li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if @resources_count > @reg_show %>
|
||||
<p class="note-marked">
|
||||
<%= t("debates.new.suggestions.message", count: @resources_count,
|
||||
query: @search_terms,
|
||||
limit: @reg_show) %>
|
||||
<%= link_to t("debates.new.suggestions.see_all"), debates_path(search: @search_terms)%>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,25 +0,0 @@
|
||||
<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>
|
||||
1
app/views/debates/suggest.js.erb
Normal file
1
app/views/debates/suggest.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render "suggest" %>
|
||||
@@ -4,9 +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, data: {ajax_target: "ajax_suggest", ajax_show: "#ajax_suggest_show", ajax_url: suggest_proposals_path}%>
|
||||
<%= f.text_field :title, maxlength: Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_proposals_path}%>
|
||||
</div>
|
||||
<div id="ajax_suggest_show"></div>
|
||||
<div id="js-suggest"></div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :question, t("proposals.form.proposal_question") %>
|
||||
|
||||
22
app/views/proposals/_suggest.html.erb
Normal file
22
app/views/proposals/_suggest.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<div class="small-12 column" >
|
||||
<% if @search_terms && @resources_count > 0 %>
|
||||
<div class="alert-box radius warning">
|
||||
<p class="note-marked">
|
||||
<%= t("proposals.new.suggestions.found", count: @resources_count, query: @search_terms)%>
|
||||
</p>
|
||||
<ul>
|
||||
<% @proposals.take(@reg_show).each do |proposal| %>
|
||||
<li> <%= link_to proposal.title, proposal %> </li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% if @resources_count > @reg_show %>
|
||||
<p class="note-marked">
|
||||
<%= t("proposals.new.suggestions.message", count: @resources_count,
|
||||
query: @search_terms,
|
||||
limit: @reg_show) %>
|
||||
<%= link_to t("proposals.new.suggestions.see_all"), proposals_path(search: @search_terms)%>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -1,25 +0,0 @@
|
||||
<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>
|
||||
1
app/views/proposals/suggest.js.erb
Normal file
1
app/views/proposals/suggest.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render "suggest" %>
|
||||
@@ -125,7 +125,7 @@ en:
|
||||
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}"
|
||||
message: "You are seeing %{limit} of %{count} debates containing the term '%{query}'"
|
||||
see_all: "See all"
|
||||
show:
|
||||
author_deleted: User deleted
|
||||
@@ -308,9 +308,9 @@ en:
|
||||
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}"
|
||||
one: "There is a proposal with the term '%{query}', you can contribute to it instead of creating a new"
|
||||
other: "There are proposals with 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!
|
||||
|
||||
@@ -126,7 +126,7 @@ es:
|
||||
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}"
|
||||
message: "Estás viendo %{limit} de %{count} debates que contienen el término '%{query}'"
|
||||
see_all: "Ver todos"
|
||||
show:
|
||||
author_deleted: Usuario eliminado
|
||||
@@ -309,10 +309,10 @@ es:
|
||||
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"
|
||||
one: "Existe una propuesta con el término '%{query}', puedes contribuir en ella en vez de crear una nueva."
|
||||
other: "Existen propuestas con el término '%{query}', puedes contribuir en ellas en vez de crear una nueva."
|
||||
message: "Estás viendo %{limit} de %{count} propuestas que contienen el término '%{query}'"
|
||||
see_all: "Ver todas"
|
||||
proposal:
|
||||
already_supported: "¡Ya has apoyado esta propuesta, compártela!"
|
||||
comments:
|
||||
|
||||
@@ -118,6 +118,7 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
t.integer "cached_votes_score", default: 0
|
||||
t.integer "hot_score", limit: 8, default: 0
|
||||
t.integer "confidence_score", default: 0
|
||||
t.string "external_link", limit: 100
|
||||
t.integer "geozone_id"
|
||||
end
|
||||
|
||||
@@ -128,6 +129,7 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree
|
||||
add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree
|
||||
add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree
|
||||
add_index "debates", ["description"], name: "index_debates_on_description", using: :btree
|
||||
add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree
|
||||
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
|
||||
add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree
|
||||
@@ -201,7 +203,7 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
create_table "locks", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "tries", default: 0
|
||||
t.datetime "locked_until", default: '2000-01-01 07:01:01', null: false
|
||||
t.datetime "locked_until", default: '2000-01-01 00:01:01', null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
@@ -261,6 +263,7 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree
|
||||
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
|
||||
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
|
||||
add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree
|
||||
add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
|
||||
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
|
||||
add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree
|
||||
@@ -319,8 +322,8 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
t.boolean "featured", default: false
|
||||
t.integer "debates_count", default: 0
|
||||
t.integer "proposals_count", default: 0
|
||||
t.string "kind"
|
||||
t.integer "spending_proposals_count", default: 0
|
||||
t.string "kind"
|
||||
end
|
||||
|
||||
add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree
|
||||
@@ -396,8 +399,8 @@ ActiveRecord::Schema.define(version: 20160126090634) do
|
||||
t.boolean "public_activity", default: true
|
||||
t.boolean "newsletter", default: false
|
||||
t.integer "notifications_count", default: 0
|
||||
t.string "locale"
|
||||
t.boolean "registering_with_oauth", default: false
|
||||
t.string "locale"
|
||||
t.string "oauth_email"
|
||||
end
|
||||
|
||||
@@ -865,7 +865,6 @@ feature 'Debates' do
|
||||
expect(page).to have_content('User deleted')
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
context "Filter" do
|
||||
|
||||
pending "By category" do
|
||||
@@ -948,42 +947,42 @@ feature 'Debates' do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'Suggesting debates' do
|
||||
|
||||
scenario 'Shows up to 5 suggestions per debate', :js do
|
||||
scenario 'Shows up to 5 suggestions', :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)
|
||||
debate1 = create(:debate, title: "First debate has 1 vote", cached_votes_up: 1)
|
||||
debate2 = create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2)
|
||||
debate3 = create(:debate, title: "Third debate has 3 votes", cached_votes_up: 3)
|
||||
debate4 = create(:debate, title: "This one has 4 votes", description: "This is the fourth debate", cached_votes_up: 4)
|
||||
debate5 = create(:debate, title: "Fifth debate has 5 votes", cached_votes_up: 5)
|
||||
debate6 = create(:debate, title: "Sixth debate has 6 votes", description: 'This is the sixth debate', cached_votes_up: 6)
|
||||
debate7 = create(:debate, title: "This has seven votes, and is not suggest", description: 'This is the seven', cached_votes_up: 7)
|
||||
|
||||
visit new_debate_path
|
||||
fill_in 'debate_title', with: 'Quijote'
|
||||
page.find("body").click
|
||||
fill_in 'debate_title', with: 'debate'
|
||||
check "debate_terms_of_service"
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to have_content ("You are seeing 5 of 6 debates containing the term Quijote")
|
||||
within('div#js-suggest') do
|
||||
expect(page).to have_content ("You are seeing 5 of 6 debates containing the term 'debate'")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'No found suggestions for debate', :js do
|
||||
scenario 'No found suggestions', :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")
|
||||
debate1 = create(:debate, title: "First debate has 10 vote", cached_votes_up: 10)
|
||||
debate2 = create(:debate, title: "Second debate has 2 votes", cached_votes_up: 2)
|
||||
|
||||
visit new_debate_path
|
||||
fill_in 'debate_title', with: 'La Celestina'
|
||||
page.find("body").click
|
||||
fill_in 'debate_title', with: 'proposal'
|
||||
check "debate_terms_of_service"
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to_not have_content ('You are seeing')
|
||||
within('div#js-suggest') do
|
||||
expect(page).to_not have_content ('You are seeing')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1023,7 +1023,6 @@ feature 'Proposals' do
|
||||
expect(page).to have_content('User deleted')
|
||||
end
|
||||
|
||||
<<<<<<< HEAD
|
||||
context "Filter" do
|
||||
|
||||
scenario "By category" do
|
||||
@@ -1107,28 +1106,28 @@ feature 'Proposals' do
|
||||
end
|
||||
|
||||
context 'Suggesting proposals' do
|
||||
|
||||
scenario 'Shows up to 5 suggestions per proposal', :js do
|
||||
scenario 'Show up to 5 suggestions', :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)
|
||||
create(:proposal, title: 'First proposal, has search term')
|
||||
create(:proposal, title: 'Second title')
|
||||
create(:proposal, title: 'Third proposal, has search term')
|
||||
create(:proposal, title: 'Fourth proposal, has search term')
|
||||
create(:proposal, title: 'Fifth proposal, has search term')
|
||||
create(:proposal, title: 'Sixth proposal, has search term')
|
||||
create(:proposal, title: 'Seventh proposal, has search term')
|
||||
|
||||
visit new_proposal_path
|
||||
fill_in 'proposal_title', with: 'proposal'
|
||||
page.find("body").click
|
||||
fill_in 'proposal_title', with: 'search'
|
||||
check "proposal_terms_of_service"
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to have_content ("You are seeing 5 of 6 proposals containing the term proposal")
|
||||
within('div#js-suggest') do
|
||||
expect(page).to have_content ("You are seeing 5 of 6 proposals containing the term 'search'")
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'No found suggestions for debate', :js do
|
||||
scenario 'No found suggestions', :js do
|
||||
author = create(:user)
|
||||
login_as(author)
|
||||
|
||||
@@ -1137,10 +1136,10 @@ feature 'Proposals' do
|
||||
|
||||
visit new_proposal_path
|
||||
fill_in 'proposal_title', with: 'debate'
|
||||
page.find("body").click
|
||||
check "proposal_terms_of_service"
|
||||
|
||||
within('div#ajax_suggest_show') do
|
||||
expect(page.html).to_not have_content ('You are seeing')
|
||||
within('div#js-suggest') do
|
||||
expect(page).to_not have_content ('You are seeing')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user