[#248,model][s]: normalize Field types where possible by mapping standard type aliases to default type name - fixes #248.

* view.graph.js improve graph view by making sure datetime for an axis is judged by whether it is date, datetime or time not just date!
* backend.ckan.js some type conversions now done in core model so can be removed
This commit is contained in:
Rufus Pollock
2012-10-12 22:06:56 +01:00
parent aaae34f91d
commit 7819b3b185
5 changed files with 45 additions and 10 deletions

View File

@@ -380,6 +380,9 @@ my.Field = Backbone.Model.extend({
if (this.attributes.label === null) {
this.set({label: this.id});
}
if (this.attributes.type.toLowerCase() in this._typeMap) {
this.attributes.type = this._typeMap[this.attributes.type.toLowerCase()];
}
if (options) {
this.renderer = options.renderer;
this.deriver = options.deriver;
@@ -389,6 +392,17 @@ my.Field = Backbone.Model.extend({
}
this.facets = new my.FacetList();
},
_typeMap: {
'text': 'string',
'double': 'number',
'float': 'number',
'numeric': 'number',
'int': 'integer',
'datetime': 'date-time',
'bool': 'boolean',
'timestamp': 'date-time',
'json': 'object'
},
defaultRenderers: {
object: function(val, field, doc) {
return JSON.stringify(val);
@@ -396,7 +410,7 @@ my.Field = Backbone.Model.extend({
geo_point: function(val, field, doc) {
return JSON.stringify(val);
},
'float': function(val, field, doc) {
'number': function(val, field, doc) {
var format = field.get('format');
if (format === 'percentage') {
return val + '%';