From 523bcacac786b59fa1410407be18155232585c1a Mon Sep 17 00:00:00 2001 From: Jun Matsushita Date: Mon, 11 Jan 2016 20:25:16 +0100 Subject: [PATCH] More work on facets including live counts. #6 --- assets/css/style.css | 6 ++ layouts/projects.html | 49 +++++++++- layouts/tools.html | 206 ++++++++++++++++++++++++++++++++++++++++-- metalsmith.json | 3 + 4 files changed, 254 insertions(+), 10 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index 103e933..948d122 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -164,4 +164,10 @@ ul { font-size: 20px; color: #222; float: right; +} + +.small legend { + font-weight: bold; + font-size: 17px; + margin-bottom:0px; } \ No newline at end of file diff --git a/layouts/projects.html b/layouts/projects.html index 12c3646..e89725f 100644 --- a/layouts/projects.html +++ b/layouts/projects.html @@ -2,7 +2,7 @@ {% block main %} {{ contents | safe }} -
+
@@ -59,7 +59,8 @@
- + +
NameDescription
NameDescription
@@ -141,8 +142,50 @@ search: {ele: '#searchbox'}, //search: {ele: '#searchbox', fields: ['runtime']}, // With specific fields callbacks: { + afterAddRecords: function(records){ + $('#total_results').text('Found : ' + records.length); + + _.chain(meta) + .keys() + .omit("library","data_modeling","bulk_upload","displays_lists","network_viz","network_editing","network_analysis","embeddable","document_viz","timelines","maps") + .each(function(k){ + var checkboxes = $('#' + k + '_criteria :input'); + var qResult = JsonQuery(records); + + checkboxes.each(function(){ + var c = $(this) + var q = {}; + q[k] = c.val(); + var count = qResult.where(q).count; + c.next().text(c.val() + ' (' + count + ')') + }); + }) + + }, afterFilter: function(result){ - $('#total_results').text(result.length); + if(!result.length){ + $('#total_results').text("No results found"); + } + else + { + $('#total_results').text('Found : ' + result.length); + } + + _.chain(meta) + .keys() + .omit("library","data_modeling","bulk_upload","displays_lists","network_viz","network_editing","network_analysis","embeddable","document_viz","timelines","maps") + .each(function(k){ + var checkboxes = $('#' + k + '_criteria :input'); + var qResult = JsonQuery(result); + + checkboxes.each(function(){ + var c = $(this) + var q = {}; + q[k] = c.val(); + var count = qResult.where(q).count; + c.next().text(c.val() + ' (' + count + ')') + }); + }) } } //appendToContainer: appendToContainer diff --git a/layouts/tools.html b/layouts/tools.html index 2c702e3..888c53f 100644 --- a/layouts/tools.html +++ b/layouts/tools.html @@ -2,7 +2,7 @@ {% block main %} {{ contents | safe }} -
+
@@ -10,9 +10,88 @@
-

