<commit_before>'use strict';
/*global $:false, console:false */

angular.module('fbCal')
  .controller('ModalCtrl', function ($scope, $sce, $sanitize, $wix, $log, $timeout, eventId, server) {
    $scope.eventId = eventId;

    var eventInfo;
    var feedObject;

    // $scope.eventId = "1512622455616642";

    var showErrorModal = function() {
      $scope.messageTitle = "Oh no!";
      $('#messageTitle').css('color', 'red');
      $scope.messageBody = 'Something terrible happened. Please exit and try again.';
      $('#message').modal('show');
    };

    var processEventInfo = function() {
      $scope.id = eventInfo.id;
      $scope.name = eventInfo.name;
      $scope.owner = eventInfo.owner.name;
      console.log($scope.name);
      processDesciption();
      processTime();
      processLocation();
      //display modal info here - before this just show some loading screen
    };

    var processDesciption = function() {
      $scope.description = eventInfo.description.replace(/\r?\n/g, "<br>");
      $scope.description = $sanitize($scope.description);
      $sce.trustAsHtml($scope.description);
      $scope.showDescription = true;
    };

    var processTime = function() {
      var startTime = new Date(eventInfo.start_time);
      var endTime = new Date(eventInfo.end_time);
      //find a way to tell if they're on the same day
      var onSameDay;
      var startHour = startTime.toLocaleTimeString().toLowerCase();
      var endHour = endTime.toLocaleTimeString().toLowerCase();
      startHour = startHour.replace(/:\d\d /, "");
      endHour = endHour.replace(/:\d\d /, "");
      var startDateString = startTime.toLocaleDateString();
      var startDayString = startTime.toString().replace(/ .+/, ", ");
      if (onSameDay) {
        $scope.shortTime = startDayString + startDateString + " at " +
                           startHour + "-" + endHour;
      } else {
        var endDateString = endTime.toLocaleDateString();
        var endDayString = endTime.toString().replace(/ .+/, ", ");
        $scope.shortTime = startDayString + startDateString + " - " + endDayString + endDateString;
        $scope.longTime = startDayString + startDateString + " at " + startHour +
                          " to " + endDayString + endDateString + " at " +
                          endHour;
      }
    };

    var processLocation = function() {
      $scope.location = eventInfo.location;
      if (eventInfo.venue && (eventInfo.venue.street || eventInfo.venue.city ||
                              eventInfo.venue.state || 
                              eventInfo.venue.country)) {
        $scope.venue = eventInfo.venue.street + ", " + eventInfo.venue.city + 
                         ", " + eventInfo.venue.state + ", " +
                         eventInfo.venue.country + " " + eventInfo.venue.zip;
        $scope.venue = $scope.venue.replace(/, undefined/, "")
                                       .replace(/undefined, /, "")
                                       .replace(/undefined/, "")
                                       .replace(/ $/, "")
                                       .replace(/, $/, "");
      }
    };

    var processCover = function(coverObject) {
      console.log('processing cover');
      if (coverObject.cover && coverObject.cover.source) {
        var cover = coverObject.cover;
        var height = 296 + $scope.settings.borderWidth;

        height = 306;
        // cover.source = "https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-xfa1/t31.0-8/q71/s720x720/10286851_801238859907126_3448618267544264515_o.jpg";
        var cssClass = {'background-image' : 'url(' + cover.source + ')',
                        'height' : height + 'px',
                        'background-position' : cover.offset_x + '% ' +
                                                cover.offset_y + '%'
                       };
        $('#header').css(cssClass);
      }
    };

    var processGuest = function(guestObject) {
      console.log('processing guest');
      console.log(guestObject);

    };

    var processFeed = function() {
      console.log('processing feed');
      console.log(feedObject);
      //if feedFromServer is empty, display end of feed message
    };



    if (!$scope.eventId) {
      showErrorModal();
      $timeout(function() {
        $wix.closeWindow('Closed Modal');
      }, 7000);
    } else {
      server.getModalEvent($scope.eventId, "all")
        .then(function(response) {
          server.getModalEvent($scope.eventId, "cover")
            .then(function(response) {
              server.getModalEvent($scope.eventId, "guests")
                .then(function(response) {
                  server.getModalEvent($scope.eventId, "feed")
                    .then(function(response) {
                      feedObject = response;
                      processFeed();<commit_msg>Added error messages for when guest data fails to load<commit_after>'use strict';
/*global $:false, console:false */

angular.module('fbCal')
  .controller('ModalCtrl', function ($scope, $sce, $sanitize, $wix, $log, $timeout, eventId, server) {
    $scope.eventId = eventId;

    var eventInfo;
    var feedObject;

    // $scope.eventId = "1512622455616642";

    var showErrorModal = function() {
      $scope.messageTitle = "Oh no!";
      $('#messageTitle').css('color', 'red');
      $scope.messageBody = 'Something terrible happened. Please exit and try again.';
      $('#message').modal('show');
    };

    var processEventInfo = function() {
      $scope.id = eventInfo.id;
      $scope.name = eventInfo.name;
      $scope.owner = eventInfo.owner.name;
      console.log($scope.name);
      processDesciption();
      processTime();
      processLocation();
      //display modal info here - before this just show some loading screen
    };

    var processDesciption = function() {
      $scope.description = eventInfo.description.replace(/\r?\n/g, "<br>");
      $scope.description = $sanitize($scope.description);
      $sce.trustAsHtml($scope.description);
      $scope.showDescription = true;
    };

    var processTime = function() {
      var startTime = new Date(eventInfo.start_time);
      var endTime = new Date(eventInfo.end_time);
      //find a way to tell if they're on the same day
      var onSameDay;
      var startHour = startTime.toLocaleTimeString().toLowerCase();
      var endHour = endTime.toLocaleTimeString().toLowerCase();
      startHour = startHour.replace(/:\d\d /, "");
      endHour = endHour.replace(/:\d\d /, "");
      var startDateString = startTime.toLocaleDateString();
      var startDayString = startTime.toString().replace(/ .+/, ", ");
      if (onSameDay) {
        $scope.shortTime = startDayString + startDateString + " at " +
                           startHour + "-" + endHour;
      } else {
        var endDateString = endTime.toLocaleDateString();
        var endDayString = endTime.toString().replace(/ .+/, ", ");
        $scope.shortTime = startDayString + startDateString + " - " + endDayString + endDateString;
        $scope.longTime = startDayString + startDateString + " at " + startHour +
                          " to " + endDayString + endDateString + " at " +
                          endHour;
      }
    };

    var processLocation = function() {
      $scope.location = eventInfo.location;
      if (eventInfo.venue && (eventInfo.venue.street || eventInfo.venue.city ||
                              eventInfo.venue.state || 
                              eventInfo.venue.country)) {
        $scope.venue = eventInfo.venue.street + ", " + eventInfo.venue.city + 
                         ", " + eventInfo.venue.state + ", " +
                         eventInfo.venue.country + " " + eventInfo.venue.zip;
        $scope.venue = $scope.venue.replace(/, undefined/, "")
                                       .replace(/undefined, /, "")
                                       .replace(/undefined/, "")
                                       .replace(/ $/, "")
                                       .replace(/, $/, "");
      }
    };

    var processCover = function(coverObject) {
      console.log('processing cover');
      if (coverObject.cover && coverObject.cover.source) {
        var cover = coverObject.cover;
        var height = 296 + $scope.settings.borderWidth;

        height = 306;
        // cover.source = "https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-xfa1/t31.0-8/q71/s720x720/10286851_801238859907126_3448618267544264515_o.jpg";
        var cssClass = {'background-image' : 'url(' + cover.source + ')',
                        'height' : height + 'px',
                        'background-position' : cover.offset_x + '% ' +
                                                cover.offset_y + '%'
                       };
        $('#header').css(cssClass);
      }
    };

    var processGuest = function(guestObject) {
      console.log('processing guest');
      console.log(guestObject);
      if (guestObject.data) {
        $scope.stats = guestObject.data[0];
      } else {
        $scope.guestFailed = true;
      }

    };

    var processFeed = function() {
      console.log('processing feed');
      console.log(feedObject);
      //if feedFromServer is empty, display end of feed message
    };



    if (!$scope.eventId) {
      showErrorModal();
      $timeout(function() {
        $wix.closeWindow('Closed Modal');
      }, 7000);
    } else {
      server.getModalEvent($scope.eventId, "all")
        .then(function(response) {
          server.getModalEvent($scope.eventId, "cover")
            .then(function(response) {
              server.getModalEvent($scope.eventId, "guests")
                .then(function(response) {
                  server.getModalEvent($scope.eventId, "feed")
                    .then(function(response) {
                      feedObject = response;
                      processFeed();
{'fraction_non_alphanumeric': 0.13978386021613978, 'fraction_numerical': 0.016462983537016463, 'mean_word_length': 1.9269878805793674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '808424', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2753, 'n_words': 507}