Implemented export of config as JSON
This commit is contained in:
		| @@ -351,7 +351,8 @@ python3 /home/pi/Inky-Calendar/modules/inkycal.py.</p> | ||||
|  | ||||
|     </form> | ||||
|     <br> | ||||
|     <button class="ts primary button" onClick="generate();">Generate</button> | ||||
|     <button class="ts primary button" onClick="generate(false);">Generate</button> | ||||
|     <button class="ts secondary button" onClick="generate(true);">Generate (as JSON, experimental)</button> | ||||
|   <br><br> | ||||
|   <kbd>Developed by Toby Chui for Inky-Calendar Project, modified by aceisace. Licensed under MIT</kbd> | ||||
|   <details class="ts accordion"> | ||||
| @@ -398,7 +399,7 @@ inkycal_image_path_body = "{image_path_body}"`; | ||||
|     } | ||||
|   }); | ||||
|  | ||||
|   function generate(){ | ||||
|   function generate(json){ | ||||
|     var ical_urls = $("#ical_urls").val().trim(); | ||||
|     if (ical_urls == ""){ | ||||
|       ical_urls = $("#ical_urls").attr("placeholder"); | ||||
| @@ -558,7 +559,10 @@ inkycal_image_path_body = "{image_path_body}"`; | ||||
|     var image_path_body = $("#image_path").val().trim(); | ||||
|  | ||||
|     //console.log(ical_urls, rss_urls, update_interval, api_key, location, week_starts_on, calibration_hours, model, language, units, hours, top_section, middle_section, bottom_section); | ||||
|     createPythonSetting(ical_urls, rss_urls, update_interval, api_key, location, week_starts_on, calibration_hours, model, language, units, hours, top_section, middle_section, bottom_section, image_path, image_path_body); | ||||
|     if(json) | ||||
|       downloadSettingsAsJson(ical_urls, rss_urls, update_interval, api_key, location, week_starts_on, calibration_hours, model, language, units, hours, top_section, middle_section, bottom_section, image_path, image_path_body) | ||||
|     else | ||||
|       createPythonSetting(ical_urls, rss_urls, update_interval, api_key, location, week_starts_on, calibration_hours, model, language, units, hours, top_section, middle_section, bottom_section, image_path, image_path_body); | ||||
|   } | ||||
|    | ||||
|   function rk(content,key,value){ | ||||
| @@ -596,6 +600,112 @@ inkycal_image_path_body = "{image_path_body}"`; | ||||
|     a.click(); | ||||
|     document.body.removeChild(a); | ||||
|   } | ||||
|  | ||||
|   function TrimSingleQuotes(text){ | ||||
|       return text.replace(/^'+/g,"").replace(/'+$/g,"") | ||||
|   } | ||||
|  | ||||
|   function downloadSettingsAsJson( | ||||
|     ical_urls, | ||||
|     rss_urls, | ||||
|     update_interval, | ||||
|     api_key, | ||||
|     location, | ||||
|     week_starts_on, | ||||
|     calibration_hours, | ||||
|     model, | ||||
|     language, | ||||
|     units, | ||||
|     hours, | ||||
|     top_section, | ||||
|     middle_section, | ||||
|     bottom_section, | ||||
|     image_path, | ||||
|     image_path_body | ||||
|   ) { | ||||
|     var result = { | ||||
|       "language"          : language,               // "en", "de", "fr", "jp" etc. | ||||
|       "units"             : units,               // "metric", "imperial" | ||||
|       "hours"             : Number(hours),       // 24, 12 | ||||
|       "model"             : model, | ||||
|       "update_interval"   : Number(update_interval),       // 10, 15, 20, 30, 60 | ||||
|       "calibration_hours" : calibration_hours.split(",").map(function(x){ return Number(x);}),              // Do not change unless you know what you are doing | ||||
|       "panels" : [] | ||||
|     }; | ||||
|  | ||||
|     switch(top_section){ | ||||
|       case "inkycal_weather": | ||||
|         result.panels.push( | ||||
|           { | ||||
|             "location"  : "top", | ||||
|             "type"      : "inkycal_weather", | ||||
|             "config"    : { | ||||
|                 "api_key"  : api_key,     //Your openweathermap API-KEY -> "api-key" | ||||
|                 "location" : location      //"City name, Country code" | ||||
|             } | ||||
|           } | ||||
|         ) | ||||
|         break; | ||||
|       default: | ||||
|         break; | ||||
|     } | ||||
|  | ||||
|     switch(middle_section){ | ||||
|       case "inkycal_agenda": | ||||
|       case "inkycal_calendar": | ||||
|         result.panels.push( | ||||
|           { | ||||
|             "location"  : "middle", | ||||
|             "type"      : middle_section, | ||||
|             "config"    : { | ||||
|                 "week_starts_on" : week_starts_on,    //"Sunday", "Monday"... | ||||
|                 "ical_urls"  : ical_urls.split().map(function(x){ return TrimSingleQuotes(x);}) | ||||
|             } | ||||
|           } | ||||
|         ) | ||||
|         break; | ||||
|       case "inkycal_image": | ||||
|         result.panels.push( | ||||
|           { | ||||
|             "location"  : "middle", | ||||
|             "type"      : middle_section, | ||||
|             "config"    : { | ||||
|                 "image_path"  : TrimSingleQuotes(image_path), | ||||
|                 "image_path_body" : image_path_body | ||||
|             } | ||||
|           } | ||||
|         ) | ||||
|         break; | ||||
|       default: | ||||
|         break; | ||||
|     } | ||||
|  | ||||
|     switch(bottom_section){ | ||||
|       case "inkycal_rss": | ||||
|         result.panels.push( | ||||
|           { | ||||
|             "location"  : "bottom", | ||||
|             "type"      : bottom_section, | ||||
|             "config"    : { | ||||
|                 "rss_urls"  : rss_urls.split().map(function(x){ return TrimSingleQuotes(x);}) | ||||
|             } | ||||
|           } | ||||
|         ) | ||||
|         break; | ||||
|       default: | ||||
|         break; | ||||
|     } | ||||
|     var config = new Blob([JSON.stringify(result, null, "\t")], {type : "text/json"}); | ||||
|     var link = document.createElement('link'); | ||||
|     link.href = window.URL.createObjectURL(config); | ||||
|     var a = document.createElement('A'); | ||||
|     a.href = link.href; | ||||
|     a.download = link.href.substr(link.href.lastIndexOf('/') + 1); | ||||
|     document.body.appendChild(a); | ||||
|     $(a).attr('download','settings.jsonc'); | ||||
|     a.click(); | ||||
|     document.body.removeChild(a); | ||||
|   } | ||||
|    | ||||
|   </script> | ||||
| </body> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user