Skip to content

Commit

Permalink
fixes to advanced search with new metadata fields
Browse files Browse the repository at this point in the history
  • Loading branch information
brookgagnon committed Jul 26, 2024
1 parent 2e24ed1 commit da0f119
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion html/sidebar/advanced_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

<input type="text" id="advanced_search_value" data-type="value" data-name="text">

<div id="advanced_search_metadata" style="display: inline-flex; align-items: flex-start; gap: 10px;"></div>
<div id="advanced_search_metadata" style="display: none; align-items: flex-start; gap: 10px;"></div>

&nbsp;

Expand Down
17 changes: 17 additions & 0 deletions js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ OB.Sidebar.advancedSearchFilterChange = function () {
const metadataOperators = metadataElement?.constructor?.comparisonOperators;

const operatorElement = document.createElement("select");
operatorElement.setAttribute("id", "advanced_search_metadata_operator");
Object.entries(metadataOperators).forEach((operator) => {
const option = document.createElement("option");
option.value = operator[0];
Expand All @@ -1375,12 +1376,14 @@ OB.Sidebar.advancedSearchFilterChange = function () {
if (metadataElement?.constructor?.comparisonField) {
const comparisonField = document.createElement("ob-field-" + metadataElement.constructor.comparisonField);
comparisonField.editable = true;
comparisonField.setAttribute("id", "advanced_search_metadata_value");
metadataContainer.appendChild(comparisonField);
}

// field uses itself as the comparison field
else {
metadataElement.editable = true;
metadataElement.setAttribute("id", "advanced_search_metadata_value");
metadataContainer.appendChild(metadataElement);
}

Expand All @@ -1401,6 +1404,20 @@ OB.Sidebar.advancedSearchAdd = function (filter_data) {
var op = filter_data.op;
var val = filter_data.val;
var filter = filter_data.filter;
} else if (document.getElementById("advanced_search_metadata").style.display != "none") {
var filter = document.getElementById("advanced_search_filter").value;
filter = filter.replace(/^metadata_/, "");
var op = document.getElementById("advanced_search_metadata_operator").value;
var val = document.getElementById("advanced_search_metadata_value").value;

// get metadata/settings for this field
const metadata = OB.Settings.media_metadata.find((metadata) => metadata.name === filter);
const type = metadata.type;

// get the operator name from the index
const operators = document.createElement(`ob-field-${type}`).constructor.comparisonOperators;

var filter_description = `${metadata.description} "${operators[op]} "${val}"`;
} else {
var $filter = $("#advanced_search_filter option:selected");
var filter = $("#advanced_search_filter").val();
Expand Down

0 comments on commit da0f119

Please sign in to comment.