Skip to content
Permalink
Browse files

add systemName to layoutturnout

  • Loading branch information...
bobjacobsen authored and mstevetodd committed Aug 20, 2019
1 parent 51deba3 commit 1c923a16016356741f0e8b513082e7e2d3bc62f9
Showing with 24 additions and 8 deletions.
  1. +18 −4 java/src/jmri/web/servlet/panel/LayoutPanelServlet.java
  2. +6 −4 web/js/panel.js
@@ -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;
@@ -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()) {
@@ -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);
@@ -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);
@@ -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);
@@ -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

0 comments on commit 1c923a1

Please sign in to comment.
You can’t perform that action at this time.