Initial commit

This commit is contained in:
zhongjin
2020-06-15 10:58:47 +08:00
commit 4f1dfe7564
8590 changed files with 1516878 additions and 0 deletions
@@ -0,0 +1,37 @@
var _ = require('underscore');
var ERRORS = {
generic: {
level: 'error',
refresh: true
},
limit: {
level: 'error',
error: 'Timeout',
message: 'The server is taking too long to respond, due to poor conectivity or a temporary error with our servers. Please try again soon.',
refresh: true
},
no_data_available: {
level: 'alert',
error: 'No data available',
message: 'There are no results for the combination of filters applied to your data. Try tweaking your filters, or zoom and pan the map to adjust the Map View.',
refresh: false
},
too_many_bins: {
level: 'error',
error: 'Too many bins returned',
message: 'There are too many bins returned. Try selecting a less granular aggregation or filtering the data source.',
refresh: false
},
dataview: {
level: 'error',
refresh: false
}
};
module.exports = function (error) {
var type = error && error.type && _.has(ERRORS, error.type)
? error.type
: 'generic';
return _.extend({}, error, ERRORS[type]);
};
@@ -0,0 +1,5 @@
var _ = require('underscore');
module.exports = function escapeHTML (str) {
return _.escape(str);
};
@@ -0,0 +1,15 @@
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
* @param {Object} object The object to query.
* @param {String} path The path of the property to get.
* @param {Any} defaultValue The value returned for undefined resolved values.
* @return {Any} Returns the resolved value.
*/
module.exports = function (object, path, defaultValue) {
var keys = path.split('.');
var value = keys.reduce(function (a, b) {
return (a || {})[b];
}, object);
return value || defaultValue;
};
@@ -0,0 +1,42 @@
var _ = require('underscore');
module.exports = {
COLORS: [
'#11A579',
'#E83f74',
'#9F5DC8',
'#EF8205',
'#29B3B2',
'#E54F3B',
'#59BB12',
'#EF57BA',
'#E2AF00',
'#12AADE'
],
/**
* Get the letter representation.
* @param {String, Object} sourceId or backbone model that have id. e.g. 'c2'
* @return {String} e.g. 'c' or an empty string if there is no letter in the given id
*/
letter: function (sourceId) {
if (!sourceId || !_.isString(sourceId)) return '';
var match = sourceId.match(/^([a-z]+)/);
return (_.isArray(match) && match[0]) || '';
},
/**
* Returns a color given a letter
* @param {String} Letter. eg: 'a', 'b', 'c', etc.
* @return {String} Hex color code: eg: '#7F3C8D'
*/
getColorForLetter: function (letter) {
if (!letter) {
return this.COLORS[0];
}
var letterNumber = letter.charCodeAt(0) - 97;
var colorIndex = ((letterNumber / this.COLORS.length % 1) * 10).toFixed();
return this.COLORS[colorIndex] || this.COLORS[0];
}
};
@@ -0,0 +1,18 @@
var moment = require('moment');
var _ = require('underscore');
var helper = {};
helper.substractOneUnit = function (timestamp, aggregation) {
if (!_.isNumber(timestamp)) {
return timestamp;
}
var result = moment.unix(timestamp).utc();
aggregation && aggregation === 'week'
? result.subtract(1, 'day')
: result.subtract(1, aggregation);
return result.unix();
};
module.exports = helper;
@@ -0,0 +1,5 @@
var _ = require('underscore');
module.exports = function unescapeHTML (str) {
return _.unescape(str);
};