graphdb-workbench
Version:
The web application for GraphDB APIs
1 lines • 5.82 kB
JavaScript
import{r as registerInstance,h,a as Host,g as getElement}from"./index-I_gcXFWK.js";import{ServiceProvider,SecurityContextService,AuthenticationService,NavigationContextService,SubscriptionList,WindowService,EventService,EventName,LocalStorageSubscriptionHandlerService,getPathName}from"@ontotext/workbench-api";function debounce(e,i=300){let t;return(...s)=>{clearTimeout(t),t=setTimeout(()=>e.apply(this,s),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-columns:15rem minmax(200px, 1fr);grid-template-rows:auto 1fr auto;grid-template-areas:"nav header" "nav main" "nav footer";min-height:100vh;margin:0}.wb-layout.expanded{grid-template-columns:4.375rem 1fr}.wb-layout nav{grid-area:nav}.wb-layout header{grid-area:header}.wb-layout main{grid-area:main}.wb-layout main .main-container{margin-left:0}.wb-layout .default-slot-wrapper{display:none}.wb-layout footer{grid-area:footer}.wb-header{position:sticky;top:0;z-index:999}',OntoLayout=class{constructor(e){registerInstance(this,e),this.securityContextService=ServiceProvider.get(SecurityContextService),this.authenticationService=ServiceProvider.get(AuthenticationService),this.navigationContextService=ServiceProvider.get(NavigationContextService),this.isLowResolution=!1,this.hasPermission=!0,this.showFooter=this.isAuthenticatedFully(),this.subscriptions=new SubscriptionList,this.isNavbarCollapsed=!1,this.windowResizeObserver=debounce(()=>this.windowResizeHandler(),50),WindowService.getWindow().addEventListener("storage",this.handleStorageChange)}componentDidLoad(){this.windowResizeHandler()}connectedCallback(){this.subscribeToSecurityChanges(),this.updateVisibility(),this.subscriptions.add(this.securityContextService.onRestrictedPagesChanged(e=>this.setPermission(e))),this.subscriptions.add(ServiceProvider.get(EventService).subscribe(EventName.NAVIGATION_END,e=>{this.navigationContextService.updatePreviousRoute(e.oldUrl),this.setPermission(this.securityContextService.getRestrictedPages())})),this.setPermission(this.securityContextService.getRestrictedPages())}disconnectedCallback(){this.subscriptions.unsubscribeAll()}render(){return h(Host,{key:"5d814f892fde4148f87848dbfb6a1297479b110d",class:"wb-layout"},h("div",{key:"3189f4fd2434630807d924b656e70e0f91aac9ec",class:"default-slot-wrapper"},h("slot",{key:"58aafe83a0ca87647bf9de541228b07f2acebdc8",name:"default"})),h("header",{key:"ee1a6fc5254f30e198b190725bdbfebf76c3932d",class:"wb-header"},this.isVisible&&h("onto-header",{key:"6eed310ab3e1707d24c4331fe70962b41e628bb9"})),h("nav",{key:"7759747f8d91d95e569e9a603b9d11c20d46a75c",class:"wb-navbar"},h("onto-navbar",{key:"08946fa871e0cb2bd84831b4ab57592ade2813b1",ref:this.assignNavbarRef(),"navbar-collapsed":this.isLowResolution})),this.hasPermission?h("div",{class:"main-slot-wrapper"},h("slot",{name:"main"})):h("onto-permission-banner",null),h("footer",{key:"4094b415a835ca67ef922404c4a105e7052fcdb9",class:"wb-footer"},this.isVisible&&h("onto-footer",{key:"d425c29158a1b26792e71b4e60193c57ee860e09"})),h("onto-tooltip",{key:"2cb4c8b15a44683773ef6796b070d9a4936bbff3"}),h("onto-toastr",{key:"f24a99bf4a4c01ff4ea0db6a23c5d0caf0c60ed4"}))}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=WindowService.getWindow().innerWidth<=WINDOW_WIDTH_FOR_COLLAPSED_NAVBAR,this.isLowResolution||this.isNavbarCollapsed?this.hostElement.classList.add("expanded"):this.hostElement.classList.remove("expanded")}handleStorageChange(e){ServiceProvider.get(LocalStorageSubscriptionHandlerService).handleStorageChange(e)}subscribeToSecurityChanges(){const e=ServiceProvider.get(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(ServiceProvider.get(EventService).subscribe(EventName.LOGOUT,()=>{this.setNavbarItemVisibility(),this.updateVisibility()})),this.subscriptions.add(e.onAuthTokenChanged(()=>{this.setNavbarItemVisibility(),this.updateVisibility()}))}setPermission(e){if(e){const i=getPathName();this.hasPermission=!e.isRestricted(i)}else this.hasPermission=!0;const i=document.querySelector(".wb-layout main");i&&(i.style.display=this.hasPermission?"block":"none")}updateVisibility(){if(this.authenticationService.isSecurityEnabled()){const e=!!this.authenticatedUser&&!!this.securityConfig,i=this.authenticationService.isAuthenticated()||this.authenticationService.hasFreeAccess();this.isVisible=e&&i,this.showFooter=i}else this.isVisible=!0,this.showFooter=!0}isAuthenticatedFully(){const e=ServiceProvider.get(AuthenticationService);return!e.isSecurityEnabled()||e.isAuthenticated()||e.hasFreeAccess()}shouldShowMenu(e){return this.isAuthenticatedFully()&&ServiceProvider.get(AuthenticationService).hasRole(e)}assignNavbarRef(){return e=>{this.navbarRef=e,this.navbarRef.menuItems=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 s=e=>{var i;e.shouldShow=this.shouldShowMenu(e.role),(null===(i=e.children)||void 0===i?void 0:i.length)&&e.children.forEach(s)};null===(t=null===(i=this.navbarRef)||void 0===i?void 0:i.menuItems)||void 0===t||t.forEach(e=>{e.items.forEach(s)}),this.navbarRef.menuItems=[...this.navbarRef.menuItems]}get hostElement(){return getElement(this)}};OntoLayout.style=ontoLayoutCss;export{OntoLayout as onto_layout};