UNPKG

graphdb-workbench

Version:
1 lines 9 kB
import{Host,h}from"@stencil/core";import{ServiceProvider,LicenseContextService,SubscriptionList,MonitoringService,RepositoryContextService,SecurityContextService,FibonacciGenerator,OntoToastrService,RepositoryLocationContextService,EventService,EventName,getPathName,isHomePage,NamespacesService,NamespacesContextService,RepositoryList,RepositoryService,LanguageService,LanguageContextService,ObjectUtil,getCurrentRoute,AuthenticationService,WindowService}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";export class OntoHeader{constructor(){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.UPDATE_ACTIVE_OPERATION_TIME_INTERVAL=2e3,this.fibonacciGenerator=new FibonacciGenerator,this.authService=ServiceProvider.get(AuthenticationService),this.eventService=ServiceProvider.get(EventService),this.shouldShowSearch=!0,this.isHomePage=isHomePage(),this.isActiveLocationLoading=!1,this.repositoryItems=[],this.subscriptions=new SubscriptionList,this.skipUpdateActiveOperationsTimes=0,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.subscribeToEvents(),this.currentRoute=getCurrentRoute(),this.startOperationPolling()}render(){var e,t,i,s,o,r;return h(Host,{key:"8222e10554a901e025c47424aea4b6294f240ea4"},h("div",{key:"8a0b771d5dbddcb7acff61e7a436d2e4a097277f",class:"header-component"},h("onto-search-icon",{key:"d24c7f1be0241391078cc730a1ef2a5a86172e8f",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:"b75323ddf445ea121fd6067723bf8550b861f4e5","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:"25a3345c6482a2794032b161a78bc98204aff061",currentRepository:this.currentRepository,items:this.repositoryItems,repositorySizeInfoFetcher:this.repositorySizeInfoFetcher,totalTripletsFormatter:this.totalTripletsFormatter,canWriteRepo:this.canWriteRepo}),(null===(i=this.securityConfig)||void 0===i?void 0:i.enabled)&&(null===(s=this.securityConfig)||void 0===s?void 0:s.userLoggedIn)?h("onto-user-menu",{user:this.user,securityConfig:this.securityConfig}):"",(null===(o=this.securityConfig)||void 0===o?void 0:o.enabled)&&!(null===(r=this.securityConfig)||void 0===r?void 0:r.userLoggedIn)&&"login"!==this.currentRoute?h("onto-user-login",null):"",h("onto-language-selector",{key:"16cba1ff6d691fe0b7442d88940ec9f9ee22aebd","dropdown-alignment":"right"})))}subscribeToEvents(){this.subscribeToSecurityContextChange(),this.subscribeToRepositoryListChanged(),this.subscribeToLicenseChange(),this.subscribeToRepositoryChange(),this.subscribeToActiveRepositoryLocationChange(),this.subscribeToActiveRepoLoadingChange(),this.subscribeToNavigationEnd(),this.subscribeToLanguageChanged(),this.subscribeToAuthenticatedUserChange()}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=e,this.shouldShowSearch=this.shouldShowRdfSearch(),this.loadNamespaces(),this.updateRepositoryItems()}))}subscribeToSecurityContextChange(){this.subscriptions.add(this.securityContextService.onAuthenticatedUserChanged(e=>{this.user=e})),this.subscriptions.add(this.securityContextService.onSecurityConfigChanged(e=>{this.securityConfig=e}))}subscribeToAuthenticatedUserChange(){this.subscriptions.add(this.securityContextService.onAuthenticatedUserChanged(()=>{this.updateRepositoryItems()}))}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()}))}subscribeToLanguageChanged(){this.subscriptions.add(ServiceProvider.get(LanguageContextService).onSelectedLanguageChanged(e=>this.setupTotalRepositoryFormater(e)))}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.authService.canReadRepo(e)||this.authService.canReadGqlRepo(e)).map(e=>(new DropdownItem).setName(h(SelectorItemButton,{repository:e})).setValue(e).setDropdownTooltipTrigger("mouseenter focus").setGuideSelector(`repository-id-${e.id}`))}canWriteRepoInLocation(e){return!0}loadNamespaces(){this.currentRepository&&this.authService.canReadRepo(this.currentRepository)&&this.namespacesService.getNamespaces(this.currentRepository.id).then(e=>this.namespaceContextService.updateNamespaces(e))}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.authService.canReadRepo(this.currentRepository)}setupTotalRepositoryFormater(e){e||(e=this.languageService.getDefaultLanguage()),this.totalTripletsFormatter=new Intl.NumberFormat(e,{style:"decimal",minimumFractionDigits:0,maximumFractionDigits:0})}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:{}}}}