divio/django-cms

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

Summary

Maintainability
F
1 wk
Test Coverage

File cms.pagetree.js has 743 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.pagetree.js - About 1 day to fix

    Function _events has 157 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _events: function _events() {
            var that = this;
    
            // set events for the nodeId updates
            this.ui.tree.on('after_close.jstree', function(e, el) {
    Severity: Major
    Found in cms/static/cms/js/modules/cms.pagetree.js - About 6 hrs to fix

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

          _setup: function _setup() {
              var that = this;
              var columns = [];
              var obj = {
                  language: this.options.lang.code,
      Severity: Major
      Found in cms/static/cms/js/modules/cms.pagetree.js - About 3 hrs to fix

        PageTree has 28 functions (exceeds 20 allowed). Consider refactoring.
        Open

        var PageTree = new Class({
            options: {
                pasteSelector: '.js-cms-tree-item-paste'
            },
            initialize: function initialize(options) {
        Severity: Minor
        Found in cms/static/cms/js/modules/cms.pagetree.js - About 3 hrs to fix

          Function _copyNode has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              _copyNode: function _copyNode(obj) {
                  var that = this;
                  var node = { position: 0 };
          
                  if (obj) {
          Severity: Major
          Found in cms/static/cms/js/modules/cms.pagetree.js - About 2 hrs to fix

            Function _setupSearch has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                _setupSearch: function _setupSearch() {
                    var that = this;
                    var click = this.click + '.search';
            
                    var filterActive = false;
            Severity: Minor
            Found in cms/static/cms/js/modules/cms.pagetree.js - About 1 hr to fix

              Function _setup has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  _setup: function _setup() {
                      var that = this;
                      var columns = [];
                      var obj = {
                          language: this.options.lang.code,
              Severity: Minor
              Found in cms/static/cms/js/modules/cms.pagetree.js - About 1 hr 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 _paste has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  _paste: function _paste(event) {
                      // hide helpers after we picked one
                      this._disablePaste();
              
                      var copyFromId = this._getNodeId(
              Severity: Minor
              Found in cms/static/cms/js/modules/cms.pagetree.js - About 1 hr 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 _paste has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _paste: function _paste(event) {
                      // hide helpers after we picked one
                      this._disablePaste();
              
                      var copyFromId = this._getNodeId(
              Severity: Minor
              Found in cms/static/cms/js/modules/cms.pagetree.js - About 1 hr to fix

                Function _setAjaxPost has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    _setAjaxPost: function _setAjaxPost(trigger) {
                        var that = this;
                
                        this.ui.container.on(this.click, trigger, function(e) {
                            e.preventDefault();
                Severity: Minor
                Found in cms/static/cms/js/modules/cms.pagetree.js - About 1 hr to fix

                  Function check_callback has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                                  check_callback: function(operation, node, node_parent, node_position, more) {
                  Severity: Minor
                  Found in cms/static/cms/js/modules/cms.pagetree.js - About 35 mins to fix

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

                        _copyNode: function _copyNode(obj) {
                            var that = this;
                            var node = { position: 0 };
                    
                            if (obj) {
                    Severity: Minor
                    Found in cms/static/cms/js/modules/cms.pagetree.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

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

                                data.data.nodes.forEach(function(nodeId) {
                                    var descendantIds = that._getDescendantsIds(nodeId);
                    
                                    [nodeId].concat(descendantIds).forEach(function(id) {
                                        $('.jsgrid_' + id + '_col').addClass('jstree-is-dragging');
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 2 hrs to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 348..354

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

                    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

                                data.data.nodes.forEach(function(nodeId) {
                                    var descendantIds = that._getDescendantsIds(nodeId);
                    
                                    [nodeId].concat(descendantIds).forEach(function(id) {
                                        $('.jsgrid_' + id + '_col').removeClass('jstree-is-dragging jstree-is-dragging-copy');
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 2 hrs to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 286..292

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

                    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

                                this.ui.container.on(this.click, this.options.pasteSelector, function(e) {
                                    e.preventDefault();
                                    if ($(this).hasClass('cms-pagetree-dropdown-item-disabled')) {
                                        return;
                                    }
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 2 hrs to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 393..399

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

                    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

                            this.ui.container.on(this.click, this.options.pasteSelector, function(e) {
                                e.preventDefault();
                                if ($(this).hasClass('cms-pagetree-dropdown-item-disabled')) {
                                    return;
                                }
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 2 hrs to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 54..60

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

                    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.ui.container.on(this.click, '.js-cms-tree-item-copy', function(e) {
                                e.preventDefault();
                                that._cutOrCopy({ type: 'copy', element: $(this) });
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 381..384

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

                    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.ui.container.on(this.click, '.js-cms-tree-item-cut', function(e) {
                                e.preventDefault();
                                that._cutOrCopy({ type: 'cut', element: $(this) });
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 387..390

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

                    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.ui.document.on('keyup.pagetree.alt-mode', function(e) {
                                if (e.keyCode === KEYS.SHIFT) {
                                    that.ui.container.removeClass('cms-pagetree-alt-mode');
                                }
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 252..256

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

                    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.ui.document.on('keydown.pagetree.alt-mode', function(e) {
                                if (e.keyCode === KEYS.SHIFT) {
                                    that.ui.container.addClass('cms-pagetree-alt-mode');
                                }
                            });
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 258..262

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

                    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 $.ajax({
                                method: 'post',
                                url: that.options.urls.move.replace('{id}', obj.id),
                                data: obj
                            })
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 750..761

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

                    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 $.ajax({
                                method: 'post',
                                url: that.options.urls.copy.replace('{id}', data.id),
                                data: data
                            })
                    Severity: Major
                    Found in cms/static/cms/js/modules/cms.pagetree.js and 1 other location - About 1 hr to fix
                    cms/static/cms/js/modules/cms.pagetree.js on lines 642..653

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

                    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