2019-04-24 14:02:11 +02:00
import { Component , ViewChild } from "@angular/core" ;
2019-04-05 19:29:28 +02:00
import { SearchUtilsClass } from "../../openaireLibrary/searchPages/searchUtils/searchUtils.class" ;
import { ErrorMessagesComponent } from "../../openaireLibrary/utils/errorMessages.component" ;
import { ErrorCodes } from "../../openaireLibrary/utils/properties/errorCodes" ;
import { EnvProperties } from "../../openaireLibrary/utils/properties/env-properties" ;
import { ActivatedRoute } from "@angular/router" ;
2020-04-28 10:05:03 +02:00
import { AdvancedField , Filter , Value } from "../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class" ;
2019-04-05 19:29:28 +02:00
import { SearchFields } from "../../openaireLibrary/utils/properties/searchFields" ;
import { CommunitiesService } from "../../openaireLibrary/connect/communities/communities.service" ;
2019-09-13 09:47:29 +02:00
import { Session , User } from "../../openaireLibrary/login/utils/helper.class" ;
2019-04-05 19:29:28 +02:00
import { CommunityInfo } from "../../openaireLibrary/connect/community/communityInfo" ;
import { StringUtils } from "../../openaireLibrary/utils/string-utils.class" ;
2019-04-24 14:02:11 +02:00
import { HelperFunctions } from "../../openaireLibrary/utils/HelperFunctions.class" ;
2019-09-13 09:47:29 +02:00
import { UserManagementService } from "../../openaireLibrary/services/user-management.service" ;
2020-04-24 18:33:03 +02:00
import { Breadcrumb } from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component" ;
2020-04-28 10:05:03 +02:00
import { NewSearchPageComponent } from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component" ;
2020-11-12 16:59:26 +01:00
import { properties } from "../../../environments/environment" ;
import { Subscriber } from "rxjs" ;
2019-04-05 19:29:28 +02:00
@Component ( {
selector : 'search-communities' ,
template : `
2021-05-12 09:31:21 +02:00
< new - search - page pageTitle = "Search Communities"
[ hasPrefix ] = true prefix = "OpenAIRE Connect | " [ piwikSiteId ] = "piwikSiteId"
2020-06-04 13:38:43 +02:00
searchFormClass = "communitiesSearchForm"
[ formPlaceholderText ] = "'Search for Research Gateways…'"
type = "communities" entityType = "community"
[ results ] = "results" [ searchUtils ] = "searchUtils"
[ showResultCount ] = true
[ disableForms ] = "disableForms"
2021-03-08 16:40:49 +01:00
[ showIndexInfo ] = false
2020-06-04 13:38:43 +02:00
[ simpleView ] = "true"
[ fieldIds ] = "fieldIds" [ fieldIdsMap ] = "fieldIdsMap" [ selectedFields ] = "selectedFields"
2021-05-12 09:31:21 +02:00
[ simpleSearchLink ] = "searchLink" [ entitiesSelection ] = "false" [ showBreadcrumb ] = "true" [ basicMetaDescription ] = "['Research communities', 'Discover OpenAIRE research gateways for research communities.']" >
2020-06-04 13:38:43 +02:00
< / n e w - s e a r c h - p a g e >
2019-04-05 19:29:28 +02:00
`
} )
export class SearchCommunitiesComponent {
2019-08-02 16:56:03 +02:00
public piwikSiteId = null ;
2019-04-05 19:29:28 +02:00
private errorCodes : ErrorCodes ;
private errorMessages : ErrorMessagesComponent ;
2019-04-13 20:21:51 +02:00
public results : CommunityInfo [ ] = [ ] ;
public totalResults : CommunityInfo [ ] = [ ] ;
2020-11-12 16:59:26 +01:00
public subscriptions = [ ] ;
2019-04-05 19:29:28 +02:00
public filters = [ ] ;
2020-06-04 13:38:43 +02:00
public searchFields : SearchFields = new SearchFields ( ) ;
public searchUtils : SearchUtilsClass = new SearchUtilsClass ( ) ;
public selectedFields : AdvancedField [ ] = [ ] ;
2019-04-05 19:29:28 +02:00
public disableForms : boolean = false ;
public baseUrl : string = null ;
2020-04-28 10:05:03 +02:00
public fieldIds : string [ ] = [ "q" ] ;
2020-06-04 13:38:43 +02:00
public refineFields : string [ ] = this . searchFields . COMMUNITIES_SEARCH_FIELDS ;
public fieldIdsMap = {
[ "q" ] : {
name : "All fields" ,
type : "keyword" ,
param : "q" ,
operator : "op" ,
equalityOperator : "=" ,
filterType : null
}
} ;
2020-04-29 09:53:37 +02:00
public keyword = "" ;
2020-04-28 10:05:03 +02:00
public searchLink ;
2019-08-05 12:31:12 +02:00
public showType = false ;
2020-04-24 18:33:03 +02:00
public breadcrumbs : Breadcrumb [ ] = [ { name : 'home' , route : '/' } , { name : 'communities' } ] ;
2020-06-04 13:38:43 +02:00
properties : EnvProperties ;
@ViewChild ( NewSearchPageComponent ) searchPage : NewSearchPageComponent ;
2019-09-13 09:47:29 +02:00
private user : User ;
2020-06-04 13:38:43 +02:00
private userFilterLoaded : boolean = false ;
constructor ( private route : ActivatedRoute ,
private _communitiesService : CommunitiesService ,
private userManagementService : UserManagementService ) {
2019-04-05 19:29:28 +02:00
this . errorCodes = new ErrorCodes ( ) ;
this . errorMessages = new ErrorMessagesComponent ( ) ;
this . searchUtils . status = this . errorCodes . LOADING ;
}
2020-06-04 13:38:43 +02:00
2019-04-05 19:29:28 +02:00
public ngOnInit() {
2020-04-29 09:53:37 +02:00
var firstLoad = true ;
2020-11-12 16:59:26 +01:00
this . properties = properties ;
this . piwikSiteId = this . properties . piwikSiteId ;
this . baseUrl = this . properties . searchLinkToCommunities ;
2021-02-19 18:52:12 +01:00
2020-11-12 16:59:26 +01:00
this . subscriptions . push ( this . route . queryParams . subscribe ( params = > {
2019-07-03 15:32:59 +02:00
this . searchPage . resultsPerPage = 10 ;
2020-06-04 13:38:43 +02:00
this . keyword = ( params [ 'fv0' ] ? params [ 'fv0' ] : '' ) ;
2020-04-29 09:53:37 +02:00
this . keyword = StringUtils . URIDecode ( this . keyword ) ;
2020-06-04 13:38:43 +02:00
this . searchUtils . page = ( params [ 'page' ] === undefined ) ? 1 : + params [ 'page' ] ;
this . searchUtils . sortBy = ( params [ 'sortBy' ] === undefined ) ? '' : params [ 'sortBy' ] ;
this . searchUtils . size = ( params [ 'size' ] === undefined ) ? this . searchPage . resultsPerPage : + params [ 'size' ] ;
2020-04-28 10:05:03 +02:00
this . searchUtils . baseUrl = this . baseUrl ;
2019-05-03 11:37:58 +02:00
this . searchPage . searchUtils = this . searchUtils ;
2020-06-04 13:38:43 +02:00
if ( this . searchUtils . size != 5 && this . searchUtils . size != 10 && this . searchUtils . size != 20 && this . searchUtils . size != 50 ) {
2019-04-07 18:08:10 +02:00
this . searchUtils . size = this . searchPage . resultsPerPage ;
}
2020-06-04 13:38:43 +02:00
if ( this . searchUtils . sortBy && this . searchUtils . sortBy != "creationdate,descending" && this . searchUtils . sortBy != "creationdate,ascending" ) {
2019-04-07 18:08:10 +02:00
this . searchUtils . sortBy = "" ;
}
2019-04-05 19:29:28 +02:00
this . searchPage . refineFields = this . refineFields ;
2020-04-28 10:05:03 +02:00
this . searchLink = this . properties . searchLinkToCommunities ;
2020-04-29 09:53:37 +02:00
this . selectedFields = [ ] ;
2020-06-04 13:38:43 +02:00
this . searchPage . prepareSearchPage ( this . fieldIds , this . selectedFields , this . refineFields , [ ] , this . fieldIdsMap , null , params , "community" , null ) ;
2020-04-28 10:05:03 +02:00
let queryParams = params ; //this.searchPage.getQueryParamsFromUrl(params);
2020-06-04 13:38:43 +02:00
if ( typeof document !== 'undefined' ) {
2020-11-12 16:59:26 +01:00
this . subscriptions . push ( this . userManagementService . getUserInfo ( ) . subscribe ( user = > {
2019-11-08 12:04:10 +01:00
this . user = user ;
this . initCommunities ( queryParams ) ;
2020-11-12 16:59:26 +01:00
} ) ) ;
2020-06-04 13:38:43 +02:00
} else {
2019-09-13 09:47:29 +02:00
this . initCommunities ( queryParams ) ;
2019-11-08 12:04:10 +01:00
}
2020-11-12 16:59:26 +01:00
} ) ) ;
2019-04-05 19:29:28 +02:00
}
2021-02-19 18:52:12 +01:00
2020-11-12 16:59:26 +01:00
ngOnDestroy() {
this . subscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
}
} ) ;
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
2019-04-12 11:50:10 +02:00
/ * *
2019-04-13 20:21:51 +02:00
* Initialize communities from Communities APIs
2019-04-12 11:50:10 +02:00
*
* @param params
* /
2020-04-28 10:05:03 +02:00
private initCommunities ( params ) {
2020-11-12 16:59:26 +01:00
this . subscriptions . push ( this . _communitiesService . getCommunitiesState ( ) . subscribe (
2020-06-04 13:38:43 +02:00
data = > {
if ( ! data ) {
return ;
}
for ( let i = 0 ; i < data . length ; i ++ ) {
this . totalResults [ i ] = data [ i ] ;
this . totalResults [ i ] . isManager = false ;
this . totalResults [ i ] . isSubscribed = false ;
if ( this . user ) {
this . totalResults [ i ] . isManager = this . isCommunityManager ( this . totalResults [ i ] ) ;
2021-02-19 18:52:12 +01:00
this . totalResults [ i ] . isSubscribed = Session . isSubscribedTo ( 'community' , this . totalResults [ i ] . communityId , this . user ) ;
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
}
if ( this . user ) {
2021-02-19 18:52:12 +01:00
this . _getResults ( params ) ;
2020-06-04 13:38:43 +02:00
} else {
this . _getResults ( params ) ;
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
} ,
err = > {
this . handleError ( 'Error getting communities' , err ) ;
this . searchUtils . status = this . errorMessages . getErrorCode ( err . status ) ;
this . disableForms = false ;
}
2020-11-12 16:59:26 +01:00
) ) ;
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
2019-04-13 20:21:51 +02:00
/ * *
* Get all communities from Communities API and apply permission access validator ,
* keyword searching , filter , paging and sorting .
*
* @param params , status
* @private
* /
2020-06-05 15:03:25 +02:00
private _getResults ( params ) {
2019-04-13 20:21:51 +02:00
this . searchUtils . status = this . errorCodes . LOADING ;
this . disableForms = true ;
this . results = this . totalResults ;
2020-12-02 16:28:03 +01:00
this . filters = this . createFilters ( ) ;
2019-04-13 20:21:51 +02:00
this . searchUtils . totalResults = 0 ;
2019-04-15 12:48:18 +02:00
this . applyParams ( params ) ;
2019-04-13 20:21:51 +02:00
}
2020-06-04 13:38:43 +02:00
2019-04-13 20:21:51 +02:00
/ * *
* Return the communities in which user has permission to view or manage .
* /
private showCommunities() {
let ret : CommunityInfo [ ] = [ ] ;
2020-06-04 13:38:43 +02:00
for ( let result of this . results ) {
2019-04-13 20:21:51 +02:00
if ( result . status == 'hidden' ) {
continue ;
} else if ( result . status == "manager" ) {
2020-06-04 13:38:43 +02:00
let mail = ( this . user ) ? this . user.email : null ;
2019-04-13 20:21:51 +02:00
if ( mail == null ) { // no user
continue ;
2019-09-13 09:47:29 +02:00
} else if ( Session . isCommunityCurator ( this . user ) || Session . isPortalAdministrator ( this . user ) ) {
2019-04-13 20:21:51 +02:00
ret . push ( result ) ;
} else if ( result . managers . indexOf ( mail ) != - 1 ) {
ret . push ( result ) ;
}
continue ;
}
ret . push ( result ) ;
}
this . results = ret ;
}
2020-06-04 13:38:43 +02:00
2019-04-12 16:16:08 +02:00
/ * *
* Apply permission access validator ,
* keyword searching , filter , paging and sorting .
*
* @param params
* @param status
* /
2019-04-15 12:48:18 +02:00
public applyParams ( params : Map < string , string > ) {
2019-04-12 16:16:08 +02:00
this . showCommunities ( ) ;
2020-06-04 13:38:43 +02:00
if ( this . keyword && this . keyword != '' ) {
2019-04-12 16:16:08 +02:00
this . searchForKeywords ( ) ;
}
this . checkFilters ( params ) ;
this . sort ( ) ;
this . searchUtils . totalResults = this . results . length ;
2020-12-02 16:28:03 +01:00
this . filters = this . searchPage . prepareFiltersToShow ( this . filters , this . searchUtils . totalResults ) ;
2020-06-04 13:38:43 +02:00
this . results = this . results . slice ( ( this . searchUtils . page - 1 ) * this . searchUtils . size , ( this . searchUtils . page * this . searchUtils . size ) ) ;
2019-04-15 12:48:18 +02:00
this . searchUtils . status = this . errorCodes . DONE ;
2020-06-04 13:38:43 +02:00
if ( this . searchUtils . totalResults == 0 ) {
2019-04-12 16:16:08 +02:00
this . searchUtils . status = this . errorCodes . NONE ;
}
this . disableForms = false ;
2020-06-04 13:38:43 +02:00
if ( this . searchUtils . status == this . errorCodes . DONE ) {
2019-04-12 16:16:08 +02:00
// Page out of limit!!!
2020-06-04 13:38:43 +02:00
let totalPages : any = this . searchUtils . totalResults / ( this . searchUtils . size ) ;
if ( ! ( Number . isInteger ( totalPages ) ) ) {
2019-04-12 16:16:08 +02:00
totalPages = ( parseInt ( totalPages , 10 ) + 1 ) ;
}
2020-06-04 13:38:43 +02:00
if ( totalPages < this . searchUtils . page ) {
2019-04-12 16:16:08 +02:00
this . searchUtils . totalResults = 0 ;
this . searchUtils . status = this . errorCodes . OUT_OF_BOUND ;
}
}
}
2020-06-04 13:38:43 +02:00
2019-04-12 11:50:10 +02:00
/ * *
* Parse the given keywords into array and check if any of the requirements field of a community includes
* one of the given words .
* /
2019-04-07 18:08:10 +02:00
private searchForKeywords() {
2020-06-04 13:38:43 +02:00
let ret : CommunityInfo [ ] = [ ] ;
let keywords : string [ ] = this . keyword . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
for ( let i = 0 ; i < this . results . length ; i ++ ) {
for ( let keyword of keywords ) {
keyword = keyword . toLowerCase ( ) ;
2020-06-05 15:03:25 +02:00
if ( keyword != '' && ( StringUtils . containsWord ( this . results [ i ] . title , keyword ) || StringUtils . containsWord ( this . results [ i ] . shortTitle , keyword ) ||
StringUtils . containsWord ( this . results [ i ] . communityId , keyword ) || StringUtils . containsWord ( this . results [ i ] . description , keyword ) ) ) {
2020-06-04 13:38:43 +02:00
ret . push ( this . results [ i ] ) ;
break ;
}
2019-04-07 18:08:10 +02:00
}
2020-06-04 13:38:43 +02:00
}
this . results = ret ;
2019-04-07 18:08:10 +02:00
}
2020-06-04 13:38:43 +02:00
2019-04-12 11:50:10 +02:00
/ * *
* Check the current results if they satisfy the values of each filter category and
* update the number of possible results in each value .
*
* @param params
* /
2020-06-05 15:03:25 +02:00
private checkFilters ( params ) {
2019-04-13 20:21:51 +02:00
let typeResults : CommunityInfo [ ] = this . applyFilter ( 'type' , params ) ;
2019-04-15 11:16:29 +02:00
let statusResults : CommunityInfo [ ] = this . results ;
let roleResults : CommunityInfo [ ] = this . results ;
2020-06-04 13:38:43 +02:00
if ( this . user ) {
2019-04-15 11:16:29 +02:00
statusResults = this . applyFilter ( 'status' , params ) ;
roleResults = this . applyFilter ( 'role' , params ) ;
this . resetFilterNumbers ( 'status' ) ;
this . updateFilterNumbers ( typeResults . filter ( value = > {
return roleResults . includes ( value ) ;
} ) , 'status' ) ;
this . resetFilterNumbers ( 'role' ) ;
this . updateFilterNumbers ( statusResults . filter ( value = > {
return typeResults . includes ( value ) ;
} ) , 'role' ) ;
}
2019-04-07 18:08:10 +02:00
this . resetFilterNumbers ( 'type' ) ;
2019-04-12 10:54:55 +02:00
this . updateFilterNumbers ( statusResults . filter ( value = > {
return roleResults . includes ( value ) ;
} ) , 'type' ) ;
2019-04-07 18:08:10 +02:00
this . results = statusResults . filter ( value = > {
return typeResults . includes ( value ) ;
2019-04-12 10:54:55 +02:00
} )
this . results = this . results . filter ( value = > {
return roleResults . includes ( value ) ;
2019-04-07 18:08:10 +02:00
} ) ;
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
2019-04-12 11:50:10 +02:00
/ * *
* Apply filter with filterId and return the results
*
* @param filterId
* @param params
* /
2020-04-28 10:05:03 +02:00
private applyFilter ( filterId : string , params ) : CommunityInfo [ ] {
2020-06-04 13:38:43 +02:00
let results : CommunityInfo [ ] = [ ] ;
2019-04-12 11:50:10 +02:00
let values : string [ ] = [ ] ;
2020-06-05 15:03:25 +02:00
if ( params [ filterId ] ) {
2020-06-04 13:38:43 +02:00
values = ( StringUtils . URIDecode ( params [ filterId ] ) ) . split ( /,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/ , - 1 ) ;
2019-04-12 11:50:10 +02:00
}
2020-06-04 13:38:43 +02:00
if ( filterId == 'type' ) {
2019-04-12 11:50:10 +02:00
for ( let i = 0 ; i < this . results . length ; i ++ ) {
if ( values . length == 0 ) {
results . push ( this . results [ i ] ) ;
} else {
for ( let value of values ) {
2019-04-13 20:21:51 +02:00
if ( this . results [ i ] . type == value . replace ( /["']/g , "" ) ) {
2019-04-12 11:50:10 +02:00
results . push ( this . results [ i ] ) ;
break ;
}
}
}
}
2020-06-04 13:38:43 +02:00
} else if ( filterId == 'status' ) {
2019-04-12 11:50:10 +02:00
for ( let i = 0 ; i < this . results . length ; i ++ ) {
if ( values . length == 0 ) {
results . push ( this . results [ i ] ) ;
} else {
for ( let value of values ) {
if ( value . replace ( /["']/g , "" ) == 'subscribed' ) {
if ( this . results [ i ] . isSubscribed ) {
results . push ( this . results [ i ] ) ;
break ;
}
} else if ( value . replace ( /["']/g , "" ) == 'nonsubscribed' ) {
if ( ! this . results [ i ] . isSubscribed ) {
results . push ( this . results [ i ] ) ;
break ;
}
}
}
}
}
2020-06-04 13:38:43 +02:00
} else if ( filterId == 'role' ) {
2019-04-12 11:50:10 +02:00
for ( let i = 0 ; i < this . results . length ; i ++ ) {
if ( values . length == 0 ) {
results . push ( this . results [ i ] ) ;
} else {
for ( let value of values ) {
if ( value . replace ( /["']/g , "" ) == 'manager' ) {
if ( this . results [ i ] . isManager ) {
results . push ( this . results [ i ] ) ;
break ;
}
}
}
}
}
}
return results ;
}
2020-06-04 13:38:43 +02:00
/ * *
* Reset the values of filter with id filterId with zero .
*
* @param filterId
* /
2019-04-07 18:08:10 +02:00
private resetFilterNumbers ( filterId : string ) {
2019-04-05 19:29:28 +02:00
for ( let i = 0 ; i < this . filters . length ; i ++ ) {
2020-06-04 13:38:43 +02:00
if ( this . filters [ i ] . filterId == filterId ) {
2019-04-07 18:08:10 +02:00
for ( let j = 0 ; j < this . filters [ i ] . values . length ; j ++ ) {
this . filters [ i ] . values [ j ] . number = 0 ;
}
break ;
2019-04-05 19:29:28 +02:00
}
}
2019-04-07 18:08:10 +02:00
}
2020-06-04 13:38:43 +02:00
/ * *
* Update the values of filter with id filterId based on
* results .
*
* @param results
* @param filterId
* /
2019-04-13 20:21:51 +02:00
private updateFilterNumbers ( results : CommunityInfo [ ] , filterId : string ) {
2020-06-04 13:38:43 +02:00
for ( let k = 0 ; k < results . length ; k ++ ) {
2019-04-05 19:29:28 +02:00
for ( let i = 0 ; i < this . filters . length ; i ++ ) {
2020-06-04 13:38:43 +02:00
if ( this . filters [ i ] . filterId == filterId ) {
if ( this . filters [ i ] . filterId == 'type' ) {
for ( let j = 0 ; j < this . filters [ i ] . values . length ; j ++ ) {
if ( results [ k ] . type == this . filters [ i ] . values [ j ] . id ) {
this . filters [ i ] . values [ j ] . number ++ ;
}
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
} else if ( this . filters [ i ] . filterId == 'status' ) {
if ( results [ k ] . isSubscribed ) {
this . filters [ i ] . values [ 0 ] . number ++ ;
} else {
this . filters [ i ] . values [ 1 ] . number ++ ;
2019-04-12 10:54:55 +02:00
}
2020-06-04 13:38:43 +02:00
} else if ( this . filters [ i ] . filterId == 'role' ) {
if ( results [ k ] . isManager ) {
this . filters [ i ] . values [ 0 ] . number ++ ;
2019-04-07 18:08:10 +02:00
}
2020-06-04 13:38:43 +02:00
}
break ;
2019-04-05 19:29:28 +02:00
}
}
}
}
2020-06-04 13:38:43 +02:00
/ * *
* Sorting results based on sortBy .
* /
2019-04-07 18:08:10 +02:00
private sort() {
2020-06-04 13:38:43 +02:00
if ( this . searchUtils . sortBy == '' ) {
2019-04-07 18:08:10 +02:00
this . results . sort ( ( left , right ) : number = > {
2019-04-13 20:21:51 +02:00
if ( left . title > right . title ) {
2019-04-07 18:08:10 +02:00
return 1 ;
2019-04-13 20:21:51 +02:00
} else if ( left . title < right . title ) {
2019-04-07 18:08:10 +02:00
return - 1 ;
} else {
return 0 ;
}
} )
2020-06-04 13:38:43 +02:00
} else if ( this . searchUtils . sortBy == 'creationdate,descending' ) {
2019-04-07 18:08:10 +02:00
this . results . sort ( ( left , right ) : number = > {
2019-04-13 20:21:51 +02:00
if ( ! right . date || left . date > right . date ) {
2019-04-07 18:08:10 +02:00
return - 1 ;
2019-04-13 20:21:51 +02:00
} else if ( ! left . date || left . date < right . date ) {
2019-04-07 18:08:10 +02:00
return 1 ;
} else {
return 0 ;
}
} )
2020-06-04 13:38:43 +02:00
} else if ( this . searchUtils . sortBy == 'creationdate,ascending' ) {
2019-04-07 18:08:10 +02:00
this . results . sort ( ( left , right ) : number = > {
2019-04-13 20:21:51 +02:00
if ( ! right . date || left . date > right . date ) {
2019-04-07 18:08:10 +02:00
return 1 ;
2019-04-13 20:21:51 +02:00
} else if ( ! left . date || left . date < right . date ) {
2019-04-07 18:08:10 +02:00
return - 1 ;
} else {
return 0 ;
}
} )
}
}
2020-06-04 13:38:43 +02:00
2019-04-05 19:29:28 +02:00
private isCommunityManager ( community : CommunityInfo ) : boolean {
2021-02-19 18:52:12 +01:00
return Session . isPortalAdministrator ( this . user ) || Session . isCommunityCurator ( this . user ) || Session . isManager ( 'community' , community . communityId , this . user ) ;
2019-04-05 19:29:28 +02:00
}
2020-06-04 13:38:43 +02:00
/ * *
* Create Search Communities filters .
*
* /
2019-04-05 19:29:28 +02:00
private createFilters ( ) : Filter [ ] {
2019-08-05 12:31:12 +02:00
let filter_names = [ ] ;
let filter_ids = [ ] ;
2019-04-05 19:29:28 +02:00
let searchFields = new SearchFields ( ) ;
let filter_original_ids = searchFields . COMMUNITIES_SEARCH_FIELDS ;
2019-08-05 12:31:12 +02:00
let value_names = [ ] ;
2020-06-04 13:38:43 +02:00
let value_original_ids = [ ] ;
2019-08-05 12:31:12 +02:00
this . showType = this . results . filter ( community = > community . type === 'ri' ) . length > 0 ;
2020-06-04 13:38:43 +02:00
if ( this . showType ) {
2019-08-05 12:31:12 +02:00
filter_names . push ( "Type" ) ;
filter_ids . push ( "type" ) ;
2020-06-04 13:38:43 +02:00
value_names . push ( [ "Research Communities" , "Research Initiatives" ] ) ;
value_original_ids . push ( [ "community" , "ri" ] ) ;
2019-08-05 12:31:12 +02:00
} else {
filter_original_ids = searchFields . COMMUNITIES_SEARCH_FIELDS . splice ( 0 , 1 ) ;
}
2020-06-04 13:38:43 +02:00
if ( this . user ) {
2019-08-05 12:31:12 +02:00
filter_names . push ( "Status" ) ;
filter_ids . push ( "status" ) ;
2020-06-04 13:38:43 +02:00
value_names . push ( [ "Subscribed" , "Non-subscribed" ] ) ;
2019-08-05 12:31:12 +02:00
value_original_ids . push ( [ "subscribed" , "nonsubscribed" ] ) ;
filter_names . push ( "Role" ) ;
filter_ids . push ( "role" ) ;
2020-06-04 13:38:43 +02:00
value_names . push ( [ "Manager" ] ) ;
2019-08-05 12:31:12 +02:00
value_original_ids . push ( [ "manager" ] ) ;
2020-05-05 10:52:11 +02:00
this . userFilterLoaded = true ;
2019-04-05 19:29:28 +02:00
}
let filters : Filter [ ] = [ ] ;
2020-06-04 13:38:43 +02:00
for ( let i = 0 ; i < filter_names . length ; i ++ ) {
2019-04-05 19:29:28 +02:00
let values : Value [ ] = [ ] ;
2020-06-04 13:38:43 +02:00
for ( let j = 0 ; j < value_names [ i ] . length ; j ++ ) {
let value : Value = { name : value_names [ i ] [ j ] , id : value_original_ids [ i ] [ j ] , number : 0 , selected : false } ;
2019-04-05 19:29:28 +02:00
values . push ( value ) ;
}
2020-06-04 13:38:43 +02:00
let filter : Filter = {
title : filter_names [ i ] ,
filterId : filter_ids [ i ] ,
originalFilterId : filter_original_ids [ i ] ,
values : values ,
countSelectedValues : 0 ,
"filterOperator" : 'or' ,
valueIsExact : true ,
filterType : "checkbox"
} ;
2019-04-05 19:29:28 +02:00
filters . push ( filter ) ;
}
return filters ;
}
2020-06-04 13:38:43 +02:00
2019-04-05 19:29:28 +02:00
private handleError ( message : string , error ) {
console . error ( 'Communities Search Page: ' + message , error ) ;
}
2020-06-04 13:38:43 +02:00
2019-04-05 19:29:28 +02:00
}