use of de.metas.ui.web.menu.datatypes.json.JSONMenuNode in project metasfresh-webui-api by metasfresh.
the class MenuRestController method getRoot.
@GetMapping("/root")
public JSONMenuNode getRoot(@RequestParam(name = PARAM_Depth, required = false, defaultValue = "1") final int depth, @RequestParam(name = PARAM_ChildrenLimit, required = false, defaultValue = "0") final int childrenLimit, @RequestParam(name = "favorites", required = false, defaultValue = "false") final boolean onlyFavorites) {
userSession.assertLoggedIn();
final MenuTree menuTree = getMenuTree();
//
// Get the root node with favorites only, if asked
MenuNode rootNode;
if (onlyFavorites) {
rootNode = menuTree.getRootNodeWithFavoritesOnly(menuTreeRepository);
if (rootNode.getChildren().isEmpty()) {
// If there were no favorites, return all
rootNode = menuTree.getRootNode();
}
} else {
rootNode = menuTree.getRootNode();
}
return JSONMenuNode.builder(rootNode).setMaxDepth(depth).setMaxChildrenPerNode(childrenLimit).setIsFavoriteProvider(menuTreeRepository).build();
}
use of de.metas.ui.web.menu.datatypes.json.JSONMenuNode in project metasfresh-webui-api by metasfresh.
the class MenuRestController method getNode.
@GetMapping("/node/{nodeId}")
public JSONMenuNode getNode(@PathVariable(PARAM_NodeId) final String nodeId, @RequestParam(name = PARAM_Depth, required = false, defaultValue = "1") final int depth, @RequestParam(name = PARAM_ChildrenLimit, required = false, defaultValue = "0") final int childrenLimit) {
userSession.assertLoggedIn();
final MenuNode node = getMenuTree().getNodeById(nodeId);
return JSONMenuNode.builder(node).setMaxDepth(depth).setMaxChildrenPerNode(childrenLimit).setIsFavoriteProvider(menuTreeRepository::isFavorite).build();
}
use of de.metas.ui.web.menu.datatypes.json.JSONMenuNode in project metasfresh-webui-api by metasfresh.
the class MenuRestController method getPath.
@GetMapping("/elementPath")
public JSONMenuNode getPath(@RequestParam(name = PARAM_Type, required = true) final JSONMenuNodeType jsonType, @RequestParam(name = PARAM_ElementId, required = true) final String elementIdStr, @RequestParam(name = PARAM_IncludeLastNode, required = false, defaultValue = "false") @ApiParam("Shall we include the last node") final boolean includeLastNode) {
userSession.assertLoggedIn();
final MenuNodeType menuNodeType = jsonType.toMenuNodeType();
final DocumentId elementId = DocumentId.of(elementIdStr);
final List<MenuNode> path = getMenuTree().getPath(menuNodeType, elementId).orElseGet(() -> getPathOfMissingElement(menuNodeType, elementId, userSession.getAD_Language()));
final boolean skipRootNode = true;
return JSONMenuNode.ofPath(path, skipRootNode, includeLastNode, menuTreeRepository);
}
use of de.metas.ui.web.menu.datatypes.json.JSONMenuNode in project metasfresh-webui-api by metasfresh.
the class MenuRestController method patchNode.
@PatchMapping("/node/{nodeId}")
public List<JSONMenuNode> patchNode(@PathVariable(PARAM_NodeId) final String nodeId, @RequestBody final List<JSONDocumentChangedEvent> events) {
userSession.assertLoggedIn();
final JSONPatchMenuNodeRequest request = JSONPatchMenuNodeRequest.ofChangeEvents(events);
final MenuTree menuTree = getMenuTree();
final MenuNode node = menuTree.getNodeById(nodeId);
final LinkedHashMap<String, MenuNode> changedMenuNodesById = new LinkedHashMap<>();
if (request.getFavorite() != null) {
menuTreeRepository.setFavorite(node, request.getFavorite());
menuTree.streamNodesByAD_Menu_ID(node.getAD_Menu_ID()).forEach(changedNode -> changedMenuNodesById.put(changedNode.getId(), changedNode));
}
return JSONMenuNode.ofList(changedMenuNodesById.values(), menuTreeRepository);
}
use of de.metas.ui.web.menu.datatypes.json.JSONMenuNode in project metasfresh-webui-api by metasfresh.
the class MenuRestController method query.
@GetMapping("/queryPaths")
public JSONMenuNode query(@RequestParam(name = PARAM_NameQuery, required = true) final String nameQuery, @RequestParam(name = PARAM_ChildrenLimit, required = false, defaultValue = "0") final int childrenLimit, @RequestParam(name = "childrenInclusive", required = false, defaultValue = "false") @ApiParam("true if groups that were matched shall be populated with it's leafs, even if those leafs are not matching") final boolean includeLeafsIfGroupAccepted) {
userSession.assertLoggedIn();
final MenuNode rootFiltered = getMenuTree().filter(nameQuery, includeLeafsIfGroupAccepted);
if (rootFiltered == null) {
throw new NoMenuNodesFoundException();
}
if (rootFiltered.getChildren().isEmpty()) {
throw new NoMenuNodesFoundException();
}
return JSONMenuNode.builder(rootFiltered).setMaxLeafNodes(childrenLimit).setIsFavoriteProvider(menuTreeRepository).build();
}
Aggregations