2022-05-05 19:54:01 +02:00
import { ChangeDetectorRef , Component , ElementRef , Input , ViewChild } from '@angular/core' ;
2019-07-22 11:16:50 +02:00
import { ActivatedRoute , Router } from '@angular/router' ;
import { Meta , Title } from '@angular/platform-browser' ;
import { OrganizationService } from '../../services/organization.service' ;
import { OrganizationInfo } from '../../utils/entities/organizationInfo' ;
import { ReportsService } from '../../services/reports.service' ;
import { FetchProjects } from '../../utils/fetchEntitiesClasses/fetchProjects.class' ;
2019-09-11 11:45:54 +02:00
import { SearchResearchResultsService } from '../../services/searchResearchResults.service' ;
2019-07-22 11:16:50 +02:00
import { SearchDataprovidersService } from '../../services/searchDataproviders.service' ;
import { SearchProjectsService } from '../../services/searchProjects.service' ;
import { ErrorCodes } from '../../utils/properties/errorCodes' ;
import { RouterHelper } from '../../utils/routerHelper.class' ;
import { ModalLoading } from '../../utils/modal/loading.component' ;
import { PiwikService } from '../../utils/piwik/piwik.service' ;
import { StringUtils } from '../../utils/string-utils.class' ;
import { EnvProperties } from '../../utils/properties/env-properties' ;
import { SEOService } from '../../sharedComponents/SEO/SEO.service' ;
2019-04-24 14:31:01 +02:00
import { HelperFunctions } from "../../utils/HelperFunctions.class" ;
2019-07-22 11:16:50 +02:00
import { HelperService } from "../../utils/helper/helper.service" ;
2019-11-07 10:51:09 +01:00
import { Location } from "@angular/common" ;
2020-05-26 16:42:47 +02:00
import { FetchResearchResults } from "../../utils/fetchEntitiesClasses/fetchResearchResults.class" ;
import { FetchDataproviders } from "../../utils/fetchEntitiesClasses/fetchDataproviders.class" ;
2020-06-10 13:05:59 +02:00
import { IndexInfoService } from "../../utils/indexInfo.service" ;
2020-11-11 15:43:13 +01:00
import { Subscriber } from "rxjs" ;
2020-11-18 17:06:27 +01:00
import { properties } from "../../../../environments/environment" ;
2022-05-05 08:32:18 +02:00
import { OpenaireEntities } from '../../utils/properties/searchFields' ;
2022-05-05 12:44:46 +02:00
import { Option } from '../../sharedComponents/input/input.component' ;
2017-12-19 13:53:46 +01:00
2022-05-05 19:54:01 +02:00
declare var ResizeObserver ;
2017-12-19 13:53:46 +01:00
@Component ( {
2019-07-22 11:16:50 +02:00
selector : 'organization' ,
templateUrl : 'organization.component.html' ,
2017-12-19 13:53:46 +01:00
} )
export class OrganizationComponent {
2018-04-11 10:59:01 +02:00
@Input ( ) piwikSiteId = null ;
2019-07-22 11:16:50 +02:00
@Input ( ) communityId = null ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
public organizationInfo : OrganizationInfo ;
public organizationId : string ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
// Message variables
public warningMessage = "" ;
public errorMessage = "" ;
public showLoading : boolean = true ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
// CSV variables
public downloadURLAPI : string ;
public csvProjectParamsHead : string ;
public csvParamsTail : string ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
// Variables for publications, research data, projects, dataproviders tabs
public fetchProjects : FetchProjects ;
2020-05-26 16:42:47 +02:00
public fetchPublications : FetchResearchResults ;
public fetchDatasets : FetchResearchResults ;
public fetchSoftware : FetchResearchResults ;
public fetchOrps : FetchResearchResults ;
2022-05-05 08:32:18 +02:00
public fetchDataproviders : FetchDataproviders ;
2020-05-26 16:42:47 +02:00
public searchNumber : number = 5 ;
2020-05-29 16:15:35 +02:00
// Request results of each tab only the one time (first time tab is clicked)
private reloadPublications : boolean = true ;
private reloadDatasets : boolean = true ;
private reloadSoftware : boolean = true ;
private reloadOrps : boolean = true ;
private reloadDataproviders : boolean = true ;
2020-05-27 12:47:40 +02:00
// Active tab variable for responsiveness
public activeTab : string = "" ;
2022-05-05 08:32:18 +02:00
@ViewChild ( 'downloadReportsModal' ) downloadReportsModal ;
2020-05-25 20:58:13 +02:00
@ViewChild ( 'downloadReportModal' ) downloadReportModal ;
@ViewChild ( 'downloadFunderReportModal' ) downloadFunderReportModal ;
2022-05-04 11:47:51 +02:00
@ViewChild ( 'addThisModal' ) addThisModal ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
@ViewChild ( ModalLoading ) loading : ModalLoading ;
// Alert box when CSV: Project Publications for a funder is requested
@ViewChild ( 'AlertModalApplyAll' ) alertApplyAll ;
// Alert box when something is wrong with CSV requests
@ViewChild ( 'AlertModalCsvError' ) alertCsvError ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
public routerHelper : RouterHelper = new RouterHelper ( ) ;
public errorCodes : ErrorCodes = new ErrorCodes ( ) ;
public pageContents = null ;
public divContents = null ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
// Helper variables to specify funder in downloadPublicationsFile function
2022-05-05 19:54:01 +02:00
public contentTypes : [ string , string , string ] [ ] = [
[ 'results' , 'all ' + OpenaireEntities . RESULTS , OpenaireEntities . RESULTS_FILE ] ,
[ 'publications' , OpenaireEntities . PUBLICATIONS , OpenaireEntities . PUBLICATIONS_FILE ] ,
[ 'datasets' , OpenaireEntities . DATASETS , OpenaireEntities . DATASETS_FILE ] ,
[ 'software' , OpenaireEntities . SOFTWARE , OpenaireEntities . SOFTWARE_FILE ] ,
[ 'other' , OpenaireEntities . OTHER , OpenaireEntities . OTHER_FILE ] ,
2020-03-16 14:09:46 +01:00
] ;
2022-05-05 19:54:01 +02:00
public contentFileName : string = '' ;
2020-03-16 14:09:46 +01:00
public funderContentType : string = '' ;
public funder : any = "" ;
2019-07-22 11:16:50 +02:00
private funderId : string ;
2020-03-16 14:09:46 +01:00
private funderCount : number ;
2022-05-04 11:47:51 +02:00
2022-05-05 12:44:46 +02:00
public funderOptions : Option [ ] = [ ] ;
2022-05-04 11:47:51 +02:00
public offset : number ;
public stickyHeader : boolean = false ;
public graph_offset : number = 0 ;
2022-05-05 19:54:01 +02:00
public graph_height : number = 0 ;
@ViewChild ( "graph_and_feedback" ) graph_and_feedback ;
2022-05-06 15:31:40 +02:00
// public shouldSticky: boolean = true;
2022-05-04 11:47:51 +02:00
2020-11-11 15:43:13 +01:00
subscriptions = [ ] ;
2021-06-22 10:04:38 +02:00
innerReportSubscriptions = [ ] ;
2019-07-22 11:16:50 +02:00
properties : EnvProperties ;
2022-05-05 14:29:15 +02:00
public openaireEntities = OpenaireEntities ;
2020-03-16 14:09:46 +01:00
public indexUpdateDate : Date ;
public showFeedback : boolean = false ;
public feedbackFields : string [ ] = [ 'Name' , 'Country' , 'Other' ] ;
2021-12-17 14:39:32 +01:00
2019-10-02 16:15:08 +02:00
@ViewChild ( 'AlertModalDeletedByInference' ) alertModalDeletedByInference ;
2020-03-16 14:09:46 +01:00
@ViewChild ( 'projectsModal' ) projectsModal ;
2019-10-02 16:15:08 +02:00
public deleteByInferenceOpened : boolean = false ;
2021-12-17 14:39:32 +01:00
2020-11-11 15:43:13 +01:00
2022-05-04 11:47:51 +02:00
2019-07-22 11:16:50 +02:00
constructor ( private element : ElementRef ,
private _organizationService : OrganizationService ,
private _piwikService : PiwikService ,
private route : ActivatedRoute ,
private _searchDataprovidersService : SearchDataprovidersService ,
private _reportsService : ReportsService ,
2019-09-11 11:45:54 +02:00
private _searchResearchResultsService : SearchResearchResultsService ,
2019-07-22 11:16:50 +02:00
private _searchProjectsService : SearchProjectsService ,
private _meta : Meta ,
private _title : Title ,
private _router : Router ,
private helper : HelperService ,
2019-11-07 10:51:09 +01:00
private seoService : SEOService ,
2020-06-10 13:05:59 +02:00
private _location : Location ,
2022-05-05 19:54:01 +02:00
private indexInfoService : IndexInfoService ,
private cdr : ChangeDetectorRef ) {
2019-07-22 11:16:50 +02:00
this . fetchProjects = new FetchProjects ( this . _searchProjectsService ) ;
2020-05-27 12:47:40 +02:00
this . fetchDataproviders = new FetchDataproviders ( this . _searchDataprovidersService ) ;
this . fetchPublications = new FetchResearchResults ( this . _searchResearchResultsService ) ;
this . fetchDatasets = new FetchResearchResults ( this . _searchResearchResultsService ) ;
this . fetchSoftware = new FetchResearchResults ( this . _searchResearchResultsService ) ;
this . fetchOrps = new FetchResearchResults ( this . _searchResearchResultsService ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
ngOnInit() {
2020-11-18 17:06:27 +01:00
this . properties = properties ;
2020-06-10 13:05:59 +02:00
if ( typeof document !== 'undefined' ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . indexInfoService . getLastIndexDate ( this . properties ) . subscribe ( lastIndexUpdate = > {
2020-06-10 13:05:59 +02:00
if ( lastIndexUpdate ) {
this . indexUpdateDate = new Date ( lastIndexUpdate ) ;
}
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-03-16 14:09:46 +01:00
}
2019-07-22 11:16:50 +02:00
//this.getDivContents();
this . getPageContents ( ) ;
2020-09-18 12:10:18 +02:00
this . updateUrl ( this . properties . domain + this . properties . baseLink + this . _router . url ) ;
2021-12-17 14:39:32 +01:00
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . _router . url ) ;
2020-11-18 17:06:27 +01:00
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . route . queryParams . subscribe ( params = > {
2019-07-22 11:16:50 +02:00
this . organizationInfo = null ;
this . updateTitle ( "Organization" ) ;
this . updateDescription ( "" ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . organizationId = params [ 'organizationId' ] ;
2021-12-17 14:39:32 +01:00
2020-06-16 18:42:51 +02:00
if ( this . organizationId && StringUtils . isOpenAIREID ( this . organizationId ) ) {
2019-07-22 11:16:50 +02:00
this . getOrganizationInfo ( ) ;
} else {
this . showLoading = false ;
2022-05-11 11:55:14 +02:00
this . _router . navigate ( [ this . properties . errorLink ] , {
2020-03-16 14:09:46 +01:00
queryParams : {
"page" : this . _location . path ( true ) ,
"page_type" : "organization"
}
} ) ;
2019-07-22 11:16:50 +02:00
}
this . csvParamsTail = '" and relorganizationid exact "' + this . organizationId + '" ))' ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2019-07-22 11:16:50 +02:00
this . downloadURLAPI = this . properties . csvAPIURL ;
2020-03-16 14:09:46 +01:00
//this.csvAffiliatedPublications = this.downloadURLAPI + "?format=csv&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relorganizationid exact \"" + this.organizationId + "\"))";
this . csvProjectParamsHead = 'format=csv&type=projects&fq=((funder exact "' ;
2019-07-22 11:16:50 +02:00
//this.csvPublicationParamsHead = 'format=csv-special&type=publications&page=0&query=((((oaftype exact result) and (resulttypeid exact publication)) and (funderid exact ';
2022-05-04 11:47:51 +02:00
}
2022-05-05 19:54:01 +02:00
ngAfterViewInit() {
if ( typeof document !== 'undefined' ) {
2022-06-16 00:44:03 +02:00
this . offset = Number . parseInt ( getComputedStyle ( document . documentElement ) . getPropertyValue ( '--header-height' ) ) ;
2022-05-06 15:31:40 +02:00
// let bottom = document.getElementById('bottom');
// if(bottom) {
// let observer = new IntersectionObserver(entries => {
// entries.forEach(entry => {
// this.shouldSticky = !entry.isIntersecting;
// })
// });
// this.subscriptions.push(observer);
// observer.observe(bottom);
// }
2022-05-05 19:54:01 +02:00
if ( this . graph_and_feedback ) {
this . observeGraphAndFeedback ( ) ;
}
}
}
ngAfterContentChecked() {
2022-05-16 23:31:28 +02:00
if ( this . graph_and_feedback && typeof document !== 'undefined' ) {
2022-05-05 19:54:01 +02:00
this . graph_offset = this . calcGraphOffset ( this . graph_and_feedback . nativeElement ) ;
2022-05-04 11:47:51 +02:00
}
}
2022-05-05 19:54:01 +02:00
public observeGraphAndFeedback() {
let resizeObs = new ResizeObserver ( entries = > {
entries . forEach ( entry = > {
setTimeout ( ( ) = > {
// console.log(entry);
this . graph_offset = this . calcGraphOffset ( entry . target ) ;
this . cdr . detectChanges ( ) ;
} ) ;
} )
} ) ;
this . subscriptions . push ( resizeObs ) ;
resizeObs . observe ( this . graph_and_feedback . nativeElement ) ;
}
calcGraphOffset ( element ) {
this . graph_height = element . offsetHeight ;
return window . innerHeight - this . graph_height ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private getPageContents() {
2020-06-29 15:15:52 +02:00
if ( this . communityId ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . helper . getPageHelpContents ( this . properties , this . communityId , this . _router . url ) . subscribe ( contents = > {
2020-06-29 15:15:52 +02:00
this . pageContents = contents ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-06-29 15:15:52 +02:00
}
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private getDivContents() {
2020-06-29 15:15:52 +02:00
if ( this . communityId ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . helper . getDivHelpContents ( this . properties , this . communityId , this . _router . url ) . subscribe ( contents = > {
2020-06-29 15:15:52 +02:00
this . divContents = contents ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-06-29 15:15:52 +02:00
}
2019-07-22 11:16:50 +02:00
}
2020-11-11 15:43:13 +01:00
2019-07-22 11:16:50 +02:00
ngOnDestroy() {
2020-11-11 15:43:13 +01:00
this . subscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
2022-05-05 19:54:01 +02:00
} else if ( subscription instanceof ( ResizeObserver || IntersectionObserver ) ) {
subscription . disconnect ( ) ;
2020-11-11 15:43:13 +01:00
}
} ) ;
2021-06-22 10:04:38 +02:00
this . innerReportSubscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
}
} ) ;
2020-11-11 15:43:13 +01:00
this . fetchDatasets . clearSubscriptions ( ) ;
this . fetchPublications . clearSubscriptions ( ) ;
this . fetchSoftware . clearSubscriptions ( ) ;
2022-06-10 13:56:32 +02:00
this . fetchOrps . clearSubscriptions ( ) ;
2020-11-11 15:43:13 +01:00
this . fetchDataproviders . clearSubscriptions ( ) ;
this . fetchProjects . clearSubscriptions ( ) ;
2019-07-22 11:16:50 +02:00
}
2020-11-11 15:43:13 +01:00
2020-03-16 14:09:46 +01:00
private getTotalResearchResults() {
2020-05-27 12:47:40 +02:00
this . fetchPublications . getNumForEntity ( 'publication' , 'organization' , this . organizationId , this . properties ) ;
this . fetchDatasets . getNumForEntity ( 'dataset' , 'organization' , this . organizationId , this . properties ) ;
this . fetchSoftware . getNumForEntity ( 'software' , 'organization' , this . organizationId , this . properties ) ;
this . fetchOrps . getNumForEntity ( 'other' , 'organization' , this . organizationId , this . properties ) ;
2020-03-16 14:09:46 +01:00
}
2021-12-17 14:39:32 +01:00
2020-03-16 14:09:46 +01:00
private getTotalDataproviders() {
2020-05-27 12:47:40 +02:00
this . fetchDataproviders . getNumForEntity ( 'organization' , this . organizationId , this . properties ) ;
}
2021-12-17 14:39:32 +01:00
2020-05-29 16:15:35 +02:00
// private searchContentProviders() {
// this.fetchDataproviders.getResultsForEntity("organization", this.organizationId, 1, this.searchNumber, this.properties);
// }
private searchContentProviders ( page : number , size : number ) {
if ( this . reloadDataproviders &&
( this . fetchDataproviders . searchUtils . status == this . errorCodes . LOADING ||
2020-05-31 15:09:26 +02:00
( this . fetchDataproviders . searchUtils . status == this . errorCodes . DONE && this . fetchDataproviders . searchUtils . totalResults > 0 )
)
) {
2020-05-29 16:15:35 +02:00
this . fetchDataproviders . getResultsForEntity ( "organization" , this . organizationId , page , size , this . properties ) ;
}
this . reloadDataproviders = false ;
2020-05-27 12:47:40 +02:00
}
2021-12-17 14:39:32 +01:00
2020-05-29 16:15:35 +02:00
// private searchPublications() {
// this.fetchPublications.getResultsForEntity("publication", "organization", this.organizationId, 1, size, this.properties);
// }
private searchPublications ( page : number , size : number ) {
if ( this . reloadPublications &&
( this . fetchPublications . searchUtils . status == this . errorCodes . LOADING ||
2020-05-31 15:09:26 +02:00
( this . fetchPublications . searchUtils . status == this . errorCodes . DONE && this . fetchPublications . searchUtils . totalResults > 0 )
)
) {
2020-05-29 16:15:35 +02:00
this . fetchPublications . getResultsForEntity ( "publication" , "organization" , this . organizationId , page , size , this . properties ) ;
}
this . reloadPublications = false ;
2020-05-27 12:47:40 +02:00
}
2021-12-17 14:39:32 +01:00
2020-05-29 16:15:35 +02:00
// private searchDatasets() {
// this.fetchDatasets.getResultsForEntity("dataset", "organization", this.organizationId, 1, this.searchNumber, this.properties);
// }
private searchDatasets ( page : number , size : number ) {
if ( this . reloadDatasets &&
( this . fetchDatasets . searchUtils . status == this . errorCodes . LOADING ||
2020-05-31 15:09:26 +02:00
( this . fetchDatasets . searchUtils . status == this . errorCodes . DONE && this . fetchDatasets . searchUtils . totalResults > 0 )
)
) {
2020-05-29 16:15:35 +02:00
this . fetchDatasets . getResultsForEntity ( "dataset" , "organization" , this . organizationId , page , size , this . properties ) ;
}
this . reloadDatasets = false ;
2020-05-27 12:47:40 +02:00
}
2020-05-29 16:15:35 +02:00
// private searchSoftware() {
// this.fetchSoftware.getResultsForEntity("software", "organization", this.organizationId, 1, this.searchNumber, this.properties);
// }
private searchSoftware ( page : number , size : number ) {
if ( this . reloadSoftware &&
( this . fetchSoftware . searchUtils . status == this . errorCodes . LOADING ||
2020-05-31 15:09:26 +02:00
( this . fetchSoftware . searchUtils . status == this . errorCodes . DONE && this . fetchSoftware . searchUtils . totalResults > 0 )
)
) {
2020-05-29 16:15:35 +02:00
this . fetchSoftware . getResultsForEntity ( "software" , "organization" , this . organizationId , page , size , this . properties ) ;
}
this . reloadSoftware = false ;
2020-05-27 12:47:40 +02:00
}
2020-05-29 16:15:35 +02:00
// private searchOrps() {
// this.fetchOrps.getResultsForEntity("other", "organization", this.organizationId, 1, this.searchNumber, this.properties);
// }
private searchOrps ( page : number , size : number ) {
if ( this . reloadOrps &&
( this . fetchOrps . searchUtils . status == this . errorCodes . LOADING ||
2020-05-31 15:09:26 +02:00
( this . fetchOrps . searchUtils . status == this . errorCodes . DONE && this . fetchOrps . searchUtils . totalResults > 0 )
)
) {
2020-05-29 16:15:35 +02:00
this . fetchOrps . getResultsForEntity ( "other" , "organization" , this . organizationId , page , size , this . properties ) ;
}
this . reloadOrps = false ;
2020-03-16 14:09:46 +01:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private getOrganizationInfo() {
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . warningMessage = '' ;
this . errorMessage = ""
this . showLoading = true ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . organizationInfo = null ;
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _organizationService . getOrganizationInfo ( this . organizationId , this . properties ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
if ( data == null ) {
this . showLoading = false ;
2022-05-11 11:55:14 +02:00
this . _router . navigate ( [ this . properties . errorLink ] , {
2020-03-16 14:09:46 +01:00
queryParams : {
"page" : this . _location . path ( true ) ,
"page_type" : "organization"
}
} ) ;
2022-06-01 14:29:19 +02:00
this . errorMessage = 'No ' + OpenaireEntities . ORGANIZATION + ' found' ;
2019-07-22 11:16:50 +02:00
} else {
this . organizationInfo = data ;
2021-03-08 15:42:26 +01:00
this . organizationId = this . organizationInfo . objIdentifier ; // reset in case the parameter was a canonical url. The related queries and reports should have the dedup id
this . csvParamsTail = '" and relorganizationid exact "' + this . organizationId + '" ))' ;
2020-09-18 09:57:42 +02:00
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . properties . searchLinkToOrganization + this . organizationInfo . relcanId ) ;
2020-07-14 12:18:40 +02:00
this . updateTitle ( ( this . organizationInfo . title . name ? this . organizationInfo . title . name : ( this . organizationInfo . name ? this . organizationInfo . name : 'No title available' ) ) ) ;
this . updateDescription ( "Organization, country, " +
( this . organizationInfo . title . name ? this . organizationInfo . title . name : 'No title available' ) +
( ( this . organizationInfo . title . name && this . organizationInfo . title . name != this . organizationInfo . name ) ? ( ', ' ) : '' ) +
( this . organizationInfo . name ? this . organizationInfo . name : '' ) ) ;
2019-07-22 11:16:50 +02:00
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _piwikService . trackView ( this . properties , this . organizationInfo . title . name , this . piwikSiteId ) . subscribe ( ) ) ;
2019-07-22 11:16:50 +02:00
}
var refineFields : string [ ] = [ "funder" ] ;
2020-06-10 13:05:59 +02:00
if ( typeof document !== 'undefined' ) {
this . getTotalResearchResults ( ) ;
this . getTotalDataproviders ( ) ;
}
2020-05-29 16:15:35 +02:00
this . fetchProjects . getResultsForOrganizations ( this . organizationId , "" , 1 , this . searchNumber , refineFields , this . properties ) ;
2022-05-04 11:47:51 +02:00
// console.log(this.fetchProjects);
2019-07-22 11:16:50 +02:00
this . showLoading = false ;
}
} ,
err = > {
//console.log(err)
this . handleError ( "Error getting organization for id: " + this . organizationId , err ) ;
2020-03-16 14:09:46 +01:00
if ( err . status == 404 ) {
2022-05-11 11:55:14 +02:00
this . _router . navigate ( [ this . properties . errorLink ] , {
2020-03-16 14:09:46 +01:00
queryParams : {
"page" : this . _location . path ( true ) ,
"page_type" : "organization"
}
} ) ;
2021-12-17 14:39:32 +01:00
} else if ( err . name == "TimeoutError" ) {
this . errorMessage = 'An error occurred please try again later' ;
} else {
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . properties . searchLinkToOrganizations ) ;
this . errorMessage = 'No organization found' ;
2019-10-31 12:39:23 +01:00
}
2019-07-22 11:16:50 +02:00
this . showLoading = false ;
}
2020-11-11 15:43:13 +01:00
) ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
public downloadFile ( url : string , filename : string ) {
this . openLoading ( ) ;
this . setMessageLoading ( "Downloading CSV file" ) ;
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _reportsService . downloadCSVFile ( url ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
this . closeLoading ( ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
var url = window . URL . createObjectURL ( data ) ;
var a = window . document . createElement ( 'a' ) ;
window . document . body . appendChild ( a ) ;
a . setAttribute ( 'style' , 'display: none' ) ;
a . href = url ;
a . download = filename + ".csv" ;
a . click ( ) ;
window . URL . revokeObjectURL ( url ) ;
a . remove ( ) ; // remove the element
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
//window.open(window.URL.createObjectURL(data));
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
2021-02-10 13:50:02 +01:00
this . subscriptions . push ( this . _piwikService . trackDownload ( this . properties , "DownloadCSV" + filename , this . piwikSiteId ) . subscribe ( ) ) ;
2019-07-22 11:16:50 +02:00
}
} ,
err = > {
//console.log("Error downloading the file.");
this . handleError ( "Error downloading file: " + filename + ".csv" , err ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . closeLoading ( ) ;
this . confirmOpenCsvError ( ) ;
} / * ,
( ) = > console . log ( 'Completed file download.' ) * /
2020-11-11 15:43:13 +01:00
) ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2020-03-16 14:09:46 +01:00
private downloadFileByFunder() {
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . openLoading ( ) ;
this . setMessageLoading ( "Downloading CSV file" ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
let response : string [ ] = [ ] ;
let totalResponse : string = "" ;
let projects = [ ] ;
2020-03-16 14:09:46 +01:00
let counter : number = this . funderCount ;
2019-07-22 11:16:50 +02:00
let title : boolean = false ;
let title_index : number = 0 ;
2021-12-17 14:39:32 +01:00
2022-05-05 19:54:01 +02:00
let filename : string = 'funder-project-' + this . contentFileName + '-report' ;
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _searchProjectsService . getProjectsForOrganizations ( this . organizationId , ' and (funder exact "' + this . encodeURI ( this . funderId ) + '" ) ' , 1 , this . funderCount , [ ] , this . properties ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
projects = data [ 1 ] ;
for ( let index = 0 ; index < projects . length ; index ++ ) {
2021-06-22 10:04:38 +02:00
this . innerReportSubscriptions . push ( this . _searchResearchResultsService . numOfEntityResults ( this . funderContentType , projects [ index ] . id , "project" , this . properties ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
//if(data == 0 && title) { // if no publications for this project
if ( data == 0 && ( counter > 1 || title ) ) { // if no publications for this project
counter -- ;
response [ index ] = "" ;
//console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
if ( counter == 0 ) {
//for(let i=count-1; i>=0; i--) {
for ( let i = 0 ; i < projects . length ; i ++ ) {
if ( response [ i ] != "" ) {
if ( i == title_index ) {
totalResponse = response [ i ] + totalResponse ;
} else {
totalResponse += response [ i ] ;
}
}
}
this . closeLoading ( ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
var csvurl = window . URL . createObjectURL ( new Blob ( [ totalResponse ] , { type : 'text/csv' } ) ) ;
var a = window . document . createElement ( 'a' ) ;
window . document . body . appendChild ( a ) ;
a . setAttribute ( 'style' , 'display: none' ) ;
a . href = csvurl ;
a . download = filename + ".csv" ;
a . click ( ) ;
window . URL . revokeObjectURL ( csvurl ) ;
a . remove ( ) ; // remove the element
2021-02-10 13:50:02 +01:00
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . subscriptions . push ( this . _piwikService . trackDownload ( this . properties , "DownloadCSV" + filename , this . piwikSiteId ) . subscribe ( ) ) ;
}
2019-07-22 11:16:50 +02:00
}
} else {
let url : string ;
if ( ! title ) {
title_index = index ;
//console.info(title_index);
2020-05-27 12:47:40 +02:00
url = this . downloadURLAPI + '?format=csv-special&' + this . getTypeParam ( this . funderContentType ) + '&fq=((relprojectid exact "' + projects [ index ] . id + '"))' ;
2019-07-22 11:16:50 +02:00
} else {
2020-05-27 12:47:40 +02:00
url = this . downloadURLAPI + '?format=csv-special-notitle&' + this . getTypeParam ( this . funderContentType ) + '&fq=((relprojectid exact "' + projects [ index ] . id + '"))' ;
2019-07-22 11:16:50 +02:00
}
title = true ;
2020-11-11 15:43:13 +01:00
2021-06-22 10:04:38 +02:00
this . innerReportSubscriptions . push ( this . _reportsService . getCSVResponse ( url ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
counter -- ;
response [ index ] = data ;
//console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
if ( counter == 0 ) {
//for(let i=count-1; i>=0; i--) {
for ( let i = 0 ; i < projects . length ; i ++ ) {
if ( response [ i ] != "" ) {
if ( i == title_index ) {
totalResponse = response [ i ] + totalResponse ;
} else {
totalResponse += response [ i ] ;
}
}
}
this . closeLoading ( ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
var csvurl = window . URL . createObjectURL ( new Blob ( [ totalResponse ] , { type : 'text/csv' } ) ) ;
var a = window . document . createElement ( 'a' ) ;
window . document . body . appendChild ( a ) ;
a . setAttribute ( 'style' , 'display: none' ) ;
a . href = csvurl ;
a . download = filename + ".csv" ;
a . click ( ) ;
window . URL . revokeObjectURL ( csvurl ) ;
a . remove ( ) ; // remove the element
2021-02-10 13:50:02 +01:00
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . subscriptions . push ( this . _piwikService . trackDownload ( this . properties , "DownloadCSV" + filename , this . piwikSiteId ) . subscribe ( ) ) ;
}
2019-07-22 11:16:50 +02:00
}
} ,
err = > {
this . handleError ( "Error downloading file: " + filename , err ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . closeLoading ( ) ;
this . confirmOpenCsvError ( ) ;
2021-06-22 10:04:38 +02:00
this . innerReportSubscriptions . forEach ( subscription = > subscription . unsubscribe ( ) ) ;
2019-07-22 11:16:50 +02:00
} / * ,
( ) = > console . log ( 'Completed file download.' ) * /
2020-11-11 15:43:13 +01:00
) ) ;
2019-07-22 11:16:50 +02:00
}
} ,
err = > {
this . handleError ( "Error getting number of publications for project with id: " + projects [ index ] . id , err ) ;
2021-06-17 15:33:16 +02:00
this . closeLoading ( ) ;
2021-06-22 10:04:38 +02:00
this . confirmOpenCsvError ( ) ;
this . innerReportSubscriptions . forEach ( subscription = > subscription . unsubscribe ( ) ) ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2019-07-22 11:16:50 +02:00
}
} ,
err = > {
this . handleError ( "Error getting projects for organization with id: " + this . organizationId , err ) ;
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
this . closeLoading ( ) ;
this . confirmOpenCsvError ( ) ;
}
2020-11-11 15:43:13 +01:00
) ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private updateDescription ( description : string ) {
2019-12-05 17:07:07 +01:00
this . _meta . updateTag ( { content : description.substring ( 0 , 160 ) } , "name='description'" ) ;
this . _meta . updateTag ( { content : description.substring ( 0 , 160 ) } , "property='og:description'" ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private updateTitle ( title : string ) {
2019-08-02 16:55:32 +02:00
var _prefix = "" ;
2019-12-05 17:07:07 +01:00
// if(!this.communityId) {
// _prefix = "OpenAIRE | ";
// }
// var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
this . _title . setTitle ( title ) ;
this . _meta . updateTag ( { content : title } , "property='og:title'" ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private updateUrl ( url : string ) {
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private openLoading() {
2022-05-05 08:32:18 +02:00
this . closeDownloadReportsModal ( ) ;
2021-06-17 15:33:16 +02:00
2019-07-22 11:16:50 +02:00
if ( this . loading ) {
this . loading . open ( ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private closeLoading() {
if ( this . loading ) {
this . loading . close ( ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private setMessageLoading ( message : string ) {
if ( this . loading ) {
this . loading . message = message ;
2019-02-15 13:50:24 +01:00
}
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2022-05-05 19:54:01 +02:00
public confirmOpenApplyAll ( contentType : string , contentFileName : string ) {
2019-07-22 11:16:50 +02:00
this . alertApplyAll . cancelButton = true ;
this . alertApplyAll . okButton = true ;
this . alertApplyAll . alertTitle = "CSV FILE" ;
this . alertApplyAll . message = "Do you wish to download a CSV file? Note that this process may take a while." ;
this . alertApplyAll . okButtonText = "Yes" ;
this . alertApplyAll . cancelButtonText = "No" ;
this . alertApplyAll . open ( ) ;
2020-03-16 14:09:46 +01:00
this . funderId = this . funder . id ;
this . funderCount = this . funder . number ;
this . funderContentType = contentType ;
2022-05-05 19:54:01 +02:00
this . contentFileName = contentFileName ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2020-03-16 14:09:46 +01:00
public confirmCloseApplyAll() {
this . downloadFileByFunder ( ) ;
2019-07-22 11:16:50 +02:00
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
public confirmOpenCsvError() {
this . alertCsvError . cancelButton = false ;
this . alertCsvError . okButton = true ;
this . alertCsvError . alertTitle = "ERROR DOWNLOADING CSV FILE" ;
this . alertCsvError . message = "There was an error in csv downloading. Please try again later." ;
this . alertCsvError . okButtonText = "OK" ;
this . alertCsvError . open ( ) ;
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
encodeURI ( input : string ) : string {
return StringUtils . URIEncode ( input ) ;
}
2021-12-17 14:39:32 +01:00
2019-07-22 11:16:50 +02:00
private handleError ( message : string , error ) {
console . error ( "Organizaton Landing Page: " + message , error ) ;
}
2021-12-17 14:39:32 +01:00
2019-10-02 16:15:08 +02:00
openDeletedByInference() {
this . deleteByInferenceOpened = true ;
this . alertModalDeletedByInference . cancelButton = false ;
this . alertModalDeletedByInference . okButton = false ;
2022-05-06 15:31:40 +02:00
this . alertModalDeletedByInference . alertTitle = "Other versions" ;
2019-10-02 16:15:08 +02:00
this . alertModalDeletedByInference . open ( ) ;
}
2021-12-17 14:39:32 +01:00
2020-03-16 14:09:46 +01:00
public getTypeParam ( type : string ) : string {
2020-05-27 12:47:40 +02:00
if ( type == 'results' ) {
2020-03-16 14:09:46 +01:00
type = 'publications&type=datasets&type=software&type=other' ;
}
2020-05-27 12:47:40 +02:00
return 'type=' + type ;
2020-03-16 14:09:46 +01:00
}
2021-12-17 14:39:32 +01:00
2020-03-16 14:09:46 +01:00
getCSVAffiliated ( contentType : string ) : string {
return this . downloadURLAPI + '?format=csv&' + this . getTypeParam ( contentType ) + '&fq=(relorganizationid exact "' + this . organizationId + '")' ;
}
2021-12-17 14:39:32 +01:00
2020-03-16 14:09:46 +01:00
getFunderProjects ( ) : string {
2020-05-27 12:47:40 +02:00
return this . downloadURLAPI + '?' + this . csvProjectParamsHead + encodeURI ( this . funder . id ) + this . csvParamsTail ;
2020-03-16 14:09:46 +01:00
}
2021-12-17 14:39:32 +01:00
2022-05-05 08:32:18 +02:00
openDownloadReportsModal() {
this . funder = this . fetchProjects . funders [ 0 ] ;
this . downloadReportsModal . cancelButton = false ;
this . downloadReportsModal . okButton = false ;
this . downloadReportsModal . alertTitle = "Download" ;
this . downloadReportsModal . open ( ) ;
}
2020-05-31 15:44:52 +02:00
2022-05-05 08:32:18 +02:00
closeDownloadReportsModal() {
this . downloadReportsModal . cancel ( ) ;
2021-06-17 15:33:16 +02:00
}
2022-05-04 11:47:51 +02:00
public openAddThisModal() {
this . addThisModal . cancelButton = false ;
this . addThisModal . okButton = false ;
this . addThisModal . alertTitle = "Share this organization in your social networks" ;
this . addThisModal . open ( ) ;
}
2020-05-31 15:44:52 +02:00
public getParamsForSearchLink ( type : string = "" ) {
if ( type ) {
return this . routerHelper . createQueryParams ( [ 'f0' , 'fv0' , 'type' , 'qf' , 'sortBy' ] , [ 'relorganizationid' , this . organizationId , type , 'false' , 'resultdateofacceptance,descending' ] ) ;
} else {
return this . routerHelper . createQueryParams ( [ 'f0' , 'fv0' ] , [ 'relorganizationid' , this . organizationId ] ) ;
}
}
2021-12-17 14:39:32 +01:00
2020-05-27 12:47:40 +02:00
public onSelectActiveTab ( activeTabId ) {
if ( this . activeTab != activeTabId ) { // tab really changed
if ( activeTabId == 'projects' ) {
this . activeTab = 'projects' ;
} else if ( activeTabId == 'dataProviders' ) {
this . activeTab = 'dataProviders' ;
2020-05-29 16:15:35 +02:00
this . searchContentProviders ( 1 , this . searchNumber ) ;
2020-05-27 12:47:40 +02:00
} else if ( activeTabId == 'publications' ) {
this . activeTab = 'publications' ;
2020-05-29 16:15:35 +02:00
this . searchPublications ( 1 , this . searchNumber ) ;
2020-05-27 12:47:40 +02:00
} else if ( activeTabId == 'datasets' ) {
this . activeTab = 'datasets' ;
2020-05-29 16:15:35 +02:00
this . searchDatasets ( 1 , this . searchNumber ) ;
2020-05-27 12:47:40 +02:00
} else if ( activeTabId == 'software' ) {
this . activeTab = 'software' ;
2020-05-29 16:15:35 +02:00
this . searchSoftware ( 1 , this . searchNumber ) ;
2020-05-27 12:47:40 +02:00
} else if ( activeTabId == 'other' ) {
this . activeTab = "other" ;
2020-05-29 16:15:35 +02:00
this . searchOrps ( 1 , this . searchNumber ) ;
2020-05-27 12:47:40 +02:00
}
}
}
2021-12-17 14:39:32 +01:00
2020-05-27 12:47:40 +02:00
public get total ( ) : number {
let total = this . fetchPublications . searchUtils . totalResults ;
total += this . fetchDatasets . searchUtils . totalResults ;
total += this . fetchSoftware . searchUtils . totalResults ;
total += this . fetchOrps . searchUtils . totalResults ;
return total ;
}
2021-12-17 14:39:32 +01:00
2020-05-29 16:15:35 +02:00
// public get numberOfTabs(): number {
// if (this.tabsAreInitialized) {
// return this._numberOfTabs;
// }
// if (!this.organizationInfo
// || this.fetchProjects.searchUtils.status === this.errorCodes.LOADING
// || this.fetchDataproviders.searchUtils.status === this.errorCodes.LOADING
// || this.fetchPublications.searchUtils.status == this.errorCodes.LOADING
// || this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING
// || this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING
// || this.fetchOrps.searchUtils.status == this.errorCodes.LOADING) {
// return 0;
// }
// if (this.fetchProjects.searchUtils.totalResults > 0) {
// if (this._numberOfTabs == 0) {
// this.firstTab = 'projects';
// }
// this._numberOfTabs++;
// }
// if (this.fetchDataproviders.searchUtils.totalResults > 0) {
// if (this._numberOfTabs == 0) {
// this.firstTab = 'dataProviders';
// this.searchContentProviders(1, this.searchNumber);
// }
// this._numberOfTabs++;
// }
// if (this.fetchPublications.searchUtils.totalResults > 0) {
// if (this._numberOfTabs == 0) {
// this.firstTab = 'publications';
// this.searchPublications(1, this.searchNumber);
// }
// this._numberOfTabs++;
// }
// if (this.fetchDatasets.searchUtils.totalResults > 0) {
// if (this._numberOfTabs == 0) {
// this.firstTab = 'datasets';
// this.searchDatasets(1, this.searchNumber);
// }
// this._numberOfTabs++;
// }
// if (this.fetchSoftware.searchUtils.totalResults > 0) {
// if (this._numberOfTabs == 0) {
// this.firstTab = 'software';
// this.searchSoftware(1, this.searchNumber);
// }
// this._numberOfTabs++;
// }
// if (this.fetchOrps.searchUtils.totalResults > 0) {
// if (this._numberOfTabs == 0) {
// this.firstTab = 'other';
// this.searchOrps(1, this.searchNumber);
// }
// this._numberOfTabs++;
// }
// this.activeTab = this.firstTab;
// this.tabsAreInitialized = true;
// return this._numberOfTabs;
// }
2021-12-17 14:39:32 +01:00
2022-05-05 12:44:46 +02:00
public buildFunderOptions() {
this . funderOptions = [ ] ;
if ( this . fetchProjects . funders && this . fetchProjects . funders . length > 0 ) {
for ( let funder of this . fetchProjects . funders ) {
this . funderOptions . push ( { "label" : funder . name , "value" : funder } ) ;
}
this . funder = this . funderOptions [ 0 ] ;
}
}
2020-05-25 20:58:13 +02:00
public scroll() {
HelperFunctions . scroll ( ) ;
}
2017-12-19 13:53:46 +01:00
}