Allow suggestion if preset with same name exists, pick suggestion w highest count..#2224

This commit is contained in:
Bryan Housel
2014-05-28 13:17:48 -04:00
parent a796d4b1ea
commit 941ee1d88c
2 changed files with 712 additions and 641 deletions
+10 -13
View File
@@ -90,15 +90,7 @@ function generateFields() {
}
function suggestionsToPresets(presets) {
var existing = {},
countThreshold = 0;
for (var preset in presets) {
existing[presets[preset].name] = {
category: preset,
count: -1
};
}
var existing = {};
for (var key in suggestions) {
for (var value in suggestions[key]) {
@@ -107,14 +99,19 @@ function suggestionsToPresets(presets) {
tags = {},
count = suggestions[key][value][name].count;
tags = _.extend({name: name}, suggestions[key][value][name].tags);
if (!existing[name] && count > countThreshold) addPreset(item, tags, name, count);
if (existing[name] && count > existing[name].count) {
delete presets[existing[name].category];
delete existing[name];
}
if (!existing[name]) {
tags = _.extend({name: name}, suggestions[key][value][name].tags);
addSuggestion(item, tags, name, count);
}
}
}
}
function addPreset(category, tags, name, count) {
function addSuggestion(category, tags, name, count) {
var tag = category.split('/'),
parent = presets[tag[0] + '/' + tag[1]];
+702 -628
View File
File diff suppressed because it is too large Load Diff