beforeEach(function (done) {
    this.el = document.createElement('div');
    this.el.id = 'wdmtmp';
    document.body.appendChild(this.el);
    var vizjson = {
      bounds: [[24.206889622398023, -84.0234375], [76.9206135182968, 169.1015625]],
      center: '[41.40578459184651, 2.2230148315429688]',
      user: {},
      datasource: {
        maps_api_template: 'asd',
        user_name: 'pepe'
      },
      layers: [{
        id: 'l-1',
        type: 'CartoDB'
      }],
      widgets: []
    };

    deepInsights.createDashboard('#wdmtmp', vizjson, {}, function (error, dashboard) {
      if (error) {
        throw new Error('error creating dashboard ' + error);
      }
      this.dashboard = dashboard;
      this.analysis = this.dashboard.getMap().analysis;

      this.layerDefinitionsCollection = new Backbone.Collection();
      this.widgetDefinitionsCollection = new Backbone.Collection();
      this.analysisDefinitionsCollection = new Backbone.Collection();
      this.analysisDefinitionNodesCollection = new Backbone.Collection();

      this.integrations = new DeepInsightsIntegrations({
        deepInsightsDashboard: dashboard,
        analysisDefinitionsCollection: this.analysisDefinitionsCollection,
        analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
        layerDefinitionsCollection: this.layerDefinitionsCollection,
        widgetDefinitionsCollection: this.widgetDefinitionsCollection
      });

      // for some reason the spec run gets stuck if done is called within this callback, so defer it to get feedback
      _.defer(function () {
        done();
      });
    }.bind(this));
  });
