divio/django-cms

View on GitHub
cms/static/cms/js/modules/cms.structureboard.js

Summary

Maintainability
F
1 wk
Test Coverage

File cms.structureboard.js has 1105 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * Copyright https://github.com/divio/django-cms
 */

import $ from 'jquery';
Severity: Major
Found in cms/static/cms/js/modules/cms.structureboard.js - About 2 days to fix

    StructureBoard has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class StructureBoard {
        constructor() {
            // elements
            this._setupUI();
    
    
    Severity: Minor
    Found in cms/static/cms/js/modules/cms.structureboard.js - About 6 hrs to fix

      Function _drag has 143 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _drag(elem = this.ui.sortables) {
              var that = this;
      
              elem
                  .nestedSortable({
      Severity: Major
      Found in cms/static/cms/js/modules/cms.structureboard.js - About 5 hrs to fix

        Function _drag has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
        Open

            _drag(elem = this.ui.sortables) {
                var that = this;
        
                elem
                    .nestedSortable({
        Severity: Minor
        Found in cms/static/cms/js/modules/cms.structureboard.js - About 5 hrs to fix

        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 handleMovePlugin has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
        Open

            handleMovePlugin(data) {
                if (data.plugin_parent) {
                    if (data.plugin_id) {
                        const draggable = $(`.cms-draggable-${data.plugin_id}:last`);
        
        
        Severity: Minor
        Found in cms/static/cms/js/modules/cms.structureboard.js - About 4 hrs to fix

        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 _loadContent has 65 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            _loadContent() {
                var that = this;
        
                // case when content mode is already loaded
                if (CMS.config.settings.mode === 'edit' || this._loadedContent) {
        Severity: Major
        Found in cms/static/cms/js/modules/cms.structureboard.js - About 2 hrs to fix

          Function handleMovePlugin has 61 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              handleMovePlugin(data) {
                  if (data.plugin_parent) {
                      if (data.plugin_id) {
                          const draggable = $(`.cms-draggable-${data.plugin_id}:last`);
          
          
          Severity: Major
          Found in cms/static/cms/js/modules/cms.structureboard.js - About 2 hrs to fix

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

                invalidateState(action, data, { propagate = true } = {}) {
                    // eslint-disable-next-line default-case
                    switch (action) {
                        case 'COPY': {
                            this.handleCopyPlugin(data);
            Severity: Major
            Found in cms/static/cms/js/modules/cms.structureboard.js - About 2 hrs to fix

              Function _loadStructure has 53 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _loadStructure() {
                      // case when structure mode is already loaded
                      if (CMS.config.settings.mode === 'structure' || this._loadedStructure) {
                          return Promise.resolve();
                      }
              Severity: Major
              Found in cms/static/cms/js/modules/cms.structureboard.js - About 2 hrs to fix

                Function _setupModeSwitcher has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    _setupModeSwitcher() {
                        const modes = this.ui.toolbarModeLinks;
                        let cmdPressed;
                
                        $(Helpers._getWindow())
                Severity: Minor
                Found in cms/static/cms/js/modules/cms.structureboard.js - About 2 hrs to fix

                  Function isAllowed has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                                  isAllowed: function(placeholder, placeholderParent, originalItem) {
                                      // cancel if action is executed
                                      if (CMS.API.locked) {
                                          return false;
                                      }
                  Severity: Minor
                  Found in cms/static/cms/js/modules/cms.structureboard.js - About 1 hr to fix

                    Function update has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                                    update: function(event, ui) {
                                        // cancel if isAllowed returns false
                                        if (!that.state) {
                                            return false;
                                        }
                    Severity: Minor
                    Found in cms/static/cms/js/modules/cms.structureboard.js - About 1 hr to fix

                      Function addJsScriptsNeededForRender has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          addJsScriptsNeededForRender(newScripts, oldScripts) {
                              const scriptSrcList = [];
                              let classListCollection = [];
                              const that = this;
                      
                      
                      Severity: Minor
                      Found in cms/static/cms/js/modules/cms.structureboard.js - About 1 hr to fix

                        Function _showAndHighlightPlugin has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            _showAndHighlightPlugin(successTimeout = 200, seeThrough = false) {
                                // cancel show if live modus is active
                                if (CMS.config.mode === 'live') {
                                    return Promise.resolve(false);
                                }
                        Severity: Minor
                        Found in cms/static/cms/js/modules/cms.structureboard.js - About 1 hr to fix

                          Function refreshContent has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              refreshContent(contentMarkup) {
                                  this._requestcontent = null;
                                  if (!this._loadedStructure) {
                                      this._requeststructure = null;
                                  }
                          Severity: Minor
                          Found in cms/static/cms/js/modules/cms.structureboard.js - About 1 hr to fix

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

                                _setup() {
                                    var that = this;
                            
                                    // cancel if there is no structure / content switcher
                                    if (!this.ui.toolbarModeSwitcher.length) {
                            Severity: Minor
                            Found in cms/static/cms/js/modules/cms.structureboard.js - About 1 hr to fix

                              Function show has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  show({ init = false, saveState = true } = {}) {
                                      // cancel show if live modus is active
                                      if (CMS.config.mode === 'live') {
                                          return Promise.resolve(false);
                                      }
                              Severity: Minor
                              Found in cms/static/cms/js/modules/cms.structureboard.js - About 35 mins to fix

                              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 invalidateState has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  invalidateState(action, data, { propagate = true } = {}) {
                                      // eslint-disable-next-line default-case
                                      switch (action) {
                                          case 'COPY': {
                                              this.handleCopyPlugin(data);
                              Severity: Minor
                              Found in cms/static/cms/js/modules/cms.structureboard.js - About 35 mins to fix

                              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

                              Avoid too many return statements within this function.
                              Open

                                                  return that.state;
                              Severity: Major
                              Found in cms/static/cms/js/modules/cms.structureboard.js - About 30 mins to fix

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

                                    getId(el) {
                                        // cancel if no element is defined
                                        if (el === undefined || el === null || el.length <= 0) {
                                            return false;
                                        }
                                Severity: Minor
                                Found in cms/static/cms/js/modules/cms.structureboard.js - About 25 mins to fix

                                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 _setup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    _setup() {
                                        var that = this;
                                
                                        // cancel if there is no structure / content switcher
                                        if (!this.ui.toolbarModeSwitcher.length) {
                                Severity: Minor
                                Found in cms/static/cms/js/modules/cms.structureboard.js - About 25 mins to fix

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

                                                if (
                                                    e.keyCode === KEYS.CMD_LEFT ||
                                                    e.keyCode === KEYS.CMD_RIGHT ||
                                                    e.keyCode === KEYS.CMD_FIREFOX ||
                                                    e.keyCode === KEYS.SHIFT ||
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 2 hrs to fix
                                cms/static/cms/js/modules/cms.toolbar.js on lines 191..199

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

                                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

                                                    if (index === 0) {
                                                        placeholderDraggables.prepend(draggable);
                                                    } else if (index !== -1) {
                                                        placeholderDraggables.find(`.cms-draggable-${pluginOrder[index - 1]}`).after(draggable);
                                                    }
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 1 hr to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 1143..1147

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

                                                if (index === 0) {
                                                    placeholderDraggables.prepend(draggable);
                                                } else if (index !== -1) {
                                                    placeholderDraggables.find(`.cms-draggable-${pluginOrder[index - 1]}`).after(draggable);
                                                }
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 1 hr to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 1166..1170

                                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

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

                                                    that.ui.sortables.each(function() {
                                                        var element = $(this);
                                
                                                        if (element.children().length === 0) {
                                                            element.removeClass('cms-hidden');
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 1 hr to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 871..877

                                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

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

                                                    that.ui.sortables.each(function() {
                                                        var element = $(this);
                                
                                                        if (element.children().length === 0) {
                                                            element.addClass('cms-hidden');
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 1 hr to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 795..801

                                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

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

                                        return that
                                            ._requestMode('content')
                                            .done(function(contentMarkup) {
                                                that._requestcontent = null;
                                                hideLoader();
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 1 hr to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 388..446

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

                                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

                                        return this
                                            ._requestMode('structure')
                                            .done(contentMarkup => {
                                                this._requeststructure = null;
                                                hideLoader();
                                Severity: Major
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 1 hr to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 481..557

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

                                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

                                            remove(
                                                CMS._instances,
                                                instance => instance.options.plugin_id && Number(instance.options.plugin_id) === Number(pluginId)
                                            );
                                Severity: Minor
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 40 mins to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 1453..1456

                                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

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

                                            remove(
                                                CMS._instances,
                                                instance => instance.options.plugin_id && Number(instance.options.plugin_id) === Number(id)
                                            );
                                Severity: Minor
                                Found in cms/static/cms/js/modules/cms.structureboard.js and 1 other location - About 40 mins to fix
                                cms/static/cms/js/modules/cms.structureboard.js on lines 1432..1435

                                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