<commit_before>$(function () {
   /* Variables */

   var dataHandler = new dbHandler('192.168.1.42', 1337, function () {
      // if an error occurs, change the page to an error page
      // TODO: make this work
      if(err) {
         console.log(err);
         $.post('localhost:1337/error', { error: err })
            .done(function () {
               window.location.replace("/error.html");
            })
            .fail(function () {
               window.location.replace("/error_fail.html");
            });
      }
   });

   var currentType = "Main";

   var foodTableTitles = {
      name: "Name",
      time: "Time",
      portions: "Portions",
      effort: "Effort"
   };

   /* Food information functionalities */
   
   var foodInfo = new eatables.structure($("div.foodbox"));

   /* Table functionalities */

   // creates a sortable table with no data
   var resultTable = new eatables.table("foods", null, foodTableTitles, 
      true, function (err) {

      if(err) {
         console.log("result table craetion error: " + err);
         return;
      }

      // only adds the destination function if table is created
      // an unfortunate side effect of using socket.io instead of ajax
      dataHandler.onResponse('type_request', function (data) {
            console.log("got response");

            if(resultTable) 
               resultTable.changeData(data.results); 
      });
   });

   resultTable.onClick("tr", function (data) {
      console.log("got data");
      var alaotsikko = data.type + " / " + data.effort;
      foodInfo.change("h2.otsikko", "text", data.name);
      foodInfo.change("h3.alaotsikko", "text", alaotsikko);
      foodInfo.change("td#time", "text", data.time || "-"),
      foodInfo.change("td#portions", "text", data.portions || "-");
      foodInfo.change("td#recipe", "text", data.recipe || "-");
   });<commit_msg>improved the file structure a bit<commit_after>$(function () {
   /* Variables */

   var dataHandler = new dbHandler('192.168.1.42', 1337, function () {
      // if an error occurs, change the page to an error page
      // TODO: make this work
      if(err) {
         console.log(err);
         $.post('localhost:1337/error', { error: err })
            .done(function () {
               window.location.replace("/error.html");
            })
            .fail(function () {
               window.location.replace("/error_fail.html");
            });
      }
   });

   var currentType = "Main";

   /* Food information functionalities */
   
   var foodInfo = new eatables.structure($("div.foodbox"));

   /* Table functionalities */

   var foodTableTitles = {
      name: "Name",
      time: "Time",
      portions: "Portions",
      effort: "Effort"
   };

   // creates a sortable table with no data
   var resultTable = new eatables.table("foods", null, foodTableTitles, 
      true, function (err) {

      if(err) {
         console.log("result table craetion error: " + err);
         return;
      }

      // only adds the destination function if table is created
      // an unfortunate side effect of using socket.io instead of ajax
      dataHandler.onResponse('type_request', function (data) {
            console.log("got response");

            if(resultTable) 
               resultTable.changeData(data.results); 
      });
   });

   resultTable.onClick("tr", function (data) {
      console.log("got data");
      var alaotsikko = data.type + " / " + data.effort;
      foodInfo.change("h2.otsikko", "text", data.name);
      foodInfo.change("h3.alaotsikko", "text", alaotsikko);
      foodInfo.change("td#time", "text", data.time || "-"),
      foodInfo.change("td#portions", "text", data.portions || "-");
      foodInfo.change("td#recipe", "text", data.recipe || "-");
   });
{'fraction_non_alphanumeric': 0.15153115100316789, 'fraction_numerical': 0.01003167898627244, 'mean_word_length': 2.2219387755102042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4987213', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1104, 'n_words': 259}