Skip to content

Commit

Permalink
Let comboboxes filter against terms, not just values
Browse files Browse the repository at this point in the history
Add terms property to fields
Make terms translatable for searchable fields
Account for fields' terms and keys when filtering with the Add field menu (close #5763)
  • Loading branch information
quincylvania committed Aug 9, 2019
1 parent f8b6772 commit 67afa20
Show file tree
Hide file tree
Showing 43 changed files with 1,144 additions and 377 deletions.
37 changes: 30 additions & 7 deletions build_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ module.exports = function buildData() {
// The Noun Project icons used
var tnpIcons = {};

// all fields searchable under "add field"
var searchableFieldIDs = {};

// Start clean
shell.rm('-f', [
'data/presets/categories.json',
Expand All @@ -76,10 +79,10 @@ module.exports = function buildData() {
]);

var categories = generateCategories(tstrings, faIcons, tnpIcons);
var fields = generateFields(tstrings, faIcons);
var presets = generatePresets(tstrings, faIcons, tnpIcons);
var fields = generateFields(tstrings, faIcons, tnpIcons, searchableFieldIDs);
var presets = generatePresets(tstrings, faIcons, tnpIcons, searchableFieldIDs);
var defaults = read('data/presets/defaults.json');
var translations = generateTranslations(fields, presets, tstrings);
var translations = generateTranslations(fields, presets, tstrings, searchableFieldIDs);
var taginfo = generateTaginfo(presets, fields);
var territoryLanguages = generateTerritoryLanguages();

Expand Down Expand Up @@ -174,7 +177,7 @@ function generateCategories(tstrings, faIcons, tnpIcons) {
}


function generateFields(tstrings, faIcons, tnpIcons) {
function generateFields(tstrings, faIcons, tnpIcons, searchableFieldIDs) {
var fields = {};
glob.sync(__dirname + '/data/presets/fields/**/*.json').forEach(function(file) {
var field = read(file);
Expand All @@ -183,9 +186,14 @@ function generateFields(tstrings, faIcons, tnpIcons) {
validate(file, field, fieldSchema);

var t = tstrings.fields[id] = {
label: field.label
label: field.label,
terms: (field.terms || []).join(',')
};

if (field.universal) {
searchableFieldIDs[id] = true;
}

if (field.placeholder) {
t.placeholder = field.placeholder;
}
Expand Down Expand Up @@ -321,7 +329,7 @@ function stripLeadingUnderscores(str) {
}


function generatePresets(tstrings, faIcons, tnpIcons) {
function generatePresets(tstrings, faIcons, tnpIcons, searchableFieldIDs) {
var presets = {};

glob.sync(__dirname + '/data/presets/presets/**/*.json').forEach(function(file) {
Expand All @@ -335,6 +343,12 @@ function generatePresets(tstrings, faIcons, tnpIcons) {
terms: (preset.terms || []).join(',')
};

if (preset.moreFields) {
preset.moreFields.forEach(function(fieldID) {
searchableFieldIDs[fieldID] = true;
});
}

presets[id] = preset;

// fontawesome icon, remember for later
Expand All @@ -352,7 +366,7 @@ function generatePresets(tstrings, faIcons, tnpIcons) {
}


function generateTranslations(fields, presets, tstrings) {
function generateTranslations(fields, presets, tstrings, searchableFieldIDs) {
var translations = JSON.parse(JSON.stringify(tstrings)); // deep clone

Object.keys(translations.fields).forEach(function(id) {
Expand Down Expand Up @@ -380,6 +394,15 @@ function generateTranslations(fields, presets, tstrings) {
if (f.placeholder) {
field['placeholder#'] = id + ' field placeholder';
}

if (searchableFieldIDs[id]) {
if (f.terms && f.terms.length) {
field['terms#'] = 'terms: ' + f.terms.join();
}
field.terms = '<translate with synonyms or related terms for \'' + field.label + '\', separated by commas>';
} else {
delete field.terms;
}
});

Object.keys(translations.presets).forEach(function(id) {
Expand Down
Loading

0 comments on commit 67afa20

Please sign in to comment.