123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /*
- * Copyright 2019 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import * as React from "../../common/keycloak/web_modules/react.js";
- import { Route, Switch } from "../../common/keycloak/web_modules/react-router-dom.js";
- import { NavItem, NavExpandable } from "../../common/keycloak/web_modules/@patternfly/react-core.js";
- import { Msg } from "./widgets/Msg.js";
- import { PageNotFound } from "./content/page-not-found/PageNotFound.js";
- import { ForbiddenPage } from "./content/forbidden-page/ForbiddenPage.js";
- ;
- export function isModulePageDef(item) {
- return item.modulePath !== undefined;
- }
- export function isExpansion(contentItem) {
- return contentItem.content !== undefined;
- }
- function groupId(group) {
- return 'grp-' + group;
- }
- function itemId(group, item) {
- return 'grp-' + group + '_itm-' + item;
- }
- function isChildOf(parent, child) {
- for (var item of parent.content) {
- if (isExpansion(item) && isChildOf(item, child)) return true;
- if (parent.groupId === child.groupId) return true;
- }
- return false;
- }
- function createNavItems(activePage, contentParam, groupNum) {
- if (typeof content === 'undefined') return React.createElement(React.Fragment, null);
- const links = contentParam.map(item => {
- const navLinkId = `nav-link-${item.id}`;
- if (isExpansion(item)) {
- return React.createElement(NavExpandable, {
- id: navLinkId,
- groupId: item.groupId,
- key: item.groupId,
- title: Msg.localize(item.label, item.labelParams),
- isExpanded: isChildOf(item, activePage)
- }, createNavItems(activePage, item.content, groupNum + 1));
- } else {
- const page = item;
- return React.createElement(NavItem, {
- id: navLinkId,
- groupId: item.groupId,
- itemId: item.itemId,
- key: item.itemId,
- to: '#/' + page.path,
- isActive: activePage.itemId === item.itemId,
- type: "button"
- }, Msg.localize(page.label, page.labelParams));
- }
- });
- return React.createElement(React.Fragment, null, links);
- }
- export function makeNavItems(activePage) {
- console.log({
- activePage
- });
- return createNavItems(activePage, content, 0);
- }
- function setIds(contentParam, groupNum) {
- if (typeof contentParam === 'undefined') return groupNum;
- let expansionGroupNum = groupNum;
- for (let i = 0; i < contentParam.length; i++) {
- const item = contentParam[i];
- if (isExpansion(item)) {
- item.itemId = itemId(groupNum, i);
- expansionGroupNum = expansionGroupNum + 1;
- item.groupId = groupId(expansionGroupNum);
- expansionGroupNum = setIds(item.content, expansionGroupNum);
- console.log('currentGroup=' + expansionGroupNum);
- } else {
- item.groupId = groupId(groupNum);
- item.itemId = itemId(groupNum, i);
- }
- }
- ;
- return expansionGroupNum;
- }
- export function initGroupAndItemIds() {
- setIds(content, 0);
- console.log({
- content
- });
- } // get rid of Expansions and put all PageDef items into a single array
- export function flattenContent(pageDefs) {
- const flat = [];
- for (let item of pageDefs) {
- if (isExpansion(item)) {
- flat.push(...flattenContent(item.content));
- } else {
- flat.push(item);
- }
- }
- return flat;
- }
- export function makeRoutes() {
- if (typeof content === 'undefined') return React.createElement("span", null);
- const pageDefs = flattenContent(content);
- const routes = pageDefs.map(page => {
- if (isModulePageDef(page)) {
- const node = React.createElement(page.module[page.componentName], {
- 'pageDef': page
- });
- return React.createElement(Route, {
- key: page.itemId,
- path: '/' + page.path,
- exact: true,
- render: () => node
- });
- } else {
- const pageDef = page;
- return React.createElement(Route, {
- key: page.itemId,
- path: '/' + page.path,
- exact: true,
- component: pageDef.component
- });
- }
- });
- return React.createElement(Switch, null, routes, React.createElement(Route, {
- path: "/forbidden",
- component: ForbiddenPage
- }), React.createElement(Route, {
- component: PageNotFound
- }));
- }
- //# sourceMappingURL=ContentPages.js.map
|