@ -1,206 +1,119 @@
import { Component , EventEmitter , Input , Output , ViewChild } from '@angular/core' ;
import { FormBuilder } from "@angular/forms" ;
import { EnvProperties } from "../../utils/properties/env-properties" ;
import { SearchCustomFilter } from "./searchUtils.class" ;
import { ConfigurationService } from "../../utils/configuration/configuration.service" ;
import { Router } from "@angular/router" ;
import { MatSelect } from "@angular/material/select" ;
import { Subscription } from "rxjs" ;
import { properties } from '../../../../environments/environment' ;
import { InputComponent , Option } from "../../sharedComponents/input/input.component" ;
import { OpenaireEntities } from "../../utils/properties/searchFields" ;
@Component ( {
selector : 'entities-selection' ,
template : `
< span * ngIf = "!disableSelect && show>1 && selectedEntity"
class = " entitiesSelection portal-box uk-text-small clickable" style = ""
( click ) = "open()" >
< mat - select * ngIf = "!onlyresults" [ ( value ) ] = " selectedEntity "
( valueChange ) = "entityChanged()" [ disableOptionCentering ] = "true" [ panelClass ] = "matPanelClass" >
< mat - option * ngIf = "simpleView && showAll"
value = "all" > All content
< / m a t - o p t i o n >
< mat - option * ngIf = "showResearchOutcomes" value = "result" > Research outcomes < / m a t - o p t i o n >
< mat - option * ngIf = "showProjects" value = "project" > Projects < / m a t - o p t i o n >
< mat - option * ngIf = "showDataProviders" value = "dataprovider" > Content providers < / m a t - o p t i o n >
< mat - option * ngIf = "showOrganizations" value = "organization" > Organizations < / m a t - o p t i o n >
< / m a t - s e l e c t >
< mat - select * ngIf = "onlyresults" [ ( value ) ] = " selectedEntity "
( valueChange ) = "entityChanged()" [ disableOptionCentering ] = "true" [ panelClass ] = "matPanelClass" >
< mat - option
* ngIf = "simpleView && showAll"
value = "all" > All research outcomes
< / m a t - o p t i o n >
< mat - option * ngIf = "showPublications" value = "publications" > Publications < / m a t - o p t i o n >
< mat - option * ngIf = "showDatasets" value = "datasets" > Datasets < / m a t - o p t i o n >
< mat - option * ngIf = "showSoftware" value = "software" > Software < / m a t - o p t i o n >
< mat - option * ngIf = "showOther" value = "other" > Other Research products < / m a t - o p t i o n >
< / m a t - s e l e c t >
< / span >
< span * ngIf = "currentEntity && disableSelect" class = "entitiesSelection portal-box uk-text-small " style = "" >
< div >
< span * ngIf = "currentEntity=='all'" > { { onlyresults ? 'All research outcomes' : 'All content' } } < / span >
< span * ngIf = "currentEntity=='result'" > Research outcomes < / span >
< span * ngIf = "currentEntity=='project'" > Projects < / span >
< span * ngIf = "currentEntity=='dataprovider'" > Content providers < / span >
< span * ngIf = "currentEntity=='organization'" > Organizations < / span >
< span * ngIf = "currentEntity=='publications'" > Publications < / span >
< span * ngIf = "currentEntity=='datasets'" > Datasets < / span >
< span * ngIf = "currentEntity=='software'" > Software < / span >
< span * ngIf = "currentEntity=='other'" > Other Research products < / span >
< / div >
< / span >
<!-- < span * ngIf = "onlyresults && !disableSelect" >
< select * ngIf = "show" [ ( ngModel ) ] = " selectedEntity " class = "uk-select uk-width-auto portal-box uk-text-small" ( ngModelChange ) = " entityChanged ( ) " >
< option
* ngIf = "simpleView && (show)>1 && !(this.customFilter && this.customFilter.queryFieldName=='communityId' )"
value = "all" > All research outcomes
< / option >
< option * ngIf = "showPublications" value = "publications" > Publications < / option >
< option * ngIf = "showDatasets" value = "datasets" > Datasets < / option >
< option * ngIf = "showSoftware" value = "software" > Software < / option >
< option * ngIf = "showOther" value = "other" > Other Research products < / option >
< / select >
< / span > -- >
< ng - container * ngIf = "simpleView" >
< div # input input placeholder = "Type" hint = "What type of content?" inputClass = "advanced-search"
[ options ] = "entities" [ ( value ) ] = "selectedEntity" ( valueChange ) = "entityChanged()" type = "select" > < / div >
< / n g - c o n t a i n e r >
`
} )
export class EntitiesSelectionComponent {
showResearchOutcomes : boolean = false ;
showPublications : boolean = false ;
showDatasets : boolean = false ;
showSoftware : boolean = false ;
showOther : boolean = false ;
showProjects : boolean = false ;
showDataProviders : boolean = false ;
showOrganizations : boolean = false ;
showAll : boolean = true ;
@Input ( ) allEnable = false ;
@Input ( ) properties : EnvProperties = properties ;
@Input ( ) onlyresults : boolean = false ;
@Input ( ) customFilter : SearchCustomFilter = null ;
@Input ( ) @Output ( ) selectedEntity = "Research Outcomes ";
@Input ( ) currentEntity = " Research Outcomes ";
@Input ( ) selectedEntity = "result" ;
@Input ( ) currentEntity = "result" ;
@Input ( ) simpleView : boolean = true ;
@Input ( ) onChangeNavigate : boolean = true ;
@Output ( ) selectionChange = new EventEmitter ( ) ;
@Input ( ) onlyresults : boolean = false ;
@Input ( ) matPanelClass = "matSelectionPanel" ;
@Input ( ) disableSelect : boolean = false ;
show = 0 ;
@ViewChild ( MatSelect ) matSelect : MatSelect ;
subs : Subscription [ ] = [ ] ;
constructor ( private _fb : FormBuilder , private config : ConfigurationService , private router : Router ) { }
@Output ( ) selectionChange = new EventEmitter ( ) ;
@ViewChild ( 'input' ) input : InputComponent ;
public entities : Option [ ] = [ ] ;
public properties : EnvProperties = properties ;
private subscriptions : Subscription [ ] = [ ] ;
constructor ( private config : ConfigurationService , private router : Router ) {
}
ngOnInit() {
this . show = 0 ;
if ( ! this . allEnable ) {
if ( ( this . customFilter && this . customFilter . queryFieldName == "communityId" ) || ( this . properties . adminToolsCommunity !== "monitor" ) ) {
//this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
this . subs . push ( this . config . communityInformationState . subscribe ( data = > {
if ( data ) {
let showEntity = { } ;
let showPage = { } ;
if ( data [ 'entities' ] ) {
for ( let i = 0 ; i < data [ 'entities' ] . length ; i ++ ) {
showEntity [ "" + data [ 'entities' ] [ i ] [ "pid" ] + "" ] = data [ 'entities' ] [ i ] [ "isEnabled" ] ;
}
if ( ( this . customFilter && this . customFilter . queryFieldName == "communityId" ) || ( this . properties . adminToolsCommunity !== "monitor" ) ) {
//this.config.getCommunityInformation(this.properties, (this.customFilter && this.customFilter.queryFieldName == "communityId") ? this.customFilter.valueId : this.properties.adminToolsCommunity).subscribe(data => {
this . subscriptions . push ( this . config . communityInformationState . subscribe ( data = > {
if ( data ) {
let showEntity = { } ;
let showPage = { } ;
if ( data [ 'entities' ] ) {
for ( let i = 0 ; i < data [ 'entities' ] . length ; i ++ ) {
showEntity [ "" + data [ 'entities' ] [ i ] [ "pid" ] + "" ] = data [ 'entities' ] [ i ] [ "isEnabled" ] ;
}
if ( data [ 'pages' ] ) {
for ( let i = 0 ; i < data [ 'pages' ] . length ; i ++ ) {
showPage [ "" + data [ 'pages' ] [ i ] [ "route" ] + "" ] = data [ 'pages' ] [ i ] [ "isEnabled" ] ;
}
}
if ( data [ 'pages' ] ) {
for ( let i = 0 ; i < data [ 'pages' ] . length ; i ++ ) {
showPage [ "" + data [ 'pages' ] [ i ] [ "route" ] + "" ] = data [ 'pages' ] [ i ] [ "isEnabled" ] ;
}
this . showResearchOutcomes = showPage [ this . simpleView?this.properties.searchLinkToResults :this.properties.searchLinkToAdvancedResults ] && ( showEntity [ "publication" ] || showEntity [ "dataset" ] || showEntity [ "software" ] || showEntity [ "orp" ] ) ;
this . showPublications = showPage [ this . simpleView?this.properties.searchLinkToResults :this.properties.searchLinkToAdvancedResults ] && showEntity [ "publication" ] ;
this . showDatasets = showPage [ this . simpleView?this.properties.searchLinkToResults :this.properties.searchLinkToAdvancedResults ] && showEntity [ "dataset" ] ;
this . showSoftware = showPage [ this . simpleView?this.properties.searchLinkToResults :this.properties.searchLinkToAdvancedResults ] && showEntity [ "software" ] ;
this . showOther = showPage [ this . simpleView?this.properties.searchLinkToResults :this.properties.searchLinkToAdvancedResults ] && showEntity [ "orp" ] ;
this . showProjects = showPage [ this . simpleView?this.properties.searchLinkToProjects :this.properties.searchLinkToAdvancedProjects ] && showEntity [ "project" ] ;
this . showOrganizations = showPage [ this . simpleView?this.properties.searchLinkToOrganizations :this.properties.searchLinkToAdvancedOrganizations ] && showEntity [ "organization" ] ;
this . showDataProviders = showPage [ this . simpleView?this.properties.searchLinkToDataProviders :this.properties.searchLinkToAdvancedDataProviders ] && showEntity [ "datasource" ] ;
if ( this . customFilter && this . customFilter . queryFieldName == "communityId" || this . properties . adminToolsCommunity === "connect" ) {
//for community pages: no organization in simple search, only results in advanced
this . showAll = false ;
this . showOrganizations = false ;
if ( ! this . simpleView ) {
this . showProjects = false ;
this . showDataProviders = false ;
}
}
if ( this . onlyresults ) {
this . entities . push ( { label : 'All ' + OpenaireEntities . RESULTS . toLowerCase ( ) , value : 'all' } ) ;
if ( showPage [ this . simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ] && showEntity [ "publication" ] ) {
this . entities . push ( { label : OpenaireEntities.PUBLICATIONS , value : 'publications' } ) ;
}
if ( this . showResearchOutcomes ) {
this . show++ ;
if ( showPage [ this . simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ] && showEntity [ "dataset" ] ) {
this . entities . push ( { label : OpenaireEntities.DATASETS , value : 'datasets' } ) ;
}
if ( this . showDataProviders ) {
this . show++ ;
if ( showPage [ this . simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ] && showEntity [ "software" ] ) {
this . entities . push ( { label : OpenaireEntities.SOFTWARE , value : 'software' } ) ;
}
if ( this . showOrganizations ) {
this . show++ ;
if ( showPage [ this . simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ] && showEntity [ "orp" ] ) {
this . entities . push ( { label : OpenaireEntities.OTHER , value : 'other' } ) ;
}
if ( this . showProjects ) {
this . show ++ ;
} else {
this . entities . push ( { label : 'All Content' , value : 'all' } ) ;
if ( showPage [ this . simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ]
&& ( showEntity [ "publication" ] || showEntity [ "dataset" ] || showEntity [ "software" ] || showEntity [ "orp" ] ) ) {
this . entities . push ( { label : OpenaireEntities.RESULTS , value : 'result' } ) ;
}
if ( this . show == 1 ) {
this . disableSelect = true ;
if ( showPage [ this . simpleView ? this . properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects ] && showEntity [ "project" ] ) {
this . entities . push ( { label : OpenaireEntities.PROJECTS , value : 'project' } ) ;
}
if ( showPage [ this . simpleView ? this . properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations ] && showEntity [ "organization" ] ) {
this . entities . push ( { label : OpenaireEntities.ORGANIZATIONS , value : 'organization' } ) ;
}
if ( showPage [ this . simpleView ? this . properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders ] && showEntity [ "datasource" ] ) {
this . entities . push ( { label : OpenaireEntities.DATASOURCES , value : 'dataprovider' } ) ;
}
}
if ( this . customFilter && this . customFilter . queryFieldName == "communityId" || this . properties . adminToolsCommunity === "connect" ) {
//for community pages: no organization in simple search, only results in advanced
this . entities = this . entities . filter ( option = > option . value !== 'organization' && option . value !== 'all' ) ;
if ( ! this . simpleView ) {
this . entities = this . entities . filter ( option = > option . value !== 'project' && option . value !== 'dataprovider' ) ;
}
}
} ) ) ;
} else if ( ( this . customFilter && this . customFilter . queryFieldName == "community" ) && this . properties . adminToolsCommunity === "monitor" ) {
this . show = 1 ;
this . disableSelect = true ;
} else if ( this . customFilter && ( this . customFilter . queryFieldName == "relfunder" || this . customFilter . queryFieldName == "funder" ) ) {
/ * t h i s . s h o w R e s e a r c h O u t c o m e s = t r u e ;
this . showPublications = true ;
this . showDatasets = true ;
this . showSoftware = true ;
this . showOther = true ;
this . showProjects = true ;
this . showAll = false ;
this . show = 2 ; * /
this . show = 1 ;
this . disableSelect = true ;
} else if ( this . customFilter && this . customFilter . queryFieldName == "relorganizationid" ) {
/ * t h i s . s h o w R e s e a r c h O u t c o m e s = t r u e ;
this . showPublications = true ;
this . showDatasets = true ;
this . showSoftware = true ;
this . showOther = true ;
this . showProjects = true ;
this . showDataProviders = true ;
this . showAll = false ;
this . show = 3 ; * /
this . show = 1 ;
this . disableSelect = true ;
this . disableSelect = this . entities . length == 1 ;
}
} ) ) ;
} else if ( ( this . customFilter && this . customFilter . queryFieldName == "community" ) && this . properties . adminToolsCommunity === "monitor" ) {
this . disableSelect = true ;
} else if ( this . customFilter && ( this . customFilter . queryFieldName == "relfunder" || this . customFilter . queryFieldName == "funder" ) ) {
this . disableSelect = true ;
} else if ( this . customFilter && this . customFilter . queryFieldName == "relorganizationid" ) {
this . disableSelect = true ;
} else {
if ( this . onlyresults ) {
this . entities . push ( { label : 'All ' + OpenaireEntities . RESULTS . toLowerCase ( ) , value : 'all' } ) ;
this . entities . push ( { label : OpenaireEntities.PUBLICATIONS , value : 'publications' } ) ;
this . entities . push ( { label : OpenaireEntities.DATASETS , value : 'datasets' } ) ;
this . entities . push ( { label : OpenaireEntities.SOFTWARE , value : 'software' } ) ;
this . entities . push ( { label : OpenaireEntities.OTHER , value : 'other' } ) ;
} else {
this . showResearchOutcomes = true ;
this . showPublications = true ;
this . showDatasets = true ;
this . showSoftware = true ;
this . showOther = true ;
this . showProjects = true ;
this . showOrganizations = true ;
this . showDataProviders = true ;
this . showAll = false ;
this . show = 4 ;
this . entities . push ( { label : 'All Content' , value : 'all' } ) ;
this . entities . push ( { label : OpenaireEntities.RESULTS , value : 'result' } ) ;
this . entities . push ( { label : OpenaireEntities.PROJECTS , value : 'project' } ) ;
this . entities . push ( { label : OpenaireEntities.ORGANIZATIONS , value : 'organization' } ) ;
this . entities . push ( { label : OpenaireEntities.DATASOURCES , value : 'dataprovider' } ) ;
}
} else {
this . showResearchOutcomes = true ;
this . showPublications = true ;
this . showDatasets = true ;
this . showSoftware = true ;
this . showOther = true ;
this . showProjects = true ;
this . showOrganizations = true ;
this . showDataProviders = true ;
this . showAll = true ;
this . show = 5 ;
console . log ( this . entities ) ;
}
this . selectedEntity = this . currentEntity ;
this . selectionChange . emit ( {
@ -209,16 +122,16 @@ export class EntitiesSelectionComponent {
advancedUrl : this.getUrl ( false )
} ) ;
}
public ngOnDestroy() {
for ( let sub of this . sub s) {
sub . unsubscribe ( ) ;
for ( let sub scription of this . sub scription s) {
sub scription . unsubscribe ( ) ;
}
}
entityChanged() {
if ( ! this . simpleView || this . onChangeNavigate ) {
this . router . navigate ( [ this . getUrl ( this . simpleView ) ] , { queryParams : this.customFilter ?this.customFilter.getParameters( ) : { } } ) ;
this . router . navigate ( [ this . getUrl ( this . simpleView ) ] , { queryParams : this.customFilter ? this . customFilter . getParameters( ) : { } } ) ;
} else {
this . selectionChange . emit ( {
entity : this.selectedEntity ,
@ -229,36 +142,21 @@ export class EntitiesSelectionComponent {
}
getUrl ( simpleView : boolean ) {
let url = "" ;
getUrl ( simpleView : boolean ) : string {
if ( ! this . onlyresults ) {
if ( this . selectedEntity == "all" ) {
url = ( simpleView ? "/search/find/" : null ) ;
return ( simpleView ? "/search/find/" : null ) ;
} else if ( this . selectedEntity == "result" ) {
url = ( simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ) ;
return ( simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ) ;
} else if ( this . selectedEntity == "project" ) {
url = ( simpleView ? this . properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects ) ;
return ( simpleView ? this . properties.searchLinkToProjects : this.properties.searchLinkToAdvancedProjects ) ;
} else if ( this . selectedEntity == "dataprovider" ) {
url = ( simpleView ? this . properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders ) ;
return ( simpleView ? this . properties.searchLinkToDataProviders : this.properties.searchLinkToAdvancedDataProviders ) ;
} else if ( this . selectedEntity == "organization" ) {
url = ( simpleView ? this . properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations ) ;
return ( simpleView ? this . properties.searchLinkToOrganizations : this.properties.searchLinkToAdvancedOrganizations ) ;
}
} else {
url = ( simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ) ;
}
return url ;
}
toggle() {
if ( this . matSelect ) {
this . matSelect . toggle ( ) ;
return ( simpleView ? this . properties.searchLinkToResults : this.properties.searchLinkToAdvancedResults ) ;
}
}
open() {
if ( this . matSelect && ! this . matSelect . focused ) {
this . matSelect . open ( ) ;
}
}
}