CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/builder/editor/layers/layer-views/data-layer-view.js

Summary

Maintainability
F
5 days
Test Coverage

File data-layer-view.js has 445 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var Backbone = require('backbone');
var _ = require('underscore');
var CoreView = require('backbone/core-view');
var template = require('./data-layer.tpl');
var fetchingTemplate = require('./data-layer-fetching.tpl');

    exports has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    module.exports = CoreView.extend({
      module: 'editor:layers:layer-views:data-layer-view',
    
      tagName: 'li',
    
    

      Function _initViews has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _initViews: function () {
          var geometryTemplate = this._getGeometryTemplate(this._queryGeometryModel.get('simple_geom'));
      
          this._inlineEditor = new InlineEditorView({
            template: templateInlineEditor,

        Function _getContextMenuOptions has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _getContextMenuOptions: function () {
            var menuItems = [{
              label: _t('editor.layers.options.edit'),
              val: 'edit-layer',
              action: this._onEditLayer.bind(this)

          Function render has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            render: function () {
              this.clearSubViews();
          
              var isAnimation = this._styleModel.isAnimation();
              var fetching = this._viewState.get('isFetchingRows');

            Function _initViews has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              _initViews: function () {
                var geometryTemplate = this._getGeometryTemplate(this._queryGeometryModel.get('simple_geom'));
            
                this._inlineEditor = new InlineEditorView({
                  template: templateInlineEditor,

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function _getContextMenuOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              _getContextMenuOptions: function () {
                var menuItems = [{
                  label: _t('editor.layers.options.edit'),
                  val: 'edit-layer',
                  action: this._onEditLayer.bind(this)

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

              _bindEvents: function () {
                this.listenTo(this.model, 'change', this.render);
                this.listenToOnce(this.model, 'destroy', this._onDestroy);
                this.listenTo(this._queryGeometryModel, 'change:simple_geom', this._setViewState);
                this.listenTo(this._queryRowsStatus, 'change:status', this._onQueryRowsStatusChanged);
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-content-view.js on lines 56..62
            lib/assets/javascripts/deep-insights/widgets/category/list/items-view.js on lines 50..58

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 115.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              _renameLayer: function () {
                var newName = this._inlineEditor.getValue();
            
                if (newName !== '') {
                  // Optimistic
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 380..395

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 109.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

              _confirmDeleteLayer: function () {
                this._modals.create(function (modalModel) {
                  var deleteLayerConfirmationView = new DeleteLayerConfirmationView({
                    userActions: this._userActions,
                    modals: this._modals,
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 339..352

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 104.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                this._modals.create(function (modalModel) {
                  return new ModalExportDataView({
                    fromView: 'main',
                    modalModel: modalModel,
                    queryGeometryModel,
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 366..377

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 96.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                var toggleMenuTooltip = new TipsyTooltipView({
                  el: this.$('.js-toggle'),
                  gravity: 's',
                  title: function () {
                    return this._isHidden() ? _t('editor.layers.options.show') : _t('editor.layers.options.hide');
            lib/assets/javascripts/builder/dataset/dataset-header/dataset-header-view.js on lines 102..108

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 72.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                if (this._hasContextMenu()) {
                  this._hideContextMenu();
                } else {
                  this._showContextMenu({
                    x: event.pageX,
            lib/assets/javascripts/builder/components/context-menu-factory-view.js on lines 98..105
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 269..276

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 58.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 6 locations. Consider refactoring.
            Open

                this._menuView.model.bind('change:visible', function (model, isContextMenuVisible) {
                  if (this._hasContextMenu() && !isContextMenuVisible) {
                    this._hideContextMenu();
                  }
                }, this);
            lib/assets/javascripts/builder/components/context-menu-factory-view.js on lines 70..74
            lib/assets/javascripts/builder/components/table/body/table-body-view.js on lines 305..309
            lib/assets/javascripts/builder/components/table/head/table-head-item-view.js on lines 171..175
            lib/assets/javascripts/builder/editor/layers/basemap-content-views/basemap-mosaic-remove-view.js on lines 59..63
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 329..333

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 58.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

              _onSaveSuccess: function (newName) {
                this.$('.js-title').text(newName).show();
                this._inlineEditor.hide();
              },
            lib/assets/javascripts/builder/editor/editor-header.js on lines 295..298
            lib/assets/javascripts/builder/editor/editor-header.js on lines 300..303
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 403..406
            lib/assets/javascripts/builder/editor/layers/layer-views/data-layer-view.js on lines 470..473

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 51.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

              _onSaveError: function (oldName) {
                this.$('.js-title').text(oldName).show();
                this._inlineEditor.hide();
              },
            lib/assets/javascripts/builder/editor/editor-header.js on lines 295..298
            lib/assets/javascripts/builder/editor/editor-header.js on lines 300..303
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 403..406
            lib/assets/javascripts/builder/editor/layers/layer-views/data-layer-view.js on lines 465..468

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 51.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if (this._viewState.get('needsGeocoding')) {
                  var georeferenceTooltip = new TipsyTooltipView({
                    el: this.$('.js-geocode'),
                    gravity: 'w',
                    offset: 0
            lib/assets/javascripts/builder/editor/layers/layer-views/data-layer-view.js on lines 155..162

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 50.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if (this._isTorque()) {
                  var torqueTooltip = new TipsyTooltipView({
                    el: this.$('.js-torqueIcon'),
                    gravity: 's',
                    offset: 0
            lib/assets/javascripts/builder/editor/layers/layer-views/data-layer-view.js on lines 164..171

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 50.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

              _hideContextMenu: function () {
                this.removeView(this._menuView);
                this._menuView.clean();
                delete this._menuView;
              },
            lib/assets/javascripts/builder/components/context-menu-factory-view.js on lines 89..93
            lib/assets/javascripts/builder/editor/layers/basemap-content-views/basemap-mosaic-remove-view.js on lines 31..35
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 197..201
            lib/assets/javascripts/builder/editor/layers/layer-header-view.js on lines 354..358

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 48.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status