Browse code

Make bundling parameters configurable

Natasha Kerensikova authored on13/04/2016 23:34:20
Showing2 changed files
... ...
@@ -38,11 +38,23 @@
38 38
     var options = {
39 39
       "url": document.getElementById("url").value,
40 40
       "dataField": document.getElementById("dataField").value,
41
+      "bundleMax": document.getElementById("bundleMaxSize").value,
42
+      "bundleSeparator": encodeURIComponent(document.getElementById("bundleSeparator").value),
43
+    }
44
+
45
+    if (!document.getElementById("bundleEnable").checked) {
46
+       options.bundleMax = "1";
41 47
     }
42 48
 
43 49
     console.log("returning " + JSON.stringify(options));
44 50
     document.location = return_to + encodeURIComponent(JSON.stringify(options));
45 51
   }
52
+
53
+  function updateBundleVisibility() {
54
+    document.getElementById("bundleFields").style.display
55
+     = document.getElementById("bundleEnable").checked
56
+     ? "block" : "none";
57
+  }
46 58
   </script>
47 59
 </head>
48 60
 <body>
... ...
@@ -68,6 +80,30 @@
68 80
     </div>
69 81
   </div>
70 82
 
83
+  <div class="item-container">
84
+    <div class="item-container-header">Data Bundling</div>
85
+    <div class="item-container-content">
86
+      <label class="item">
87
+        Enable Data Bundling
88
+        <input type="checkbox" class="item-toggle" name="bundleEnable" id="bundleEnable" onchange="updateBundleVisibility();">
89
+      </label>
90
+      <div id=bundleFields>
91
+        <label class="item">
92
+          Max Bundle Size
93
+          <div class="item-input-wrapper item-slider-text">
94
+            <input type="text" class="item-input" name="bundleMaxSize" id="bundleMaxSize" value="1">
95
+          </div>
96
+        </label>
97
+        <label class="item">
98
+          Line Separator
99
+          <div class="item-input-wrapper">
100
+            <input type="text" class="item-input" name="bundleSeparator" id="bundleSeparator" placeholder="%0d%0a">
101
+          </div>
102
+        </label>
103
+      </div>
104
+    </div>
105
+  </div>
106
+
71 107
   <div class="item-container">
72 108
     <div class="button-container">
73 109
       <input id="submitButton" type="button" class="item-button" value="SUBMIT" onClick="onSubmit()">
... ...
@@ -80,8 +116,16 @@
80 116
     if (versionTag) {
81 117
       document.getElementsByTagName("h1")[0].childNodes[0].nodeValue = "Health Export " + versionTag;
82 118
     }
119
+
120
+    var initBundleSize = parseInt(getQueryParam("bundle_max", "1"), 10);
121
+    if (!(initBundleSize >= 1)) initBundleSize = 1;
122
+
83 123
     document.getElementById("url").value = getQueryParam("url", "");
84 124
     document.getElementById("dataField").value = getQueryParam("data_field", "");
125
+    document.getElementById("bundleEnable").checked = (initBundleSize > 1);
126
+    document.getElementById("bundleMaxSize").value = initBundleSize;
127
+    document.getElementById("bundleSeparator").value = encodeURIComponent(getQueryParam("bundle_sep", ""));
128
+    updateBundleVisibility();
85 129
   </script>
86 130
 </body>
87 131
 </html>
... ...
@@ -16,7 +16,7 @@
16 16
 
17 17
 var cfg_endpoint = null;
18 18
 var cfg_data_field = null;
19
-var cfg_bundle_max = 30;
19
+var cfg_bundle_max = 1;
20 20
 var cfg_bundle_separator = "\r\n";
21 21
 
22 22
 var to_send = [];
... ...
@@ -78,6 +78,10 @@ Pebble.addEventListener("ready", function() {
78 78
 
79 79
    cfg_endpoint = localStorage.getItem("cfgEndpoint");
80 80
    cfg_data_field = localStorage.getItem("cfgDataField");
81
+   cfg_bundle_max = parseInt(localStorage.getItem("cfgBundleMax") || "1", 10);
82
+   cfg_bundle_separator = localStorage.getItem("cfgBundleSeparator");
83
+
84
+   if (!(cfg_bundle_max >= 1)) cfg_bundle_max = 1;
81 85
 
82 86
    var msg = {};
83 87
 
... ...
@@ -113,6 +117,12 @@ Pebble.addEventListener("showConfiguration", function() {
113 117
    if (cfg_data_field) {
114 118
       settings += "&data_field=" + encodeURIComponent(cfg_data_field);
115 119
    }
120
+   if (cfg_bundle_max) {
121
+      settings += "&bundle_max=" + encodeURIComponent(cfg_bundle_max);
122
+   }
123
+   if (cfg_bundle_separator) {
124
+      settings += "&bundle_sep=" + encodeURIComponent(cfg_bundle_separator);
125
+   }
116 126
 
117 127
    Pebble.openURL("https://cdn.rawgit.com/faelys/pebble-health-export/v1.0/config.html" + settings);
118 128
 });
... ...
@@ -131,6 +141,16 @@ Pebble.addEventListener("webviewclosed", function(e) {
131 141
       localStorage.setItem("cfgDataField", cfg_data_field);
132 142
    }
133 143
 
144
+   if (configData.bundleMax) {
145
+      cfg_bundle_max = parseInt(configData.bundleMax, 10);
146
+      if (!(cfg_bundle_max >= 1)) cfg_bundle_max = 1;
147
+      localStorage.setItem("cfgBundleMax", cfg_bundle_max);
148
+   }
149
+   if (configData.bundleSeparator) {
150
+      cfg_bundle_separator = decodeURIComponent(configData.bundleSeparator);
151
+      localStorage.setItem("cfgBundleSeparator", cfg_bundle_separator);
152
+   }
153
+
134 154
    if (!wasConfigured && cfg_endpoint && cfg_data_field) {
135 155
       Pebble.sendAppMessage({ "lastSent": 0 });
136 156
    }