krateng/maloja

View on GitHub
maloja/web/static/js/edit.js

Summary

Maintainability
F
3 days
Test Coverage

File edit.js has 403 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// JS for all web interface editing / deletion of scrobble data

// HELPERS
function selectAll(e) {
    // https://stackoverflow.com/a/6150060/6651341
Severity: Minor
Found in maloja/web/static/js/edit.js - About 5 hrs to fix

    Function doneEditing has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function doneEditing() {
        window.getSelection().removeAllRanges();
        var namefield = document.getElementById('main_entity_name');
        namefield.contentEditable = "false";
        newname = namefield.textContent;
    Severity: Minor
    Found in maloja/web/static/js/edit.js - About 1 hr to fix

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

      function removeAssociate(element) {
          const parentElement = element.closest('[data-entity_id]');
          var entity_type = parentElement.dataset.entity_type;
          var entity_id = parentElement.dataset.entity_id;
          entity_id = parseInt(entity_id);
      Severity: Minor
      Found in maloja/web/static/js/edit.js - About 1 hr to fix

        Function associate has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function associate(element) {
            const parentElement = element.closest('[data-entity_id]');
            var entity_type = parentElement.dataset.entity_type;
            var entity_id = parentElement.dataset.entity_id;
            entity_id = parseInt(entity_id);
        Severity: Minor
        Found in maloja/web/static/js/edit.js - About 1 hr to fix

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

          function toggleAssociationIcons(element) {
              var entity_type = element.dataset.entity_type;
              var entity_id = element.dataset.entity_id;
              entity_id = parseInt(entity_id);
          
          
          Severity: Minor
          Found in maloja/web/static/js/edit.js - About 1 hr to fix

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

            function editEntity() {
            
                var namefield = document.getElementById('main_entity_name');
                try {
                    namefield.contentEditable = "plaintext-only"; // not supported by Firefox
            Severity: Minor
            Found in maloja/web/static/js/edit.js - About 1 hr to fix

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

              function toggleAssociationIcons(element) {
                  var entity_type = element.dataset.entity_type;
                  var entity_id = element.dataset.entity_id;
                  entity_id = parseInt(entity_id);
              
              
              Severity: Minor
              Found in maloja/web/static/js/edit.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

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

                          callback_func = function(req){
                              if (req.status == 200) {
              
                                  toggleAssociationIcons(parentElement);
                                  notifyCallback(req);
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 3 hrs to fix
              maloja/web/static/js/edit.js on lines 469..483

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

              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

                          callback_func = function(req){
                              if (req.status == 200) {
              
                                  toggleAssociationIcons(parentElement);
                                  notifyCallback(req);
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 3 hrs to fix
              maloja/web/static/js/edit.js on lines 422..436

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

              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

              function cancelAssociate(element) {
                  const parentElement = element.closest('[data-entity_id]');
              
                  var entity_type = parentElement.dataset.entity_type;
              
              
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 2 hrs to fix
              maloja/web/static/js/edit.js on lines 503..512

              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

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

              function cancelMerge(element) {
                  const parentElement = element.closest('[data-entity_id]');
              
                  var entity_type = parentElement.dataset.entity_type;
              
              
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 2 hrs to fix
              maloja/web/static/js/edit.js on lines 513..522

              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

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

              function toggleDeleteConfirm(element) {
                  element.parentElement.parentElement.classList.toggle('active');
                  element.parentElement.parentElement.parentElement.classList.toggle('active');
              }
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 1 hr to fix
              maloja/web/static/js/edit.js on lines 35..38

              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

              function toggleReparseConfirm(element) {
                  element.parentElement.parentElement.classList.toggle('active');
                  element.parentElement.parentElement.parentElement.classList.toggle('active');
              }
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 1 hr to fix
              maloja/web/static/js/edit.js on lines 14..17

              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

                  if (current_stored.indexOf(entity_id) > -1) {
                      element.classList.add('marked_for_associate');
                  } else {
                      element.classList.remove('marked_for_associate');
                  }
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 1 hr to fix
              maloja/web/static/js/edit.js on lines 349..353

              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

                  if (current_stored.indexOf(entity_id) > -1) {
                      element.classList.add('marked_for_merge');
                  } else {
                      element.classList.remove('marked_for_merge');
                  }
              Severity: Major
              Found in maloja/web/static/js/edit.js and 1 other location - About 1 hr to fix
              maloja/web/static/js/edit.js on lines 313..317

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

                  if (current_stored.length > 0) {
                      element.classList.add('somethingmarked_for_associate');
                  }
                  else {
                      element.classList.remove('somethingmarked_for_associate');
              Severity: Major
              Found in maloja/web/static/js/edit.js and 2 other locations - About 40 mins to fix
              maloja/web/static/js/edit.js on lines 332..337
              maloja/web/static/js/edit.js on lines 356..361

              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

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

                  if (current_stored.length > 0) {
                      element.classList.add('somethingmarked_for_merge');
                  }
                  else {
                      element.classList.remove('somethingmarked_for_merge');
              Severity: Major
              Found in maloja/web/static/js/edit.js and 2 other locations - About 40 mins to fix
              maloja/web/static/js/edit.js on lines 319..324
              maloja/web/static/js/edit.js on lines 332..337

              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

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

                  if (sourcelist.length > 0) {
                      element.classList.add('sources_marked_for_associate');
                  }
                  else {
                      element.classList.remove('sources_marked_for_associate');
              Severity: Major
              Found in maloja/web/static/js/edit.js and 2 other locations - About 40 mins to fix
              maloja/web/static/js/edit.js on lines 319..324
              maloja/web/static/js/edit.js on lines 356..361

              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