<commit_before>'use strict';

/* Controllers */

var NCMainControllers = angular.module('NCMainControllers', ['ngCookies']);

NCMainControllers.controller('LoginCheck', function($scope, $cookies, $location) {
  var absUrl = "";
  console.log("Cookie check controller initialised");

  //check for cookie, if exists keep login, if not redirect the user to login page
  var cookie = $cookies.get('sessionCookie');
  console.log(cookie);

  if (cookie == undefined) {
    //to do if user is not logged in
    window.alert("You are not logged in.");
    absUrl = $location.absUrl();
    absUrl = absUrl.substring(0, absUrl.indexOf("/home/home.html"));
    absUrl = absUrl + "/login/login.html";
    window.location.replace(absUrl);
  }

  $scope.logOut = function() {
    //delete cookie here
    console.log("Deleting cookie");
    $cookies.remove('sessionCookie', {path: '/app/content/home/home.html'});
    var cookie = $cookies.get('sessionCookie');
    console.log(cookie);
    absUrl = $location.absUrl();
    absUrl = absUrl.substring(0, absUrl.indexOf("/home/home.html"));
    absUrl = absUrl + "/login/login.html";
    window.location.replace(absUrl);
  }
});

NCMainControllers.controller('EventListCtrl', function($scope, $firebaseArray) {
    var $load = $('<div class="loading"><img class="loadingimg" src="../../img/loading.gif"></div>').appendTo('body')
    , db = new Firebase("https://popping-heat-6810.firebaseio.com/events")
  db.on('value', function () {
    $load.hide()
  })

  var ref = new Firebase("https://popping-heat-6810.firebaseio.com/events");
  // download the data into a local object
  $scope.events = $firebaseArray(ref);
  // synchronize the object with a three-way data binding
  // click on `index.html` above to see it used in the DOM!
  // syncObject.$bindTo($scope, "events");
});

NCMainControllers.controller('AddAmountCtrl', function($scope, $firebaseObject, $cookies) {
  console.log('AddAmountCtrl');
  $scope.userEmail = $cookies.get('sessionCookie');
  $scope.amount = function(){
    console.log('amount function');
var ref = new Firebase("https://popping-heat-6810.firebaseio.com/Variables/Balance");
  var obj = new $firebaseObject(ref);
 obj.$loaded().then(function() {
    var sum =0;
    sum = (parseInt(obj.$value));
    console.log("Current Balance: "+sum);
      sum = sum + 500;
      console.log("After adding 500: "+sum);<commit_msg>"Add 500" button is user specfic now<commit_after>'use strict';

/* Controllers */

var NCMainControllers = angular.module('NCMainControllers', ['ngCookies']);

NCMainControllers.controller('LoginCheck', function($scope, $cookies, $location) {
  var absUrl = "";
  console.log("Cookie check controller initialised");

  //check for cookie, if exists keep login, if not redirect the user to login page
  var cookie = $cookies.get('sessionCookie');
  console.log(cookie);

  if (cookie == undefined) {
    //to do if user is not logged in
    window.alert("You are not logged in.");
    absUrl = $location.absUrl();
    absUrl = absUrl.substring(0, absUrl.indexOf("/home/home.html"));
    absUrl = absUrl + "/login/login.html";
    window.location.replace(absUrl);
  }

  $scope.logOut = function() {
    //delete cookie here
    console.log("Deleting cookie");
    $cookies.remove('sessionCookie', {path: '/app/content/home/home.html'});
    var cookie = $cookies.get('sessionCookie');
    console.log(cookie);
    absUrl = $location.absUrl();
    absUrl = absUrl.substring(0, absUrl.indexOf("/home/home.html"));
    absUrl = absUrl + "/login/login.html";
    window.location.replace(absUrl);
  }
});

NCMainControllers.controller('EventListCtrl', function($scope, $firebaseArray) {
    var $load = $('<div class="loading"><img class="loadingimg" src="../../img/loading.gif"></div>').appendTo('body')
    , db = new Firebase("https://popping-heat-6810.firebaseio.com/events")
  db.on('value', function () {
    $load.hide()
  })

  var ref = new Firebase("https://popping-heat-6810.firebaseio.com/events");
  // download the data into a local object
  $scope.events = $firebaseArray(ref);
  // synchronize the object with a three-way data binding
  // click on `index.html` above to see it used in the DOM!
  // syncObject.$bindTo($scope, "events");
});


NCMainControllers.controller('AddAmountCtrl', function($scope, $firebaseObject, $cookies) {
  console.log('AddAmountCtrl');
   var email = $cookies.get('sessionCookie');
   email = email.substring(0, email.indexOf("@"));
   email = email.toLowerCase();
   email = email.toString();
   console.log(email);
  $scope.userEmail = $cookies.get('sessionCookie');

  $scope.amount = function(){
    console.log('amount function');
var ref = new Firebase("https://nucoins.firebaseio.com/usersData/"+email+"/Balance");
  var obj = new $firebaseObject(ref);
 obj.$loaded().then(function() {
    var sum =0;
    sum = (parseInt(obj.$value));
    console.log("Current Balance: "+sum);
      sum = sum + 500;
      console.log("After adding 500: "+sum);
{'fraction_non_alphanumeric': 0.17235152487961478, 'fraction_numerical': 0.008426966292134831, 'mean_word_length': 4.066056910569106, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3303388', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1573, 'n_words': 352}