<commit_before>var app = angular.module('trand');
app.controller('combinationsController', combinations);
app.$inject = ['$http', '$scope', '$location', 'userService', '$sce', 'collectionsService', '$timeout', 'awsService'];

function combinations($http, $scope, $location, userService, $sce, $rootScope, collectionsService, $timeout, awsService) {
  var vm = this;
  vm.saveResult = true;
  $scope._ = _;
  $scope.posX = 0;
  $scope.posY = 0;

  var today = new Date();
  vm.timeNow = today.getTime();

  $scope.moveX = function (pixels) {
    $scope.posX = $scope.posX + pixels;
  };
  $scope.moveY = function (pixels) {
    $scope.posY = $scope.posY + pixels;
  };
  $scope.$evalAsync(function () {
    $scope.$broadcast('content.changed', 1000);
  });

  $scope.center = function () {
    $scope.posX = 600;
    $scope.posY = 410;
  };

  $scope.last = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    if ((theOne[0].index)===0) {
      theOne[0].index = theOne[0].data.length - 1 ;
    } else {
      theOne[0].index -- ;
    }
    theOne[0].imgUrl = theOne[0].data[theOne[0].index].item.image.sizes.Best.url;
  }

  $scope.next = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    if ((theOne[0].index + 1) === theOne[0].data.length) {
      theOne[0].index = 0;
    } else {
      theOne[0].index ++ ;
    }
    theOne[0].imgUrl = theOne[0].data[theOne[0].index].item.image.sizes.Best.url;
  }

  $scope.showInBox = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    theOne[0].show = !theOne[0].show;
  }

  $scope.setPosition = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    var current = document.getElementById('combox-'+ name + '-draggable');
    theOne[0].position = current.getAttribute('style');
  }

  $scope.select = function (name, index) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    theOne[0].index = index;
    theOne[0].imgUrl = theOne[0].data[theOne[0].index].item.image.sizes.Best.url;
  }

  $scope.save = function () {
    $rootScope.currentCombination.author = $scope.author;
    $rootScope.currentCombination.title = $scope.title;
    $rootScope.currentCombination.eventType = $scope.eventType;
    $rootScope.currentCombination.descrition = $scope.descrition;
  }

  vm.newComb = function () {
    vm.saveResult = false;
    $( "#img-out" ).empty();
    var pSaveImgsToTmp = new Promise(function(resolve, reject) {
      var bodyParts = ['top', 'bot', 'fullbody', 'foot', 'neck', 'head', 'eye', 'bags'];

      var json = [];
      for (var i = 0; i < bodyParts.length; i++) {
        var theOne = document.getElementById('combox-' + bodyParts[i] + '-img');
        if (theOne != null) {
          var src = theOne.getAttribute('src');
        } else {
          var src = 'n/a'
        }
        json.push({name: bodyParts[i], src: src});
      }
      var tmp = awsService.saveInTmp(json);
      tmp.then(function (res) {
        var p1 = new Promise(function(resolve, reject) {
          $rootScope.newImgUrls = res.data;
          var tmp = document.createElement('div');
          tmp.setAttribute('id', 'tmp-save');
          tmp.className = 'hidden';
          document.body.appendChild(tmp);

          for (var i = 0; i < $rootScope.newImgUrls.length; i++) {
            var img = document.createElement('img');
            img.src = $rootScope.newImgUrls[i].src;
            img.setAttribute('id', 'newImg-'+$rootScope.newImgUrls[i].name);
            tmp.appendChild(img);
          }

          resolve();
        });
        p1.then(function(){
          resolve();
        })
      });
    });

    var pSaveFilesToDB = new Promise(function(resolve, reject) {
      $scope.thumbShow = 'save';
      $scope.saveMsg = 'Saving...';
      var rootArray = $rootScope.queryLists;
      var saveComb = [];
      for (var i = 0; i < rootArray.length; i++) {
        var theOne = rootArray[i].data[rootArray[i].index];
        var object = {
          imgUrl: rootArray[i].imgUrl,
          index: rootArray[i].index,
          name: rootArray[i].name,
          order: rootArray[i].order,
          position: rootArray[i].position,
          show: rootArray[i].show,
          item: {},
        }
        saveComb.push(object);
        saveComb[i].item.id = theOne.item.id;
        saveComb[i].item.clickUrl = theOne.item.clickUrl;
        saveComb[i].item.name = theOne.item.name;
        if (theOne.item.brand) {
          saveComb[i].item.brandName = theOne.item.brand.name;
        }
        saveComb[i].item.price = theOne.item.price;
        saveComb[i].item.retailerName = theOne.item.retailer.name;
        saveComb[i].item.categories = theOne.item.categories;
      }
      var json = {
        information: $rootScope.currentCombination,
        combinations: saveComb,
      }
      var newComb = $http.post('/combinations/new', json);
      newComb.then(function (response) {
        if (response.status == '201') {
          $rootScope.currentCombination._id = response.data;
        }
        vm.directlink = $location.absUrl().replace(/combinations/, 'ideas') + '/' + response.data;
        resolve();
      })
    });<commit_msg>Fix directlink issue.<commit_after>var app = angular.module('trand');
app.controller('combinationsController', combinations);
app.$inject = ['$http', '$scope', '$location', 'userService', '$sce', 'collectionsService', '$timeout', 'awsService'];

function combinations($http, $scope, $location, userService, $sce, $rootScope, collectionsService, $timeout, awsService) {
  var vm = this;
  vm.saveResult = true;
  $scope._ = _;
  $scope.posX = 0;
  $scope.posY = 0;

  var today = new Date();
  vm.timeNow = today.getTime();

  $scope.moveX = function (pixels) {
    $scope.posX = $scope.posX + pixels;
  };
  $scope.moveY = function (pixels) {
    $scope.posY = $scope.posY + pixels;
  };
  $scope.$evalAsync(function () {
    $scope.$broadcast('content.changed', 1000);
  });

  $scope.center = function () {
    $scope.posX = 600;
    $scope.posY = 410;
  };

  $scope.last = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    if ((theOne[0].index)===0) {
      theOne[0].index = theOne[0].data.length - 1 ;
    } else {
      theOne[0].index -- ;
    }
    theOne[0].imgUrl = theOne[0].data[theOne[0].index].item.image.sizes.Best.url;
  }

  $scope.next = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    if ((theOne[0].index + 1) === theOne[0].data.length) {
      theOne[0].index = 0;
    } else {
      theOne[0].index ++ ;
    }
    theOne[0].imgUrl = theOne[0].data[theOne[0].index].item.image.sizes.Best.url;
  }

  $scope.showInBox = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    theOne[0].show = !theOne[0].show;
  }

  $scope.setPosition = function (name) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    var current = document.getElementById('combox-'+ name + '-draggable');
    theOne[0].position = current.getAttribute('style');
  }

  $scope.select = function (name, index) {
    var theOne = _.where($rootScope.queryLists, {name: name});
    theOne[0].index = index;
    theOne[0].imgUrl = theOne[0].data[theOne[0].index].item.image.sizes.Best.url;
  }

  $scope.save = function () {
    $rootScope.currentCombination.author = $scope.author;
    $rootScope.currentCombination.title = $scope.title;
    $rootScope.currentCombination.eventType = $scope.eventType;
    $rootScope.currentCombination.descrition = $scope.descrition;
  }

  vm.newComb = function () {
    vm.saveResult = false;
    $( "#img-out" ).empty();
    var pSaveImgsToTmp = new Promise(function(resolve, reject) {
      var bodyParts = ['top', 'bot', 'fullbody', 'foot', 'neck', 'head', 'eye', 'bags'];

      var json = [];
      for (var i = 0; i < bodyParts.length; i++) {
        var theOne = document.getElementById('combox-' + bodyParts[i] + '-img');
        if (theOne != null) {
          var src = theOne.getAttribute('src');
        } else {
          var src = 'n/a'
        }
        json.push({name: bodyParts[i], src: src});
      }
      var tmp = awsService.saveInTmp(json);
      tmp.then(function (res) {
        var p1 = new Promise(function(resolve, reject) {
          $rootScope.newImgUrls = res.data;
          var tmp = document.createElement('div');
          tmp.setAttribute('id', 'tmp-save');
          tmp.className = 'hidden';
          document.body.appendChild(tmp);

          for (var i = 0; i < $rootScope.newImgUrls.length; i++) {
            var img = document.createElement('img');
            img.src = $rootScope.newImgUrls[i].src;
            img.setAttribute('id', 'newImg-'+$rootScope.newImgUrls[i].name);
            tmp.appendChild(img);
          }

          resolve();
        });
        p1.then(function(){
          resolve();
        })
      });
    });

    var pSaveFilesToDB = new Promise(function(resolve, reject) {
      $scope.thumbShow = 'save';
      $scope.saveMsg = 'Saving...';
      var rootArray = $rootScope.queryLists;
      var saveComb = [];
      for (var i = 0; i < rootArray.length; i++) {
        var theOne = rootArray[i].data[rootArray[i].index];
        var object = {
          imgUrl: rootArray[i].imgUrl,
          index: rootArray[i].index,
          name: rootArray[i].name,
          order: rootArray[i].order,
          position: rootArray[i].position,
          show: rootArray[i].show,
          item: {},
        }
        saveComb.push(object);
        saveComb[i].item.id = theOne.item.id;
        saveComb[i].item.clickUrl = theOne.item.clickUrl;
        saveComb[i].item.name = theOne.item.name;
        if (theOne.item.brand) {
          saveComb[i].item.brandName = theOne.item.brand.name;
        }
        saveComb[i].item.price = theOne.item.price;
        saveComb[i].item.retailerName = theOne.item.retailer.name;
        saveComb[i].item.categories = theOne.item.categories;
      }
      var json = {
        information: $rootScope.currentCombination,
        combinations: saveComb,
      }
      var newComb = $http.post('/combinations/new', json);
      newComb.then(function (response) {
        console.log(response.data);
        if (response.status == '201') {
          $rootScope.currentCombination._id = response.data;
        }
        vm.directlink = $location.absUrl().replace(/combinations/, 'ideas') + '/' + response.data;
        resolve();
      })
    });
{'fraction_non_alphanumeric': 0.1699582225598177, 'fraction_numerical': 0.008545385491834409, 'mean_word_length': 2.5814348860931657, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '3129000', 'n_tokens_mistral': 3546, 'n_tokens_neox': 3463, 'n_words': 621}