Skip to content

Commit

Permalink
add systemName to layoutturnout
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjacobsen authored and mstevetodd committed Aug 20, 2019
1 parent 51deba3 commit 1c923a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 18 additions & 4 deletions java/src/jmri/web/servlet/panel/LayoutPanelServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import jmri.InstanceManager;
import jmri.Sensor;
import jmri.SensorManager;
import jmri.Turnout;
import jmri.TurnoutManager;
import jmri.jmrit.display.Positionable;
import jmri.jmrit.display.layoutEditor.LayoutBlock;
import jmri.jmrit.display.layoutEditor.LayoutBlockManager;
import jmri.jmrit.display.layoutEditor.LayoutEditor;
import jmri.jmrit.display.layoutEditor.LayoutTrack;
import jmri.util.ColorUtil;

import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
Expand Down Expand Up @@ -88,8 +92,8 @@ protected String getXmlPanel(String name) {
}

// include LayoutBlocks
LayoutBlockManager tm = InstanceManager.getDefault(LayoutBlockManager.class);
java.util.Iterator<LayoutBlock> iter = tm.getNamedBeanSet().iterator();
LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
java.util.Iterator<LayoutBlock> iter = lbm.getNamedBeanSet().iterator();
SensorManager sm = InstanceManager.sensorManagerInstance();
int num = 0;
while (iter.hasNext()) {
Expand All @@ -100,7 +104,7 @@ protected String getXmlPanel(String name) {
}
if (b.getUseCount() > 0) {
// save only those LayoutBlocks that are in use--skip abandoned ones
Element elem = new Element("layoutblock").setAttribute("systemname", b.getSystemName());
Element elem = new Element("layoutblock").setAttribute("systemName", b.getSystemName());
String uname = b.getUserName();
if (uname != null && !uname.isEmpty()) {
elem.setAttribute("username", uname);
Expand Down Expand Up @@ -137,18 +141,28 @@ protected String getXmlPanel(String name) {
log.debug("Number of layoutblock elements: {}", num);

// include LayoutTracks
TurnoutManager tm = InstanceManager.turnoutManagerInstance();
List<LayoutTrack> layoutTracks = editor.getLayoutTracks();
for (Object sub : layoutTracks) {
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
if (e.getName() == "layoutturnout") { // add turnout systemName for layoutturnout
Attribute tna = e.getAttribute("turnoutname");
if (tna != null) {
Turnout t = tm.getTurnout(tna.getValue());
if (t != null) {
e.setAttribute("systemName", t.getSystemName());
}
}
}
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel LayoutTrack element: " + e);
}
}
log.debug("Number of layoutblock elements: {}", layoutTracks.size());
log.debug("Number of LayoutTrack elements: {}", layoutTracks.size());

//write out formatted document
Document doc = new Document(panel);
Expand Down
10 changes: 6 additions & 4 deletions web/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ function processPanelXML($returnedData, $success, $xhr) {
// icon names based on states returned from JSON server,
$widget['state'] = UNKNOWN; //initial state is unknown
$widget.jsonType = ""; //default to no JSON type (avoid undefined)
if (typeof $widget["id"] !== "undefined") {
$widget.systemName = $widget["id"];

if ((typeof $widget["systemName"] == "undefined") && //set systemName from id if missing
(typeof $widget["id"] !== "undefined")) {
$widget.systemName = $widget["id"];
}
$widget["id"] = "widget-" + $gUnique(); //set id to a unique value (since same element can be in multiple widgets)
$widget['widgetFamily'] = $getWidgetFamily($widget, this);
Expand Down Expand Up @@ -579,8 +581,8 @@ function processPanelXML($returnedData, $success, $xhr) {
//store these blocks in a persistent var
//by both username and systemname since references may be by either
$gBlks[$widget.username] = $widget
$gBlks[$widget.systemname] = $widget;
jmri.getLayoutBlock($widget.systemname);
$gBlks[$widget.systemName] = $widget;
jmri.getLayoutBlock($widget.systemName);
break;
case "layoutturnout" :
$widget['name'] = $widget.turnoutname; //normalize name
Expand Down

0 comments on commit 1c923a1

Please sign in to comment.