Class: QueryRuleView

QueryRuleView()

A view that provides an UI for a user to construct a single filter that is part of a complex query

Screenshot

Constructor

new QueryRuleView()

Since:
  • 2.14.0
Source:

Extends

  • Backbone.View

Members

className :string

The HTML class names for this view element
Type:
  • string
Source:

excludeFields :Array.<string>

Search index fields to exclude in the metadata field selector
Type:
  • Array.<string>
Source:

fieldsClass :string

The class to add to the field select element
Type:
  • string
Source:

model :Filter|BooleanFilter|NumericFilter|DateFilter|FilterGroup

A single Filter model that is part of a Filters collection, such as the definition filters for a Collection or Portal or the filters for a Search model. The Filter model must be part of a Filters collection (i.e. there must be a model.collection property)
Type:
Source:

nestedExcludeFields :Array.<string>

Query fields to exclude in the metadata field selector for any Query Rules that are in nested Query Builders (i.e. in nested Filter Groups). This is a list of field names that exist in the query service index (i.e. Solr), but which should be hidden in nested Query Builders
Type:
  • Array.<string>
Source:

nestedLevelsAllowed :number

The maximum number of levels of nested Rule Groups (i.e. nested FilterGroup models) that a user is permitted to build in the Query Builder that contains this rule. This value should be passed to the rule by the parent Query Builder. This value minus one will be passed on to any child Query Builders (those that render nested FilterGroup models).
Type:
  • number
Since:
  • 2.17.0
Source:

operatorClass :string

The class to add to the operator select element
Type:
  • string
Source:

operatorOptions :Array.<OperatorOption>

The list of operators that will be available in the dropdown list that connects the query fields to the values. Each operator must be unique.
Type:
Source:

removeClass :string

The class to add to the element that a user should click to remove a rule.
Type:
  • string
Source:

removeRuleID :string

An ID for the element that a user should click to remove a rule. A unique ID will be appended to this ID, and the ID will be added to the template.
Type:
  • string
Source:

ruleColorPalette :Array.<string>|string

An array of hex color codes used to help distinguish between different rules. If this is a nested Query Rule, and the rule should inherit its colour from the parent Query Rule, then set ruleColorPalette to "inherit".
Type:
  • Array.<string> | string
Source:

ruleInfoClass :string

The class to add to the rule number and other information on the left
Type:
  • string
Source:

specialFields :Array.<SpecialField>

A list of additional fields which are not retrieved from the query API, but which should be added to the list of options. This can be used to add abstracted fields which are a combination of multiple query fields, or to add a duplicate field that has a different label. These special fields are passed on to QueryFieldSelectView#addFields.
Type:
Since:
  • 2.15.0
Source:

type :string

The type of View this is
Type:
  • string
Source:

valueSelectUImap :Array.<ValueInputOption>

This list defines which type of value input to show depending on filter type, category, and query fields. The value input options are ordered from *most* specific to *least*, since the first match will be selected. The filter model must match either the queryFields, or both the filterTypes AND the categories for a UI to be selected.
Type:
Source:

valuesClass :string

The class to add to the value select element
Type:
  • string
Source:

Methods

addFieldSelect()

Create and insert an input that allows the user to select a metadata field to query
Source:

addOperatorSelect(selectedOperator)

Create and insert an input field where the user can select an operator for the given rule. Operators will vary depending on filter model type.
Parameters:
Name Type Description
selectedOperator string optional. The label of an operator to pre-select. Set to an empty string to render an empty operator selector.
Source:

addRemoveButton()

addRemoveButton - Create and insert the button to remove the Query Rule
Source:

addRuleInfo()

Insert container for the color-coded rule numbering.
Source:

addValueSelect()

Create and insert an input field where the user can provide a search value
Source:

convertFromSpecialFields(fields, fields) → {Array.<string>|Array.<string>}

Takes a list of query field names and checks if it contains any of the special field names. Returns the list with the special field names replaced with the actual field names that those special fields represent. Stores the name of each special field name removed in an array set on the view's selectedSpecialFields property. selectedSpecialFields is cleared each time this function runs. This function is the opposite of QueryRuleView#convertToSpecialFields
Parameters:
Name Type Description
fields Array.<string> The list of field names to convert
fields Array.<string> The list of fields to convert to actual query service index fields
Since:
  • 2.15.0
Source:
Returns:
  • - The converted list of field names. If there were no special fields detected, or if there's an error, then then the field names are returned unchanged.
    Type
    Array.<string>
  • - Returns the list of fields with any special field replaced with real fields from the query service index
    Type
    Array.<string>

