CartoDB/cartodb20

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

Summary

Maintainability
F
5 days
Test Coverage

File infowindow-base-view.js has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var Backbone = require('backbone');
var CoreView = require('backbone/core-view');
var _ = require('underscore');
var checkAndBuildOpts = require('builder/helpers/required-opts');
var PanelWithOptionsView = require('builder/components/view-options/panel-with-options-view');

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

    module.exports = CoreView.extend({
      module: 'infowindow-base-view',
    
      initialize: function (opts) {
        checkAndBuildOpts(opts, REQUIRED_OPTS, this);

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

        _initViews: function () {
          var self = this;
      
          var infoboxSstates = [
            {

        Function _configPanes has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _configPanes: function () {
            var self = this;
        
            var tabPaneTabs = [{
              selected: !self.model.isCustomTemplate(),

          Function _initModels has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _initModels: function () {
              var content;
              if (this.model.isCustomTemplate()) {
                content = this.model.get('template');
              } else {

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

              _saveInfowindowHTML: function () {
                var content = this._codemirrorModel.get('content');
                // Parse
                var errors = this._getErrors(content);
            
            

            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

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

                if (!edition && customTemplate) {
                  this._infoboxModel.set({ state: 'confirm' });
                  this._overlayModel.set({ visible: true });
                } else if (this._isLayerHidden()) {
                  this._infoboxModel.set({ state: 'layer-hidden' });
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 329..340
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 453..464

            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 145.

            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 3 locations. Consider refactoring.
            Open

              _initBinds: function () {
                this.listenTo(this.model, 'change', this._onChange);
                this.listenTo(this._layerDefinitionModel, 'change:visible', this._infoboxState);
            
                this.listenTo(this._editorModel, 'change:edition', this._onChangeEdition);
            lib/assets/javascripts/builder/editor/layers/layer-content-views/infowindow/infowindows-view.js on lines 63..70
            lib/assets/javascripts/deep-insights/widgets/time-series/time-series-header-view.js on lines 99..106

            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 136.

            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 4 locations. Consider refactoring.
            Open

                var panelWithOptionsView = new PanelWithOptionsView({
                  className: 'Editor-content',
                  editorModel: self._editorModel,
                  infoboxModel: self._infoboxModel,
                  infoboxCollection: infoboxCollection,
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 406..427
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 251..272
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 197..218

            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 126.

            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 4 locations. Consider refactoring.
            Open

              _onChangeEdition: function () {
                this._infoboxState();
            
                var edition = this._editorModel.get('edition');
                var index = edition ? 1 : 0;
            lib/assets/javascripts/builder/dataset/dataset-options/dataset-options-view.js on lines 126..133
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 284..291
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 326..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 102.

            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 8 locations. Consider refactoring.
            Open

                  }, {
                    state: 'layer-hidden',
                    createContentView: function () {
                      return Infobox.createWithAction({
                        type: 'alert',
            lib/assets/javascripts/builder/editor/layers/layer-content-views/analyses/analyses-view.js on lines 84..97
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 366..379
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 388..401
            lib/assets/javascripts/builder/editor/layers/layer-content-views/infowindow/infowindow-base-view.js on lines 90..103
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 207..220
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 220..233
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 233..246

            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 84.

            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 8 locations. Consider refactoring.
            Open

                  {
                    state: 'confirm',
                    createContentView: function () {
                      return Infobox.createWithAction({
                        type: 'alert',
            lib/assets/javascripts/builder/editor/layers/layer-content-views/analyses/analyses-view.js on lines 84..97
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 366..379
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 388..401
            lib/assets/javascripts/builder/editor/layers/layer-content-views/infowindow/infowindow-base-view.js on lines 103..116
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 207..220
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 220..233
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 233..246

            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 84.

            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 3 locations. Consider refactoring.
            Open

                this._togglerModel = new Backbone.Model({
                  labels: [_t('editor.infowindow.html-toggle.values'), _t('editor.infowindow.html-toggle.html')],
                  active: this._editorModel.isEditing(),
                  disabled: this._editorModel.isDisabled(),
                  isDisableable: true,
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 62..68
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 72..78

            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 82.

            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 2 locations. Consider refactoring.
            Open

              render: function () {
                this.clearSubViews();
                this.$el.empty();
            
                this._initViews();
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 74..83

            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 67.

            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 6 locations. Consider refactoring.
            Open

              _showHiddenLayer: function () {
                var savingOptions = {
                  shouldPreserveAutoStyle: true
                };
                this._layerDefinitionModel.toggleVisible();
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 455..461
            lib/assets/javascripts/builder/editor/layers/layer-content-views/infowindow/infowindows-view.js on lines 225..231
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 278..284
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legends-view.js on lines 218..224
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 467..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 57.

            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 10 locations. Consider refactoring.
            Open

              _onTogglerChanged: function () {
                var checked = this._togglerModel.get('active');
                this._editorModel.set({ edition: checked });
              },
            lib/assets/javascripts/builder/dataset/dataset-options/dataset-options-view.js on lines 135..138
            lib/assets/javascripts/builder/dataset/dataset-options/dataset-options-view.js on lines 140..143
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 293..296
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 298..301
            lib/assets/javascripts/builder/editor/layers/layer-content-views/infowindow/infowindow-base-view.js on lines 317..320
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 193..196
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 198..201
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 335..338
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 340..343

            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 10 locations. Consider refactoring.
            Open

              _onChangeDisabled: function () {
                var disabled = this._editorModel.get('disabled');
                this._togglerModel.set({ disabled: disabled });
              },
            lib/assets/javascripts/builder/dataset/dataset-options/dataset-options-view.js on lines 135..138
            lib/assets/javascripts/builder/dataset/dataset-options/dataset-options-view.js on lines 140..143
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 293..296
            lib/assets/javascripts/builder/editor/layers/layer-content-views/data/data-view.js on lines 298..301
            lib/assets/javascripts/builder/editor/layers/layer-content-views/infowindow/infowindow-base-view.js on lines 322..325
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 193..196
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 198..201
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 335..338
            lib/assets/javascripts/builder/editor/style/style-view.js on lines 340..343

            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

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

              _toggleOverlay: function () {
                var isDisabled = this._overlayModel.get('visible');
                this.$('.js-overlay').toggleClass('is-disabled', isDisabled);
              },
            lib/assets/javascripts/builder/editor/layers/layer-content-views/legend/legend-base-type-view.js on lines 173..176

            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 49.

            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