+ +
+
+
+ Tool Features +
+
+
@@ -27,6 +106,13 @@
+
+
+
+ Deployment +
+
+
@@ -41,11 +127,19 @@
+
+
+
+ Programming Language +
+
+
- + +
NameDescription
NameDescription
@@ -69,8 +163,9 @@ index, store = $.getJSON("searchMeta.json"), data = $.getJSON("searchIndex.json"), - meta = {} - res = {}; + meta = {}, + res = {}, + multiCriteria = ["feature"]; data.then(function(data) { store.then(function(store) { @@ -98,6 +193,7 @@ _.chain(meta) .keys() + .filter(function(k){return (k.lastIndexOf("feature_",0) !== 0)}) .each(function(k){ meta[k] = _.unique(meta[k]); if (k!="content_type") @@ -111,10 +207,26 @@ '
'); }); }) + // Deal with multicolumn criteria + + _.each(multiCriteria, function(mc) { + _.chain(meta) + .keys() + .filter(function(k){return (k.lastIndexOf(mc,0) === 0)}) + .each(function(k){ + $('#' + mc + '_multicriteria').append( + '
' + + ' ' + + '
'); + }) + }) var ks = _.keys(store); var results = _.chain(ks) - .filter(function(k){ return store[k].content_type=="tool"}) + .filter(function(k){ return (store[k].content_type=="tool" && store[k].published!="No")}) .map(function(k) { // add store key of object as path key of array object var ret = _.extend( { path: k.replace(".md", ".html") } , store[k] ); @@ -127,8 +239,23 @@ search: {ele: '#searchbox'}, //search: {ele: '#searchbox', fields: ['runtime']}, // With specific fields callbacks: { + afterAddRecords: function(records){ + $('#total_results').text('Found : ' + records.length); + + updateCounts(meta, records); + + }, afterFilter: function(result){ - $('#total_results').text(result.length); + if(!result.length){ + $('#total_results').text("No results found"); + } + else + { + $('#total_results').text('Found : ' + result.length); + } + + updateCounts(meta, result); + } } //appendToContainer: appendToContainer @@ -136,12 +263,28 @@ FJS.addCriteria({field: 'content_type', ele: '#content_type_criteria input:checkbox'}); +// FJS.addCriteria({field: 'library', ele: '#tool_features_library'}); +// FJS.addCriteria({field: 'maps', ele: '#tool_features_maps'}); + _.chain(meta) .keys() + .filter(function(k){ return _.any(multiCriteria, function(mc) {return (k.lastIndexOf(mc + '_',0) !== 0)}) }) .each(function(k){ FJS.addCriteria({field: k, ele: '#' + k + '_criteria input:checkbox'}); }) + // Deal with multicolumn criteria + + _.each(multiCriteria, function(mc) { + _.chain(meta) + .keys() + .filter(function(k){return (k.lastIndexOf(mc,0) === 0)}) + .each(function(k){ + FJS.addCriteria({field: k, ele: '#' + k + '_criteria input'}); + }) + }) + + }) }) /* @@ -164,6 +307,43 @@ }); */ + + function updateCounts(meta, res) { + _.chain(meta) + .keys() + .filter(function(k){ return _.any(multiCriteria, function(mc) {return (k.lastIndexOf(mc + '_',0) !== 0)}) }) + .each(function(k){ + var checkboxes = $('#' + k + '_criteria :input'); + var qResult = JsonQuery(res); + + checkboxes.each(function(){ + var c = $(this) + var q = {}; + q[k] = c.val(); + var count = qResult.where(q).count; + c.next().text(c.val() + ' (' + count + ')') + }); + }) + + _.each(multiCriteria, function(mc) { + _.chain(meta) + .keys() + .filter(function(k){return (k.lastIndexOf(mc,0) === 0)}) + .each(function(k){ + var checkboxes = $('#' + k + '_criteria :input'); + var qResult = JsonQuery(res); + + checkboxes.each(function(){ + var c = $(this) + var q = {}; + q[k] = c.val(); + var count = qResult.where(q).count; + c.next().text(makeTitle(k.replace(mc + '_','')) + ' (' + count + ')') + }); + }) + }) + } + }); function prepareResults(results, store) { @@ -193,5 +373,17 @@ }); } + +function makeTitle(slug) { + var words = slug.split('_'); + + for(var i = 0; i < words.length; i++) { + var word = words[i]; + words[i] = word.charAt(0).toUpperCase() + word.slice(1); + } + + return words.join(' '); +} + {% endblock %} diff --git a/metalsmith.json b/metalsmith.json index eb29bb9..176ebe3 100644 --- a/metalsmith.json +++ b/metalsmith.json @@ -130,6 +130,9 @@ "description", "practice", "practice_2", + "deployment", + "programming_language", + "feature_coding","feature_data_modeling","feature_bulk_upload","feature_displays_lists","feature_network_viz","feature_network_editing","feature_network_analysis","feature_embeddable","feature_document_viz","feature_timelines","feature_maps", "phase", "geographic_focus", "intended_impact",