Files
iD/modules/presets/category.js
Quincy Morgan a1af118f0e Ensure locales and presets are loaded before the UI loads (close #7406)
Consolidate localization behavior and init to a coreLocalizer function and singleton
Explicitly support `en-US` locale
Rename coreData to coreFileFetcher and export a singleton rather than using a property of coreContext
Add `apiConnections` property of coreContext to simplify adding a source switcher
Replace some init functions with re-callable, promise-supporting `ensureLoaded` functions
Make coreContext itself load the UI if a container has been specified at init time
Fix code tests
2020-03-31 12:23:31 -07:00

43 lines
1.1 KiB
JavaScript

import { t } from '../core/localizer';
import { presetCollection } from './collection';
//
// `presetCategory` builds a `presetCollection` of member presets,
// decorated with some extra methods for searching and matching geometry
//
export function presetCategory(categoryID, category, all) {
let _this = Object.assign({}, category); // shallow copy
_this.id = categoryID;
_this.members = presetCollection(
category.members.map(presetID => all.item(presetID)).filter(Boolean)
);
_this.geometry = _this.members.collection
.reduce((acc, preset) => {
for (let i in preset.geometry) {
const geometry = preset.geometry[i];
if (acc.indexOf(geometry) === -1) {
acc.push(geometry);
}
}
return acc;
}, []);
_this.matchGeometry = (geom) => _this.geometry.indexOf(geom) >= 0;
_this.matchAllGeometry = (geometries) => _this.members.collection
.some(preset => preset.matchAllGeometry(geometries));
_this.matchScore = () => -1;
_this.name = () => t(`presets.categories.${categoryID}.name`, { 'default': categoryID });
_this.terms = () => [];
return _this;
}