<commit_before>'use strict';

define(['angular', 'jquery'], function(angular, $) {

    var app = angular.module('my-app.layout.controllers', []);

    app.controller('DefaultViewController', [
      '$scope',
      '$location',
      '$localStorage',
      '$sessionStorage',
      'APP_FLAGS',
      function($scope, $location, $localStorage, $sessionStorage, APP_FLAGS){
        $scope.loading = [];
        if(!APP_FLAGS[$localStorage.layoutMode]) {
          //layout mode set weird, reset to default
          $localStorage.layoutMode = APP_FLAGS.defaultView;
        }
        $location.path('/' + $localStorage.layoutMode);
    }]);

    app.controller('LayoutController', [
        '$location',
        '$localStorage',
        '$sessionStorage',
        '$scope',
        '$rootScope',
        'layoutService',
        'miscService',
        'sharedPortletService',
        '$mdToast',
        function($location,
                 $localStorage,
                 $sessionStorage,
                 $scope,
                 $rootScope,
                 layoutService,
                 miscService,
                 sharedPortletService,
                 $mdToast) {
            this.portletType = function portletType(portlet) {
                if (portlet.staticContent != null
                    && portlet.altMaxUrl == false) {
                    return "SIMPLE";
                } else if(portlet.altMaxUrl == false && (portlet.renderOnWeb || $localStorage.webPortletRender)){
                    return "EXCLUSIVE";
                } else {
                    return "NORMAL";
                }
            };

            this.maxStaticPortlet = function gotoMaxStaticPortlet(portlet) {
                sharedPortletService.setProperty(portlet);
                $location.path('/static/'+portlet.fname);
            };

            this.directToPortlet = function directToPortlet(url) {
                $location.path(url);
            };
            this.removePortlet = function removePortletFunction(nodeId, title) {
                layoutService.removeFromHome(nodeId, title).success(function(){
                    $scope.$apply(function(request, text){
                        var result = $.grep($scope.layout, function(e) { return e.nodeId === nodeId});
                        var index = $.inArray(result[0], $scope.layout);
                        //remove
                        $scope.layout.splice(index,1);
                        $mdToast.show($mdToast.simple().textContent(title + " removed.").hideDelay(3000));
                        if($sessionStorage.marketplace != null) {
                            var marketplaceEntries = $.grep($sessionStorage.marketplace, function(e) { return e.fname === result[0].fname});
                            if(marketplaceEntries.length > 0) {
                                marketplaceEntries[0].hasInLayout = false;
                            }
                        }
                    });
                }).error(
                function(request, text, error){
                    alert('Issue deleting ' + title + ' from your list of favorites, try again later.');
                });
            };

            $scope.sortableOptions = {
                delay:250,
                cursorAt : {top: 30, left: 30},
                stop: function(e, ui) {
                    if(ui.item.sortable.dropindex != ui.item.sortable.index) {

                        var node = $scope.layout[ui.item.sortable.dropindex];
                        console.log("Change happened, logging move of " + node.fname + " from " + ui.item.sortable.index + " to " + ui.item.sortable.dropindex);
                        //index, length, movingNodeId, previousNodeId, nextNodeId
                        var prevNodeId = ui.item.sortable.dropindex != 0 ? $scope.layout[ui.item.sortable.dropindex - 1].nodeId : "";
                        var nextNodeId = ui.item.sortable.dropindex != $scope.layout.length - 1 ? $scope.layout[ui.item.sortable.dropindex + 1].nodeId : "";
                        layoutService.moveStuff(ui.item.sortable.dropindex, $scope.layout.length, node.nodeId, prevNodeId, nextNodeId);

                    }
                }
            };

            this.init = function(){
              if(typeof $rootScope.layout === 'undefined' || $rootScope.layout == null) {

                  $rootScope.layout = [];
                  $scope.layoutEmpty = false;

                  layoutService.getLayout().then(function(data){
                      $rootScope.layout = data.layout;
                      if(data.layout && data.layout.length == 0) {
                          $scope.layoutEmpty = true;
                      }
                  });
              }
            };

            this.init();

        }]);

   app.controller('BaseWidgetFunctionsController', [
     '$scope',
     '$location',
     '$sessionStorage',
     '$localStorage',
     '$mdToast',
     'sharedPortletService',
     'layoutService',
     'childController',
     function($scope,
              $location,
              $sessionStorage,
              $localStorage,
              $mdToast,
              sharedPortletService,
              layoutService,
              childController) {
       childController.portletType = function portletType(portlet) {
           if (portlet.widgetType) {
               if('option-link' === portlet.widgetType) {
                   return "OPTION_LINK";
               } else if('weather' === portlet.widgetType) {
                   return "WEATHER";
               } else if('generic' === portlet.widgetType) {
                   return "GENERIC";
               } else if('rss' === portlet.widgetType) {
                   return "RSS";
               } else if('list-of-links' === portlet.widgetType) {
                   return "LOL";
               } else if ('search-with-links' === portlet.widgetType) {
                   return "SWL";
               } else {
                   return "WIDGET";
               }

           }else if(portlet.pithyStaticContent != null) {
               return "PITHY";
           } else if (portlet.staticContent != null
               && portlet.altMaxUrl == false) {
               return "SIMPLE";
           } else {
               return "NORMAL";
           }
       };

       childController.renderURL = function renderURL(portlet) {
         if(portlet.altMaxUrl == false && (portlet.renderOnWeb || $localStorage.webPortletRender)) {
           return 'exclusive/' + portlet.fname;
         } else {
           return portlet.url;
         }
       }

       childController.maxStaticPortlet = function gotoMaxStaticPortlet(portlet) {
           sharedPortletService.setProperty(portlet);
           $location.path('/static/'+portlet.fname);
       };

       childController.directToPortlet = function directToPortlet(url) {
           $location.path(url);
       };
       childController.removePortlet = function removePortletFunction(nodeId, title) {
           layoutService.removeFromHome(nodeId, title).success(function(){
               $scope.$apply(function(request, text){
                   var result = $.grep($scope.layout, function(e) { return e.nodeId === nodeId});
                   var index = $.inArray(result[0], $scope.layout);
                   //remove
                   $scope.layout.splice(index,1);
                   $mdToast.show($mdToast.simple().textContent(title + " removed.").hideDelay(3000));
                   if($sessionStorage.marketplace != null) {
                       var marketplaceEntries = $.grep($sessionStorage.marketplace, function(e) { return e.fname === result[0].fname});
                       if(marketplaceEntries.length > 0) {
                           marketplaceEntries[0].hasInLayout = false;
                       }
                   }
               });
           }).error(
           function(request, text, error){
               alert('Issue deleting ' + title + ' from your list of favorites, try again later.');
           });
       };
     }
   ]);<commit_msg>List-of-links with only one link should fall back to normal widget display<commit_after>'use strict';

define(['angular', 'jquery'], function(angular, $) {

    var app = angular.module('my-app.layout.controllers', []);

    app.controller('DefaultViewController', [
      '$scope',
      '$location',
      '$localStorage',
      '$sessionStorage',
      'APP_FLAGS',
      function($scope, $location, $localStorage, $sessionStorage, APP_FLAGS){
        $scope.loading = [];
        if(!APP_FLAGS[$localStorage.layoutMode]) {
          //layout mode set weird, reset to default
          $localStorage.layoutMode = APP_FLAGS.defaultView;
        }
        $location.path('/' + $localStorage.layoutMode);
    }]);

    app.controller('LayoutController', [
        '$location',
        '$localStorage',
        '$sessionStorage',
        '$scope',
        '$rootScope',
        'layoutService',
        'miscService',
        'sharedPortletService',
        '$mdToast',
        function($location,
                 $localStorage,
                 $sessionStorage,
                 $scope,
                 $rootScope,
                 layoutService,
                 miscService,
                 sharedPortletService,
                 $mdToast) {
            this.portletType = function portletType(portlet) {
                if (portlet.staticContent != null
                    && portlet.altMaxUrl == false) {
                    return "SIMPLE";
                } else if(portlet.altMaxUrl == false && (portlet.renderOnWeb || $localStorage.webPortletRender)){
                    return "EXCLUSIVE";
                } else {
                    return "NORMAL";
                }
            };

            this.maxStaticPortlet = function gotoMaxStaticPortlet(portlet) {
                sharedPortletService.setProperty(portlet);
                $location.path('/static/'+portlet.fname);
            };

            this.directToPortlet = function directToPortlet(url) {
                $location.path(url);
            };
            this.removePortlet = function removePortletFunction(nodeId, title) {
                layoutService.removeFromHome(nodeId, title).success(function(){
                    $scope.$apply(function(request, text){
                        var result = $.grep($scope.layout, function(e) { return e.nodeId === nodeId});
                        var index = $.inArray(result[0], $scope.layout);
                        //remove
                        $scope.layout.splice(index,1);
                        $mdToast.show($mdToast.simple().textContent(title + " removed.").hideDelay(3000));
                        if($sessionStorage.marketplace != null) {
                            var marketplaceEntries = $.grep($sessionStorage.marketplace, function(e) { return e.fname === result[0].fname});
                            if(marketplaceEntries.length > 0) {
                                marketplaceEntries[0].hasInLayout = false;
                            }
                        }
                    });
                }).error(
                function(request, text, error){
                    alert('Issue deleting ' + title + ' from your list of favorites, try again later.');
                });
            };

            $scope.sortableOptions = {
                delay:250,
                cursorAt : {top: 30, left: 30},
                stop: function(e, ui) {
                    if(ui.item.sortable.dropindex != ui.item.sortable.index) {

                        var node = $scope.layout[ui.item.sortable.dropindex];
                        console.log("Change happened, logging move of " + node.fname + " from " + ui.item.sortable.index + " to " + ui.item.sortable.dropindex);
                        //index, length, movingNodeId, previousNodeId, nextNodeId
                        var prevNodeId = ui.item.sortable.dropindex != 0 ? $scope.layout[ui.item.sortable.dropindex - 1].nodeId : "";
                        var nextNodeId = ui.item.sortable.dropindex != $scope.layout.length - 1 ? $scope.layout[ui.item.sortable.dropindex + 1].nodeId : "";
                        layoutService.moveStuff(ui.item.sortable.dropindex, $scope.layout.length, node.nodeId, prevNodeId, nextNodeId);

                    }
                }
            };

            this.init = function(){
              if(typeof $rootScope.layout === 'undefined' || $rootScope.layout == null) {

                  $rootScope.layout = [];
                  $scope.layoutEmpty = false;

                  layoutService.getLayout().then(function(data){
                      $rootScope.layout = data.layout;
                      if(data.layout && data.layout.length == 0) {
                          $scope.layoutEmpty = true;
                      }
                  });
              }
            };

            this.init();

        }]);

   app.controller('BaseWidgetFunctionsController', [
     '$scope',
     '$location',
     '$sessionStorage',
     '$localStorage',
     '$mdToast',
     'sharedPortletService',
     'layoutService',
     'childController',
     function($scope,
              $location,
              $sessionStorage,
              $localStorage,
              $mdToast,
              sharedPortletService,
              layoutService,
              childController) {
       childController.portletType = function portletType(portlet) {
           if (portlet.widgetType) {
               if('option-link' === portlet.widgetType) {
                   return "OPTION_LINK";
               } else if('weather' === portlet.widgetType) {
                   return "WEATHER";
               } else if('generic' === portlet.widgetType) {
                   return "GENERIC";
               } else if('rss' === portlet.widgetType) {
                   return "RSS";
               } else if('list-of-links' === portlet.widgetType) {
				   if (portlet.widgetConfig.links.length != 1) {
					   return "LOL";
				   } else if (portlet.widgetConfig.links.length === 1 && portlet.altMaxUrl) {
					   // If list of links has only one link and if it is the same as the portlet URL, display the
					   // normal portlet view
					   if (portlet.widgetConfig.links[0].href === portlet.url) {
						   return "NORMAL";
					   }
				   }
               } else if ('search-with-links' === portlet.widgetType) {
                   return "SWL";
               } else {
                   return "WIDGET";
               }
           }else if(portlet.pithyStaticContent != null) {
               return "PITHY";
           } else if (portlet.staticContent != null
               && portlet.altMaxUrl == false) {
               return "SIMPLE";
           } else {
               return "NORMAL";
           }
       };

       childController.renderURL = function renderURL(portlet) {
         if(portlet.altMaxUrl == false && (portlet.renderOnWeb || $localStorage.webPortletRender)) {
           return 'exclusive/' + portlet.fname;
         } else {
           return portlet.url;
         }
       };

       childController.maxStaticPortlet = function gotoMaxStaticPortlet(portlet) {
           sharedPortletService.setProperty(portlet);
           $location.path('/static/'+portlet.fname);
       };

       childController.directToPortlet = function directToPortlet(url) {
           $location.path(url);
       };
       childController.removePortlet = function removePortletFunction(nodeId, title) {
           layoutService.removeFromHome(nodeId, title).success(function(){
               $scope.$apply(function(request, text){
                   var result = $.grep($scope.layout, function(e) { return e.nodeId === nodeId});
                   var index = $.inArray(result[0], $scope.layout);
                   //remove
                   $scope.layout.splice(index,1);
                   $mdToast.show($mdToast.simple().textContent(title + " removed.").hideDelay(3000));
                   if($sessionStorage.marketplace != null) {
                       var marketplaceEntries = $.grep($sessionStorage.marketplace, function(e) { return e.fname === result[0].fname});
                       if(marketplaceEntries.length > 0) {
                           marketplaceEntries[0].hasInLayout = false;
                       }
                   }
               });
           }).error(
           function(request, text, error){
               alert('Issue deleting ' + title + ' from your list of favorites, try again later.');
           });
       };
     }
   ]);
{'fraction_non_alphanumeric': 0.12172656673288784, 'fraction_numerical': 0.0037926675094816687, 'mean_word_length': 1.5120217752910934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3522744', 'n_tokens_mistral': 4368, 'n_tokens_neox': 4109, 'n_words': 731}