From 78b75c7a88b0890c145889528cbc48f3647ee152 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Thu, 28 Sep 2017 10:47:44 +0000 Subject: [PATCH] Removes `list` dataview type --- NEWS.md | 7 +- docs/MapConfig-Dataviews-extension.md | 41 +------ lib/cartodb/models/dataview/index.js | 3 +- lib/cartodb/models/dataview/list.js | 66 ----------- .../models/dataview/overviews/index.js | 3 +- lib/cartodb/models/dataview/overviews/list.js | 11 -- package.json | 2 +- test/acceptance/widgets/list.js | 51 --------- test/acceptance/widgets/ported/list.js | 106 ------------------ .../dataviews-widgets-adapter.test.js | 73 ------------ 10 files changed, 11 insertions(+), 352 deletions(-) delete mode 100644 lib/cartodb/models/dataview/list.js delete mode 100644 lib/cartodb/models/dataview/overviews/list.js delete mode 100644 test/acceptance/widgets/list.js delete mode 100644 test/acceptance/widgets/ported/list.js diff --git a/NEWS.md b/NEWS.md index c20ae985..f0ea0728 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,12 @@ # Changelog -## 3.13.0 +## 4.0.0 Released 2017-mm-dd + +Backward incompatible changes: + - Removes `list` dataview type. + +Announcements: - Upgrades camshaft, cartodb-query-tables, and turbo-carto: better support for query variables. Bugfixes: diff --git a/docs/MapConfig-Dataviews-extension.md b/docs/MapConfig-Dataviews-extension.md index d8e23a82..c2b2b8da 100644 --- a/docs/MapConfig-Dataviews-extension.md +++ b/docs/MapConfig-Dataviews-extension.md @@ -8,50 +8,13 @@ This specification describes an extension for This extension depends on Analyses extension. It extends MapConfig with a new attribute: `dataviews`. -It makes possible to get tabular data from analysis nodes: lists, aggregated lists, aggregations, and histograms. +It makes possible to get tabular data from analysis nodes: aggregated lists, aggregations, and histograms. ## 2.1. Dataview types -### List - -A list is a simple result set per row where is possible to retrieve several columns from the original layer query. - -Definition -``` -{ - // REQUIRED - // string, `type` the list type - “type”: “list”, - // REQUIRED - // object, `options` dataview params - “options”: { - // REQUIRED - // array, `columns` to select for the list - “columns”: [“name”, “description”] - } -} -``` - -Expected output -``` -{ - "type": "list", - "rows": [ - { - "{columnName1}": "val1", - "{columnName2}": 100 - }, - { - "{columnName1}": "val2", - "{columnName2}": 200 - } - ] -} -``` - ### Aggregation -An aggregation is very similar to a list but results are aggregated by a column and a given aggregation function. +An aggregation is a list with aggregated results by a column and a given aggregation function. Definition ``` diff --git a/lib/cartodb/models/dataview/index.js b/lib/cartodb/models/dataview/index.js index d508f1bb..05cfaab7 100644 --- a/lib/cartodb/models/dataview/index.js +++ b/lib/cartodb/models/dataview/index.js @@ -1,6 +1,5 @@ module.exports = { Aggregation: require('./aggregation'), Formula: require('./formula'), - Histogram: require('./histogram'), - List: require('./list') + Histogram: require('./histogram') }; diff --git a/lib/cartodb/models/dataview/list.js b/lib/cartodb/models/dataview/list.js deleted file mode 100644 index 33993777..00000000 --- a/lib/cartodb/models/dataview/list.js +++ /dev/null @@ -1,66 +0,0 @@ -var dot = require('dot'); -dot.templateSettings.strip = false; - -var BaseWidget = require('./base'); - -var TYPE = 'list'; - -var listSqlTpl = dot.template('select {{=it._columns}} from ({{=it._query}}) as _cdb_list'); - -/** -{ - type: 'list', - options: { - columns: ['name', 'description'] - } -} -*/ - -function List(query, options) { - options = options || {}; - - if (!Array.isArray(options.columns)) { - throw new Error('List expects `columns` array in widget options'); - } - - BaseWidget.apply(this); - - this.query = query; - this.columns = options.columns; -} - -List.prototype = new BaseWidget(); -List.prototype.constructor = List; - -module.exports = List; - -List.prototype.sql = function(psql, override, callback) { - if (!callback) { - callback = override; - } - - var listSql = listSqlTpl({ - _query: this.query, - _columns: this.columns.join(', ') - }); - - return callback(null, listSql); -}; - -List.prototype.format = function(result) { - return { - rows: result.rows - }; -}; - -List.prototype.getType = function() { - return TYPE; -}; - -List.prototype.toString = function() { - return JSON.stringify({ - _type: TYPE, - _query: this.query, - _columns: this.columns.join(', ') - }); -}; diff --git a/lib/cartodb/models/dataview/overviews/index.js b/lib/cartodb/models/dataview/overviews/index.js index c541973e..ac032749 100644 --- a/lib/cartodb/models/dataview/overviews/index.js +++ b/lib/cartodb/models/dataview/overviews/index.js @@ -1,6 +1,5 @@ module.exports = { Aggregation: require('./aggregation'), Formula: require('./formula'), - Histogram: require('./histogram'), - List: require('./list') + Histogram: require('./histogram') }; diff --git a/lib/cartodb/models/dataview/overviews/list.js b/lib/cartodb/models/dataview/overviews/list.js deleted file mode 100644 index 6ec731f4..00000000 --- a/lib/cartodb/models/dataview/overviews/list.js +++ /dev/null @@ -1,11 +0,0 @@ -var BaseOverviewsDataview = require('./base'); -var BaseDataview = require('../list'); - -function List(query, options, queryRewriter, queryRewriteData, params, queries) { - BaseOverviewsDataview.call(this, query, options, BaseDataview, queryRewriter, queryRewriteData, params, queries); -} - -List.prototype = Object.create(BaseOverviewsDataview.prototype); -List.prototype.constructor = List; - -module.exports = List; diff --git a/package.json b/package.json index ba7422b4..36b3f355 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "windshaft-cartodb", - "version": "3.13.0", + "version": "4.0.0", "description": "A map tile server for CartoDB", "keywords": [ "cartodb" diff --git a/test/acceptance/widgets/list.js b/test/acceptance/widgets/list.js deleted file mode 100644 index 87fbf7df..00000000 --- a/test/acceptance/widgets/list.js +++ /dev/null @@ -1,51 +0,0 @@ -require('../../support/test_helper'); - -var assert = require('../../support/assert'); -var TestClient = require('../../support/test-client'); - -describe('list widgets', function() { - - it("should expose layer list", function(done) { - - var listWidgetMapConfig = { - version: '1.5.0', - layers: [ - { - type: 'mapnik', - options: { - sql: 'select * from test_table', - cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }', - cartocss_version: '2.3.0', - widgets: { - names: { - type: 'list', - options: { - columns: ['name'] - } - } - } - } - } - ] - }; - - var testClient = new TestClient(listWidgetMapConfig); - - testClient.getWidget('names', function(err, res) { - if (err) { - return done(err); - } - - var expectedList = [ - {name:"Hawai"}, - {name:"El Estocolmo"}, - {name:"El Rey del Tallarín"}, - {name:"El Lacón"}, - {name:"El Pico"} - ]; - assert.deepEqual(JSON.parse(res.body).rows, expectedList); - - testClient.drain(done); - }); - }); -}); diff --git a/test/acceptance/widgets/ported/list.js b/test/acceptance/widgets/ported/list.js deleted file mode 100644 index e33156f7..00000000 --- a/test/acceptance/widgets/ported/list.js +++ /dev/null @@ -1,106 +0,0 @@ -require('../../../support/test_helper'); - -var assert = require('../../../support/assert'); -var TestClient = require('../../../support/test-client'); -var _ = require('underscore'); - -describe('widgets', function() { - - describe('lists', function() { - - afterEach(function(done) { - if (this.testClient) { - this.testClient.drain(done); - } else { - done(); - } - }); - - function listsMapConfig(columns) { - return { - version: '1.5.0', - layers: [ - { - type: 'mapnik', - options: { - sql: 'select * from test_table', - cartocss: '#layer0 { marker-fill: red; marker-width: 10; }', - cartocss_version: '2.0.1', - widgets: { - places: { - type: 'list', - options: { - columns: columns || ['name', 'address'] - } - } - } - } - } - ] - }; - } - - var EXPECTED_NAMES = ['Hawai', 'El Estocolmo', 'El Rey del Tallarín', 'El Lacón', 'El Pico']; - - it('can be fetched from a valid list', function(done) { - var columns = ['name', 'address']; - this.testClient = new TestClient(listsMapConfig(columns)); - this.testClient.getWidget('places', function (err, res, list) { - assert.ok(!err, err); - assert.ok(list); - assert.equal(list.type, 'list'); - assert.equal(list.rows.length, 5); - - assert.ok(onlyHasFields(list, columns)); - - var names = list.rows.map(function (item) { - return item.name; - }); - assert.deepEqual(names, EXPECTED_NAMES); - - var expectedAddresses = [ - 'Calle de Pérez Galdós 9, Madrid, Spain', - 'Calle de la Palma 72, Madrid, Spain', - 'Plaza Conde de Toreno 2, Madrid, Spain', - 'Manuel Fernández y González 8, Madrid, Spain', - 'Calle Divino Pastor 12, Madrid, Spain' - ]; - var addresses = list.rows.map(function (item) { - return item.address; - }); - assert.deepEqual(addresses, expectedAddresses); - - done(); - }); - }); - - it('should fetch just one column', function(done) { - var columns = ['name']; - this.testClient = new TestClient(listsMapConfig(columns)); - this.testClient.getWidget('places', function (err, res, list) { - assert.ok(!err, err); - assert.ok(list); - assert.equal(list.type, 'list'); - assert.equal(list.rows.length, 5); - - assert.ok(onlyHasFields(list, columns)); - - var names = list.rows.map(function (item) { - return item.name; - }); - assert.deepEqual(names, EXPECTED_NAMES); - - done(); - }); - }); - - function onlyHasFields(list, expectedFields) { - var fields = (!!list.rows[0]) ? Object.keys(list.rows[0]) : []; - - return _.difference(fields, expectedFields).length === 0 && - _.difference(expectedFields, fields).length === 0; - } - - }); - -}); diff --git a/test/unit/cartodb/mapconfig/dataviews-widgets-adapter.test.js b/test/unit/cartodb/mapconfig/dataviews-widgets-adapter.test.js index 797ce06e..b78d8a85 100644 --- a/test/unit/cartodb/mapconfig/dataviews-widgets-adapter.test.js +++ b/test/unit/cartodb/mapconfig/dataviews-widgets-adapter.test.js @@ -143,79 +143,6 @@ describe('dataviews-widgets-adapter', function() { } } }, - { - "input": { - "version": "1.4.0", - "layers": [ - { - "type": "mapnik", - "options": { - "sql": "select * from test_table", - "cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }", - "cartocss_version": "2.3.0", - "widgets": { - "names": { - "type": "list", - "options": { - "columns": [ - "name" - ] - } - } - } - } - } - ] - }, - "expected": { - "version": "1.4.0", - "layers": [ - { - "type": "mapnik", - "options": { - "source": { - "id": "cdb-layer-source-0" - }, - "cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }", - "cartocss_version": "2.3.0", - // keep them for now - "widgets": { - "names": { - "type": "list", - "options": { - "columns": [ - "name" - ] - } - } - } - } - } - ], - "analyses": [ - { - "id": "cdb-layer-source-0", - "type": "source", - "params": { - "query": "select * from test_table" - } - } - ], - "dataviews": { - "names": { - "source": { - "id": "cdb-layer-source-0" - }, - "type": "list", - "options": { - "columns": [ - "name" - ] - } - } - } - } - }, { "input": { "version": "1.4.0",