Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Reload BasicUI if sitemap has been changed #3846

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,10 @@ public void modelChanged(String modelName, EventType type) {
for (Entry<String, PageChangeListener> listenerEntry : pageChangeListeners.entrySet()) {
String sitemapWithPage = listenerEntry.getKey();
String sitemapName = extractSitemapName(sitemapWithPage);
String pageId = extractPageId(sitemapWithPage);

if (sitemapName.equals(changedSitemapName)) {
EList<Widget> widgets = collectWidgets(sitemapName, pageId);
listenerEntry.getValue().sitemapContentChanged(widgets);
listenerEntry.getValue().sitemapContentChanged();
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,13 @@ private boolean definesVisibility(Widget w, String name) {
return false;
}

public void sitemapContentChanged(EList<Widget> widgets) {
updateItemsAndWidgets(widgets);
public void sitemapContentChanged() {
SitemapChangedEvent changeEvent = new SitemapChangedEvent();
changeEvent.pageId = pageId;
changeEvent.sitemapName = sitemapName;
for (SitemapSubscriptionCallback callback : distinctCallbacks) {
callback.onEvent(changeEvent);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.io.rest.sitemap.internal;

/**
* Event to notify the browser that the sitemap has been changed
*
* @author Stefan Triller - Initial Contribution
*
*/
public class SitemapChangedEvent extends SitemapEvent {
public final String TYPE = "SITEMAP_CHANGED";
}
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,15 @@ public Widget getWidget(Sitemap sitemap, String id) {
w.setItem(id);
} else {
try {
w = sitemap.getChildren().get(Integer.valueOf(id.substring(0, 2)));
for (int i = 2; i < id.length(); i += 2) {
w = ((LinkableWidget) w).getChildren().get(Integer.valueOf(id.substring(i, i + 2)));
int widgetID = Integer.valueOf(id.substring(0, 2));
if (widgetID < sitemap.getChildren().size()) {
w = sitemap.getChildren().get(widgetID);
for (int i = 2; i < id.length(); i += 2) {
int childWidgetID = Integer.valueOf(id.substring(i, i + 2));
if (childWidgetID < ((LinkableWidget) w).getChildren().size()) {
w = ((LinkableWidget) w).getChildren().get(childWidgetID);
}
}
}
} catch (NumberFormatException e) {
// no valid number, so the requested page id does not exist
Expand Down
10 changes: 10 additions & 0 deletions extensions/ui/org.eclipse.smarthome.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,16 @@
value,
title;

if (data.TYPE === "SITEMAP_CHANGED") {
var oldLocation = window.location.href;
var parts = oldLocation.split("?");
if (parts.length > 1) {
window.location.href = parts[0] + "?sitemap="+data.sitemapName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces:

"?sitemap=" + data

} else {
window.location.href = oldLocation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.location.reload(true);

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


_t.pause();
return;

}

if (!(data.widgetId in smarthome.dataModel) && (data.widgetId !== smarthome.UI.page)) {
return;
}
Expand Down

Large diffs are not rendered by default.