Skip to content

Commit

Permalink
Cache org name search results #3369
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 12, 2024
1 parent 5d3e4f2 commit 9b80989
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 21 additions & 14 deletions grails-app/assets/components/javascript/associated-orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,31 @@ ko.components.register('associated-orgs', {
this.toDate = ko.observable(associatedOrg.toDate).extend({simpleDate:false});
this.label = ko.observable(this.name());

this.updateLabel = function() {
if (this.organisationId) {
var self = this;
findMatchingOrganisation(self.organisationId(), function(matchingOrg) {
if (matchingOrg && matchingOrg._source) {
if (matchingOrg._source.name && matchingOrg._source.name != self.name()) {
self.label(self.name() + ' (' + matchingOrg._source.name + ')');
}
}
});
var previousOrganisationId = null;
var organisationName = null;
var self = this;
function setLabel() {
if (organisationName && organisationName != self.name()) {
self.label(self.name() + ' (' + organisationName + ')');
}
else {
this.label(this.name());
self.label(self.name());
}
}
function updateLabel() {
if (self.organisationId() && self.organisationId() != previousOrganisationId) {

findMatchingOrganisation(self.organisationId(), function(matchingOrg) {
previousOrganisationId = self.organisationId();
organisationName = matchingOrg && matchingOrg._source ? matchingOrg._source.name : null;
setLabel();
});
}
setLabel();
}
this.organisationId.subscribe(this.updateLabel, this);
this.name.subscribe(this.updateLabel, this);
this.updateLabel();
this.organisationId.subscribe(updateLabel, this);
this.name.subscribe(updateLabel, this);
updateLabel();


this.toJSON = function() {
Expand Down
4 changes: 4 additions & 0 deletions grails-app/assets/stylesheets/organisation.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,7 @@ ul.ui-autocomplete {
min-width: 7em;
}

ul.ui-menu {
list-style: none;
}

0 comments on commit 9b80989

Please sign in to comment.