Main.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2018 Red Hat, Inc. and/or its affiliates.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import * as React from "../../common/keycloak/web_modules/react.js";
  17. import * as ReactDOM from "../../common/keycloak/web_modules/react-dom.js";
  18. import { HashRouter } from "../../common/keycloak/web_modules/react-router-dom.js";
  19. import { App } from "./App.js";
  20. import { flattenContent, initGroupAndItemIds, isExpansion, isModulePageDef } from "./ContentPages.js";
  21. import { KeycloakService } from "./keycloak-service/keycloak.service.js";
  22. import { KeycloakContext } from "./keycloak-service/KeycloakContext.js";
  23. import { AccountServiceClient } from "./account-service/account.service.js";
  24. import { AccountServiceContext } from "./account-service/AccountServiceContext.js";
  25. export class Main extends React.Component {
  26. constructor(props) {
  27. super(props);
  28. }
  29. componentDidMount() {
  30. isReactLoading = false;
  31. toggleReact();
  32. }
  33. render() {
  34. const keycloakService = new KeycloakService(keycloak);
  35. return React.createElement(HashRouter, null, React.createElement(KeycloakContext.Provider, {
  36. value: keycloakService
  37. }, React.createElement(AccountServiceContext.Provider, {
  38. value: new AccountServiceClient(keycloakService)
  39. }, React.createElement(App, null))));
  40. }
  41. }
  42. ;
  43. const e = React.createElement;
  44. function removeHidden(items) {
  45. const visible = [];
  46. for (let item of items) {
  47. if (item.hidden && eval(item.hidden)) continue;
  48. if (isExpansion(item)) {
  49. visible.push(item);
  50. item.content = removeHidden(item.content);
  51. if (item.content.length === 0) {
  52. visible.pop(); // remove empty expansion
  53. }
  54. } else {
  55. visible.push(item);
  56. }
  57. }
  58. return visible;
  59. }
  60. content = removeHidden(content);
  61. initGroupAndItemIds();
  62. function loadModule(modulePage) {
  63. return new Promise((resolve, reject) => {
  64. console.log('loading: ' + resourceUrl + modulePage.modulePath);
  65. import(resourceUrl + modulePage.modulePath).then(module => {
  66. modulePage.module = module;
  67. resolve(modulePage);
  68. }).catch(error => {
  69. console.warn('Unable to load ' + modulePage.label + ' because ' + error.message);
  70. reject(modulePage);
  71. });
  72. });
  73. }
  74. ;
  75. const moduleLoaders = [];
  76. flattenContent(content).forEach(item => {
  77. if (isModulePageDef(item)) {
  78. moduleLoaders.push(loadModule(item));
  79. }
  80. }); // load content modules and start
  81. Promise.all(moduleLoaders).then(() => {
  82. const domContainer = document.querySelector('#main_react_container');
  83. ReactDOM.render(e(Main), domContainer);
  84. });
  85. //# sourceMappingURL=Main.js.map