Skip to content

Commit

Permalink
support for using a different field when getting comparison value inp…
Browse files Browse the repository at this point in the history
…ut, used with advanced search
  • Loading branch information
brookgagnon committed Jul 26, 2024
1 parent 9ff4daf commit 2e24ed1
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 16 deletions.
16 changes: 13 additions & 3 deletions js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ OB.Sidebar.advancedSearchFilterChange = function () {
if (type) {
metadataContainer.innerHTML = "";
const metadataElement = document.createElement("ob-field-" + type);
const metadataOperators = metadataElement?.constructor?.operators;
const metadataOperators = metadataElement?.constructor?.comparisonOperators;

const operatorElement = document.createElement("select");
Object.entries(metadataOperators).forEach((operator) => {
Expand All @@ -1371,8 +1371,18 @@ OB.Sidebar.advancedSearchFilterChange = function () {

metadataContainer.appendChild(operatorElement);

metadataElement.editable = true;
metadataContainer.appendChild(metadataElement);
// field specifies a different comparison field
if (metadataElement?.constructor?.comparisonField) {
const comparisonField = document.createElement("ob-field-" + metadataElement.constructor.comparisonField);
comparisonField.editable = true;
metadataContainer.appendChild(comparisonField);
}

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

metadataContainer.style.display = "inline-flex";
} else {
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { html, render } from "../vendor.js";
import { OBField } from "../base/field.js";

class OBFieldBool extends OBField {
static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/country.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OBField } from "../base/field.js";
class OBFieldCountry extends OBField {
static countries = null;

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OBFieldDatetime extends OBField {
valueFormat = "YYYY-MM-DD HH:mm:ss";
valueStringFormat = "MMM D, YYYY h:mm A";

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
gt: "greater than",
Expand Down
4 changes: 3 additions & 1 deletion ui/fields/formatted.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ class OBFieldFormatted extends OBField {
#init;
#editorInstance;

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
contains: "contains",
ncontains: "does not contain",
};

static comparisonField = "text";

renderEdit() {
if (this.#editorInstance) {
// update value only
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/genre.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OBFieldGenre extends OBField {
#currentGenre;
#genres;

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OBFieldLanguage extends OBField {
static languages = null;
static popularLanguages = null;

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OBFieldMedia extends OBField {

#init;

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OBField } from "../base/field.js";
import { html, render } from "../vendor.js";

class OBFieldNumber extends OBField {
static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
gt: "greater than",
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OBFieldPlaylist extends OBField {
#playlistContent;
#setValue;

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OBFieldSelect extends OBField {
#options;
filterVal = "";

static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
};
Expand Down
4 changes: 3 additions & 1 deletion ui/fields/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class OBFieldTags extends OBField {
#suggestions;
#currentTag;

static operators = {
static comparisonOperators = {
has: "has",
nhas: "does not have",
};

static comparisonField = "text";

// TODO loading tags and suggestions via OB-OPTION and OB-TAGS temporarily disabled.
// fix needed as these are currently overwriting set value.
/*
Expand Down
2 changes: 1 addition & 1 deletion ui/fields/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OBField } from "../base/field.js";
import { html, render } from "../vendor.js";

class OBFieldText extends OBField {
static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
contains: "contains",
Expand Down
4 changes: 3 additions & 1 deletion ui/fields/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { OBField } from "../base/field.js";
import { html, render } from "../vendor.js";

class OBFieldTextarea extends OBField {
static operators = {
static comparisonOperators = {
eq: "is",
neq: "is not",
contains: "contains",
ncontains: "does not contain",
};

static comparisonField = "text";

renderView() {
render(html`<div id="view">${this.value}</div>`, this.root);
}
Expand Down

0 comments on commit 2e24ed1

Please sign in to comment.