fossasia/loklak_webclient

View on GitHub
app/js/components/select.js

Summary

Maintainability
F
1 wk
Test Coverage

File select.js has 1348 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * ui-select
 * http://github.com/angular-ui/ui-select
 * Version: 0.12.1 - 2015-07-28T03:50:59.076Z
 * License: MIT
Severity: Major
Found in app/js/components/select.js - About 3 days to fix

    Function link has 262 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        link: function(scope, element, attrs, ctrls) {
    
          var $select = ctrls[0];
          var ngModel = scope.ngModel = ctrls[1];
          var $selectMultiple = scope.$selectMultiple;
    Severity: Major
    Found in app/js/components/select.js - About 1 day to fix

      Function compile has 193 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          compile: function(tElement, tAttrs) {
      
            //Multiple or Single depending if multiple attribute presence
            if (angular.isDefined(tAttrs.multiple))
              tElement.append("<ui-select-multiple/>").removeAttr('multiple');
      Severity: Major
      Found in app/js/components/select.js - About 7 hrs to fix

        Function link has 100 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            link: function(scope, element, attrs, $select) {
              if (scope[attrs.uiSelectSort] === null) {
                throw uiSelectMinErr('sort', "Expected a list to sort");
              }
        
        
        Severity: Major
        Found in app/js/components/select.js - About 4 hrs to fix

          Function link has 89 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              link: function(scope, element, attrs, ctrls) {
          
                var $select = ctrls[0];
                var ngModel = ctrls[1];
          
          
          Severity: Major
          Found in app/js/components/select.js - About 3 hrs to fix

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

              ctrl.parseRepeatAttr = function(repeatAttr, groupByExp, groupFilterExp) {
                function updateGroups(items) {
                  var groupFn = $scope.$eval(groupByExp);
                  ctrl.groups = [];
                  angular.forEach(items, function(item) {
            Severity: Major
            Found in app/js/components/select.js - About 2 hrs to fix

              Function select has 46 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                ctrl.select = function(item, skipFocusser, $event) {
                  if (item === undefined || !item._uiSelectChoiceDisabled) {
              
                    if ( ! ctrl.items && ! ctrl.search ) return;
              
              
              Severity: Minor
              Found in app/js/components/select.js - About 1 hr to fix

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

                      function _handleMatchSelection(key){
                        var caretPosition = _getCaretPosition($select.searchInput[0]),
                            length = $select.selected.length,
                            // none  = -1,
                            first = 0,
                Severity: Minor
                Found in app/js/components/select.js - About 1 hr to fix

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

                      compile: function(tElement, tAttrs) {
                  
                        if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
                  
                        return function link(scope, element, attrs, $select, transcludeFn) {
                  Severity: Minor
                  Found in app/js/components/select.js - About 1 hr to fix

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

                        controller: ['$scope','$timeout', function($scope, $timeout){
                    
                          var ctrl = this,
                              $select = $scope.$select,
                              ngModel;
                    Severity: Minor
                    Found in app/js/components/select.js - About 1 hr to fix

                      Function link has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            return function link(scope, element, attrs, $select, transcludeFn) {
                      
                              // var repeat = RepeatParser.parse(attrs.repeat);
                              var groupByExp = attrs.groupBy;
                              var groupFilterExp = attrs.groupFilter;
                      Severity: Minor
                      Found in app/js/components/select.js - About 1 hr to fix

                        Function _dropHandler has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                              var _dropHandler = function(droppedItemIndex) {
                                var theList = scope.$eval(attrs.uiSelectSort),
                                  itemToMove = theList[droppedItemIndex],
                                  newIndex = null;
                        
                        
                        Severity: Minor
                        Found in app/js/components/select.js - About 1 hr to fix

                          Function _handleDropDownSelection has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            function _handleDropDownSelection(key) {
                              var processed = true;
                              switch (key) {
                                case KEY.DOWN:
                                  if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
                          Severity: Minor
                          Found in app/js/components/select.js - About 1 hr to fix

                            Function getNewActiveMatchIndex has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                    function getNewActiveMatchIndex(){
                                      switch(key){
                                        case KEY.LEFT:
                                          // Select previous/first item
                                          if(~$selectMultiple.activeMatchIndex) return prev;
                            Severity: Minor
                            Found in app/js/components/select.js - About 1 hr to fix

                              Avoid deeply nested control flow statements.
                              Open

                                          if ( ctrl.activeIndex === 0 ) {
                                            // ctrl.tagging pushes items to ctrl.items, so we only have empty val
                                            // for `item` if it is a detected duplicate
                                            if ( item === undefined ) return;
                              
                              
                              Severity: Major
                              Found in app/js/components/select.js - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                              if ( ctrl.search.length > 0 ) {
                                                tagged = true;
                                              }
                                Severity: Major
                                Found in app/js/components/select.js - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                              if ( ctrl.activeIndex < 0 ) {
                                                item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
                                                if (!item || angular.equals( ctrl.items[0], item ) ) {
                                                  return;
                                                }
                                  Severity: Major
                                  Found in app/js/components/select.js - About 45 mins to fix

                                    Consider simplifying this complex logical expression.
                                    Open

                                            if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
                                              return;
                                            }
                                    Severity: Major
                                    Found in app/js/components/select.js - About 40 mins to fix

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

                                          link: function (scope, element, attrs, ctrl, transclude) {
                                      Severity: Minor
                                      Found in app/js/components/select.js - About 35 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                        return prev;
                                        Severity: Major
                                        Found in app/js/components/select.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                        else return false;
                                          Severity: Major
                                          Found in app/js/components/select.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                        return;
                                            Severity: Major
                                            Found in app/js/components/select.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                            else return last;
                                              Severity: Major
                                              Found in app/js/components/select.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                                return curr;
                                                Severity: Major
                                                Found in app/js/components/select.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                                return;
                                                  Severity: Major
                                                  Found in app/js/components/select.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                                  return;
                                                    Severity: Major
                                                    Found in app/js/components/select.js - About 30 mins to fix

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

                                                              scope.$watch('searchEnabled', function() {
                                                                  var searchEnabled = scope.$eval(attrs.searchEnabled);
                                                                  $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled;
                                                              });
                                                      Severity: Major
                                                      Found in app/js/components/select.js and 1 other location - About 1 hr to fix
                                                      app/js/components/select.js on lines 825..828

                                                      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 (e.which == KEY.DOWN  || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){
                                                      Severity: Major
                                                      Found in app/js/components/select.js and 1 other location - About 1 hr to fix
                                                      app/js/components/leaflet.js on lines 775..775

                                                      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

                                                              scope.$watch('sortable', function() {
                                                                  var sortable = scope.$eval(attrs.sortable);
                                                                  $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable;
                                                              });
                                                      Severity: Major
                                                      Found in app/js/components/select.js and 1 other location - About 1 hr to fix
                                                      app/js/components/select.js on lines 820..823

                                                      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

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

                                                                if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) {
                                                      Severity: Minor
                                                      Found in app/js/components/select.js and 1 other location - About 55 mins to fix
                                                      app/js/components/select.js on lines 1601..1601

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

                                                      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 (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
                                                      Severity: Minor
                                                      Found in app/js/components/select.js and 1 other location - About 55 mins to fix
                                                      app/js/components/select.js on lines 1352..1352

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

                                                      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 ( items.length > 0 && tagItem ) {
                                                                    hasTag = true;
                                                                    items = items.slice(1,items.length);
                                                                    stashArr = stashArr.slice(1,stashArr.length);
                                                                  }
                                                      Severity: Minor
                                                      Found in app/js/components/select.js and 1 other location - About 50 mins to fix
                                                      app/js/components/select.js on lines 1399..1403

                                                      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

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

                                                                  if ( item !== undefined && items.length > 0 && tagItem ) {
                                                                    hasTag = true;
                                                                    items = items.slice(1,items.length);
                                                                    stashArr = stashArr.slice(1,stashArr.length);
                                                                  }
                                                      Severity: Minor
                                                      Found in app/js/components/select.js and 1 other location - About 50 mins to fix
                                                      app/js/components/select.js on lines 1376..1380

                                                      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

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

                                                              $timeout(function(){
                                                                ctrl.onSelectCallback($scope, {
                                                                  $item: item,
                                                                  $model: ctrl.parserResult.modelMapper($scope, locals)
                                                                });
                                                      Severity: Minor
                                                      Found in app/js/components/select.js and 1 other location - About 35 mins to fix
                                                      app/js/components/select.js on lines 1135..1140

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

                                                      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

                                                              $timeout(function(){
                                                                $select.onRemoveCallback($scope, {
                                                                  $item: removedChoice,
                                                                  $model: $select.parserResult.modelMapper($scope, locals)
                                                                });
                                                      Severity: Minor
                                                      Found in app/js/components/select.js and 1 other location - About 35 mins to fix
                                                      app/js/components/select.js on lines 529..534

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

                                                      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