<commit_before>function Log (data) {
  this.id = data.id;
  this.log_date = data.log_date;
  this.next = data.next;
  this.prev = data.prev;
  this.user_id = data.user_id;
  this.per_recipe_stats = data.per_recipe_stats;
  this.total_stats = data.total_stats;
}

Log.prototype.date = function() {
  var date = new Date(this.log_date);
  var options = {
    weekday: 'long',
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    timeZone: 'UTC'
  };
  return date.toLocaleString('en-US', options);
}

Handlebars.registerHelper('num', function(number) {
  return number.toFixed(1).toLocaleString();
});

Handlebars.registerHelper('title', function(string) {
  return string.titleize();
});

$(function() {
  $('#log-history').on('click', function(event) {
    event.preventDefault();
    event.stopPropagation();

    $('section.flash').empty();

    var url = event.target.pathname;
    var request = $.getJSON(url);

    request.done(function(data) {
      var log = new Log(data);
      var template = HandlebarsTemplates['logs/stats'];
      var chart = Chartkick.charts["chart-1"];
      var chart_data = {
        Carbs: data.total_stats.total_carbs,
        Protein: data.total_stats.total_protein,
        Fat: data.total_stats.total_fat
      };

      function historyLink(data) {
        var historyTemplate = HandlebarsTemplates['logs/history'];
        var result = "";

        if (data.prev !== null) {
          result += historyTemplate({
            direction: "prev",
            userId: data.user_id,
            logId: data.prev,
            linkText: "Previous"
          });
        }

        if (data.next !== null) {
          result += historyTemplate({
            direction: "next",
            userId: data.user_id,
            logId: data.next,
            linkText: "Next"
          });
        }

        return result;
      }

      $('#log-show-date').text("Log Date: " + log.date());
      $('#log-history').html(historyLink(log));
      chart.updateData(chart_data);
      $('#log-show-stats-table-body').html(template(data));
    });

    request.fail(function(data) {
      var message = {error: "Your request couldn't be processed!"};
      var template = HandlebarsTemplates['flashes'];
      var $flashes = $('section.flash');

      $flashes.html(template(message));
    });
  })
});

$(function() {
  $('#log-show-form form').on('submit', function(event) {
    event.preventDefault();
    event.stopPropagation();

    $('section.flash').empty();

    var $form = $(this);
    var values = $form.serialize();
    var url = $form.attr('action') + '.json';
    var post = $.ajax({
      type: "PATCH",
      url: url,
      data: values,<commit_msg>Fix bug with Logs show entry form<commit_after>function Log (data) {
  this.id = data.id;
  this.log_date = data.log_date;
  this.next = data.next;
  this.prev = data.prev;
  this.user_id = data.user_id;
  this.per_recipe_stats = data.per_recipe_stats;
  this.total_stats = data.total_stats;
}

Log.prototype.date = function() {
  var date = new Date(this.log_date);
  var options = {
    weekday: 'long',
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    timeZone: 'UTC'
  };
  return date.toLocaleString('en-US', options);
}

Handlebars.registerHelper('num', function(number) {
  return number.toFixed(1).toLocaleString();
});

Handlebars.registerHelper('title', function(string) {
  return string.titleize();
});

$(function() {
  $('#log-history').on('click', function(event) {
    event.preventDefault();
    event.stopPropagation();

    $('section.flash').empty();

    var url = event.target.pathname;
    var request = $.getJSON(url);

    request.done(function(data) {
      var log = new Log(data);
      var template = HandlebarsTemplates['logs/stats'];
      var chart = Chartkick.charts["chart-1"];
      var chart_data = {
        Carbs: data.total_stats.total_carbs,
        Protein: data.total_stats.total_protein,
        Fat: data.total_stats.total_fat
      };

      function historyLink(data) {
        var historyTemplate = HandlebarsTemplates['logs/history'];
        var result = "";

        if (data.prev !== null) {
          result += historyTemplate({
            direction: "prev",
            userId: data.user_id,
            logId: data.prev,
            linkText: "Previous"
          });
        }

        if (data.next !== null) {
          result += historyTemplate({
            direction: "next",
            userId: data.user_id,
            logId: data.next,
            linkText: "Next"
          });
        }

        return result;
      }

      function formID(data) {
        return "edit_log_" + data.id;
      }

      function formAction(data) {
        return "/users/" + data.user_id + "/logs/" + data.id;
      }

      $('#log-show-date').text("Log Date: " + log.date());
      $('#log-history').html(historyLink(log));
      chart.updateData(chart_data);
      $('#log-show-form form').attr('id', formID(data));
      $('#log-show-form form').attr('action', formAction(data));
      $('#log-show-stats-table-body').html(template(data));
    });

    request.fail(function(data) {
      var message = {error: "Your request couldn't be processed!"};
      var template = HandlebarsTemplates['flashes'];
      var $flashes = $('section.flash');

      $flashes.html(template(message));
    });
  })
});

$(function() {
  $('#log-show-form form').on('submit', function(event) {
    event.preventDefault();
    event.stopPropagation();

    $('section.flash').empty();

    var $form = $(this);
    var values = $form.serialize();
    var url = $form.attr('action') + '.json';
    var post = $.ajax({
      type: "PATCH",
      url: url,
      data: values,
{'fraction_non_alphanumeric': 0.16614255765199162, 'fraction_numerical': 0.0006988120195667365, 'mean_word_length': 2.5559006211180124, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6587778', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1787, 'n_words': 343}