Skip to content

Commit

Permalink
Update search
Browse files Browse the repository at this point in the history
Search now shows org cards and explains what the match is against.  It
links to org and proposal pages

Issue #34
  • Loading branch information
slifty committed Oct 1, 2021
1 parent ad1b1bc commit 4e53905
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions cgap/static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,50 @@ app.component('ProposalSearch', {
}

// Create a dictionary of of org + proposal objects
const proposalGroups = this.matches.reduce(
const proposalGroupsObject = this.matches.reduce(
function (accumulator, match) {
if (!(match.organization.id in accumulator)) {
accumulator[match.organization.id] = {
organization: match.organization,
proposals: [],
matches: ['title'],
matches: [],
}
}
accumulator[match.organization.id].proposals.push(match);
return accumulator;
},
{},
)
const proposalGroups = Object.values(proposalGroupsObject)
.map((group) => {
if (hasMatch(group.organization.name, this.inputValue)) {
group.matches.push("Org Name");
}
if (hasMatch(group.organization.website, this.inputValue)) {
group.matches.push("Website");
}
if (hasMatch(group.organization.address, this.inputValue)) {
group.matches.push("Address");
}
if (hasMatch(group.organization.phone, this.inputValue)) {
group.matches.push("Phone");
}
if (hasMatch(group.organization.ceo_name, this.inputValue)) {
group.matches.push("CEO");
}

return proposalGroups;
const matchedProposals = group.proposals.filter((proposal) => {
return hasMatch(proposal.description, this.inputValue)
|| hasMatch(proposal.name, this.inputValue);
})
if (matchedProposals.length > 0) {
group.matches.push("Proposal");
}
return group;
})

// We want to filter here as well to prevent common UX lag between API requests
return this.matches.filter((match) => {
return hasMatch(match.organization.name, this.inputValue)
|| hasMatch(match['description'], this.inputValue);
});
return proposalGroups.filter((match) => { return match.matches.length !== 0; });
},
hasMatches() {
return this.filteredMatches.length >= 0 && this.inputValue !== '';
Expand Down Expand Up @@ -101,10 +123,10 @@ app.component('ProposalSearch', {
<h6>Proposals</h6>
<ul class="list-group list-group-flush">
<li v-for="proposal in match.proposals" class="list-group-item">
{{proposal.description}} <a :href='generateProposalViewUrl(proposal.id)'>(view)</a>
{{proposal.name}}, {{proposal.requested_budget}} <a :href='generateProposalViewUrl(proposal.id)'>(view)</a>
</li>
</ul>
<p class="card-text">Matched on: <span v-for="term in match.matches" class="badge bg-secondary">{{term}}</span></p>
<p class="card-text">Matched on: <span v-for="term in match.matches" class="badge bg-secondary ms-1">{{term}}</span></p>
</div>
</div>
</div>
Expand Down

0 comments on commit 4e53905

Please sign in to comment.