UNPKG

graphdb-workbench

Version:
1 lines 5.57 kB
"use strict";var index=require("./index-jdsA9lN2.js"),workbenchApi=require("@ontotext/workbench-api");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-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){index.registerInstance(this,e),this.authenticationService=workbenchApi.ServiceProvider.get(workbenchApi.AuthenticationService),this.authorizationService=workbenchApi.ServiceProvider.get(workbenchApi.AuthorizationService),this.navigationContextService=workbenchApi.ServiceProvider.get(workbenchApi.NavigationContextService),this.isLowResolution=!1,this.showHeader=this.isAuthenticatedFully(),this.subscriptions=new workbenchApi.SubscriptionList,this.isNavbarCollapsed=!1,this.windowResizeObserver=debounce(()=>this.windowResizeHandler(),50),workbenchApi.WindowService.getWindow().addEventListener("storage",this.handleStorageChange)}componentDidLoad(){this.windowResizeHandler()}connectedCallback(){this.subscribeToSecurityChanges(),this.updateVisibility(),this.subscribeToNavigationEnd()}disconnectedCallback(){this.subscriptions.unsubscribeAll()}render(){return index.h(index.Host,{key:"43839b39292ee9e9cb0069d0fc7bf37d5349becc",class:"wb-layout"},index.h("div",{key:"81001d71c4d01825f83719cac61d34d1fc35b2b1",class:"default-slot-wrapper"},index.h("slot",{key:"5fe786622416da21561472f6da834c4c233d13fc",name:"default"})),index.h("header",{key:"b1b90981f77f98aad86b57be0d8dcb6abe541866",class:"wb-header"},this.showHeader&&index.h("onto-header",{key:"b1edea3608955812df1dd6de8e60df3e6138577a"})),index.h("nav",{key:"e633af3ed9c81dbb200ca6e212b5dba802a6db10",class:"wb-navbar"},index.h("onto-navbar",{key:"b5bf00eaed42a98be5b0e5e3becc20d0b30914b0",ref:this.assignNavbarRef(),"navbar-collapsed":this.isLowResolution})),index.h("div",{key:"bd8f85e4c5cdb36c7bd46855c1665d44bd73397e",class:"main-slot-wrapper"},index.h("slot",{key:"c2dbb842f63c92ea6f74a683860dcbfb49949be1",name:"main"})),index.h("footer",{key:"db49d5698c19ae3bfc3144e61226ff8e24830961",class:"wb-footer"},index.h("onto-footer",{key:"4b5c21c7ba8544c647d216f23aaef94fc8c47858"})),index.h("onto-tooltip",{key:"8af057e1dfe06c4268e2163f989730301aae443e"}),index.h("onto-toastr",{key:"037436b1c9bd88bc2fcae2fce8f0a99d943b0e43"}))}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")}handleStorageChange(e){workbenchApi.ServiceProvider.get(workbenchApi.LocalStorageSubscriptionHandlerService).handleStorageChange(e)}subscribeToSecurityChanges(){const e=workbenchApi.ServiceProvider.get(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(workbenchApi.ServiceProvider.get(workbenchApi.EventService).subscribe(workbenchApi.EventName.LOGIN,()=>{this.setNavbarItemVisibility(),this.updateVisibility()})),this.subscriptions.add(workbenchApi.ServiceProvider.get(workbenchApi.EventService).subscribe(workbenchApi.EventName.LOGOUT,()=>{this.setNavbarItemVisibility(),this.updateVisibility(),workbenchApi.navigate("login")}))}updateVisibility(){this.authenticationService.isSecurityEnabled()?this.showHeader=this.authenticationService.isAuthenticated()||this.authorizationService.hasFreeAccess():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.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(workbenchApi.ServiceProvider.get(workbenchApi.EventService).subscribe(workbenchApi.EventName.NAVIGATION_END,e=>{this.navigationContextService.updatePreviousRoute(e.oldUrl)}))}get hostElement(){return index.getElement(this)}};OntoLayout.style=ontoLayoutCss,exports.onto_layout=OntoLayout;