use of jmri.server.web.spi.WebMenuItem in project JMRI by JMRI.
the class WebAppManager method getNavigation.
public String getNavigation(Profile profile, Locale locale) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
ArrayNode navigation = mapper.createArrayNode();
List<WebMenuItem> items = new ArrayList<>();
this.getManifests(profile).forEach((WebManifest manifest) -> {
manifest.getNavigationMenuItems().stream().filter((WebMenuItem item) -> // NOI18N
!item.getPath().startsWith("help") && // NOI18N
!item.getPath().startsWith("user") && !items.contains(item)).forEachOrdered((item) -> {
items.add(item);
});
});
items.sort((WebMenuItem o1, WebMenuItem o2) -> o1.getPath().compareToIgnoreCase(o2.getPath()));
// TODO: get order correct
for (int i = 0; i < items.size(); i++) {
WebMenuItem item = items.get(i);
ObjectNode navItem = this.getMenuItem(item, mapper, locale);
ArrayNode children = mapper.createArrayNode();
for (int j = i + 1; j < items.size(); j++) {
if (!items.get(j).getPath().startsWith(item.getPath())) {
break;
}
// TODO: add children to arbitrary depth
ObjectNode child = this.getMenuItem(items.get(j), mapper, locale);
if (items.get(j).getHref() != null) {
children.add(child);
}
i++;
}
navItem.set("children", children);
// TODO: add badges
if (item.getHref() != null || children.size() != 0) {
// TODO: handle separator before
navigation.add(navItem);
// TODO: handle separator after
}
}
return mapper.writeValueAsString(navigation);
}
Aggregations