fenix-ui-converter
Advanced tools
Comparing version 1.0.0-beta.8 to 1.0.0-beta.9
@@ -1,2 +0,2 @@ | ||
define(["jquery","underscore","loglevel","handlebars"],function(e,t,r,o){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){var o,n;o=[r(2),r(3),r(4),r(5)],n=function(e,t,r,o){"use strict";function n(){return this}return n.prototype.toD3P=function(o,n){var i={},u=this;return t.each(n.values,function(t,n){var a=u.cleanArray(t),c=o[n]||{},s=c.format||{},l=s.dimension||n;a.length>0?i[l]=e.extend(!0,{},u.compileFilter(n,a,o)):r.warn(n+" column excluded from FENIX conversion because it has no values")}),i},n.prototype.toFilter=function(o,n){var i={},u=this;return t.each(n.values,function(t,n){var a=u.cleanArray(t),c=o[n]||{},s=c.format||{},l=s.metadataAttribute;return l?void(a.length>0?i[l]=e.extend(!0,{},u.compileFilter(n,a,o)):r.warn(n+" column excluded from FENIX filter because it has no values")):void r.warn(n+" impossible to find format.metadataAttribute configuration")}),i},n.prototype.compileFilter=function(e,t,o){var n=o[e]||{},i=n.format||{},u=i.template,a=i.output||"codes";if(u)return this.compileTemplate(e,t,n,u);var c,s=i.dimension||e;switch(a.toLocaleLowerCase()){case"freetext":return this.createFreeTextFilter(e,t,n,s);case"codes":return c='{ "codes":[{"uid": "{{{uid}}}", "version": "{{version}}", "codes": [{{{codes}}}] } ]}',this.compileTemplate(e,t,n,s,c);case"time":return this.createTimeFilter(e,t,n,s);case"number":return this.createNumberFilter(e,t,n,s);case"enumeration":return this.createEnumerationFilter(e,t,n,s);default:return r.warn(e+" not included in the result set. Missing format configuration."),{}}},n.prototype.compileTemplate=function(n,i,u,a,c){var s=e.extend(!0,u.cl,u.format,{codes:'"'+i.join('","')+'"'});if(c||r.error("Impossible to find '"+n+"' process template. Check your '"+n+"'.filter.process configuration."),!s.uid)return void r.error("Impossible to find '"+n+"' code list configuration for FENIX output format export.");var l=o.compile(c),f=JSON.parse(l(s)),p=f.codes;return t.each(p,function(e){e.version||delete e.version}),f},n.prototype.createNumberFilter=function(r,o,n,i){var u,a=[],c="object"==typeof o[0];if(c){var s=t.findWhere(o,{parent:"from"})||{},l=t.findWhere(o,{parent:"to"})||{},f={from:null,to:null};f.from=s.value,f.to=l.value,a.push(e.extend({},f))}else u=o.map(function(e){return parseInt(e,10)}).sort(function(e,t){return e-t}),t.each(u,function(e){a.push({from:e,to:e})});return{number:a}},n.prototype.createTimeFilter=function(r,o,n,i){var u,a=[],c="object"==typeof o[0];if(c){var s=t.findWhere(o,{parent:"from"})||{},l=t.findWhere(o,{parent:"to"})||{},f={from:null,to:null};f.from=s.value,f.to=l.value,a.push(e.extend({},f))}else u=o.map(function(e){return parseInt(e,10)}).sort(function(e,t){return e-t}),t.each(u,function(e){a.push({from:e,to:e})});return{time:a}},n.prototype.createEnumerationFilter=function(e,t,r,o){return{enumeration:t}},n.prototype.createFreeTextFilter=function(e,t,r,o){return{text:t[0]}},n.prototype.cleanArray=function(e){for(var t=[],r=0;r<e.length;r++)e[r]&&t.push(e[r]);return t},new n}.apply(t,o),!(void 0!==n&&(e.exports=n))},function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t){e.exports=o}])}); | ||
define(["jquery","underscore","loglevel","handlebars"],function(e,t,r,n){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){var n,o;n=[r(2),r(3),r(4),r(5)],o=function(e,t,r,n){"use strict";function o(){return this}return o.prototype.toD3P=function(n,o){var i={},u=this;return t.each(o.values,function(t,o){var a=u.cleanArray(t),c=n[o]||{},s=c.format||{},l=s.dimension||o;a.length>0?i[l]=e.extend(!0,{},u.compileFilter(o,a,n)):r.warn(o+" column excluded from FENIX conversion because it has no values")}),i},o.prototype.toFilter=function(n,o){var i={},u=this;return t.each(o.values,function(t,o){var a=u.cleanArray(t),c=n[o]||{},s=c.format||{},l=s.metadataAttribute;return l?void(a.length>0?i[l]=e.extend(!0,{},u.compileFilter(o,a,n)):r.warn(o+" column excluded from FENIX filter because it has no values")):void r.warn(o+" impossible to find format.metadataAttribute configuration")}),i},o.prototype.compileFilter=function(e,t,n){var o=n[e]||{},i=o.format||{},u=i.template,a=i.output||"codes";if(u)return this.compileTemplate(e,t,o,u);var c,s=i.dimension||e;switch(a.toLocaleLowerCase()){case"freetext":return this.createFreeTextFilter(e,t,o,s);case"codes":return c='{ "codes":[{"uid": "{{{uid}}}", "version": "{{version}}", "codes": [{{{codes}}}] } ]}',this.compileTemplate(e,t,o,s,c);case"time":return this.createTimeFilter(e,t,o,s);case"number":return this.createNumberFilter(e,t,o,s);case"enumeration":return this.createEnumerationFilter(e,t,o,s);default:return r.warn(e+" not included in the result set. Missing format configuration."),{}}},o.prototype.compileTemplate=function(o,i,u,a,c){var s=e.extend(!0,u.cl,u.distinct,u.format,{codes:'"'+i.join('","')+'"'});if(c||r.error("Impossible to find '"+o+"' process template. Check your '"+o+"'.filter.process configuration."),!s.uid)return void r.error("Impossible to find '"+o+"' code list configuration for FENIX output format export.");var l=n.compile(c),f=JSON.parse(l(s)),p=f.codes;return t.each(p,function(e){e.version||delete e.version}),f},o.prototype.createNumberFilter=function(r,n,o,i){var u,a=[],c="object"==typeof n[0];if(c){var s=t.findWhere(n,{parent:"from"})||{},l=t.findWhere(n,{parent:"to"})||{},f={from:null,to:null};f.from=s.value,f.to=l.value,a.push(e.extend({},f))}else u=n.map(function(e){return parseInt(e,10)}).sort(function(e,t){return e-t}),t.each(u,function(e){a.push({from:e,to:e})});return{number:a}},o.prototype.createTimeFilter=function(r,n,o,i){var u,a=[],c="object"==typeof n[0];if(c){var s=t.findWhere(n,{parent:"from"})||{},l=t.findWhere(n,{parent:"to"})||{},f={from:null,to:null};f.from=s.value,f.to=l.value,a.push(e.extend({},f))}else u=n.map(function(e){return parseInt(e,10)}).sort(function(e,t){return e-t}),t.each(u,function(e){a.push({from:e,to:e})});return{time:a}},o.prototype.createEnumerationFilter=function(e,t,r,n){return{enumeration:t}},o.prototype.createFreeTextFilter=function(e,t,r,n){return{text:t[0]}},o.prototype.cleanArray=function(e){for(var t=[],r=0;r<e.length;r++)e[r]&&t.push(e[r]);return t},new o}.apply(t,n),!(void 0!==o&&(e.exports=o))},function(t,r){t.exports=e},function(e,r){e.exports=t},function(e,t){e.exports=r},function(e,t){e.exports=n}])}); | ||
//# sourceMappingURL=fenix-ui-converter.min.js.map |
{ | ||
"name": "fenix-ui-converter", | ||
"version": "1.0.0-beta.8", | ||
"version": "1.0.0-beta.9", | ||
"description": "FENIX ui converter", | ||
@@ -5,0 +5,0 @@ "main": "dist/fenix-ui-converter.min.js", |
@@ -126,3 +126,3 @@ if (typeof define !== 'function') { | ||
var model = $.extend(true, config.cl, config.format, {codes: '"' + values.join('","') + '"'}); | ||
var model = $.extend(true, config.cl, config.distinct, config.format, {codes: '"' + values.join('","') + '"'}); | ||
@@ -129,0 +129,0 @@ if (!template) { |
@@ -5,4 +5,4 @@ { | ||
"version": "1.13.2", | ||
"hash": "a0169510e2bf3596dc21", | ||
"time": 272, | ||
"hash": "719c2b06287a27326b90", | ||
"time": 260, | ||
"publicPath": "", | ||
@@ -18,3 +18,3 @@ "assetsByChunkName": { | ||
"name": "fenix-ui-converter.min.js", | ||
"size": 3409, | ||
"size": 3420, | ||
"chunks": [ | ||
@@ -30,3 +30,3 @@ 0 | ||
"name": "fenix-ui-converter.min.js.map", | ||
"size": 23451, | ||
"size": 23512, | ||
"chunks": [ | ||
@@ -48,3 +48,3 @@ 0 | ||
"extraAsync": false, | ||
"size": 6572, | ||
"size": 6589, | ||
"names": [ | ||
@@ -57,3 +57,3 @@ "app" | ||
], | ||
"hash": "0d6020486245ab9e1ab6", | ||
"hash": "cf36555a50a14416eeb4", | ||
"parents": [], | ||
@@ -78,3 +78,3 @@ "modules": [ | ||
"profile": { | ||
"factory": 1, | ||
"factory": 0, | ||
"building": 1 | ||
@@ -93,3 +93,3 @@ }, | ||
"index2": 4, | ||
"size": 6376, | ||
"size": 6393, | ||
"cacheable": true, | ||
@@ -105,4 +105,4 @@ "built": true, | ||
"profile": { | ||
"factory": 16, | ||
"building": 43 | ||
"factory": 11, | ||
"building": 36 | ||
}, | ||
@@ -122,3 +122,3 @@ "failed": false, | ||
], | ||
"source": "if (typeof define !== 'function') {\n var define = require('amdefine')(module);\n}\n\ndefine([\n 'jquery',\n 'underscore',\n 'loglevel',\n 'handlebars'\n], function ($, _, log, Handlebars) {\n\n 'use strict';\n\n function Converter() {\n return this;\n }\n\n Converter.prototype.toD3P = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.dimension || id;\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX conversion because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.toFilter = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.metadataAttribute;\n\n if (!key) {\n log.warn(id + \" impossible to find format.metadataAttribute configuration\");\n return;\n }\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX filter because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.compileFilter = function (id, values, items) {\n\n var config = items[id] || {},\n formatConfig = config.format || {},\n template = formatConfig.template,\n output = formatConfig.output || \"codes\";\n\n if (template) {\n return this.compileTemplate(id, values, config, template);\n }\n\n var key = formatConfig.dimension || id,\n tmpl;\n\n switch (output.toLocaleLowerCase()) {\n case \"freetext\" :\n\n return this.createFreeTextFilter(id, values, config, key);\n\n break;\n case \"codes\" :\n\n tmpl = '{ \"codes\":[{\"uid\": \"{{{uid}}}\", \"version\": \"{{version}}\", \"codes\": [{{{codes}}}] } ]}';\n return this.compileTemplate(id, values, config, key, tmpl);\n\n break;\n case \"time\" :\n\n return this.createTimeFilter(id, values, config, key);\n break;\n case \"number\" :\n\n return this.createNumberFilter(id, values, config, key);\n break;\n\n case \"enumeration\" :\n\n return this.createEnumerationFilter(id, values, config, key);\n break;\n default :\n log.warn(id + \" not included in the result set. Missing format configuration.\");\n return {};\n }\n\n };\n\n Converter.prototype.compileTemplate = function (id, values, config, key, template) {\n\n /*\n Priority\n - values\n - format configuration\n - code list configuration\n */\n\n var model = $.extend(true, config.cl, config.format, {codes: '\"' + values.join('\",\"') + '\"'});\n\n if (!template) {\n log.error(\"Impossible to find '\" + id + \"' process template. Check your '\" + id + \"'.filter.process configuration.\")\n }\n\n if (!model.uid) {\n log.error(\"Impossible to find '\" + id + \"' code list configuration for FENIX output format export.\");\n return;\n }\n\n var tmpl = Handlebars.compile(template),\n process = JSON.parse(tmpl(model)),\n codes = process.codes;\n\n //Remove empty version attributes\n _.each(codes, function (obj) {\n if (!obj.version) {\n delete obj.version;\n }\n });\n\n return process;\n\n };\n\n Converter.prototype.createNumberFilter = function (id, values, config, key) {\n\n var number = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n number.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n _.each(v, function (i) {\n number.push({from: i, to: i});\n });\n\n }\n\n return {number: number};\n };\n\n Converter.prototype.createTimeFilter = function (id, values, config, key) {\n\n var time = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n time.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n\n _.each(v, function (i) {\n time.push({from: i, to: i});\n });\n\n }\n\n return {time: time};\n };\n\n Converter.prototype.createEnumerationFilter = function (id, values, config, key) {\n\n return {enumeration: values};\n\n };\n\n Converter.prototype.createFreeTextFilter = function (id, values, config, key) {\n\n return {text: values[0]};\n };\n\n Converter.prototype.cleanArray = function (actual) {\n var newArray = [];\n for (var i = 0; i < actual.length; i++) {\n if (actual[i]) {\n newArray.push(actual[i]);\n }\n }\n return newArray;\n };\n\n return new Converter();\n\n});" | ||
"source": "if (typeof define !== 'function') {\n var define = require('amdefine')(module);\n}\n\ndefine([\n 'jquery',\n 'underscore',\n 'loglevel',\n 'handlebars'\n], function ($, _, log, Handlebars) {\n\n 'use strict';\n\n function Converter() {\n return this;\n }\n\n Converter.prototype.toD3P = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.dimension || id;\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX conversion because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.toFilter = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.metadataAttribute;\n\n if (!key) {\n log.warn(id + \" impossible to find format.metadataAttribute configuration\");\n return;\n }\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX filter because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.compileFilter = function (id, values, items) {\n\n var config = items[id] || {},\n formatConfig = config.format || {},\n template = formatConfig.template,\n output = formatConfig.output || \"codes\";\n\n if (template) {\n return this.compileTemplate(id, values, config, template);\n }\n\n var key = formatConfig.dimension || id,\n tmpl;\n\n switch (output.toLocaleLowerCase()) {\n case \"freetext\" :\n\n return this.createFreeTextFilter(id, values, config, key);\n\n break;\n case \"codes\" :\n\n tmpl = '{ \"codes\":[{\"uid\": \"{{{uid}}}\", \"version\": \"{{version}}\", \"codes\": [{{{codes}}}] } ]}';\n return this.compileTemplate(id, values, config, key, tmpl);\n\n break;\n case \"time\" :\n\n return this.createTimeFilter(id, values, config, key);\n break;\n case \"number\" :\n\n return this.createNumberFilter(id, values, config, key);\n break;\n\n case \"enumeration\" :\n\n return this.createEnumerationFilter(id, values, config, key);\n break;\n default :\n log.warn(id + \" not included in the result set. Missing format configuration.\");\n return {};\n }\n\n };\n\n Converter.prototype.compileTemplate = function (id, values, config, key, template) {\n\n /*\n Priority\n - values\n - format configuration\n - code list configuration\n */\n\n var model = $.extend(true, config.cl, config.distinct, config.format, {codes: '\"' + values.join('\",\"') + '\"'});\n\n if (!template) {\n log.error(\"Impossible to find '\" + id + \"' process template. Check your '\" + id + \"'.filter.process configuration.\")\n }\n\n if (!model.uid) {\n log.error(\"Impossible to find '\" + id + \"' code list configuration for FENIX output format export.\");\n return;\n }\n\n var tmpl = Handlebars.compile(template),\n process = JSON.parse(tmpl(model)),\n codes = process.codes;\n\n //Remove empty version attributes\n _.each(codes, function (obj) {\n if (!obj.version) {\n delete obj.version;\n }\n });\n\n return process;\n\n };\n\n Converter.prototype.createNumberFilter = function (id, values, config, key) {\n\n var number = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n number.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n _.each(v, function (i) {\n number.push({from: i, to: i});\n });\n\n }\n\n return {number: number};\n };\n\n Converter.prototype.createTimeFilter = function (id, values, config, key) {\n\n var time = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n time.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n\n _.each(v, function (i) {\n time.push({from: i, to: i});\n });\n\n }\n\n return {time: time};\n };\n\n Converter.prototype.createEnumerationFilter = function (id, values, config, key) {\n\n return {enumeration: values};\n\n };\n\n Converter.prototype.createFreeTextFilter = function (id, values, config, key) {\n\n return {text: values[0]};\n };\n\n Converter.prototype.cleanArray = function (actual) {\n var newArray = [];\n for (var i = 0; i < actual.length; i++) {\n if (actual[i]) {\n newArray.push(actual[i]);\n }\n }\n return newArray;\n };\n\n return new Converter();\n\n});" | ||
}, | ||
@@ -142,3 +142,3 @@ { | ||
"profile": { | ||
"factory": 1, | ||
"factory": 0, | ||
"building": 0 | ||
@@ -299,3 +299,3 @@ }, | ||
"profile": { | ||
"factory": 1, | ||
"factory": 0, | ||
"building": 1 | ||
@@ -314,3 +314,3 @@ }, | ||
"index2": 4, | ||
"size": 6376, | ||
"size": 6393, | ||
"cacheable": true, | ||
@@ -326,4 +326,4 @@ "built": true, | ||
"profile": { | ||
"factory": 16, | ||
"building": 43 | ||
"factory": 11, | ||
"building": 36 | ||
}, | ||
@@ -343,3 +343,3 @@ "failed": false, | ||
], | ||
"source": "if (typeof define !== 'function') {\n var define = require('amdefine')(module);\n}\n\ndefine([\n 'jquery',\n 'underscore',\n 'loglevel',\n 'handlebars'\n], function ($, _, log, Handlebars) {\n\n 'use strict';\n\n function Converter() {\n return this;\n }\n\n Converter.prototype.toD3P = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.dimension || id;\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX conversion because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.toFilter = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.metadataAttribute;\n\n if (!key) {\n log.warn(id + \" impossible to find format.metadataAttribute configuration\");\n return;\n }\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX filter because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.compileFilter = function (id, values, items) {\n\n var config = items[id] || {},\n formatConfig = config.format || {},\n template = formatConfig.template,\n output = formatConfig.output || \"codes\";\n\n if (template) {\n return this.compileTemplate(id, values, config, template);\n }\n\n var key = formatConfig.dimension || id,\n tmpl;\n\n switch (output.toLocaleLowerCase()) {\n case \"freetext\" :\n\n return this.createFreeTextFilter(id, values, config, key);\n\n break;\n case \"codes\" :\n\n tmpl = '{ \"codes\":[{\"uid\": \"{{{uid}}}\", \"version\": \"{{version}}\", \"codes\": [{{{codes}}}] } ]}';\n return this.compileTemplate(id, values, config, key, tmpl);\n\n break;\n case \"time\" :\n\n return this.createTimeFilter(id, values, config, key);\n break;\n case \"number\" :\n\n return this.createNumberFilter(id, values, config, key);\n break;\n\n case \"enumeration\" :\n\n return this.createEnumerationFilter(id, values, config, key);\n break;\n default :\n log.warn(id + \" not included in the result set. Missing format configuration.\");\n return {};\n }\n\n };\n\n Converter.prototype.compileTemplate = function (id, values, config, key, template) {\n\n /*\n Priority\n - values\n - format configuration\n - code list configuration\n */\n\n var model = $.extend(true, config.cl, config.format, {codes: '\"' + values.join('\",\"') + '\"'});\n\n if (!template) {\n log.error(\"Impossible to find '\" + id + \"' process template. Check your '\" + id + \"'.filter.process configuration.\")\n }\n\n if (!model.uid) {\n log.error(\"Impossible to find '\" + id + \"' code list configuration for FENIX output format export.\");\n return;\n }\n\n var tmpl = Handlebars.compile(template),\n process = JSON.parse(tmpl(model)),\n codes = process.codes;\n\n //Remove empty version attributes\n _.each(codes, function (obj) {\n if (!obj.version) {\n delete obj.version;\n }\n });\n\n return process;\n\n };\n\n Converter.prototype.createNumberFilter = function (id, values, config, key) {\n\n var number = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n number.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n _.each(v, function (i) {\n number.push({from: i, to: i});\n });\n\n }\n\n return {number: number};\n };\n\n Converter.prototype.createTimeFilter = function (id, values, config, key) {\n\n var time = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n time.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n\n _.each(v, function (i) {\n time.push({from: i, to: i});\n });\n\n }\n\n return {time: time};\n };\n\n Converter.prototype.createEnumerationFilter = function (id, values, config, key) {\n\n return {enumeration: values};\n\n };\n\n Converter.prototype.createFreeTextFilter = function (id, values, config, key) {\n\n return {text: values[0]};\n };\n\n Converter.prototype.cleanArray = function (actual) {\n var newArray = [];\n for (var i = 0; i < actual.length; i++) {\n if (actual[i]) {\n newArray.push(actual[i]);\n }\n }\n return newArray;\n };\n\n return new Converter();\n\n});" | ||
"source": "if (typeof define !== 'function') {\n var define = require('amdefine')(module);\n}\n\ndefine([\n 'jquery',\n 'underscore',\n 'loglevel',\n 'handlebars'\n], function ($, _, log, Handlebars) {\n\n 'use strict';\n\n function Converter() {\n return this;\n }\n\n Converter.prototype.toD3P = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.dimension || id;\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX conversion because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.toFilter = function (items, values) {\n\n var filter = {},\n self = this;\n\n _.each(values.values, function (val, id) {\n\n var v = self.cleanArray(val),\n config = items[id] || {},\n formatConfig = config.format || {};\n\n var key = formatConfig.metadataAttribute;\n\n if (!key) {\n log.warn(id + \" impossible to find format.metadataAttribute configuration\");\n return;\n }\n\n if (v.length > 0) {\n filter[key] = $.extend(true, {}, self.compileFilter(id, v, items));\n } else {\n log.warn(id + \" column excluded from FENIX filter because it has no values\");\n }\n\n });\n\n return filter;\n };\n\n Converter.prototype.compileFilter = function (id, values, items) {\n\n var config = items[id] || {},\n formatConfig = config.format || {},\n template = formatConfig.template,\n output = formatConfig.output || \"codes\";\n\n if (template) {\n return this.compileTemplate(id, values, config, template);\n }\n\n var key = formatConfig.dimension || id,\n tmpl;\n\n switch (output.toLocaleLowerCase()) {\n case \"freetext\" :\n\n return this.createFreeTextFilter(id, values, config, key);\n\n break;\n case \"codes\" :\n\n tmpl = '{ \"codes\":[{\"uid\": \"{{{uid}}}\", \"version\": \"{{version}}\", \"codes\": [{{{codes}}}] } ]}';\n return this.compileTemplate(id, values, config, key, tmpl);\n\n break;\n case \"time\" :\n\n return this.createTimeFilter(id, values, config, key);\n break;\n case \"number\" :\n\n return this.createNumberFilter(id, values, config, key);\n break;\n\n case \"enumeration\" :\n\n return this.createEnumerationFilter(id, values, config, key);\n break;\n default :\n log.warn(id + \" not included in the result set. Missing format configuration.\");\n return {};\n }\n\n };\n\n Converter.prototype.compileTemplate = function (id, values, config, key, template) {\n\n /*\n Priority\n - values\n - format configuration\n - code list configuration\n */\n\n var model = $.extend(true, config.cl, config.distinct, config.format, {codes: '\"' + values.join('\",\"') + '\"'});\n\n if (!template) {\n log.error(\"Impossible to find '\" + id + \"' process template. Check your '\" + id + \"'.filter.process configuration.\")\n }\n\n if (!model.uid) {\n log.error(\"Impossible to find '\" + id + \"' code list configuration for FENIX output format export.\");\n return;\n }\n\n var tmpl = Handlebars.compile(template),\n process = JSON.parse(tmpl(model)),\n codes = process.codes;\n\n //Remove empty version attributes\n _.each(codes, function (obj) {\n if (!obj.version) {\n delete obj.version;\n }\n });\n\n return process;\n\n };\n\n Converter.prototype.createNumberFilter = function (id, values, config, key) {\n\n var number = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n number.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n _.each(v, function (i) {\n number.push({from: i, to: i});\n });\n\n }\n\n return {number: number};\n };\n\n Converter.prototype.createTimeFilter = function (id, values, config, key) {\n\n var time = [],\n valuesAreObject = typeof values[0] === 'object',\n v;\n\n if (valuesAreObject) {\n\n var from = _.findWhere(values, {parent: \"from\"}) || {},\n to = _.findWhere(values, {parent: \"to\"}) || {},\n couple = {from: null, to: null};\n\n couple.from = from.value;\n couple.to = to.value;\n\n time.push($.extend({}, couple));\n\n } else {\n\n v = values.map(function (a) {\n return parseInt(a, 10);\n }).sort(function (a, b) {\n return a - b;\n });\n\n\n _.each(v, function (i) {\n time.push({from: i, to: i});\n });\n\n }\n\n return {time: time};\n };\n\n Converter.prototype.createEnumerationFilter = function (id, values, config, key) {\n\n return {enumeration: values};\n\n };\n\n Converter.prototype.createFreeTextFilter = function (id, values, config, key) {\n\n return {text: values[0]};\n };\n\n Converter.prototype.cleanArray = function (actual) {\n var newArray = [];\n for (var i = 0; i < actual.length; i++) {\n if (actual[i]) {\n newArray.push(actual[i]);\n }\n }\n return newArray;\n };\n\n return new Converter();\n\n});" | ||
}, | ||
@@ -363,3 +363,3 @@ { | ||
"profile": { | ||
"factory": 1, | ||
"factory": 0, | ||
"building": 0 | ||
@@ -366,0 +366,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94512