Code cleanup

Sat, 06 Aug 2022 20:23:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 06 Aug 2022 20:23:33 +0200
changeset 827
5df0d11ca02b
parent 826
4e681bc073bd
child 828
aa0a9b1a2dd7

Code cleanup

www/js/prod_edit.js file | annotate | diff | comparison | revisions
--- a/www/js/prod_edit.js	Sat Aug 06 19:50:21 2022 +0200
+++ b/www/js/prod_edit.js	Sat Aug 06 20:23:33 2022 +0200
@@ -1148,7 +1148,9 @@
     calcViability();
     calcYeast();
     kookTijd();
-//    calcInit();
+    $('#FLog').jqxButton({ disabled: (dataRecord.log_fermentation) ? false : true});
+    $('#ILog').jqxButton({ disabled: (dataRecord.log_ispindel) ? false : true});
+    $('#CLog').jqxButton({ disabled: (dataRecord.log_co2pressure) ? false : true});
     console.log('calculations ready');
     $('#jqxLoader').jqxLoader('close');
     $('#jqxTabs').jqxTabs('first');
@@ -2178,63 +2180,6 @@
   calcSupplies();
  };
 
- function calcMashEfficiency() {
-  var c, m;
-  if (parseFloat($('#brew_mash_sg').jqxNumberInput('decimal')) < 1.002)
-   return;
-  c = sg_to_plato(est_mash_sg);
-  m = sg_to_plato(parseFloat($('#brew_mash_sg').jqxNumberInput('decimal')));
-  if (c > 0.5)
-   $('#brew_mash_efficiency').val(100 * m / c);
-  else
-   $('#brew_mash_efficiency').val(0);
- };
-
- function calcEfficiencyBeforeBoil() {
-  var m = 0, i, row, tot, result = 0;
-  if (!($('#fermentableGrid').jqxGrid('getrows')))
-   return; // no grid loaded yet
-  if (dataRecord.fermentables.length == 0)
-   return; // no fermentables
-  for (i = 0; i < dataRecord.fermentables.length; i++) {
-   row = dataRecord.fermentables[i];
-   if (row.f_added == 0) { // Mash
-    m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-   }
-  }
-  tot = sg_to_plato(dataRecord.brew_preboil_sg) * (dataRecord.brew_preboil_volume / 1.04) * dataRecord.brew_preboil_sg * 10 / 1000;
-  if (m > 0)
-   result = Round((tot / m * 100), 1);
-  if (result < 0)
-   result = 0;
-  $('#brew_preboil_efficiency').val(result);
- }
-
- function calcEfficiencyAfterBoil() {
-  var m = 0, // Sugars added at mash
-  b = 0,     // Sugars added at boil
-  i, row, tot, result = 0;
-  if (!($('#fermentableGrid').jqxGrid('getrows'))) {
-   return; // grid not yet loaded.
-  }
-  for (i = 0; i < dataRecord.fermentables.length; i++) {
-   row = dataRecord.fermentables[i];
-   if (row.f_added == 0) { // Mash
-    m += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-   } else if (row.f_added == 1) { // Boil
-    b += row.f_amount * (row.f_yield / 100) * (1 - row.f_moisture / 100);
-   }
-  }
-  tot = sg_to_plato(dataRecord.brew_aboil_sg) * (dataRecord.brew_aboil_volume / 1.04) * dataRecord.brew_aboil_sg * 10 / 1000;
-  tot -= b;       // total sugars in wort  minus added sugars.
-  if (m > 0)
-   result = Round((tot / m * 100), 1);
-  if (result < 0)
-   result = 0;
-  dataRecord.brew_aboil_efficiency = result;
-  $('#brew_aboil_efficiency').val(result);
- }
-
  function GetBUGU() {
   var gu = (dataRecord.est_og - 1) * 1000;
   if (gu > 0)
@@ -2984,165 +2929,18 @@
   }
  }
 
