cartodb-4.42/lib/assets/javascripts/builder/components/modals/add-analysis/analysis-option-models/generated-analysis-option-model.js
2024-04-06 05:25:13 +00:00

36 lines
890 B
JavaScript
Executable File

var _ = require('underscore');
var AnalysisOptionModel = require('./analysis-option-model');
var camshaftReference = require('builder/data/camshaft-reference');
/**
* Model to represent a generated analysis option.
*/
module.exports = AnalysisOptionModel.extend({
/**
* @override {AnalysisOptionModel.getNodeAttrs}
*/
getFormAttrs: function () {
var attrs = AnalysisOptionModel.prototype.getFormAttrs.apply(this, arguments);
this._removeSourceIfThereAreMultipleSources(attrs);
return attrs;
},
_removeSourceIfThereAreMultipleSources: function (attrs) {
var params = camshaftReference.paramsForType(attrs.type);
var sourceCount = _.reduce(Object.keys(params), function (memo, name) {
if (params[name].type === 'node') {
memo++;
}
return memo;
}, 0);
if (sourceCount > 1) {
delete attrs.source;
}
}
});