diff --git a/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 b/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 index 4ceb9acc644a..1eb9d79ba511 100644 --- a/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 +++ b/decidim-proposals/app/assets/javascripts/decidim/proposals/admin/proposals_picker.js.es6 @@ -8,6 +8,7 @@ $(() => { } let jqxhr = null + let filterBuffer = "" toggleNoProposals() @@ -16,14 +17,28 @@ $(() => { if (pickerMore) { if (jqxhr !== null) { + if (filter.length < 3) { + return + } + + if (filter === filterBuffer) { + return + } + jqxhr.abort() } $content.html("
") jqxhr = $.get(`${pickerPath}?q=${filter}`, (data) => { + filterBuffer = filter $content.html(data) jqxhr = null toggleNoProposals() + + if (typeof window.theDataPicker === "object" && window.theDataPicker.current !== null) { + window.theDataPicker._handleCheckboxes($content); + window.theDataPicker._handleLinks($content); + } }) } else { $("#proposals_list li").each((index, li) => { diff --git a/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb b/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb index 83b589ce3102..cba57cee5d72 100644 --- a/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb +++ b/decidim-proposals/app/cells/decidim/proposals/proposals_picker_cell.rb @@ -6,7 +6,7 @@ module Decidim module Proposals # This cell renders a proposals picker. class ProposalsPickerCell < Decidim::ViewModel - MAX_PROPOSALS = 1000 + MAX_PROPOSALS = 2000 def show if filtered? @@ -50,9 +50,10 @@ def decorated_proposals def filtered_proposals @filtered_proposals ||= if filtered? - proposals.where("title::text ILIKE ?", "%#{search_text}%") - .or(proposals.where("reference ILIKE ?", "%#{search_text}%")) - .or(proposals.where("id::text ILIKE ?", "%#{search_text}%")) + table_name = Decidim::Proposals::Proposal.table_name + proposals.where(%("#{table_name}"."title"::text ILIKE ?), "%#{search_text}%") + .or(proposals.where(%("#{table_name}"."reference" ILIKE ?), "%#{search_text}%")) + .or(proposals.where(%("#{table_name}"."id"::text ILIKE ?), "%#{search_text}%")) else proposals end @@ -60,8 +61,9 @@ def filtered_proposals def proposals @proposals ||= Decidim.find_resource_manifest(:proposals).try(:resource_scope, component) - &.published - &.order(id: :asc) + &.includes(:component) + &.published + &.order(id: :asc) end def proposals_collection_name