- function en_stage_brewday(state) {
-  $('#jqxTabs').jqxTabs((state) ? 'disableAt':'enableAt', 8);	// Brewday tab
- }
-
- function en_stage_afterbrew(state) {
-  $('#jqxTabs').jqxTabs((state) ? 'enableAt':'disableAt', 9);	// Fermentation tab
- }
-
- function en_stage_tertiary(state) {
-  $('#package_date').jqxDateTimeInput({ disabled: (state) ? false:true });
- }
-
- function en_stage_aftertertiary(state) {
-
-  var spinstate = { spinButtons: (state) ? false:true, readOnly: (state) ? true:false, width: (state) ? 90:110 };
-
-  $('#primary_start_temp').jqxNumberInput(spinstate);
-  $('#primary_max_temp').jqxNumberInput(spinstate);
-  $('#primary_end_temp').jqxNumberInput(spinstate);
-  $('#primary_end_sg').jqxNumberInput(spinstate);
-  $('#primary_end_brix').jqxNumberInput(spinstate);
-  $('#primary_end_date').jqxDateTimeInput({ disabled: (state) ? true:false });
- }
-
- function en_stage_afterpackaging(state) {
-
-  var onval = { disabled: (state) ? true:false };
-  var spinstate = { spinButtons: (state) ? false:true, readOnly: (state) ? true:false, width: (state) ? 90:110 };
-
-  $('#secondary_temp').jqxNumberInput(spinstate);
-  $('#secondary_end_sg').jqxNumberInput(spinstate);
-  $('#secondary_end_date').jqxDateTimeInput(onval);
-  $('#secondary_end_brix').jqxNumberInput(spinstate);
-  $('#tertiary_temp').jqxNumberInput(spinstate);
-  $('#fg').jqxNumberInput(spinstate);
-  $('#final_brix').jqxNumberInput(spinstate);
-  $('#package_date').jqxDateTimeInput(onval);
-  $('#package_volume').jqxNumberInput(spinstate);
-  $('#package_infuse_amount').jqxNumberInput(spinstate);
-  $('#package_infuse_abv').jqxNumberInput(spinstate);
-  $('#package_infuse_notes').jqxInput(onval);
-  $('#package_ph').jqxNumberInput(spinstate);
-  $('#bottle_amount').jqxNumberInput(spinstate);
-  $('#bottle_priming_water').jqxNumberInput(spinstate);
-  $('#keg_priming_water').jqxNumberInput(spinstate);
-  $('#keg_amount').jqxNumberInput(spinstate);
-  $('#bottle_carbonation').jqxNumberInput(spinstate);
-  $('#keg_carbonation').jqxNumberInput(spinstate);
-  $('#bottle_priming_sugar').jqxDropDownList(onval);
-  $('#keg_priming_sugar').jqxDropDownList(onval);
-  $('#keg_forced_carb').jqxCheckBox(onval);
-  $('#bottle_carbonation_temp').jqxNumberInput(spinstate);
-  $('#keg_carbonation_temp').jqxNumberInput(spinstate);
- }
-
- function en_stage_b4taste(state) {
-  $('#jqxTabs').jqxTabs((state) ? 'disableAt':'enableAt', 11); // Tasting tab
- }
-
- function en_stage_locked(state) {
-
-  var onval = { disabled: (state) ? true:false };
-
-  $('#taste_date').jqxDateTimeInput(onval);
-  $('#taste_rate').jqxNumberInput({ spinButtons: (state) ? false:true, readOnly: (state) ? true:false, width: (state) ? 90:110 });
-  $('#taste_color').jqxInput(onval);
-  $('#taste_transparency').jqxInput(onval);
-  $('#taste_head').jqxInput(onval);
-  $('#taste_aroma').jqxInput(onval);
-  $('#taste_taste').jqxInput(onval);
-  $('#taste_aftertaste').jqxInput(onval);
-  $('#taste_mouthfeel').jqxInput(onval);
-  $('#taste_notes').jqxInput(onval);
-  $('#notes').jqxInput(onval);
- }
-
  function calcStage() {
-
-  var newstage = dataRecord.stage, d, date1, date2, date1_unixtime, date2_unixtime, timeDifference, timeDifferenceInDays;
-
-  if (newstage == 0 && dataRecord.est_og > 1.005 && dataRecord.est_color > 3 && dataRecord.est_ibu > 3)
-   newstage = 1;
-  if (newstage == 1 && parseFloat($('#brew_date_start').val()) > 2000)
-   newstage = 2;   // Brewday
-  if (newstage == 2 && ($('#brew_date_start').val() == ''))
-   newstage = 1;   // No brewday
-  if (newstage == 2 && parseFloat(dataRecord.brew_date_end) > 2000)
-   newstage = 3;   // Primary
-  if (newstage == 3 && parseFloat(dataRecord.primary_end_date) > 2000)
-   newstage = 4;   // Secondary
-  if (newstage == 4 && parseFloat(dataRecord.secondary_end_date) > 2000)
-   newstage = 5;   // Tertiary
-  if (newstage == 5 && parseFloat(dataRecord.package_date) > 2000)
-   newstage = 6;   // Package
-  if (newstage >= 6 && newstage < 9) {
-   d = new Date();
-   date2 = dataRecord.package_date;
-   date2 = date2.split('-');
-   // Now we convert the array to a Date object
-   date1 = new Date(d.getFullYear(), d.getMonth(), d.getDate());
-   date2 = new Date(date2[0], date2[1] - 1, date2[2]);
-   // We use the getTime() method and get the unixtime
-   date1_unixtime = parseInt(date1.getTime() / 1000);
-   date2_unixtime = parseInt(date2.getTime() / 1000);
-   // This is the calculated difference in seconds
-   timeDifference = date1_unixtime - date2_unixtime;
-   timeDifferenceInDays = timeDifference / 60 / 60 / 24;
-   if (timeDifferenceInDays > 0) {                 // At least one day
-    if (timeDifferenceInDays >= 42)         // 6 weeks
-     newstage = 9;                   // Ready to taste
-    else if (timeDifferenceInDays >= 14)    // 14 days
-     newstage = 8;                   // Mature
-    else
-     newstage = 7;                   // Carbonation
-   }
-  }
-  if (newstage == 9 && parseFloat(dataRecord.taste_date) > 2000)
-   newstage = 10;  // Ready
-
-  if (newstage != dataRecord.stage) {
-   console.log('calcStage() old: ' + dataRecord.stage + ' new: ' + newstage);
-   dataRecord.stage = newstage;
-  }
-
   /*
    * Set stage and enable or disable parts of the screens.
    */
   $('#stage').val(StageData[dataRecord.stage].nl);
-  if (dataRecord.stage >= 10) {
-   $('#locked').jqxCheckBox({ disabled: false });
-  }
 
   /*
    * Enable or disable parts of the screens.
    */
-  en_stage_brewday(dataRecord.stage < 1);		// Planning, no ingredients
-  en_stage_afterbrew(dataRecord.stage > 2);		// After the brew
-  en_stage_tertiary(dataRecord.stage == 5);		// Tertiary, allow packaging
-  en_stage_aftertertiary(dataRecord.stage >= 5);	// After all fermentation steps
-  en_stage_afterpackaging(dataRecord.stage >= 6);	// After packaging
-  en_stage_b4taste(dataRecord.stage < 9);		// Taste when at least Mature.
-  en_stage_locked(dataRecord.stage == 11);		// Locked.
- }
-
- function calcInit() {
-
-  console.log('** calcInit() start');
-  calcMashEfficiency();
-  calcEfficiencyBeforeBoil();
-  calcEfficiencyAfterBoil();
-  calcWater();
-  calcFermentation();
-//  calcCarbonation();
-  calcIBUs();
-  $('#BLog').jqxButton({ disabled: (dataRecord.log_brew) ? false : true});
-  $('#FLog').jqxButton({ disabled: (dataRecord.log_fermentation) ? false : true});
-  $('#ILog').jqxButton({ disabled: (dataRecord.log_ispindel) ? false : true});
-  $('#CLog').jqxButton({ disabled: (dataRecord.log_co2pressure) ? false : true});
-  console.log('** calcInit() ready');
+  $('#jqxTabs').jqxTabs((dataRecord.stage < 1) ? 'disableAt':'enableAt', 8);   // Brewday tab
+  $('#jqxTabs').jqxTabs((dataRecord.stage > 2) ? 'enableAt':'disableAt', 9);   // Fermentation tab
+  $('#jqxTabs').jqxTabs((dataRecord.stage < 9) ? 'disableAt':'enableAt', 11); // Tasting tab
  }
 
 

mercurial