Search in sources :

Example 1 with JSONMenuNode

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();
}
Also used : JSONMenuNode(de.metas.ui.web.menu.datatypes.json.JSONMenuNode) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with JSONMenuNode

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();
}
Also used : JSONMenuNode(de.metas.ui.web.menu.datatypes.json.JSONMenuNode) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with JSONMenuNode

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);
}
Also used : MenuNodeType(de.metas.ui.web.menu.MenuNode.MenuNodeType) JSONMenuNodeType(de.metas.ui.web.menu.datatypes.json.JSONMenuNodeType) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) JSONMenuNode(de.metas.ui.web.menu.datatypes.json.JSONMenuNode) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with JSONMenuNode

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);
}
Also used : JSONMenuNode(de.metas.ui.web.menu.datatypes.json.JSONMenuNode) JSONPatchMenuNodeRequest(de.metas.ui.web.menu.datatypes.json.JSONPatchMenuNodeRequest) LinkedHashMap(java.util.LinkedHashMap) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 5 with JSONMenuNode

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();
}
Also used : JSONMenuNode(de.metas.ui.web.menu.datatypes.json.JSONMenuNode) NoMenuNodesFoundException(de.metas.ui.web.menu.exception.NoMenuNodesFoundException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

JSONMenuNode (de.metas.ui.web.menu.datatypes.json.JSONMenuNode)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 MenuNodeType (de.metas.ui.web.menu.MenuNode.MenuNodeType)1 JSONMenuNodeType (de.metas.ui.web.menu.datatypes.json.JSONMenuNodeType)1 JSONPatchMenuNodeRequest (de.metas.ui.web.menu.datatypes.json.JSONPatchMenuNodeRequest)1 NoMenuNodesFoundException (de.metas.ui.web.menu.exception.NoMenuNodesFoundException)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 LinkedHashMap (java.util.LinkedHashMap)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1