Skip to content

Commit

Permalink
Backport fixes for proposal picker (#125)
Browse files Browse the repository at this point in the history
* fix for proposals picker

* DRAFT

* increase max proposals to 2000 in proposals picker cell

* remove useless js file

* backport changes for proposal picker.js

Co-authored-by: phoebus-84 <[email protected]>
  • Loading branch information
phoebus-84 and phoebus-84 committed Mar 10, 2022
1 parent a532a7e commit 8de1ef8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $(() => {
}

let jqxhr = null
let filterBuffer = ""

toggleNoProposals()

Expand All @@ -16,14 +17,28 @@ $(() => {

if (pickerMore) {
if (jqxhr !== null) {
if (filter.length < 3) {
return
}

if (filter === filterBuffer) {
return
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down 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

0 comments on commit 8de1ef8

Please sign in to comment.