UNPKG

graphdb-workbench

Version:
1 lines 8.08 kB
"use strict";var index=require("./index-L_ZmIeD5.js"),workbenchApi=require("@ontotext/workbench-api"),translation_service=require("./translation.service-CC6jY4U-.js");function debounce(e,i=300){let t;return(...a)=>{clearTimeout(t),t=setTimeout(()=>e.apply(this,a),i)}}const RESPONSIVE_BREAKPOINTS={MD:768},WINDOW_WIDTH_FOR_COLLAPSED_NAVBAR=RESPONSIVE_BREAKPOINTS.MD,ontoLayoutCss=()=>':host{display:block;height:100%}.wb-layout{display:grid;grid-template:"header header" auto "nav main" 1fr "nav footer" auto/15rem minmax(200px, 1fr);min-height:100vh;margin:0}.wb-layout.is-embedded{grid-template-columns:1fr;grid-template-areas:"main";padding-top:1rem}.wb-layout.hide-navbar{grid-template:"header" auto "main" 1fr "footer" auto/1fr;}.wb-layout.hide-navbar.expanded{grid-template-columns:1fr}.wb-layout.expanded{grid-template-columns:4.375rem 1fr}.wb-layout main .main-container{margin-left:0}.wb-layout .main-slot-wrapper .loader-wrapper{flex-grow:1;display:flex;align-items:center;justify-content:center}.wb-layout .main-slot-wrapper.loading{display:flex;flex-direction:column}.wb-layout .main-slot-wrapper.loading .page-content{visibility:hidden}.wb-layout .default-slot-wrapper{display:none}.wb-layout .wb-header{position:sticky;top:0;z-index:999}.wb-layout nav{grid-area:nav}.wb-layout header{grid-area:header}.wb-layout main{grid-area:main}.wb-layout footer{grid-area:footer}',OntoLayout=class{constructor(e){index.registerInstance(this,e),this.authenticationService=workbenchApi.service(workbenchApi.AuthenticationService),this.authorizationService=workbenchApi.service(workbenchApi.AuthorizationService),this.navigationContextService=workbenchApi.service(workbenchApi.NavigationContextService),this.authStorageService=workbenchApi.service(workbenchApi.AuthenticationStorageService),this.runtimeConfigurationContextService=workbenchApi.service(workbenchApi.RuntimeConfigurationContextService),this.eventService=workbenchApi.service(workbenchApi.EventService),this.applicationLifecycleContextService=workbenchApi.service(workbenchApi.ApplicationLifecycleContextService),this.fullJwtKey=`${workbenchApi.StorageKey.GLOBAL_NAMESPACE}.${this.authStorageService.NAMESPACE}.${this.authStorageService.jwtKey}`,this.fullAuthenticatedKey=`${workbenchApi.StorageKey.GLOBAL_NAMESPACE}.${this.authStorageService.NAMESPACE}.${this.authStorageService.authenticatedKey}`,this.authEvents=[this.fullJwtKey,this.fullAuthenticatedKey],this.isLowResolution=!1,this.showHeader=this.isAuthenticatedFully(),this.showNavbar=!1,this.isEmbedded=!1,this.loading=!0,this.subscriptions=new workbenchApi.SubscriptionList,this.isNavbarCollapsed=!1,this.handleStorageChange=e=>{workbenchApi.service(workbenchApi.LocalStorageSubscriptionHandlerService).handleStorageChange(e),this.handleAuthChange(e.key)},this.windowResizeObserver=debounce(()=>this.windowResizeHandler(),50),workbenchApi.WindowService.getWindow().addEventListener("storage",this.handleStorageChange)}componentDidLoad(){this.windowResizeHandler()}connectedCallback(){this.subscribeToSecurityChanges(),this.updateVisibility(),this.subscribeToNavigationEnd(),this.subscribeToRuntimeConfigurationChanges(),this.subscribeToApplicationChange()}disconnectedCallback(){this.subscriptions.unsubscribeAll()}render(){return index.h(index.Host,{key:"b8cbbca1f12bf6af844e18397d2a725d6ab4e1fc",class:{"wb-layout":!0,"is-embedded":this.isEmbedded,"hide-navbar":!this.showNavbar}},index.h("div",{key:"f2e3b7a238b82536bd7605196966bd758330c521",class:"default-slot-wrapper"},index.h("slot",{key:"5d391e2f612d9aead6c07b2ef3641b961eddc504",name:"default"})),!this.isEmbedded&&index.h("header",{key:"e43c5b68d590e12b2b3e95d4c414505f1fc82abb",class:"wb-header"},this.showHeader&&index.h("onto-header",{key:"21102b279bed2dd3ee857b399683d14c5f3eaf57"})),!this.isEmbedded&&this.showNavbar&&index.h("nav",{key:"67dcbf444a30ac933ba83f86ae9f8d08fe5f995f",class:"wb-navbar"},index.h("onto-navbar",{key:"a9816369cbbac4d5b58f607be61277d6074556bd",ref:this.assignNavbarRef(),"navbar-collapsed":this.isLowResolution})),index.h("div",{key:"f3ff0e1734eecc433dc20717e0b9f2871ea40dae",class:{"main-slot-wrapper":!0,loading:this.loading}},this.loading&&index.h("div",{key:"17d9a8024d280f70ad8684e5d114c38b184b529d",class:"loader-wrapper"},index.h("onto-loader",{key:"534a5d8f89b92051822d1d7750ca56894013c142",size:96,messageText:translation_service.TranslationService.translate("common.loading")})),index.h("slot",{key:"bcd21d932551dc6f9b9365ccbbafae690f8b7245",name:"main"})),!this.isEmbedded&&index.h("footer",{key:"9fcd224439dbb7fd35bb4c277dc343eccab40087",class:"wb-footer"},index.h("onto-footer",{key:"39d5d1c8275c527ca16aa74f6f15dc3f0cc3686c"})),index.h("onto-tooltip",{key:"6a70e6d2d67e8a9aa6b8eda66b6768735c0f6dcd"}))}onNavbarToggled(e){this.isNavbarCollapsed=e.detail.payload,this.isNavbarCollapsed?this.hostElement.classList.add("expanded"):this.hostElement.classList.remove("expanded")}onResize(){this.windowResizeObserver()}windowResizeHandler(){this.isLowResolution=workbenchApi.WindowService.getWindow().innerWidth<=WINDOW_WIDTH_FOR_COLLAPSED_NAVBAR,this.isLowResolution||this.isNavbarCollapsed?this.hostElement.classList.add("expanded"):this.hostElement.classList.remove("expanded")}handleAuthChange(e){var i;e&&this.authEvents.includes(e)&&(this.authStorageService.isAuthenticated()?workbenchApi.navigate(null!==(i=this.navigationContextService.getPreviousRoute())&&void 0!==i?i:"./"):workbenchApi.navigate("login"),workbenchApi.WindowService.getWindow().location.reload())}subscribeToSecurityChanges(){const e=workbenchApi.service(workbenchApi.SecurityContextService);this.subscriptions.add(e.onAuthenticatedUserChanged(e=>{this.authenticatedUser=e,this.updateVisibility()})),this.subscriptions.add(e.onSecurityConfigChanged(e=>{this.securityConfig=e,this.updateVisibility()})),this.subscriptions.add(this.eventService.subscribe(workbenchApi.EventName.LOGIN,()=>{this.setNavbarItemVisibility(),this.updateVisibility()})),this.subscriptions.add(this.eventService.subscribe(workbenchApi.EventName.LOGOUT,()=>{this.setNavbarItemVisibility(),this.updateVisibility(),workbenchApi.navigate("login")}))}subscribeToRuntimeConfigurationChanges(){this.subscriptions.add(this.runtimeConfigurationContextService.onRuntimeConfigurationChanged(e=>{var i;this.isEmbedded=null!==(i=null==e?void 0:e.isEmbedded)&&void 0!==i&&i}))}updateVisibility(){this.authenticationService.isSecurityEnabled()?(this.showHeader=this.authenticationService.isAuthenticated()||this.authorizationService.hasFreeAccess(),this.showNavbar=this.authenticationService.isAuthenticated()||this.authorizationService.hasFreeAccess()):(this.showNavbar=!0,this.showHeader=!0)}isAuthenticatedFully(){return!this.authenticationService.isSecurityEnabled()||this.authenticationService.isAuthenticated()||this.authorizationService.hasFreeAccess()}shouldShowMenu(e){return this.isAuthenticatedFully()&&this.authorizationService.hasRole(e)}assignNavbarRef(){return e=>{this.navbarRef=e,this.navbarRef&&(this.navbarRef.menuItems=workbenchApi.WindowService.getWindow().PluginRegistry.get("main.menu"),this.setNavbarItemVisibility())}}setNavbarItemVisibility(){var e,i,t;if(!(null===(e=this.navbarRef)||void 0===e?void 0:e.menuItems))return;const a=e=>{var i;e.shouldShow=this.shouldShowMenu(e.role),(null===(i=e.children)||void 0===i?void 0:i.length)&&e.children.forEach(a)};null===(t=null===(i=this.navbarRef)||void 0===i?void 0:i.menuItems)||void 0===t||t.forEach(e=>{e.items.forEach(a)}),this.navbarRef.menuItems=[...this.navbarRef.menuItems]}subscribeToNavigationEnd(){this.subscriptions.add(this.eventService.subscribe(workbenchApi.EventName.NAVIGATION_END,e=>{this.navigationContextService.updatePreviousRoute(e.oldUrl)}))}subscribeToApplicationChange(){this.subscriptions.add(this.applicationLifecycleContextService.onApplicationStateBeforeChange(e=>{e&&(this.loading=!0)})),this.subscriptions.add(this.applicationLifecycleContextService.onApplicationStateChange(e=>{e&&(this.loading=!1)}))}get hostElement(){return index.getElement(this)}};OntoLayout.style=ontoLayoutCss(),exports.onto_layout=OntoLayout;