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();
}
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);
}
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();
}
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();
}
Aggregations