-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial instrument filter to browse page.
- Loading branch information
Showing
16 changed files
with
278 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{% comment %} | ||
// | ||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu> | ||
// Creation Date: Thu Feb 10 21:48:42 PST 2022 | ||
// Last Modified: Thu Feb 10 21:48:45 PST 2022 | ||
// Filename: _includes/browse/buildInstrumentFilter.js | ||
// Used by: _incuode/browse/doBrowseSearch(); | ||
// Included in: _includes/browse/main.html | ||
// Syntax: ECMAScript 6 | ||
// vim: ts=3:nowrap | ||
// | ||
// Description: Create the search entry for instruments on the browse page. | ||
// This is done by searching through the browse index (or any | ||
// provided index) and collating the instrument fields | ||
// for each entry in the index. The instrument list also | ||
// gives the number of entries in the full index in | ||
// the instrument search list in parentheses after instrument | ||
// abbreviation. | ||
// | ||
{% endcomment %} | ||
|
||
POPC2.prototype.buildInstrumentFilter = function (index, target) { | ||
this.DebugMessageFunctionVerbose(); | ||
if (!index) { | ||
index = this.VARS.SEARCH_INDEX; | ||
} | ||
if (!target) { | ||
target = "#filter-instrument"; | ||
} | ||
if (!index) { | ||
console.error("ERROR: Cannot find browse index for creating instrument filter."); | ||
return; | ||
} | ||
let element = document.querySelector(target); | ||
if (!element) { | ||
console.error("ERROR: Cannot find target", target); | ||
return; | ||
} | ||
|
||
let instruments = {}; | ||
if (index.length === this.VARS.SEARCH_INDEX.length) { | ||
// Use cached instruments counts | ||
instruments = this.VARS.BROWSE_MENU_OPTIONS.instrument; | ||
} else { | ||
for (let i=0; i<index.length; i++) { | ||
let ain = index[i].AIN; | ||
if (!ain) { | ||
continue; | ||
} | ||
ain = ain.trim(); | ||
let ains = ain.split(/\s+/); | ||
for (let j=0; j<ains.length; j++) { | ||
if (ains[j].match(/^[a-z]/)) { | ||
let instrument = ains[j]; | ||
if (instrument === "empty") { | ||
continue; | ||
} | ||
if (!instruments[instrument]) { | ||
instruments[instrument] = 1; | ||
} else { | ||
instruments[instrument]++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
let limitedKeys = Object.getOwnPropertyNames(instruments); | ||
let fullKeys = Object.getOwnPropertyNames(this.VARS.BROWSE_MENU_OPTIONS.instrument); | ||
|
||
fullKeys.sort(function(a, b) { | ||
return a.localeCompare(b); | ||
}); | ||
|
||
// In the future allow multiple instruments to be selected. | ||
let selectedInstrument = ""; | ||
if (this.VARS.SEARCH && this.VARS.SEARCH.instrument) { | ||
selectedInstrument = this.VARS.SEARCH.instrument; | ||
} | ||
|
||
let output = "<select class='filter instrument'>\n"; | ||
|
||
output += "<option value=''>"; | ||
output += this.getTranslation("instrument"); | ||
output += ` [${limitedKeys.length}]`; | ||
output += "</option>\n"; | ||
|
||
for (let i=0; i<fullKeys.length; i++) { | ||
output += '<option value="'; | ||
let instrument = fullKeys[i]; | ||
let displayInstrument = this.getTranslation(instrument); | ||
output += instrument.replace(/"/g, '\\"'); | ||
output += '"' | ||
if (selectedInstrument === instrument) { | ||
output += " selected"; | ||
} | ||
output += '>'; | ||
output += displayInstrument; | ||
if (instruments[instrument]) { | ||
output += ` (${instruments[instrument]})`; | ||
} | ||
output += "</option>\n"; | ||
} | ||
|
||
output += "</select>\n"; | ||
|
||
element.innerHTML = output; | ||
let that = this; | ||
element.onchange = function() { that.doBrowseSearch(); }; | ||
}; | ||
|
||
Object.defineProperty(POPC2.prototype.buildInstrumentFilter, "name", { value: "buildInstrumentFilter" }); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{% comment %} | ||
// | ||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu> | ||
// Creation Date: Wed Oct 6 12:27:04 PDT 2021 | ||
// Last Modified: Wed Oct 6 12:27:07 PDT 2021 | ||
// Filename: _includes/browse/filterByInstrument.js | ||
// Used by: _includes/browse/doBrowseSearch.js | ||
// Included in: _includes/browse/main.html | ||
// Syntax: ECMAScript 6 | ||
// vim: ts=3:nowrap | ||
// | ||
// Description: | ||
// | ||
{% endcomment %} | ||
|
||
POPC2.prototype.filterByInstrument = function (input) { | ||
this.DebugMessageFunctionVerbose(); | ||
let type = "instrument"; | ||
let field = "AIN"; | ||
if (!input) { | ||
return []; | ||
} | ||
if (input.length == 0) { | ||
return input; | ||
} | ||
let element = document.querySelector(`select.filter.${type}`); | ||
let target = ""; | ||
if (element) { | ||
target = element.value; | ||
} | ||
if (target) { | ||
this.VARS.SEARCH[type] = target; | ||
let output = []; | ||
let re = new RegExp("\\b" + target + "\\b"); | ||
for (let i=0; i<input.length; i++) { | ||
if (re.exec(input[i][field])) { | ||
output.push(input[i]); | ||
} | ||
} | ||
return output; | ||
} else { | ||
return input; | ||
} | ||
}; | ||
|
||
Object.defineProperty(POPC2.prototype.filterByInstrument, "name", { value: "filterByInstrument" }); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{% comment %} | ||
// | ||
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu> | ||
// Creation Date: Thu Feb 10 21:00:28 PST 2022 | ||
// Last Modified: Thu Feb 10 21:00:30 PST 2022 | ||
// Filename: _includes/listeners/downloadInstrumentIndex.js | ||
// Used by: | ||
// Included in: | ||
// Syntax: ECMAScript 6 | ||
// vim: ts=3:nowrap | ||
// | ||
// Description: Download the instrument index and store its contents | ||
// into VARS.INSTRUMENT_INDEX global variable. | ||
// | ||
{% endcomment %} | ||
|
||
POPC2.prototype.downloadInstrumentIndex = function () { | ||
this.DebugMessageFunction(); | ||
let url = this.SETTINGS.instrument_index; | ||
this.DebugMessage("DOWNLOADING INSTRUMENT INDEX FROM " + url, "lightblue"); | ||
let that = this; | ||
fetch(url) | ||
.then(res => res.json()) | ||
.then(data => { | ||
that.VARS.INSTRUMENT_INDEX = data; | ||
if (!this.VARS.TRANSLATIONS) { | ||
console.error("NO TRANSLATIONS DATABASE FOR INSTRUMENT CODES"); | ||
} else { | ||
// Store instrument code translations. | ||
for (property in data) { | ||
let entry = {}; | ||
entry.TAG = property; | ||
entry.EN = data[property]["EN"]; | ||
entry.PL = data[property]["PL"]; | ||
this.VARS.TRANSLATIONS[entry.TAG] = entry; | ||
} | ||
} | ||
|
||
that.DebugMessage("DOWNLOADED INSTRUMENT INDEX FROM " + url, "lightblue"); | ||
}) | ||
.catch(err => { console.error("downloadInstrumentIndex:", err); }); | ||
}; | ||
|
||
Object.defineProperty(POPC2.prototype.downloadInstrumentIndex, "name", { value: "downloadInstrumentIndex" }); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.