archivesspace/archivesspace

View on GitHub
frontend/app/assets/javascripts/utils.js

Summary

Maintainability
F
6 days
Test Coverage

File utils.js has 864 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//= require trimpath-template-1.0.38
//= require bootstrap-datepicker
//= require bootstrap-combobox
//= require bootstrap-tagsinput

Severity: Major
Found in frontend/app/assets/javascripts/utils.js - About 2 days to fix

    Function initAddAsYouGoActions has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    AS.initAddAsYouGoActions = function ($form, $list) {
      if ($form.data('cardinality') === 'zero_to_one') {
        // nothing to do here
        return;
      }
    Severity: Major
    Found in frontend/app/assets/javascripts/utils.js - About 2 hrs to fix

      Function initTooltips has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        var initTooltips = function (scope) {
          scope = scope || $(document.body);
          $('.has-tooltip:not(.initialised)', scope).each(function () {
            var $this = $(this);
      
      
      Severity: Major
      Found in frontend/app/assets/javascripts/utils.js - About 2 hrs to fix

        Function initConfirmationAction has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          $.fn.initConfirmationAction = function () {
            $(this).each(function () {
              var $this = $(this);
        
              if ($this.hasClass('initialised')) {
        Severity: Major
        Found in frontend/app/assets/javascripts/utils.js - About 2 hrs to fix

          Function openCustomModal has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          AS.openCustomModal = function (
            id,
            title,
            contents,
            modalSize,
          Severity: Major
          Found in frontend/app/assets/javascripts/utils.js - About 2 hrs to fix

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

                  var onClick = function (event) {
                    event.preventDefault();
                    event.stopImmediatePropagation();
            
                    AS.openCustomModal(
            Severity: Minor
            Found in frontend/app/assets/javascripts/utils.js - About 1 hr to fix

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

              AS.initSubRecordSorting = function ($list) {
                var $subform = $list.closest('.subrecord-form');
                if (
                  $subform.data('cardinality') === 'zero_to_one' ||
                  $subform.data('sorting') === 'disabled'
              Severity: Minor
              Found in frontend/app/assets/javascripts/utils.js - About 1 hr to fix

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

                  var init = function () {
                    if (numberOfSubRecords() === 0) {
                      $asYouGo.hide();
                    }
                
                
                Severity: Minor
                Found in frontend/app/assets/javascripts/utils.js - About 1 hr to fix

                  Function initDateFields has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    var initDateFields = function (scope) {
                      scope = scope || $(document.body);
                      $('.date-field:not(.initialised)', scope).each(function () {
                        var $dateInput = $(this);
                  
                  
                  Severity: Minor
                  Found in frontend/app/assets/javascripts/utils.js - About 1 hr to fix

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

                    $.fn.serializeObject = function () {
                      var o = {};
                    
                      $(this).each(function () {
                        if ($(this).is('form')) {
                    Severity: Minor
                    Found in frontend/app/assets/javascripts/utils.js - About 1 hr to fix

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

                      AS.renderTemplate = function (templateId, data, cb) {
                        if (!AS.templateCache[templateId]) {
                          var templateNode = $('#' + templateId).get(0);
                          if (templateNode) {
                            var firstNode = templateNode.firstChild;
                      Severity: Minor
                      Found in frontend/app/assets/javascripts/utils.js - About 55 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 openCustomModal has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                      AS.openCustomModal = function (
                        id,
                        title,
                        contents,
                        modalSize,
                      Severity: Minor
                      Found in frontend/app/assets/javascripts/utils.js - About 55 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 openCustomModal has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        id,
                        title,
                        contents,
                        modalSize,
                        modalOpts,
                      Severity: Minor
                      Found in frontend/app/assets/javascripts/utils.js - About 45 mins to fix

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

                        AS.initAddAsYouGoActions = function ($form, $list) {
                          if ($form.data('cardinality') === 'zero_to_one') {
                            // nothing to do here
                            return;
                          }
                        Severity: Minor
                        Found in frontend/app/assets/javascripts/utils.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

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

                          var traverseMenuDown = function () {
                            var $current = $(this).find('ul li.active');
                            var $next = $current.length ? $current.next() : $(this).find('li:first');
                        
                            if ($next.length) {
                        Severity: Major
                        Found in frontend/app/assets/javascripts/utils.js and 1 other location - About 3 hrs to fix
                        frontend/app/assets/javascripts/utils.js on lines 1032..1040

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

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

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

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

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

                        Refactorings

                        Further Reading

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

                          var traverseMenuUp = function () {
                            var $current = $(this).find('ul li.active');
                            var $next = $current.length ? $current.prev() : $(this).find('li:last');
                        
                            if ($next.length) {
                        Severity: Major
                        Found in frontend/app/assets/javascripts/utils.js and 1 other location - About 3 hrs to fix
                        frontend/app/assets/javascripts/utils.js on lines 1022..1030

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

                        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

                          $(document).ready(function () {
                            $(document).bind('loadedrecordform.aspace', function (event, $container) {
                              $(
                                '.btn[data-confirmation]:not(.initialised)',
                                $container
                        Severity: Major
                        Found in frontend/app/assets/javascripts/utils.js and 2 other locations - About 1 hr to fix
                        frontend/app/assets/javascripts/subjects.crud.js on lines 26..32
                        frontend/app/assets/javascripts/utils.js on lines 973..979

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

                          $(document).ready(function () {
                            $(document).bind('loadedrecordform.aspace', function (event, $container) {
                              $('.alert', $container).initCloseAlertAction();
                            });
                        
                        
                        Severity: Major
                        Found in frontend/app/assets/javascripts/utils.js and 2 other locations - About 1 hr to fix
                        frontend/app/assets/javascripts/subjects.crud.js on lines 26..32
                        frontend/app/assets/javascripts/utils.js on lines 900..909

                        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

                              $('.has-tooltip.initialised').on('show.bs.tooltip', function () {
                                $(document).keydown(function (e) {
                                  if (e.keyCode === 27) $this.tooltip('hide');
                                });
                              });
                        Severity: Major
                        Found in frontend/app/assets/javascripts/utils.js and 1 other location - About 1 hr to fix
                        frontend/app/assets/javascripts/utils.js on lines 264..268

                        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

                              $('.has-popover.initialised').on('show.bs.popover', function () {
                                $(document).keydown(function (e) {
                                  if (e.keyCode === 27) $this.popover('hide');
                                });
                              });
                        Severity: Major
                        Found in frontend/app/assets/javascripts/utils.js and 1 other location - About 1 hr to fix
                        frontend/app/assets/javascripts/utils.js on lines 308..312

                        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

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

                                  if (!o[this.name].push) {
                                    o[this.name] = [o[this.name]];
                                  }
                        Severity: Minor
                        Found in frontend/app/assets/javascripts/utils.js and 1 other location - About 35 mins to fix
                        frontend/app/assets/javascripts/utils.js on lines 560..562

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

                        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 (!o[this.name].push) {
                                    o[this.name] = [o[this.name]];
                                  }
                        Severity: Minor
                        Found in frontend/app/assets/javascripts/utils.js and 1 other location - About 35 mins to fix
                        frontend/app/assets/javascripts/utils.js on lines 572..574

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

                        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