From d587ca08cfd64fff141136d4fe6b56c316749fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E8=BF=9B?= Date: Fri, 10 Jul 2020 06:09:07 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20widgets-types.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modals/add-widgets/widgets-types.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/assets/javascripts/builder/components/modals/add-widgets/widgets-types.js b/lib/assets/javascripts/builder/components/modals/add-widgets/widgets-types.js index d9bba85..97de582 100755 --- a/lib/assets/javascripts/builder/components/modals/add-widgets/widgets-types.js +++ b/lib/assets/javascripts/builder/components/modals/add-widgets/widgets-types.js @@ -82,6 +82,48 @@ module.exports = [ }; } }, + { + type: 'formula_mini', + createOptionModels: function (tuplesItems) { + return _.reduce(tuplesItems, function (memo, tuples) { + var columnModel = tuples[0].columnModel; + var columnName = columnModel.get('name'); + var operation = 'avg'; + var title = columnName; + + if (columnModel.get('type') === 'number') { + if (columnName === CARTODB_ID) { + operation = 'count'; + title = _t('editor.data.stats.feature-count'); + } + + var m = new FormulaOptionModel({ + tuples: tuples, + title: title, + operation: operation, + name: columnModel.get('name') + }); + memo.push(m); + } + return memo; + }, []); + }, + createTabPaneItem: function (optionsCollection) { + return { + label: _t('components.modals.add-widgets.tab-pane.formula_mini-label'), + name: 'formula_mini', + createContentView: function () { + return new ScrollView({ + createContentView: function () { + return new FormulaOptionsView({ + collection: optionsCollection + }); + } + }); + } + }; + } + }, { type: 'formula', createOptionModels: function (tuplesItems) {