Search in sources :

Example 1 with WebManifest

use of jmri.server.web.spi.WebManifest in project JMRI by JMRI.

the class WebAppManager method getAngularRoutes.

public String getAngularRoutes(Profile profile, Locale locale) {
    // NOI18N
    StringJoiner routes = new StringJoiner("\n", "\n", "");
    Set<AngularRoute> items = new HashSet<>();
    this.getManifests(profile).forEach((WebManifest manifest) -> {
        items.addAll(manifest.getAngularRoutes());
    });
    items.forEach((route) -> {
        if (route.getRedirection() != null) {
            // NOI18N
            routes.add(String.format("      .when('%s', { redirectTo: '%s' })", route.getWhen(), route.getRedirection()));
        } else if (route.getTemplate() != null && route.getController() != null) {
            // NOI18N
            routes.add(String.format("      .when('%s', { templateUrl: '%s', controller: '%s' })", route.getWhen(), route.getTemplate(), route.getController()));
        }
    });
    return routes.toString();
}
Also used : AngularRoute(jmri.server.web.spi.AngularRoute) WebManifest(jmri.server.web.spi.WebManifest) StringJoiner(java.util.StringJoiner) HashSet(java.util.HashSet)

Example 2 with WebManifest

use of jmri.server.web.spi.WebManifest 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)

Example 3 with WebManifest

use of jmri.server.web.spi.WebManifest in project JMRI by JMRI.

the class WebAppManager method getAngularSources.

public String getAngularSources(Profile profile, Locale locale) {
    // NOI18N
    StringJoiner sources = new StringJoiner("\n", "\n\n", "\n");
    List<URL> urls = new ArrayList<>();
    this.getManifests(profile).forEach((WebManifest manifest) -> {
        urls.addAll(manifest.getAngularSources());
    });
    urls.forEach((URL source) -> {
        try {
            sources.add(FileUtil.readURL(source));
        } catch (IOException ex) {
            log.error("Unable to read {}", source, ex);
        }
    });
    return sources.toString();
}
Also used : ArrayList(java.util.ArrayList) WebManifest(jmri.server.web.spi.WebManifest) IOException(java.io.IOException) StringJoiner(java.util.StringJoiner) URL(java.net.URL)

Example 4 with WebManifest

use of jmri.server.web.spi.WebManifest in project JMRI by JMRI.

the class WebAppManager method getAngularDependencies.

public String getAngularDependencies(Profile profile, Locale locale) {
    // NOI18N
    StringJoiner dependencies = new StringJoiner("',\n  '", "\n  '", "'");
    List<String> items = new ArrayList<>();
    this.getManifests(profile).forEach((WebManifest manifest) -> {
        manifest.getAngularDependencies().stream().filter((dependency) -> (!items.contains(dependency))).forEachOrdered((dependency) -> {
            items.add(dependency);
        });
    });
    items.forEach((String dependency) -> {
        dependencies.add(dependency);
    });
    return dependencies.toString();
}
Also used : OVERFLOW(java.nio.file.StandardWatchEventKinds.OVERFLOW) LifeCycle(org.eclipse.jetty.util.component.LifeCycle) URL(java.net.URL) AbstractPreferencesManager(jmri.util.prefs.AbstractPreferencesManager) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) InitializationException(jmri.util.prefs.InitializationException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) AngularRoute(jmri.server.web.spi.AngularRoute) WatchKey(java.nio.file.WatchKey) HashSet(java.util.HashSet) WebServer(jmri.web.server.WebServer) StandardWatchEventKinds(java.nio.file.StandardWatchEventKinds) ProfileUtils(jmri.profile.ProfileUtils) Locale(java.util.Locale) Map(java.util.Map) Profile(jmri.profile.Profile) Path(java.nio.file.Path) PropertyChangeEvent(java.beans.PropertyChangeEvent) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) WebMenuItem(jmri.server.web.spi.WebMenuItem) File(java.io.File) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WatchService(java.nio.file.WatchService) List(java.util.List) WebManifest(jmri.server.web.spi.WebManifest) WebServerPreferences(jmri.web.server.WebServerPreferences) FileUtil(jmri.util.FileUtil) StringJoiner(java.util.StringJoiner) FileSystems(java.nio.file.FileSystems) ArrayList(java.util.ArrayList) WebManifest(jmri.server.web.spi.WebManifest) StringJoiner(java.util.StringJoiner)

Aggregations

WebManifest (jmri.server.web.spi.WebManifest)4 ArrayList (java.util.ArrayList)3 StringJoiner (java.util.StringJoiner)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 AngularRoute (jmri.server.web.spi.AngularRoute)2 WebMenuItem (jmri.server.web.spi.WebMenuItem)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 File (java.io.File)1 FileSystems (java.nio.file.FileSystems)1 Path (java.nio.file.Path)1 StandardWatchEventKinds (java.nio.file.StandardWatchEventKinds)1 OVERFLOW (java.nio.file.StandardWatchEventKinds.OVERFLOW)1 WatchKey (java.nio.file.WatchKey)1 WatchService (java.nio.file.WatchService)1