LibreCat/LibreCat

View on GitHub

Showing 18 of 41 total issues

File librecat.js has 711 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 *
 * handling mark/unmark
 *
 */
Severity: Major
Found in public/javascripts/librecat.js - About 1 day to fix

    Function link_person has 213 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function link_person(element){
        var type = "";
        type = $(element).attr('data-type');
        var lineId = $(element).attr('id').replace(type + 'link_person_','');
    
    
    Severity: Major
    Found in public/javascripts/librecat.js - About 1 day to fix

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

              init: function() {
                  $('.dz-default.dz-message').addClass('col-md-11');
                  this.on("uploadprogress", function(file,progress,bytesSent){
                      $('html').css({ cursor: "wait" });
                      if (file['accepted'] === true) {
      Severity: Major
      Found in public/javascripts/librecat_dropzones.js - About 3 hrs to fix

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

        function add_field(name, placeholder){
                var items = $('#' + name + ' div.row.multirow');
                var index = items.index($('#' + name + ' div.row.multirow').last()) + 1;
                var blueprint = $(items[0]).clone();
                //var corrected_index = index;
        Severity: Major
        Found in public/javascripts/librecat.js - About 2 hrs to fix

          Function link_person has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

          function link_person(element){
              var type = "";
              type = $(element).attr('data-type');
              var lineId = $(element).attr('id').replace(type + 'link_person_','');
          
          
          Severity: Minor
          Found in public/javascripts/librecat.js - About 2 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 edit_file has 54 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function edit_file(fileId){
                  var json = jQuery.parseJSON($('#file_' + fileId).val());
                  if(json.file_id){
                          $('#id_file_id').val(json.file_id);
                  }
          Severity: Major
          Found in public/javascripts/librecat.js - About 2 hrs to fix

            Consider simplifying this complex logical expression.
            Open

                                else if( (old_name.find(o => o.first_name && o.first_name.toLowerCase() === firstname) && lastname == "") || (old_name.find(o => o.last_name && o.last_name.toLowerCase() === lastname) && firstname == "") || (old_name.find(o => o.last_name && o.last_name.toLowerCase() === lastname) && old_name.find(o => o.first_name && o.first_name.toLowerCase() === firstname)) ){
                                    rows += '<tr data-id="' + personId + '" data-orcid="' + orcid + '"><td><a href="' + librecat.uri_base + '/staffdirectory/' + personId + '" target="_blank">' + personId + '</a></td><td class="name" data-firstname="' + first_name + '" data-lastname="' + last_name + '"><a href="#" class="person_link">' + first_name + " " + last_name + '</a></td></tr>';
                                    if(old_name[0]){
                                        for(var j=0;j<old_name.length;j++){
                                            var old_firstname = first_name;
            Severity: Critical
            Found in public/javascripts/librecat.js - About 2 hrs to fix

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

              function edit_file(fileId){
                      var json = jQuery.parseJSON($('#file_' + fileId).val());
                      if(json.file_id){
                              $('#id_file_id').val(json.file_id);
                      }
              Severity: Minor
              Found in public/javascripts/librecat.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 init has 44 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      init: function(){
                          $('.dz-default.dz-message').addClass('qae');
                          this.on("addedfile", function(file) {
                              var fileName = Dropzone.createElement("<div class=\"row\"><div class=\"progress progress-striped active\"><div class=\"progress-bar\" id=\"" + htmlEscape(file.name) + "_progress\" style=\"width:0;text-align:left;padding-left:10px;\">" + file.name + "</span></div></div></div>");
                              file.previewElement.appendChild(fileName);
              Severity: Minor
              Found in public/javascripts/librecat_dropzones.js - About 1 hr to fix

                Function remove_field has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function remove_field(object){
                        var container = $(object).closest('div.multirow');
                        var index = $(container).index();
                        var total = $(container).parent().children('div.multirow').size();
                
                
                Severity: Minor
                Found in public/javascripts/librecat.js - About 1 hr to fix

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

                  function enable_autocomplete(field, index) {
                      var type;
                      switch(field) {
                          case "pj":
                              type = "project"
                  Severity: Minor
                  Found in public/javascripts/librecat.js - About 1 hr to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if(key == "last_name"){
                                                last_name = value;
                                            }
                    Severity: Major
                    Found in public/javascripts/librecat.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if(key == "first_name"){
                                                  first_name = value;
                                              }
                      Severity: Major
                      Found in public/javascripts/librecat.js - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if(key == "orcid"){
                                                    orcid = value;
                                                }
                        Severity: Major
                        Found in public/javascripts/librecat.js - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                              if((firstname == first_name.toLowerCase() && lastname == "") || (lastname == last_name.toLowerCase() && firstname == "") || (lastname == last_name.toLowerCase() && firstname == first_name.toLowerCase())){
                                                  rows += '<tr data-id="' + personId + '" data-orcid="' + orcid + '"><td><a href="' + librecat.uri_base + '/staffdirectory/' + personId + '" target="_blank">' + personId + '</a></td><td class="name" data-firstname="' + first_name + '" data-lastname="' + last_name + '"><a href="#" class="person_link">' + first_name + " " + last_name + '</a></td></tr>';
                                                  if(old_name[0]){
                                                      for(var j=0;j<old_name.length;j++){
                                                          var old_firstname = first_name;
                          Severity: Major
                          Found in public/javascripts/librecat.js - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                    if(key == "old_name"){
                                                        old_name = value;
                                                    }
                            Severity: Major
                            Found in public/javascripts/librecat.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                      if(key == "_id"){
                                                          personId = value;
                                                      }
                              Severity: Major
                              Found in public/javascripts/librecat.js - About 45 mins to fix

                                Consider simplifying this complex logical expression.
                                Open

                                                    if((firstname == first_name.toLowerCase() && lastname == "") || (lastname == last_name.toLowerCase() && firstname == "") || (lastname == last_name.toLowerCase() && firstname == first_name.toLowerCase())){
                                                        rows += '<tr data-id="' + personId + '" data-orcid="' + orcid + '"><td><a href="' + librecat.uri_base + '/staffdirectory/' + personId + '" target="_blank">' + personId + '</a></td><td class="name" data-firstname="' + first_name + '" data-lastname="' + last_name + '"><a href="#" class="person_link">' + first_name + " " + last_name + '</a></td></tr>';
                                                        if(old_name[0]){
                                                            for(var j=0;j<old_name.length;j++){
                                                                var old_firstname = first_name;
                                Severity: Major
                                Found in public/javascripts/librecat.js - About 40 mins to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language