archivesspace/archivesspace

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

Summary

Maintainability
F
1 wk
Test Coverage

Function linker has 517 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  $.fn.linker = function () {
    $(this).each(function () {
      var $this = $(this);
      var $linkerWrapper = $this.parents('.linker-wrapper:first');

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

    File linker.js has 542 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    //= require jquery.tokeninput
    
    $(function () {
      let resource_edit_path_regex = new RegExp(
        '^' + APP_PATH + 'resources/\\d+/edit$'
    Severity: Major
    Found in frontend/app/assets/javascripts/linker.js - About 1 day to fix

      Function initAndShowLinkerBrowseModal has 128 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            var initAndShowLinkerBrowseModal = function () {
              var currentlySelected = {};
      
              var renderItemsInModal = function (page) {
                $.each($this.tokenInput('get'), function () {
      Severity: Major
      Found in frontend/app/assets/javascripts/linker.js - About 5 hrs to fix

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

              var init = function () {
                var tokenInputConfig = $.extend({}, AS.linker_locales, {
                  animateDropdown: false,
                  preventDuplicates: true,
                  allowFreeTagging: false,
        Severity: Major
        Found in frontend/app/assets/javascripts/linker.js - About 4 hrs to fix

          Function renderItemsInModal has 91 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  var renderItemsInModal = function (page) {
                    $.each($this.tokenInput('get'), function () {
                      currentlySelected[this.id] = this.json;
                    });
          
          
          Severity: Major
          Found in frontend/app/assets/javascripts/linker.js - About 3 hrs to fix

            Function success has 74 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        success: function (html) {
                          var $modal = $('#' + config.modal_id);
            
                          var $linkerBrowseContainer = $('.linker-container', $modal);
            
            
            Severity: Major
            Found in frontend/app/assets/javascripts/linker.js - About 2 hrs to fix

              Function tokensForPrepopulation has 67 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    var tokensForPrepopulation = function () {
                      if ($this.data('multiplicity') === 'one') {
                        // If we are on a resource or archival object edit page, and open a top_container modal with a
                        // collection_resource linker then we prepopulate the collection_resource field with resource
                        // data necessary to perform the search
              Severity: Major
              Found in frontend/app/assets/javascripts/linker.js - About 2 hrs to fix

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

                      var renderCreateFormForObject = function (form_uri) {
                        var $modal = $('#' + config.modal_id);
                
                        var initCreateForm = function (formEl) {
                          $('.linker-container', $modal).html(formEl);
                Severity: Minor
                Found in frontend/app/assets/javascripts/linker.js - About 1 hr to fix

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

                                var initBrowseFormInputs = function () {
                                  // add some click handlers to allow clicking of the row
                                  $(':input[name=linker-item]', $linkerBrowseContainer).each(
                                    function () {
                                      var $input = $(this);
                  Severity: Minor
                  Found in frontend/app/assets/javascripts/linker.js - About 1 hr to fix

                    Function initCreateForm has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            var initCreateForm = function (formEl) {
                              $('.linker-container', $modal).html(formEl);
                              $('#createAndLinkButton', $modal).removeAttr('disabled');
                              $('form', $modal).ajaxForm({
                                data: {
                    Severity: Minor
                    Found in frontend/app/assets/javascripts/linker.js - About 1 hr to fix

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

                            var tag_subjects_by_term_type = function (obj) {
                              if (obj.json.jsonmodel_type == 'subject') {
                                switch (obj.json.first_term_type) {
                                  case 'cultural_context':
                                    return 'subject_type_cultural_context';
                      Severity: Minor
                      Found in frontend/app/assets/javascripts/linker.js - About 1 hr to fix

                        Consider simplifying this complex logical expression.
                        Open

                                  if (
                                    on_resource_edit_path &&
                                    modalHasResource &&
                                    resultsEmpty &&
                                    isLastLinker &&
                        Severity: Major
                        Found in frontend/app/assets/javascripts/linker.js - About 40 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                    return $this.data('selected').map(function (item) {
                                      if (typeof item == 'string') {
                                        item = JSON.parse(item);
                                      }
                                      return {
                          Severity: Major
                          Found in frontend/app/assets/javascripts/linker.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return [];
                            Severity: Major
                            Found in frontend/app/assets/javascripts/linker.js - About 30 mins to fix

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

                                                  $('td', $input.closest('tr')).click(function (event) {
                                                    event.preventDefault();
                              
                                                    $input.trigger('click');
                                                  });
                              Severity: Minor
                              Found in frontend/app/assets/javascripts/linker.js and 1 other location - About 50 mins to fix
                              frontend/app/assets/javascripts/space_calculator.js on lines 216..220

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

                              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