<commit_before>// register the directive with your app module
var app = angular.module('ddApp', ['lvl.services', 'ngAnimate', 'ui.bootstrap', 'rzModule']);

// function referenced by the drop target
app.controller('ddController', ['$scope', '$uibModal', '$log','$http', function($scope, $uibModal, $log, $http){

    $scope.tileSets = [];
    $scope.tileSet = {};
    $http.get("/api/maps/line/tilesets?populate=true").then(function(response){
	$scope.tileSets = response.data
	$scope.tileSet = $scope.tileSets[0]
    }, function(response){
        console.log("Error: " + response.statusText);
    });

    $scope.sliderOptions = {
        floor: 0,
        ceil: 0,
        vertical: true,
        showSelectionBar: true,
        showTicksValues: true,
        ticksValuesTooltip: function (v) {
            return 'Level ' + v;
        }
    };
    $scope.z = 0;
    $scope.tiles = {};
    $scope.startTile = {x: 0, y: 0, z: 0};
    $scope.numberOfDropTiles = 0;
    $scope.height = 1;
    $scope.sliderOptions.ceil = $scope.height - 1;
    $scope.width = 1;
    $scope.length = 1;
    $scope.name = "<NAME>";

    if(mapId){
        $http.get("/api/maps/" + mapId + "?populate=true").then(function(response){
            for(var i = 0; i < response.data.tiles.length; i++){
                $scope.tiles[response.data.tiles[i].x + ',' +
                             response.data.tiles[i].y + ',' +
                             response.data.tiles[i].z] = response.data.tiles[i];
            }
            $scope.startTile = response.data.startTile;
            $scope.numberOfDropTiles = response.data.numberOfDropTiles;
            $scope.height = response.data.height;
            $scope.sliderOptions.ceil = $scope.height - 1;
            $scope.width = response.data.width;
            $scope.length = response.data.length;
            $scope.name = response.data.name;

        }, function(response){
            console.log("Error: " + response.statusText);
        });
    }




    $scope.range = function(n){
        arr = [];
        for (var i=0; i < n; i++) {
            arr.push(i);
        }
        return arr;
    }

    $scope.rotateTile = function(x,y){
        // If the tile doesn't exists yet
        if(!$scope.tiles[x+','+y+','+$scope.z])
            return;
        $scope.tiles[x+','+y+','+$scope.z].rot += 90;
        if($scope.tiles[x+','+y+','+$scope.z].rot >= 360)
            $scope.tiles[x+','+y+','+$scope.z].rot = 0;
    }

    $scope.saveMap = function(){
        var map = {
            name: $scope.name,
            length: $scope.length,
            height: $scope.height,
            width: $scope.width,
            numberOfDropTiles: $scope.numberOfDropTiles,
            startTile: $scope.startTile,
            tiles: $scope.tiles
        };

        console.log(map);
        $http.post("/api/maps/createmap/", map).then(function(response){
            alert("Success!");
            console.log(response.data);
            window.location.replace("/line/editor/" + response.data.id)
        }, function(response){
            console.log(response);
            console.log("Error: " + response.statusText);
        });
    }


    $scope.open = function(x,y) {
        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: '/templates/line_editor_modal.html?gs',
            controller: 'ModalInstanceCtrl',<commit_msg>Fix saving and loading of map<commit_after>// register the directive with your app module
var app = angular.module('ddApp', ['lvl.services', 'ngAnimate', 'ui.bootstrap', 'rzModule']);

// function referenced by the drop target
app.controller('ddController', ['$scope', '$uibModal', '$log','$http', function($scope, $uibModal, $log, $http){

    
    $scope.tileSets = [];
    $scope.tileSet = {};
    $http.get("/api/maps/line/tilesets?populate=true").then(function(response){
	$scope.tileSets = response.data
	$scope.tileSet = $scope.tileSets[0]
    }, function(response){
        console.log("Error: " + response.statusText);
    });

    $scope.sliderOptions = {
        floor: 0,
        ceil: 0,
        vertical: true,
        showSelectionBar: true,
        showTicksValues: true,
        ticksValuesTooltip: function (v) {
            return 'Level ' + v;
        }
    };
    $scope.z = 0;
    $scope.tiles = {};
    $scope.startTile = {x: 0, y: 0, z: 0};
    $scope.numberOfDropTiles = 0;
    $scope.height = 1;
    $scope.sliderOptions.ceil = $scope.height - 1;
    $scope.width = 1;
    $scope.length = 1;
    $scope.name = "<NAME>";

    if(mapId){
        $http.get("/api/maps/line/" + mapId + "?populate=true").then(function(response){
            for(var i = 0; i < response.data.tiles.length; i++){
                $scope.tiles[response.data.tiles[i].x + ',' +
                             response.data.tiles[i].y + ',' +
                             response.data.tiles[i].z] = response.data.tiles[i];
            }
	    competitionId = response.data.competition;
            $scope.startTile = response.data.startTile;
            $scope.numberOfDropTiles = response.data.numberOfDropTiles;
            $scope.height = response.data.height;
            $scope.sliderOptions.ceil = $scope.height - 1;
            $scope.width = response.data.width;
            $scope.length = response.data.length;
            $scope.name = response.data.name;

        }, function(response){
            console.log("Error: " + response.statusText);
        });
    }




    $scope.range = function(n){
        arr = [];
        for (var i=0; i < n; i++) {
            arr.push(i);
        }
        return arr;
    }

    $scope.rotateTile = function(x,y){
        // If the tile doesn't exists yet
        if(!$scope.tiles[x+','+y+','+$scope.z])
            return;
        $scope.tiles[x+','+y+','+$scope.z].rot += 90;
        if($scope.tiles[x+','+y+','+$scope.z].rot >= 360)
            $scope.tiles[x+','+y+','+$scope.z].rot = 0;
    }

    $scope.saveMap = function(){

        var map = {
	    competition: competitionId,
            name: $scope.name,
            length: $scope.length,
            height: $scope.height,
            width: $scope.width,
            numberOfDropTiles: $scope.numberOfDropTiles,
            startTile: $scope.startTile,
            tiles: $scope.tiles
        };

        console.log(map);
	console.log("Update map", mapId);
	console.log("Competition ID", competitionId);
	if(mapId){
	    $http.put("/api/maps/line/" + mapId, map).then(function(response){
		alert("Updated map");
		console.log(response.data);
            }, function(response){
		console.log(response);
		console.log("Error: " + response.statusText);
		alert(response.data.msg);
            });
	}else{
            $http.post("/api/maps/line", map).then(function(response){
		alert("Created map!");
		console.log(response.data);
		competitionId = response.data.competition;
		window.location.replace("/line/editor/" + response.data.id)
            }, function(response){
		console.log(response);
		console.log("Error: " + response.statusText);
		alert(response.data.msg);
            });
	}
    }


    $scope.open = function(x,y) {
        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: '/templates/line_editor_modal.html?gs',
            controller: 'ModalInstanceCtrl',
{'fraction_non_alphanumeric': 0.16875681570338058, 'fraction_numerical': 0.0057251908396946565, 'mean_word_length': 2.119472789115646, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2116350', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2294, 'n_words': 389}