<commit_before>'use strict';

(function() {
  var app = angular.module('portal.main.controllers', []);

  app.controller('MainController', [ '$sessionStorage', '$rootScope', '$scope', 'mainService', 'miscService', function($sessionStorage, $rootScope, $scope, mainService, miscService) {


    miscService.pushPageview();
    $scope.layout = [];

    mainService.getLayout().then(function(data){
      $scope.layout = data.layout;
    });

    this.directToPortlet = function directToPortlet(url) {
      $location.path(url);
    }
    this.removePortlet = function removePortletFunction(nodeId, title) {
        $.ajax({
                url: "/portal/api/layout?action=removeElement&elementID=" + nodeId,
                type: "POST",
                data: null,
                dataType: "json",
                async: true,
                success: function (request, text){
                  $scope.$apply(function(){
                    var result = $.grep($scope.layout, function(e) { return e.nodeId === nodeId});
                    var index = $.inArray(result[0], $scope.layout);
                    //remove
                    $scope.layout.splice(index,1);
                    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;
                        }
                    }
                  });
                  miscService.pushGAEvent('Layout Modification', 'Remove', title);
                },
                error: function(request, text, error) {

                }
            });
      };
      
      $scope.sortableOptions = {
    		  'ui-floating': 'auto',
    		  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 : null;
        		      var nextNodeId = ui.item.sortable.dropindex != $scope.layout.length - 1 ? $scope.layout[ui.item.sortable.dropindex + 1].nodeId : null;
        		      mainService.moveStuff(ui.item.sortable.dropindex, $scope.layout.length, node.nodeId, prevNodeId, nextNodeId);
        		      
    		      }
    		  }
      };
      
      this.toggleDiv = function toggleDiv(nodeId) {
          //Toggle Make full row
          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-sm-6');
          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-md-6');
          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-lg-4');

          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-sm-12');

          //Toggle height : auto<commit_msg>MUMUP-1386 : make the placeholder card relative to mouse instead of original location<commit_after>'use strict';

(function() {
  var app = angular.module('portal.main.controllers', []);

  app.controller('MainController', [ '$sessionStorage', '$rootScope', '$scope', 'mainService', 'miscService', function($sessionStorage, $rootScope, $scope, mainService, miscService) {


    miscService.pushPageview();
    $scope.layout = [];

    mainService.getLayout().then(function(data){
      $scope.layout = data.layout;
    });

    this.directToPortlet = function directToPortlet(url) {
      $location.path(url);
    }
    this.removePortlet = function removePortletFunction(nodeId, title) {
        $.ajax({
                url: "/portal/api/layout?action=removeElement&elementID=" + nodeId,
                type: "POST",
                data: null,
                dataType: "json",
                async: true,
                success: function (request, text){
                  $scope.$apply(function(){
                    var result = $.grep($scope.layout, function(e) { return e.nodeId === nodeId});
                    var index = $.inArray(result[0], $scope.layout);
                    //remove
                    $scope.layout.splice(index,1);
                    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;
                        }
                    }
                  });
                  miscService.pushGAEvent('Layout Modification', 'Remove', title);
                },
                error: function(request, text, error) {

                }
            });
      };
      
      $scope.sortableOptions = {
              cursorAt : {top: 15, left: 15},
    		  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 : null;
        		      var nextNodeId = ui.item.sortable.dropindex != $scope.layout.length - 1 ? $scope.layout[ui.item.sortable.dropindex + 1].nodeId : null;
        		      mainService.moveStuff(ui.item.sortable.dropindex, $scope.layout.length, node.nodeId, prevNodeId, nextNodeId);
        		      
    		      }
    		  }
      };
      
      this.toggleDiv = function toggleDiv(nodeId) {
          //Toggle Make full row
          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-sm-6');
          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-md-6');
          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-lg-4');

          $('#portlet-id-' + nodeId).parent().parent('.portlet-container').toggleClass('col-sm-12');

          //Toggle height : auto
{'fraction_non_alphanumeric': 0.1470811220621683, 'fraction_numerical': 0.005458680818802123, 'mean_word_length': 1.9459580169718624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4142450', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1834, 'n_words': 303}