Beispiel #2
0
deepInsights.createDashboard('#dashboard', vizJSON, {
  apiKey: configModel.get('api_key'),
  no_cdn: false,
  cartodb_logo: false,
  renderMenu: false,
  show_empty_infowindow_fields: true
}, function (error, dashboard) {
  if (error) {
    throw error;
  }

  var mapId = visualizationData.map_id;

  var analysisDefinitionNodesCollection = new AnalysisDefinitionNodesCollection(null, {
    configModel: configModel
  });

  var analysisDefinitionsCollection = new AnalysisDefinitionsCollection(analysesData, {
    configModel: configModel,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    vizId: visDefinitionModel.id
  });

  var layerDefinitionsCollection = new LayerDefinitionsCollection(null, {
    configModel: configModel,
    analysisDefinitionsCollection: analysisDefinitionsCollection,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    mapId: mapId
  });

  var vis = dashboard.getMap();
  var dashboardView = dashboard.getView();

  dashboardView.listenTo(editorModel, 'change:edition', function (m) {
    dashboardView.$el.toggleClass('is-dark', m.isEditing());
  });

  dashboardView.add_related_model(editorModel);

  var infowindowManager = new InfowindowManager({
    vis: vis,
    layerDefinitionsCollection: layerDefinitionsCollection
  });

  layerDefinitionsCollection.resetByLayersData(layersData);
  infowindowManager.initBinds();

  var widgetDefinitionsCollection = new WidgetDefinitionsCollection(null, {
    configModel: configModel,
    layerDefinitionsCollection: layerDefinitionsCollection,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    mapId: mapId
  });
  window.styleManager = new StyleManager(layerDefinitionsCollection);

  vizJSON.widgets.forEach(function (d) {
    widgetDefinitionsCollection.add(d);
  });

  var deepInsightsIntegrations = new DeepInsightsIntegrations({
    deepInsightsDashboard: dashboard,
    analysisDefinitionsCollection: analysisDefinitionsCollection,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    layerDefinitionsCollection: layerDefinitionsCollection,
    widgetDefinitionsCollection: widgetDefinitionsCollection
  });

  var editorTabPaneView = createEditorMenuTabPane([
    {
      icon: 'pencil',
      selected: true,
      createContentView: function () {
        return new EditorMapView({
          analysis: vis.analysis,
          configModel: configModel,
          userModel: userModel,
          editorModel: editorModel,
          modals: modals,
          visDefinitionModel: visDefinitionModel,
          layerDefinitionsCollection: layerDefinitionsCollection,
          analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
          widgetDefinitionsCollection: widgetDefinitionsCollection
        });
      }
    }, {
      icon: 'settings',
      createContentView: function () {
        return viewFactory.createByHTML('Settings');
      }
    }, {
      icon: 'view',
      createContentView: function () {
        return viewFactory.createByHTML('View');
      }
    }
  ], {
    tabPaneOptions: {
      className: 'Editor-wrapper',
      template: EditorPaneTemplate,
      url: userModel.get('base_url'),
      avatar_url: userModel.get('avatar_url'),
      tabPaneItemOptions: {
        tagName: 'li',
        className: 'EditorMenu-navigationItem'
      }
    },
    tabPaneItemIconOptions: {
      tagName: 'button',
      template: EditorPaneIconItemTemplate,
      className: 'EditorMenu-navigationLink'
    }
  });

  $('.js-editor').prepend(editorTabPaneView.render().$el);

  editorTabPaneView.listenTo(editorModel, 'change:edition', function (m) {
    editorTabPaneView.$('.Editor-panelWrapper').toggleClass('is-larger', m.isEditing());
  });

  editorTabPaneView.add_related_model(editorModel);

  var backgroundPollingModel = new BackgroundPollingModel({
    showGeocodingDatasetURLButton: true,
    geocodingsPolling: true,
    importsPolling: true
  }, {
    configModel: configModel,
    userModel: userModel,
    vis: vis,
    layerDefinitionsCollection: layerDefinitionsCollection
  });

  var backgroundPollingView = new BackgroundPollingView({
    model: backgroundPollingModel,
    createVis: false,
    userModel: userModel,
    configModel: configModel,
    modals: modals
  });

  $('.js-editor').prepend(backgroundPollingView.render().$el);

  vis.centerMapToOrigin();

  document.title = vis.map.get('title') + ' | CartoDB';

  // Expose the root stuff to be able to inspect and modify state from developer console
  window.configModel = configModel;
  window.dashboard = dashboard;
  window.vis = vis;
  window.modals = modals;
  window.viewFactory = viewFactory;
  window.visDefinitionModel = visDefinitionModel;
  window.layerDefinitionsCollection = layerDefinitionsCollection;
  window.widgetDefinitionsCollection = widgetDefinitionsCollection;
  window.analysisDefinitionsCollection = analysisDefinitionsCollection;
  window.analysisDefinitionNodesCollection = analysisDefinitionNodesCollection;
  window.deepInsightsIntegrations = deepInsightsIntegrations;
  window.editorModel = editorModel;
});
  beforeEach(function (done) {
    spyOn(_, 'debounce').and.callFake(function (func) {
      return function () {
        func.apply(this, arguments);
      };
    });

    el = document.createElement('div');
    el.id = 'wdmtmp';
    document.body.appendChild(el);

    var vizjson = {
      bounds: [[24.206889622398023, -84.0234375], [76.9206135182968, 169.1015625]],
      center: '[41.40578459184651, 2.2230148315429688]',
      user: {},
      datasource: {
        maps_api_template: 'asd',
        user_name: 'pepe'
      },
      layers: [{
        id: 'l-1',
        kind: 'carto',
        type: 'CartoDB',
        table_name: 'something',
        cartocss: '',
        legends: [
          {
            type: 'bubble',
            title: 'My Bubble Legend',
            fillColor: '#FABADA'
          }, {
            type: 'category',
            title: 'My category Legend',
            fillColor: '#FABADA'
          }, {
            type: 'choropleth',
            title: 'My choropleth Legend',
            fillColor: '#FABADA'
          }, {
            type: 'custom',
            title: 'My custom Legend',
            fillColor: '#FABADA'
          }, {
            type: 'custom_choropleth',
            title: 'My custom_choropleth Legend',
            fillColor: '#FABADA'
          }
        ]
      }],
      options: {
        scrollwheel: false
      },
      legends: true,
      widgets: [
        {
          id: 'w-1',
          type: 'category',
          title: 'name',
          order: 0,
          layer_id: 'l-1',
          options: {
            column: 'name',
            aggregation_column: 'name',
            aggregation: 'count',
            sync_on_data_change: true,
            sync_on_bbox_change: true
          },
          style: {
            widget_style: {
              definition: {
                color: {
                  fixed: '#9DE0AD',
                  opacity: 1
                }
              }
            },
            auto_style: {
              custom: true,
              allowed: true
            }
          }
        }
      ]
    };

    spyOn($, 'ajax').and.callFake(function (options) {
      options.success({
        layergroupid: '123456789',
        metadata: {
          layers: []
        }
      });
    });

    deepInsights.createDashboard('#wdmtmp', vizjson, {
      autoStyle: true
    }, function (error, dashboard) {
      if (error) {
        throw new Error('error creating dashboard ' + error);
      }

      var layersData = [{
        id: 'l-1',
        kind: 'carto',
        options: {
          table_name: 'something',
          cartocss: '...'
        }
      }];

      var layerStyleCollection = new LayerStyleCollection();
      layerStyleCollection.resetByLayersData(layersData);

      this.integrations = new EmbedIntegrations({
        deepInsightsDashboard: dashboard,
        layerStyleCollection: layerStyleCollection
      });

      done();
    }.bind(this));
  });
