diff --git a/README.md b/README.md index cb80dc7..fbe414b 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ The CollectionSpace public browser. ## Installation -### For CollectionSpace Administrators +### For Web Site Administrators -The CollectionSpace public browser is a JavaScript application that runs in a web browser. To install the application in a WordPress site, use the [wp-collectionspace](https://github.com/collectionspace/wp-collectionspace) WordPress plugin. +The CollectionSpace public browser is a JavaScript application that runs in a web browser. To add the application to a web site, see the [installation instructions](./docs/installing.md). ### For CollectionSpace Developers diff --git a/docs/configuration/README.md b/docs/configuration/README.md new file mode 100644 index 0000000..7af810f --- /dev/null +++ b/docs/configuration/README.md @@ -0,0 +1,59 @@ +# Configuration Reference + +Configuration settings can be supplied to override the [default configuration](../../src/config/default.js). + +## `basename` +Required. + +The path to the web page containing the public browser, as seen in the URL to the page (which typically would also be the path to the index.html file, from the web root directory). For example, if the public browser is being added to a web page located at http://mymuseum.org/cspace/collection/index.html, then `basename` should be set to `/cspace/collection`. + +## `gatewayUrl` +Required. + +The URL of a CollectionSpace public gateway that has access to the collection data. Typically, this is something like `https://{cspace server hostname}/gateway/{tenant short name}`. This can vary depending on how the CollectionSpace back-end has been configured, so verify the gateway URL with your CollectionSpace administrator. + + +## `baseConfig` +The name of a configuration set to apply over the default configuration. Can be one of the following: `'anthro'`, `'bonsai'`, `'botgarden'`, `'fcart'`, `'herbarium'` `'lhmc'`, `'materials'`, `'publicart'`. These configurations adjust the public browser for use with CollectionSpace community-of-practice profiles. + +To view the contents of a named configuration set, refer to the corresponding .js file in the [config](../../src/config/) directory. + +## `filterOrder` +Default: `{ _term: 'asc' }` + +The sort order of filter values appearing in the "Refine results" sidebar. This can be set to `{ _term: 'asc' }` to sort alphabetically, or to `{ _count: 'desc' }` to sort by the number of search results containing the value (highest to lowest). + +This setting can be [overridden on a per-filter basis](#order). + +## `filterSize` +Default: `300` + +The maximum number of values to show for each filter in the "Refine results" sidebar. Increasing this shows more values, but makes searches slower. + +This setting can be [overridden on a per-filter basis](#size). + +## `filters` +Contains configuration for filter fields and groups. + +### `fields` +Contains configuration for filter fields, keyed by field name. For example, to configure the `objectProductionPerson` filter field: + +``` +filters: { + fields: { + objectProductionPerson: { + order: { _count: 'desc' }, + }, + }, +}, +``` + +To find the names of filter fields that can be configured, refer to the [default configuration](../../src/config/default.js), and any configuration set that has been applied using the [`baseConfig`](#baseConfig) setting. + +Filter field configuration can contain the following settings: + +#### `order` +Overrides the top-level [`filterOrder`](#filterOrder) setting, for this field. + +#### `size` +Overrides the top-level [`filterSize`](#filterSize) setting, for this field. diff --git a/docs/installing.md b/docs/installing.md index d33d01b..06ce1a2 100644 --- a/docs/installing.md +++ b/docs/installing.md @@ -31,12 +31,18 @@ The application must be initialized by adding some JavaScript code that calls an ``` -Two configuration options are required: +Two configuration settings are required: - `basename` - This should be set to the path to the web page containing the public browser, as seen in the URL to the page (which typically would also be the path to the index.html file, from the web root directory). For example, if the public browser is being added to a web page located at http://mymuseum.org/cspace/collection/index.html, then `basename` should be set to `/cspace/collection`. - `gatewayUrl` - This should be set to the URL of a CollectionSpace public gateway that has access to the collection data. Typically, this is something like `https://{cspace server hostname}/gateway/{tenant short name}`. This can vary depending on how the CollectionSpace back-end has been configured, so verify the gateway URL with your CollectionSpace administrator. +One other setting is required if you're using a CollectionSpace community-of-practice profile: + +- `baseConfig` - This should be set to the name of the profile. + +See the [configuration reference](./configuration/README.md) for more information about these and other settings. + ## Configuring the web server The CollectionSpace public browser application runs as a "front controller". This means that if the application is added to a web page at e.g., http://mymuseum.org/cspace/collection, then any request to a URL under http://mymuseum.org/cspace/collection should return the same HTML as http://mymuseum.org/cspace/collection. The web server must be configured to do this. In Apache, this can be done using the [FallbackResource](https://httpd.apache.org/docs/trunk/mod/mod_dir.html#fallbackresource) directive. For example: diff --git a/src/config/default.js b/src/config/default.js index 589cc6f..5ed48d8 100644 --- a/src/config/default.js +++ b/src/config/default.js @@ -113,6 +113,9 @@ export default { formatValue: displayName, }, + filterOrder: { _term: 'asc' }, + filterSize: 300, + filters: { fields: { objectName: { diff --git a/src/helpers/esQueryHelpers.js b/src/helpers/esQueryHelpers.js index 0364c78..21aeb13 100644 --- a/src/helpers/esQueryHelpers.js +++ b/src/helpers/esQueryHelpers.js @@ -120,11 +120,15 @@ export const getHistogramAgg = (field, interval = 1) => ({ }, }); -export const getTermsAgg = (field, order = { _term: 'asc' }) => ({ +export const getTermsAgg = ( + field, + order = config.get('filterOrder'), + size = config.get('filterSize'), +) => ({ terms: { field, order, - size: 300, + size, }, }); @@ -132,6 +136,7 @@ export const getFilterAgg = (filterFieldConfig) => { const { field, order, + size, type, } = filterFieldConfig; @@ -139,7 +144,7 @@ export const getFilterAgg = (filterFieldConfig) => { return getHistogramAgg(field, filterFieldConfig.interval); } - return getTermsAgg(field, order); + return getTermsAgg(field, order, size); }; let aggs;