<commit_before>angular.module('lg.controllers')
// URL to API that enables cross-origin requests to anywhere
 .value('CORSURL', '//cors-anywhere.herokuapp.com/')
 .value('APIURL', 'https://volontario-server.herokuapp.com/')
 .value('UPDATE_INTERVAL', '10000000')

.controller('MapCtrl', function($scope, $q, $ionicLoading, $compile, $http, $timeout, $interval, $cordovaDatePicker, CORSURL, APIURL, Categories,MapSettings,UPDATE_INTERVAL) {

      var markers = [];
      var markerObj = [];
      var infowindow = null;
      var updateMarkersPromise;
      var clearMarkers = function(){
        _.map(markerObj,function(item){
          item.setMap(null);
        })
      }
      var loading;
      $scope.calendar = {};

      function initialize() {

        var mapOptions = MapSettings;
        var map = new google.maps.Map(document.getElementById("map"),
            mapOptions);
        $scope.map = map;


        map.addListener('zoom_changed', function() {
          _.map(markerObj,function(item,i){
            var t =  Math.round(markers[i].traffic.average*100) || 0;
            animateCircle(i,t,0)
          })
        });



      }
      initialize();


      $scope.clearAll = function(){
        clearMarkers();
        Categories.clear();
        updateActive();
      }

      $scope.centerOnMe = function() {
        if(!$scope.map) {
          return;
        }

        $scope.loading = $ionicLoading.show({
          content: 'Loading...',
          showBackdrop: false
        });

        navigator.geolocation.getCurrentPosition(function(pos) {
          $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
          $scope.loading.hide();
        }, function(error) {
          alert('Unable to get location: ' + error.message);
        });
      };
      
      $scope.clickTest = function() {
        alert('Example of infowindow with ng-click')
      };

      var CalendarStart = '<div class="list" data-ec5-date>\
     <label class="item item-input item-stacked-label">\
     <input type="datetime-local" name="calendarStart" ng-model="calendar.Start">\
     </label>';

      var CalendarEnd = '<div class="list" data-ec5-date>\
     <label class="item item-input item-stacked-label">\
     <input type="datetime-local" name="calendarEnd" ng-model="calendar.End">\
     </label>';

      var searchLocations = function() {
        loading = $ionicLoading.show({
          content: 'Loading...',
          showBackdrop: false
        });

        /* POST /events/:id/calendar 
        /* Add user to event
        /* userId hexstring Attendee 
        /* testid = 56a24593b42e9f03002b54b7
        /* from  microtimestamp  
        /* to  microtimestamp
        /* basicAuth required
        */

        $scope.addToCalendar = function(eventId){
          
          //save to localStorage and request from a service
          var userId = "56a24593b42e9f03002b54b7";
          var Auth = 'Basic <PASSWORD>';          

          var from = $scope.calendar.Start;
          var to = $scope.calendar.End;
          var microFrom = new Date(from).getTime();
          var microTo = new Date(to).getTime();

          $http({
            url: CORSURL+APIURL+'events/'+eventId+'/calendar',
            method: 'POST',
            headers: {'Authorization': Auth},
            data: {userId:userId, from: microFrom, to: microTo}
          });

        };


        var selectedTags = Categories.getActive();
        clearMarkers();
        var locations = $http.get(CORSURL+APIURL+"/locations"),
        events = $http.get(CORSURL+APIURL+"/events?"+selectedTags);

          $q.all([locations, events]).then(function successCallback(response) {
            // this callback will be called asynchronously
            // when the response is available


            // hide loader
            $timeout(function(){
              $ionicLoading.hide();
            });
            var geocoder = new google.maps.Geocoder(); 
            var res = response[0].data.concat(response[1].data);
            var traffic;
            var tag;
            markers = [];<commit_msg>Add to calendar success / failure edit<commit_after>angular.module('lg.controllers')
// URL to API that enables cross-origin requests to anywhere
 .value('CORSURL', '//cors-anywhere.herokuapp.com/')
 .value('APIURL', 'https://volontario-server.herokuapp.com/')
 .value('UPDATE_INTERVAL', '10000000')

.controller('MapCtrl', function($scope, $q, $ionicLoading, $compile, $http, $timeout, $interval, $cordovaDatePicker, CORSURL, APIURL, Categories,MapSettings,UPDATE_INTERVAL) {

      var markers = [];
      var markerObj = [];
      var infowindow = null;
      var updateMarkersPromise;
      var clearMarkers = function(){
        _.map(markerObj,function(item){
          item.setMap(null);
        })
      }
      var loading;
      $scope.calendar = {};

      function initialize() {

        var mapOptions = MapSettings;
        var map = new google.maps.Map(document.getElementById("map"),
            mapOptions);
        $scope.map = map;


        map.addListener('zoom_changed', function() {
          _.map(markerObj,function(item,i){
            var t =  Math.round(markers[i].traffic.average*100) || 0;
            animateCircle(i,t,0)
          })
        });



      }
      initialize();


      $scope.clearAll = function(){
        clearMarkers();
        Categories.clear();
        updateActive();
      }

      $scope.centerOnMe = function() {
        if(!$scope.map) {
          return;
        }

        $scope.loading = $ionicLoading.show({
          content: 'Loading...',
          showBackdrop: false
        });

        navigator.geolocation.getCurrentPosition(function(pos) {
          $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
          $scope.loading.hide();
        }, function(error) {
          alert('Unable to get location: ' + error.message);
        });
      };
      
      $scope.clickTest = function() {
        alert('Example of infowindow with ng-click')
      };

      var CalendarStart = '<div class="list" data-ec5-date>\
     <label class="item item-input item-stacked-label">\
     <input type="datetime-local" name="calendarStart" required ng-model="calendar.Start">\
     </label>';

      var CalendarEnd = '<div class="list" data-ec5-date>\
     <label class="item item-input item-stacked-label">\
     <input type="datetime-local" name="calendarEnd" required ng-model="calendar.End">\
     </label>';

      var searchLocations = function() {
        loading = $ionicLoading.show({
          content: 'Loading...',
          showBackdrop: false
        });

        /* POST /events/:id/calendar 
        /* Add user to event
        /* userId hexstring Attendee 
        /* testid = 56a24593b42e9f03002b54b7
        /* from  microtimestamp  
        /* to  microtimestamp
        /* basicAuth required
        */

        $scope.addToCalendar = function(eventId){
          //save to localStorage and request from a service
          var userId = "56a24593b42e9f03002b54b7";
          var Auth = '<PASSWORD> dGVzdC50ZXN0QHRlc3QudGVzdDp0ZXN0';          

          var from = $scope.calendar.Start;
          var to = $scope.calendar.End;
          var microFrom = new Date(from).getTime();
          var microTo = new Date(to).getTime();

          $http({
            url: CORSURL+APIURL+'events/'+eventId+'/calendar',
            method: 'POST',
            headers: {'Authorization': Auth},
            data: {userId:userId, from: microFrom, to: microTo}
            })
          .done(function successCallBack(response){
            // add response from API
            var successText = "ilmoittautumisesi lähetettiin eteenpäin."
                updateContent(successText); 
          }, 
          function errorCallBack(response){
        });

        };

        // infoWindow new visuals after succesfull or unsuccesfull $http. 
        function updateContent(content) {
            infowindow.setContent(content);
        }

        var selectedTags = Categories.getActive();
        clearMarkers();
        var locations = $http.get(CORSURL+APIURL+"/locations"),
        events = $http.get(CORSURL+APIURL+"/events?"+selectedTags);

          $q.all([locations, events]).then(function successCallback(response) {
            // this callback will be called asynchronously
            // when the response is available


            // hide loader
            $timeout(function(){
              $ionicLoading.hide();
            });
            var geocoder = new google.maps.Geocoder(); 
            var res = response[0].data.concat(response[1].data);
            var traffic;
            var tag;
            markers = [];
{'fraction_non_alphanumeric': 0.13277157822819402, 'fraction_numerical': 0.01275335914370303, 'mean_word_length': 2.064549895324494, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '3495488', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2458, 'n_words': 506}