From c515505f5e9c2fce406b761a74f5be93d03d8279 Mon Sep 17 00:00:00 2001 From: Felix Ostrowski Date: Tue, 12 Apr 2016 19:39:31 +0200 Subject: [PATCH 1/3] Add Handlebars helpers to sort on literal values --- public/handlebars/statement.hbs | 4 +- public/js/helpers.js | 70 ++++++++++++++++++++++++++++++- public/rightsstatements.github.io | 2 +- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/public/handlebars/statement.hbs b/public/handlebars/statement.hbs index 5f63838..4d7782e 100644 --- a/public/handlebars/statement.hbs +++ b/public/handlebars/statement.hbs @@ -31,9 +31,9 @@

{{ data.definition.[@value] }}

{{i18n "notices" locale=language}}

{{{i18n "Disclaimer" locale=language}}}

{{#parameters.date}} diff --git a/public/js/helpers.js b/public/js/helpers.js index e6d3998..99ea4ab 100644 --- a/public/js/helpers.js +++ b/public/js/helpers.js @@ -6,12 +6,78 @@ Handlebars.registerHelper('a', function (href, options) { return new Handlebars.SafeString("" + href + ""); }); -Handlebars.registerHelper('id', function(id, graph, options) { +Handlebars.registerHelper('resource', function(id, graph, options) { for (var i = 0; i < graph.length; i++) { - if (graph[i]['@id'].trim() == id.trim()) { + if (graph[i]['@id'] == id) { return options.fn(graph[i]); } } }); + +Handlebars.registerHelper('property', function(property, graph, options) { + + var sort = options.hash['sort'].split(" "); + var on_property = sort[0]; + var order = sort[1]; + + var graphs = []; + + for (var i = 0; i < property.length; i++) { + for (var j = 0; j < graph.length; j++) { + if (graph[j]['@id'] == property[i]) { + graphs.push(graph[j]); + } + } + } + + var ret = ""; + + graphs.sort(order == "asc" ? sort_property_asc(on_property) : sort_property_desc(on_property)); + + for (var k = 0; k < graphs.length; k++) { + ret = ret + options.fn(graphs[k]); + } + + return ret; + +}); + +Handlebars.registerHelper('sort', function(values, options) { + // weird Rhino behavior, explicitly create array + var vals = []; + for (var i = 0; i < values.length; i++) { + vals.push(values[i]); + } + vals.sort(options.hash['direction'] == "asc" ? sort_asc : sort_desc); + var ret = ""; + for (var i = 0; i < vals.length; i++) { + ret = ret + options.fn(vals[i]); + } + return ret; +}); + +function sort_property_asc(on_property) { + return function(a, b) { + return a[on_property]['@value'] == b[on_property]['@value'] + ? 0 : +(a[on_property]['@value'] > b[on_property]['@value']) || -1; + } +} + +function sort_property_desc(on_property) { + return function(a, b) { + return a[on_property]['@value'] == b[on_property]['@value'] + ? 0 : +(a[on_property]['@value'] < b[on_property]['@value']) || -1; + } +} + +function sort_asc(a, b) { + return a['@value'] == b['@value'] + ? 0 : +(a['@value'] > b['@value']) || -1; +} + +function sort_desc(a, b) { + return a['@value'] == b['@value'] + ? 0 : +(a['@value'] < b['@value']) || -1; +} diff --git a/public/rightsstatements.github.io b/public/rightsstatements.github.io index 23dd954..ba62a1b 160000 --- a/public/rightsstatements.github.io +++ b/public/rightsstatements.github.io @@ -1 +1 @@ -Subproject commit 23dd954bc176bda3db42bcd70d605099b78c5cc0 +Subproject commit ba62a1b06c61a914babdb53aba9d3707a05fa11f From f09890a5f4c3285e2341b53dca3f5ad31d701c50 Mon Sep 17 00:00:00 2001 From: Felix Ostrowski Date: Tue, 12 Apr 2016 20:19:20 +0200 Subject: [PATCH 2/3] Move optional parameters above notices --- public/handlebars/statement.hbs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/public/handlebars/statement.hbs b/public/handlebars/statement.hbs index 4d7782e..60cc2b7 100644 --- a/public/handlebars/statement.hbs +++ b/public/handlebars/statement.hbs @@ -29,13 +29,6 @@

{{ data.prefLabel.[@value] }}

{{ data.definition.[@value] }}

-

{{i18n "notices" locale=language}}

-
    - {{#sort data.note direction="asc"}} -
  • {{ [@value] }}
  • - {{/sort}} -
-

{{{i18n "Disclaimer" locale=language}}}

{{#parameters.date}}

{{i18n data.identifier . locale=language}}

{{/parameters.date}} @@ -43,6 +36,13 @@ {{#parameters.relatedURL}}

{{{i18n data.identifier . locale=language}}}

{{/parameters.relatedURL}} +

{{i18n "notices" locale=language}}

+
    + {{#sort data.note direction="asc"}} +
  • {{ [@value] }}
  • + {{/sort}} +
+

{{{i18n "Disclaimer" locale=language}}}

From 3da24781866626d682d02f1a6fc6e1f75d8f1d91 Mon Sep 17 00:00:00 2001 From: Felix Ostrowski Date: Tue, 12 Apr 2016 20:48:10 +0200 Subject: [PATCH 3/3] Update rights-site to production-pages build --- public/rightsstatements.github.io | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/rightsstatements.github.io b/public/rightsstatements.github.io index ba62a1b..a13b11c 160000 --- a/public/rightsstatements.github.io +++ b/public/rightsstatements.github.io @@ -1 +1 @@ -Subproject commit ba62a1b06c61a914babdb53aba9d3707a05fa11f +Subproject commit a13b11c1851a6cff23c758940a78084b298b882a