camel case
This commit is contained in:
@@ -12,7 +12,7 @@ var util = require('util');
|
||||
//
|
||||
// See http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps
|
||||
//
|
||||
// @param redis_pool an instance of a "redis-mpool"
|
||||
// @param redisPool an instance of a "redis-mpool"
|
||||
// See https://github.com/CartoDB/node-redis-mpool
|
||||
// Needs version 0.x.x of the API.
|
||||
//
|
||||
@@ -20,14 +20,14 @@ var util = require('util');
|
||||
// 'max_user_templates' limit on the number of per-user
|
||||
//
|
||||
//
|
||||
function TemplateMaps (redis_pool, opts) {
|
||||
function TemplateMaps (redisPool, opts) {
|
||||
if (!(this instanceof TemplateMaps)) {
|
||||
return new TemplateMaps();
|
||||
}
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.redis_pool = redis_pool;
|
||||
this.redisPool = redisPool;
|
||||
this.opts = opts || {};
|
||||
|
||||
// Database containing templates
|
||||
@@ -44,7 +44,7 @@ function TemplateMaps (redis_pool, opts) {
|
||||
//
|
||||
// 1. User templates: set of per-user map templates
|
||||
|
||||
// User templates (HASH:tpl_id->tpl_val)
|
||||
// User templates (HASH:tplId->tpl_val)
|
||||
this.key_usr_tpl = dot.template('map_tpl|{{=it.owner}}');
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ TemplateMaps.prototype._userTemplateLimit = function () {
|
||||
* @param callback - function to pass results too.
|
||||
*/
|
||||
TemplateMaps.prototype._redisCmd = function (redisFunc, redisArgs, callback) {
|
||||
this.redis_pool.acquire(this.db_signatures, (err, redisClient) => {
|
||||
this.redisPool.acquire(this.db_signatures, (err, redisClient) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
redisClient[redisFunc.toUpperCase()](...redisArgs, (err, data) => {
|
||||
this.redis_pool.release(this.db_signatures, redisClient);
|
||||
this.redisPool.release(this.db_signatures, redisClient);
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ TemplateMaps.prototype._checkUserTemplatesLimit = function (userTemplatesKey, ow
|
||||
// @param template layergroup template, see
|
||||
// http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format
|
||||
//
|
||||
// @param callback function(err, tpl_id)
|
||||
// @param callback function(err, tplId)
|
||||
// Return template identifier (only valid for given user)
|
||||
//
|
||||
TemplateMaps.prototype.addTemplate = function (owner, template, callback) {
|
||||
@@ -260,22 +260,22 @@ TemplateMaps.prototype.addTemplate = function (owner, template, callback) {
|
||||
//
|
||||
// @param owner cartodb username of the template owner
|
||||
//
|
||||
// @param tpl_id template identifier as returned
|
||||
// @param tplId template identifier as returned
|
||||
// by addTemplate or listTemplates
|
||||
//
|
||||
// @param callback function(err)
|
||||
//
|
||||
TemplateMaps.prototype.delTemplate = function (owner, tpl_id, callback) {
|
||||
this._redisCmd('HDEL', [this.key_usr_tpl({ owner: owner }), tpl_id], (err, deleted) => {
|
||||
TemplateMaps.prototype.delTemplate = function (owner, tplId, callback) {
|
||||
this._redisCmd('HDEL', [this.key_usr_tpl({ owner: owner }), tplId], (err, deleted) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!deleted) {
|
||||
return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`));
|
||||
return callback(new Error(`Template '${tplId}' of user '${owner}' does not exist`));
|
||||
}
|
||||
|
||||
this.emit('delete', owner, tpl_id);
|
||||
this.emit('delete', owner, tplId);
|
||||
return callback();
|
||||
});
|
||||
};
|
||||
@@ -289,14 +289,14 @@ TemplateMaps.prototype.delTemplate = function (owner, tpl_id, callback) {
|
||||
//
|
||||
// @param owner cartodb username of the template owner
|
||||
//
|
||||
// @param tpl_id template identifier as returned by addTemplate
|
||||
// @param tplId template identifier as returned by addTemplate
|
||||
//
|
||||
// @param template layergroup template, see
|
||||
// http://github.com/CartoDB/Windshaft-cartodb/wiki/Template-maps#template-format
|
||||
//
|
||||
// @param callback function(err)
|
||||
//
|
||||
TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback) {
|
||||
TemplateMaps.prototype.updTemplate = function (owner, tplId, template, callback) {
|
||||
template = templateDefaults(template);
|
||||
|
||||
var invalidError = this._checkInvalidTemplate(template);
|
||||
@@ -304,19 +304,19 @@ TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback
|
||||
return callback(invalidError);
|
||||
}
|
||||
|
||||
if (tpl_id !== template.name) {
|
||||
return callback(new Error(`Cannot update name of a map template ('${tpl_id}' != '${template.name}')`));
|
||||
if (tplId !== template.name) {
|
||||
return callback(new Error(`Cannot update name of a map template ('${tplId}' != '${template.name}')`));
|
||||
}
|
||||
|
||||
var userTemplatesKey = this.key_usr_tpl({ owner });
|
||||
|
||||
this._redisCmd('HGET', [userTemplatesKey, tpl_id], (err, beforeUpdateTemplate) => {
|
||||
this._redisCmd('HGET', [userTemplatesKey, tplId], (err, beforeUpdateTemplate) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!beforeUpdateTemplate) {
|
||||
return callback(new Error(`Template '${tpl_id}' of user '${owner}' does not exist`));
|
||||
return callback(new Error(`Template '${tplId}' of user '${owner}' does not exist`));
|
||||
}
|
||||
|
||||
let templateString;
|
||||
@@ -355,7 +355,7 @@ TemplateMaps.prototype.updTemplate = function (owner, tpl_id, template, callback
|
||||
//
|
||||
// @param owner cartodb username of the templates owner
|
||||
//
|
||||
// @param callback function(err, tpl_id_list)
|
||||
// @param callback function(err, tplId_list)
|
||||
// Returns a list of template identifiers
|
||||
//
|
||||
TemplateMaps.prototype.listTemplates = function (owner, callback) {
|
||||
@@ -366,14 +366,14 @@ TemplateMaps.prototype.listTemplates = function (owner, callback) {
|
||||
//
|
||||
// @param owner cartodb username of the template owner
|
||||
//
|
||||
// @param tpl_id template identifier as returned
|
||||
// @param tplId template identifier as returned
|
||||
// by addTemplate or listTemplates
|
||||
//
|
||||
// @param callback function(err, template)
|
||||
// Return full template definition
|
||||
//
|
||||
TemplateMaps.prototype.getTemplate = function (owner, tpl_id, callback) {
|
||||
this._redisCmd('HGET', [this.key_usr_tpl({ owner: owner }), tpl_id], (err, template) => {
|
||||
TemplateMaps.prototype.getTemplate = function (owner, tplId, callback) {
|
||||
this._redisCmd('HGET', [this.key_usr_tpl({ owner: owner }), tplId], (err, template) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -446,7 +446,7 @@ function isObject (val) {
|
||||
}
|
||||
|
||||
TemplateMaps.prototype.instance = function (template, params) {
|
||||
var all_params = {};
|
||||
var allParams = {};
|
||||
var phold = template.placeholders || {};
|
||||
Object.keys(phold).forEach(function (k) {
|
||||
var val = Object.prototype.hasOwnProperty.call(params, k) ? params[k] : phold[k].default;
|
||||
@@ -473,7 +473,7 @@ TemplateMaps.prototype.instance = function (template, params) {
|
||||
// NOTE: should be checked at template create/update time
|
||||
throw new Error("Invalid placeholder type '" + type + "'");
|
||||
}
|
||||
all_params[k] = val;
|
||||
allParams[k] = val;
|
||||
});
|
||||
|
||||
// NOTE: we're deep-cloning the layergroup here
|
||||
@@ -481,7 +481,7 @@ TemplateMaps.prototype.instance = function (template, params) {
|
||||
|
||||
if (layergroup.buffersize && isObject(layergroup.buffersize)) {
|
||||
Object.keys(layergroup.buffersize).forEach(function (k) {
|
||||
layergroup.buffersize[k] = parseInt(_replaceVars(layergroup.buffersize[k], all_params), 10);
|
||||
layergroup.buffersize[k] = parseInt(_replaceVars(layergroup.buffersize[k], allParams), 10);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -492,10 +492,10 @@ TemplateMaps.prototype.instance = function (template, params) {
|
||||
// dynamic styling for this layer
|
||||
lyropt.cartocss = params.styles[i];
|
||||
} else if (lyropt.cartocss) {
|
||||
lyropt.cartocss = _replaceVars(lyropt.cartocss, all_params);
|
||||
lyropt.cartocss = _replaceVars(lyropt.cartocss, allParams);
|
||||
}
|
||||
if (lyropt.sql) {
|
||||
lyropt.sql = _replaceVars(lyropt.sql, all_params);
|
||||
lyropt.sql = _replaceVars(lyropt.sql, allParams);
|
||||
}
|
||||
// Anything else ?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user