Skip to content

Commit

Permalink
Fix various proposal picker issues when there are thousands of propos…
Browse files Browse the repository at this point in the history
…als (#8558)
  • Loading branch information
alecslupu authored and quino committed Dec 1, 2021
1 parent 338bc5c commit de57576
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ 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
end

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@ $(() => {
}

let jqxhr = null
let filterBuffer = ""

toggleNoProposals()

$(".data_picker-modal-content").on("change keyup", "#proposals_filter", (event) => {
const filter = event.target.value.toLowerCase()

if (pickerMore) {
if (filter.length < 3) {
return
}

if (filter === filterBuffer) {
return
}

if (jqxhr !== null) {
jqxhr.abort()
}

$content.html("<div class='loading-spinner'></div>")
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) => {
Expand Down

0 comments on commit de57576

Please sign in to comment.