Beispiel #4
0
    state: stateFromURL
  });
} else if (stateJSON && stateJSON !== '{}') {
  _.extend(dashboardOpts, {
    state: stateJSON
  });
}

var layerStyleCollection = new LayerStyleCollection();
layerStyleCollection.resetByLayersData(layersData);

deepInsights.createDashboard('#dashboard', vizJSON, dashboardOpts, function (error, dashboard) {
  if (error) {
    console.error('Dashboard has some errors:', error);
  }

  var map = dashboard.getMap().map;
  var scrollwheel = vizJSON.options.scrollwheel;
  var method = scrollwheel ? 'enableScrollWheel' : 'disableScrollWheel';
  map && map[method] && map[method]();

  var embedIntegrations = new EmbedIntegrations({
    deepInsightsDashboard: dashboard,
    layerStyleCollection: layerStyleCollection
  });

  window.embedIntegrations = embedIntegrations;
});

window.layerStyleCollection = layerStyleCollection;
Beispiel #5
0
deepInsights.createDashboard('#dashboard', vizJSON, {
  apiKey: configModel.get('api_key'),
  no_cdn: false,
  cartodb_logo: false,
  renderMenu: false,
  show_empty_infowindow_fields: true
}, function (error, dashboard) {
  if (error) {
    console.log('Dashboard has some errors:', error);
  }

  var mapId = visualizationData.map_id;

  var analysisDefinitionNodesCollection = new AnalysisDefinitionNodesCollection(null, {
    configModel: configModel
  });

  var analysisDefinitionsCollection = new AnalysisDefinitionsCollection(analysesData, {
    configModel: configModel,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    vizId: visDefinitionModel.id
  });

  var layerDefinitionsCollection = new LayerDefinitionsCollection(null, {
    configModel: configModel,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    mapId: mapId
  });

  var vis = dashboard.getMap();
  var dashboardView = dashboard.getView();

  dashboardView.listenTo(editorModel, 'change:edition', function (m) {
    dashboardView.$el.toggleClass('is-dark', m.isEditing());
  });

  dashboardView.add_related_model(editorModel);

  layerDefinitionsCollection.resetByLayersData(layersData);

  var widgetDefinitionsCollection = new WidgetDefinitionsCollection(null, {
    configModel: configModel,
    mapId: mapId
  });
  var styleManager = new StyleManager(layerDefinitionsCollection, vis.map);

  vizJSON.widgets.forEach(function (d) {
    widgetDefinitionsCollection.add(d);
  });

  var deepInsightsIntegrations = new DeepInsightsIntegrations({
    onboardings: onboardings,
    userModel: userModel,
    deepInsightsDashboard: dashboard,
    analysisDefinitionsCollection: analysisDefinitionsCollection,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    layerDefinitionsCollection: layerDefinitionsCollection,
    widgetDefinitionsCollection: widgetDefinitionsCollection,
    visDefinitionModel: visDefinitionModel
  });

  Notifier.init({
    editorModel: editorModel,
    visDefinitionModel: visDefinitionModel
  });

  var userActions = UserActions({
    userModel: userModel,
    analysisDefinitionsCollection: analysisDefinitionsCollection,
    analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
    layerDefinitionsCollection: layerDefinitionsCollection,
    widgetDefinitionsCollection: widgetDefinitionsCollection
  });

  var backgroundPollingModel = new BackgroundPollingModel({
    showGeocodingDatasetURLButton: false,
    geocodingsPolling: false,
    importsPolling: false
  }, {
    configModel: configModel,
    userModel: userModel,
    vis: vis,
    userActions: userActions
  });

  ImporterManager.init({
    pollingModel: backgroundPollingModel,
    createVis: false,
    userModel: userModel,
    configModel: configModel,
    modals: modals
  });

  var mapDefModel = new MapDefinitionModel(
    _.extend(
      vizJSON,
      {
        id: visualizationData.map_id
      }
    ),
    {
      parse: true,
      configModel: configModel,
      vis: vis,
      userModel: userModel,
      layerDefinitionsCollection: layerDefinitionsCollection
    }
  );

  var mapcapsCollection = new MapcapsCollection([], {
    visDefinitionModel: visDefinitionModel
  });

  mapcapsCollection.fetch({reset: true});

  var privacyOptions = CreatePrivacyOptions(visDefinitionModel, userModel);
  var privacyCollection = new PrivacyCollection(privacyOptions);

  var overlaysCollection = new OverlaysCollection([], {
    syncCollection: vis.overlaysCollection,
    configModel: configModel,
    visId: visDefinitionModel.id
  });

  overlaysCollection.fetch({reset: true});

  // Expose the root stuff to be able to inspect and modify state from developer console (before views)
  window.configModel = configModel;
  window.dashboard = dashboard;
  window.vis = vis;
  window.modals = modals;
  window.onboardings = onboardings;
  window.userActions = userActions;
  window.userModel = userModel;
  window.viewFactory = viewFactory;
  window.visDefinitionModel = visDefinitionModel;
  window.layerDefinitionsCollection = layerDefinitionsCollection;
  window.widgetDefinitionsCollection = widgetDefinitionsCollection;
  window.analysisDefinitionsCollection = analysisDefinitionsCollection;
  window.analysisDefinitionNodesCollection = analysisDefinitionNodesCollection;
  window.deepInsightsIntegrations = deepInsightsIntegrations;
  window.editorModel = editorModel;
  window.styleManager = styleManager;
  window.mapDefModel = mapDefModel;
  window.overlaysCollection = overlaysCollection;

  var editorTabPaneView = createEditorMenuTabPane([
    {
      icon: 'pencil',
      selected: true,
      createContentView: function () {
        return new EditorMapView({
          basemaps: basemaps,
          userActions: userActions,
          analysis: vis.analysis,
          configModel: configModel,
          userModel: userModel,
          editorModel: editorModel,
          pollingModel: backgroundPollingModel,
          onboardings: onboardings,
          modals: modals,
          visDefinitionModel: visDefinitionModel,
          layerDefinitionsCollection: layerDefinitionsCollection,
          analysisDefinitionNodesCollection: analysisDefinitionNodesCollection,
          widgetDefinitionsCollection: widgetDefinitionsCollection,
          mapcapsCollection: mapcapsCollection,
          privacyCollection: privacyCollection
        });
      }
    }, {
      icon: 'settings',
      createContentView: function () {
        return new SettingsView({
          mapDefinitionModel: mapDefModel,
          overlaysCollection: overlaysCollection,
          mapcapsCollection: mapcapsCollection,
          visDefinitionModel: visDefinitionModel,
          privacyCollection: privacyCollection,
          configModel: configModel,
          userModel: userModel,
          modals: modals,
          editorModel: editorModel,
          settingsCollection: new Backbone.Collection(SettingsOptions(vis.overlaysCollection, mapDefModel, userModel))
        });
      }
    }
  ], {
    tabPaneOptions: {
      className: 'Editor-wrapper',
      template: editorPaneTemplate,
      url: userModel.get('base_url'),
      avatar_url: userModel.get('avatar_url'),
      tabPaneItemOptions: {
        tagName: 'li',
        className: 'EditorMenu-navigationItem'
      }
    },
    tabPaneItemIconOptions: {
      tagName: 'button',
      template: editorPaneIconItemTemplate,
      className: 'EditorMenu-navigationLink'
    }
  });

  $('.js-editor').prepend(editorTabPaneView.render().$el);

  editorTabPaneView.listenTo(editorModel, 'change:edition', function (m) {
    editorTabPaneView.$('.Editor-panelWrapper').toggleClass('is-larger', m.isEditing());
  });
  editorTabPaneView.add_related_model(editorModel);

  var feedbackView = new FeedbackButtonView({ modals: modals });
  $('.js-editorMenu').append(feedbackView.render().el);

  vis.centerMapToOrigin();

  document.title = vis.map.get('title') + ' | CARTO';
});
  beforeEach(function (done) {
    var configModel = new ConfigModel({
      base_url: 'pepito'
    });
    this.el = document.createElement('div');
    this.el.id = 'wdmtmp';
    document.body.appendChild(this.el);
    var vizjson = {
      bounds: [[24.206889622398023, -84.0234375], [76.9206135182968, 169.1015625]],
      center: '[41.40578459184651, 2.2230148315429688]',
      user: {},
      datasource: {
        maps_api_template: 'asd',
        user_name: 'pepe'
      },
      layers: [{
        id: 'l-1',
        kind: 'carto',
        type: 'CartoDB'
      }],
      widgets: []
    };

    spyOn($, 'ajax').and.callFake(function (options) {
      options.success({
        layergroupid: '123456789',
        metadata: {
          layers: []
        }
      });
    });

    deepInsights.createDashboard('#wdmtmp', vizjson, {}, function (error, dashboard) {
      if (error) {
        throw new Error('error creating dashboard ' + error);
      }
      this.dashboard = dashboard;
      this.analysis = this.dashboard.getMap().analysis;
      spyOn(this.analysis, 'analyse').and.callThrough();

      this.visDefinitionModel = new VisDefinitionModel({
        name: 'Foo Map',
        privacy: 'PUBLIC',
        updated_at: '2016-06-21T15:30:06+00:00',
        type: 'derived'
      }, {
        configModel: configModel
      });

      this.analysisDefinitionNodesCollection = new AnalysisDefinitionNodesCollection(null, {
        configModel: configModel
      });
      this.analysisDefinitionsCollection = new AnalysisDefinitionsCollection(null, {
        configModel: configModel,
        analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
        vizId: 'v-123'
      });

      this.layerDefinitionsCollection = new LayerDefinitionsCollection(null, {
        configModel: configModel,
        analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
        mapId: 'map-123'
      });
      this.widgetDefinitionsCollection = new Backbone.Collection();

      this.integrations = new DeepInsightsIntegrations({
        deepInsightsDashboard: dashboard,
        analysisDefinitionsCollection: this.analysisDefinitionsCollection,
        analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
        layerDefinitionsCollection: this.layerDefinitionsCollection,
        widgetDefinitionsCollection: this.widgetDefinitionsCollection,
        visDefinitionModel: this.visDefinitionModel
      });

      done();
    }.bind(this));
  });
Beispiel #7
0
var deepInsights = require('cartodb-deep-insights.js');
deepInsights.createDashboard('#dashboard', window.vizJSON, {
  no_cdn: false,
  cartodb_logo: false,
  renderMenu: true,
  share_urls: true
});