NEW: @@@LABEL@@@ in view HTML is replaced by view's label attribute

This commit is contained in:
Jan-Piet Mens
2022-08-04 23:21:44 +02:00
parent 61f5ec20e8
commit dbb4dc2b08
3 changed files with 17 additions and 1 deletions
+1
View File
@@ -770,6 +770,7 @@ The `page` is a single HTML file which must be located in the `views/` directory
* `@@@LASTPOS@@@` is converted to a URI on which the Recorder will serve the last position data
* `@@@GEO@@@` is converted to a URI on which the Recorder will serve GeoJSON data from its storage.
* `@@@LABEL@@@` is replaced with the `label` attribute from the page's JSON or the empty string if that doesn't exist.
The default `page` we provide is called `vmap.html`; by default it refreshes the last position every 60 seconds, and clicking on "Load track" loads the GeoJSON track for the time frame specified by `from` and `to`.
+1 -1
View File
@@ -2,7 +2,7 @@
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>OwnTracks View</title>
<title>OwnTracks @@@LABEL@@@</title>
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
+15
View File
@@ -985,6 +985,21 @@ static int view(struct mg_connection *conn, const char *viewname)
viewname, // conn->uri,
p+strlen("@@@LASTPOS@@@"));
mg_printf_data(conn, "%s", UB(sbuf));
} else if ((p = strstr(buf, "@@@LABEL@@@")) != NULL) {
char *label;
JsonNode *t;
if ((t = json_find_member(view, "label")) == NULL) {
label = "";
} else {
label = t->string_;
}
*p = 0;
utstring_clear(sbuf);
utstring_printf(sbuf, "%s%s%s",
buf,
label,
p+strlen("@@@LABEL@@@"));
mg_printf_data(conn, "%s", UB(sbuf));
} else {
mg_printf_data(conn, "%s", buf);
}