UNPKG

graphdb-workbench

Version:
1 lines 10.9 kB
import{Host,h}from"@stencil/core";import{ServiceProvider,LicenseContextService,SubscriptionList,MonitoringService,RepositoryContextService,SecurityContextService,ConfigurationContextService,FibonacciGenerator,OntoToastrService,RepositoryLocationContextService,EventService,EventName,getPathName,isHomePage,NamespacesService,NamespacesContextService,RepositoryList,RepositoryService,LanguageService,LanguageContextService,ObjectUtil,getCurrentRoute,AuthenticationService,WindowService,AuthorizationService,navigateTo,RuntimeConfigurationContextService}from"../../../../../api/dist/ontotext-workbench-api";import{TranslationService}from"../../services/translation.service";import{HtmlUtil}from"../../utils/html-util";import{DropdownItem}from"../../models/dropdown/dropdown-item";import{SelectorItemButton}from"../onto-repository-selector/selector-item";import{ResourceSearchConstants}from"../../models/resource-search/resource-search-constants";const labelKeys={LOGO_LINK:"menu.logo.link.title"};export class OntoHeader{constructor(){this.UPDATE_ACTIVE_OPERATION_TIME_INTERVAL=2e3,this.fibonacciGenerator=new FibonacciGenerator,this.monitoringService=ServiceProvider.get(MonitoringService),this.repositoryContextService=ServiceProvider.get(RepositoryContextService),this.repositoryLocationContextService=ServiceProvider.get(RepositoryLocationContextService),this.repositoryService=ServiceProvider.get(RepositoryService),this.securityContextService=ServiceProvider.get(SecurityContextService),this.toastrService=ServiceProvider.get(OntoToastrService),this.namespacesService=ServiceProvider.get(NamespacesService),this.namespaceContextService=ServiceProvider.get(NamespacesContextService),this.languageService=ServiceProvider.get(LanguageService),this.authService=ServiceProvider.get(AuthenticationService),this.authorizationService=ServiceProvider.get(AuthorizationService),this.eventService=ServiceProvider.get(EventService),this.configurationContextService=ServiceProvider.get(ConfigurationContextService),this.runtimeConfigurationContextService=ServiceProvider.get(RuntimeConfigurationContextService),this.shouldShowSearch=!0,this.isHomePage=isHomePage(),this.showUserMenu=!1,this.showLoginButton=!1,this.isActiveLocationLoading=!1,this.repositoryItems=[],this.subscriptions=new SubscriptionList,this.skipUpdateActiveOperationsTimes=0,this.labels={[labelKeys.LOGO_LINK]:TranslationService.translate(labelKeys.LOGO_LINK)},this.canWriteRepo=e=>this.canWriteRepoInLocation(e),this.repositorySizeInfoFetcher=e=>this.repositoryService.getRepositorySizeInfo(e),this.showViewResourceMessage=e=>{e.stopPropagation(),this.toastrService.info(TranslationService.translate("rdf_search.toasts.use_view_resource")),this.shouldShowSearch=!1,HtmlUtil.focusElement("#search-resource-input-home input"),this.eventService.emit({NAME:ResourceSearchConstants.RDF_SEARCH_ICON_CLICKED})}}disconnectedCallback(){this.subscriptions.unsubscribeAll(),this.stopOperationPolling()}connectedCallback(){this.currentRepository=this.repositoryContextService.getSelectedRepository(),this.setupTotalRepositoryFormater(),this.setupExpansionRatioFormater(),this.subscribeToEvents(),this.currentRoute=getCurrentRoute(),this.startOperationPolling(),this.onTranslate(labelKeys.LOGO_LINK)}render(){var e,t;return h(Host,{key:"27bc641f0aaf6ee44ad7065006dd12040eec3584"},h("div",{key:"e3b1669493586b5be5f4f2499d226aa201e4a2f9",class:"header-component"},h("div",{key:"d77a609f0ff258608ddb2e32ca6f45c70c56732a",class:"left-section brand"},h("a",{key:"a10b4a68f097c42a14a2b37a4f42ce8375c2ff97",class:"home-page",onClick:navigateTo("./")},h("img",{key:"c3e1299cd3b949e76166d832d413222ea6a58a44",src:this.applicationLogoPath,class:"big-logo",alt:this.labels[labelKeys.LOGO_LINK]}))),h("div",{key:"e38258c67392a98d355931e3c9aced8abebf134c",class:"right-section"},h("onto-search-icon",{key:"dca1d81ab3f0b09bbb139a5c0bad9c6d3116c096",class:"rdf-search-button",onClick:this.showViewResourceMessage,"data-test":"onto-show-view-resource-message",style:{display:this.shouldShowSearch&&this.isHomePage?"block":"none"}}),h("onto-rdf-search",{key:"706f6e0ad2860208c2656d5e58b3fa75a10be85b","data-test":"onto-open-rdf-search-button",style:{display:this.shouldShowSearch&&!this.isHomePage?"block":"none"}}),(null===(e=this.activeOperations)||void 0===e?void 0:e.allRunningOperations.getItems().length)?h("onto-operations-notification",{activeOperations:this.activeOperations}):"",this.license&&!(null===(t=this.license)||void 0===t?void 0:t.valid)?h("onto-license-alert",{license:this.license}):"",h("onto-repository-selector",{key:"9ec8e3275085d15a2aae0b120633c9eb59337453",currentRepository:this.currentRepository,items:this.repositoryItems,repositorySizeInfoFetcher:this.repositorySizeInfoFetcher,totalTripletsFormatter:this.totalTripletsFormatter,expansionRatioFormatter:this.expansionRatioFormatter,canWriteRepo:this.canWriteRepo}),h("onto-language-selector",{key:"c36d93cf4d198d7cc63d673e3254e94783b21ae9","dropdown-alignment":"right"}),this.showUserMenu&&this.user?h("onto-user-menu",{user:this.user,securityConfig:this.securityConfig}):"",this.showLoginButton?h("onto-user-login",null):"")))}subscribeToEvents(){this.subscribeToSecurityContextChange(),this.subscribeToRepositoryListChanged(),this.subscribeToLicenseChange(),this.subscribeToRepositoryChange(),this.subscribeToActiveRepositoryLocationChange(),this.subscribeToActiveRepoLoadingChange(),this.subscribeToNavigationEnd(),this.subscribeToLanguageChanged(),this.subscribeToAuthenticatedUserChange(),this.subscribeToThemeModeChange()}subscribeToThemeModeChange(){this.subscriptions.add(this.runtimeConfigurationContextService.onThemeModeChanged(e=>{this.applicationLogoPath=this.configurationContextService.getApplicationLogoPath(e)}))}subscribeToRepositoryListChanged(){return this.repositoryContextService.onRepositoryListChanged(e=>{(null==e?void 0:e.getItems().length)?this.initOnRepositoryListChanged(e):this.resetOnMissingRepositories()})}subscribeToLicenseChange(){this.subscriptions.add(ServiceProvider.get(LicenseContextService).onLicenseChanged(e=>{this.license=e}))}subscribeToRepositoryChange(){this.subscriptions.add(this.repositoryContextService.onSelectedRepositoryChanged(e=>{this.currentRepository=this.repositoryContextService.findRepository(e),this.shouldShowSearch=this.shouldShowRdfSearch(),this.loadNamespaces(),this.updateRepositoryItems()}))}subscribeToSecurityContextChange(){this.subscriptions.add(this.securityContextService.onSecurityConfigChanged(e=>{this.securityConfig=e,setTimeout(()=>{this.updateVisibility()})}))}subscribeToAuthenticatedUserChange(){this.subscriptions.add(this.securityContextService.onAuthenticatedUserChanged(e=>{this.user=e,this.updateRepositoryItems(),this.updateVisibility()}))}subscribeToActiveRepositoryLocationChange(){this.subscriptions.add(this.repositoryLocationContextService.onActiveLocationChanged(()=>{this.shouldShowSearch=this.shouldShowRdfSearch()}))}subscribeToActiveRepoLoadingChange(){this.subscriptions.add(this.repositoryLocationContextService.onIsLoadingChanged(e=>{this.isActiveLocationLoading=e,this.shouldShowSearch=this.shouldShowRdfSearch()}))}subscribeToNavigationEnd(){this.subscriptions.add(this.eventService.subscribe(EventName.NAVIGATION_END,()=>{this.shouldShowSearch=this.shouldShowRdfSearch(),this.isHomePage=isHomePage(),this.currentRoute=getCurrentRoute(),this.updateVisibility()}))}subscribeToLanguageChanged(){this.subscriptions.add(ServiceProvider.get(LanguageContextService).onSelectedLanguageChanged(e=>{this.setupTotalRepositoryFormater(e),this.setupExpansionRatioFormater(e)}))}onTranslate(e){this.subscriptions.add(TranslationService.onTranslate(e,[],t=>{this.labels[e]=t}))}resetOnMissingRepositories(){this.repositoryItems=[],this.repositoryList=new RepositoryList,this.currentRepository=void 0}initOnRepositoryListChanged(e){this.repositoryList=e,this.updateRepositoryItems()}updateRepositoryItems(){this.repositoryItems=this.getRepositoriesDropdownItems()}getRepositoriesDropdownItems(){var e;if(!(null===(e=this.repositoryList)||void 0===e?void 0:e.getItems().length))return[];let t;return this.repositoryList.sortByLocationAndId(),t=this.currentRepository?this.repositoryList.filterByRepository([this.currentRepository]):this.repositoryList.getItems(),t.filter(e=>this.authorizationService.canReadRepo(e)||this.authorizationService.canReadGqlRepo(e)).map(e=>(new DropdownItem).setName(h(SelectorItemButton,{repository:e})).setValue(e).setGuideSelector(`repository-id-${e.id}`))}canWriteRepoInLocation(e){return!0}loadNamespaces(){this.currentRepository&&this.authorizationService.canReadRepo(this.currentRepository)&&this.namespacesService.getNamespaces(this.currentRepository.id).then(e=>this.namespaceContextService.updateNamespaces(e))}updateVisibility(){var e,t,i;const o=null===(e=this.securityConfig)||void 0===e?void 0:e.enabled,s=this.authService.isLoggedIn();let r=!1;try{r=this.authService.isAuthenticated()}catch(e){r=!1}const n=null===(i=null===(t=this.securityConfig)||void 0===t?void 0:t.freeAccess)||void 0===i?void 0:i.enabled;this.showLoginButton=o&&n&&!s&&"login"!==this.currentRoute,this.showUserMenu=o&&r&&s,this.shouldShowSearch=this.shouldShowRdfSearch()}startOperationPolling(){clearInterval(this.pollingInterval),this.pollingInterval=WindowService.getWindow().setInterval(()=>{this.authService.isAuthenticated()?this.skipUpdateActiveOperationsTimes>0?this.skipUpdateActiveOperationsTimes--:this.currentRepository&&this.monitoringService.getOperations(this.currentRepository.id).then(e=>{ObjectUtil.deepEqual(this.activeOperations,e)||(this.activeOperations=e),this.fibonacciGenerator.reset(),this.skipUpdateActiveOperationsTimes=0}).catch(()=>{this.activeOperations=void 0,this.skipUpdateActiveOperationsTimes=this.fibonacciGenerator.next()}):this.activeOperations=void 0},this.UPDATE_ACTIVE_OPERATION_TIME_INTERVAL)}stopOperationPolling(){clearInterval(this.pollingInterval),this.activeOperations=void 0}shouldShowRdfSearch(){return!!this.currentRepository&&(!this.isActiveLocationLoading||"/repository"===getPathName())&&this.authorizationService.canReadRepo(this.currentRepository)}setupTotalRepositoryFormater(e){e||(e=this.languageService.getDefaultLanguage()),this.totalTripletsFormatter=new Intl.NumberFormat(e,{style:"decimal",minimumFractionDigits:0,maximumFractionDigits:0})}setupExpansionRatioFormater(e){e||(e=this.languageService.getDefaultLanguage()),this.expansionRatioFormatter=new Intl.NumberFormat(e,{style:"decimal",minimumFractionDigits:2,maximumFractionDigits:2})}static get is(){return"onto-header"}static get originalStyleUrls(){return{$:["onto-header.scss"]}}static get styleUrls(){return{$:["onto-header.css"]}}static get states(){return{activeOperations:{},license:{},isFreeAccessEnabled:{},shouldShowSearch:{},isHomePage:{},repositoryList:{},currentRoute:{},currentRepository:{},securityConfig:{},user:{},showUserMenu:{},showLoginButton:{},applicationLogoPath:{}}}}