From 7c31fb286aed3b378d5bad928a26bf85ffdb5f04 Mon Sep 17 00:00:00 2001
From: Robert Sirre
Date: Sat, 15 Feb 2020 22:54:49 +0100
Subject: [PATCH] Implemented export of config as JSON
---
settings/settings-UI.html | 116 +++++++++++++++++++++++++++++++++++++-
settings/settings.jsonc | 91 ++++++++++++++++++++++++++++++
2 files changed, 204 insertions(+), 3 deletions(-)
create mode 100644 settings/settings.jsonc
diff --git a/settings/settings-UI.html b/settings/settings-UI.html
index f409d64..be05509 100644
--- a/settings/settings-UI.html
+++ b/settings/settings-UI.html
@@ -351,7 +351,8 @@ python3 /home/pi/Inky-Calendar/modules/inkycal.py.
-
+
+
Developed by Toby Chui for Inky-Calendar Project, modified by aceisace. Licensed under MIT
@@ -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);
+ }