Search in sources :

Example 1 with WebMenuItem

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WebMenuItem(jmri.server.web.spi.WebMenuItem) WebManifest(jmri.server.web.spi.WebManifest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 WebManifest (jmri.server.web.spi.WebManifest)1 WebMenuItem (jmri.server.web.spi.WebMenuItem)1