convertToSpecialFields(fields, fields) → {Array.<string>|Array.<string>}

Takes a list of query field names, checks if the model matches any of the special fields, and if it does, returns the list of fields with the actual field names replaced with the special field name. This function is the opposite of QueryRuleView#convertFromSpecialFields
Parameters:
Name Type Description
fields Array.<string> The list of field names to convert
fields Array.<string> The list of fields to convert to special fields, if the model matches any of the special field objects
Since:
  • 2.15.0
Source:
Returns:
  • - The converted list of field names. If there were no special fields detected, or if there's an error, then then the field names are returned unchanged.
    Type
    Array.<string>
  • - Returns the list of fields with actual query field names replaced with special field names, if any match
    Type
    Array.<string>

events() → {Object}

A function that creates and returns the Backbone events object.
Source:
Returns:
Returns a Backbone events object
Type
Object

getCategory(fields) → {string}

getCategory - Given an array of query fields, get the user-facing category that these fields belong to. If there are fields from multiple categories, then a default "Text" category is returned.
Parameters:
Name Type Description
fields Array.<string> An array of query (Solr) fields
Source:
Returns:
The label for the category that the given fields belong to
Type
string

getOperatorOptions(fieldsopt)

Get a list of operatorOptions that are allowed for this view's filter model
Parameters:
Name Type Attributes Description
fields Array.<string> <optional>
Optional list of fields to use instead of the fields set on this view's Filter model
Since:
  • 2.15.0
Source:

getPaletteColor(indexopt, defaultColoropt) → {string}

Selects a color from the rule colour palette array, given an index. If the index is greater than the length of the palette, then the palette is effectively repeated until long enough (i.e. colours will be recycled). If no index in provided, the first colour in the palette will be selected.
Parameters:
Name Type Attributes Default Description
index number <optional>
0 The position of the rule within the Filters collection.
defaultColor string <optional>
"#57b39c" A default colour to use in case there is problem with this function (hex color code beginning with '#').
Source:
Returns:
- Returns a hex color code string
Type
string

getSelectedOperator() → {string}

getSelectedOperator - Based on values set on the model, get the label to show in the "operator" filed of the Query Rule
Source:
Returns:
The operator label
Type
string

getSpecialField(fieldsopt) → {SpecialField|null}

Determines whether the filter model that this rule renders matches one of the special fields set on this view. If it does, returns the first special field object that matches. For a filter model to match to one of the special fields, it must contain all of the fields listed in the special field's "fields" property. If the special field has an array set for "values", then the model's values must also exactly match the special field's values.
Parameters:
Name Type Attributes Description
fields Array.<string> <optional>
Optionally set a list of query fields to search with. If not set, then the fields that are set on the view's filter model are used.
Since:
  • 2.15.0
Source:
Returns:
- The matching special field, or null if no match was found.
Type
SpecialField | null

handleFieldChange(newFields)

handleFieldChange - Called when the Query Field Select View triggers a change event. Updates the model with the new fields, and if required, 1) converts the filter model to a different type based on the types of fields selected, 2) updates the operator select and the value select
Parameters:
Name Type Description
newFields Array.<string> The list of new query fields that were selected
Source:

handleOperatorChange(newOperatorLabel)

handleOperatorChange - When the operator selection is changed, update the model and re-set the value UI when required
Parameters:
Name Type Description
newOperatorLabel Array.<string> The new operator label within an array, e.g. ["is greater than"]
Source:

handleValueChange(newValues)

handleValueChange - Called when the select values for rule are changed. Updates the model.
Parameters:
Name Type Description
newValues Array.<string> The new values that were selected
Source:

initialize(options)

Creates a new QueryRuleView
Parameters:
Name Type Description
options Object A literal object with options to pass to the view
Source:

previewRemove()

Indicate to the user that the rule will be removed when they hover over the remove button.
Source:

removeInput(inputType)

Remove one of the three input fields from the rule
Parameters:
Name Type Description
inputType string Which of the inputs to remove? "field", "operator", or "value"
Source:

removeSelf()

removeSelf - When the delete button is clicked, remove this entire View and associated model
Source:

render() → {QueryRule}

render - Render the view
Source:
Returns:
Returns the view
Type
QueryRule

updateRuleInfo()

Adds or updates the color-coded Query Rule information displayed to the user. This needs to be run when rules are added or removed. Rule information includes the rule number, but may one day also display information such as the number of results that there are for this individual rule.
Source: