Skip to content

Commit 5705c80

Browse files
authored
Merge pull request #2347 from vitorrm/feature/add-skin-to-navigate
Feature/add skin to navigate
2 parents 260f369 + c5a5d34 commit 5705c80

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

appdaemon/adapi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3475,7 +3475,7 @@ def dash_navigate(
34753475
sticky: int = 0,
34763476
deviceid: str | None = None,
34773477
dashid: str | None = None,
3478-
) -> None:
3478+
skin: str | None = None) -> None:
34793479
"""Forces all connected Dashboards to navigate to a new URL.
34803480
34813481
Args:
@@ -3496,6 +3496,7 @@ def dash_navigate(
34963496
dashid (str): If set, all devices currently on a dashboard which the title contains
34973497
the substring dashid will navigate. ex: if dashid is "kichen", it will match
34983498
devices which are on "kitchen lights", "kitchen sensors", "ipad - kitchen", etc.
3499+
skin (str): If set, the skin will change to the skin defined on the param.
34993500
35003501
Returns:
35013502
None.
@@ -3518,6 +3519,8 @@ def dash_navigate(
35183519
kwargs["deviceid"] = deviceid
35193520
if dashid is not None:
35203521
kwargs["dashid"] = dashid
3522+
if skin is not None:
3523+
kwargs["skin"] = skin
35213524
self.fire_event("ad_dashboard", timeout=timeout, **kwargs)
35223525

35233526
#

appdaemon/assets/javascript/dashboard.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ function setCookie(cname, cvalue) {
1818
document.cookie = cname + "=" + cvalue + "; expires=Sat, 1 Jan 2050 12:00:00 UTC;";
1919
}
2020

21+
function getQueryStringParams() {
22+
var query = location.search.substring(1);
23+
// Parse existing query string if it exists
24+
var query_params = [];
25+
if (query) {
26+
query_params = query.split('&');
27+
}
28+
return query_params;
29+
}
30+
31+
function setQueryStringParam(query_params, param_name, new_value) {
32+
// Remove existing parameter if present
33+
for (var i = 0; i < query_params.length; i++) {
34+
if (query_params[i].startsWith(param_name + "=")) {
35+
query_params.splice(i, 1);
36+
break;
37+
}
38+
}
39+
// Add new parameter
40+
var param = param_name + "=" + encodeURIComponent(new_value);
41+
query_params.push(param);
42+
return query_params;
43+
}
44+
2145
function get_monitored_entities(widgets)
2246
{
2347
index = 0;
@@ -103,38 +127,21 @@ var DashStream = function(transport, protocol, domain, port, title, widgets)
103127
{
104128
if (data.data.command === "navigate")
105129
{
106-
var timeout_params = "";
130+
var query_params = getQueryStringParams();
131+
if ("skin" in data.data)
132+
{
133+
query_params = setQueryStringParam(query_params, "skin", data.data.skin)
134+
}
107135
if ("timeout" in data.data)
108136
{
109-
var timeout = data.data.timeout;
110-
if (location.search === "")
111-
{
112-
timeout_params = "?";
113-
}
114-
else
115-
{
116-
timeout_params = "&";
117-
}
118-
if ("return" in data.data)
119-
{
120-
ret = data.data.return
121-
}
122-
else
123-
{
124-
ret = location.pathname
125-
}
126-
if ("sticky")
127-
{
128-
sticky = data.data.sticky;
129-
}
130-
else
131-
{
132-
sticky = 0;
133-
}
134-
135-
timeout_params += "timeout=" + timeout + "&return=" + ret + "&sticky=" + sticky;
137+
query_params.push("timeout=" + data.data.timeout)
138+
var ret = "return" in data.data ? data.data.return : location.pathname
139+
query_params.push("return=" + ret)
140+
query_params.push("sticky=" + data.data.sticky)
136141
}
137-
window.location.href = data.data.target + location.search + timeout_params;
142+
// Rebuild query string with existing params
143+
var new_query_params = query_params.length > 0 ? "?" + query_params.join("&") : "";
144+
window.location.href = data.data.target + new_query_params;
138145
}
139146
}
140147
Object.keys(widgets).forEach(function (key) {

0 commit comments

Comments
 (0)