openaire-library/landingPages/dataProvider/dataProvider.component.ts

852 lines
40 KiB
TypeScript

import {merge as observableMerge} from 'rxjs';
import {Component, Input, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Meta, Title} from '@angular/platform-browser';
import {EnvProperties} from '../../utils/properties/env-properties';
import {DataProviderInfo} from '../../utils/entities/dataProviderInfo';
import {DataProviderService} from './dataProvider.service';
import {FetchResearchResults} from '../../utils/fetchEntitiesClasses/fetchResearchResults.class';
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
import {SearchProjectsService} from '../../services/searchProjects.service';
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
import {ErrorCodes} from '../../utils/properties/errorCodes';
import {RouterHelper} from '../../utils/routerHelper.class';
import {PiwikService} from '../../utils/piwik/piwik.service';
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {HelperService} from "../../utils/helper/helper.service";
import {Location} from "@angular/common";
import {StringUtils} from "../../utils/string-utils.class";
import {SearchResult} from "../../utils/entities/searchResult";
import {ResultPreview} from "../../utils/result-preview/result-preview";
import {IndexInfoService} from "../../utils/indexInfo.service";
import {properties} from "../../../../environments/environment";
@Component({
selector: 'dataprovider',
templateUrl: 'dataProvider.component.html',
})
export class DataProviderComponent {
@Input() piwikSiteId = null;
@Input() communityId = null;
public dataProviderInfo: DataProviderInfo;
public datasourceId: string;
// Message variables
public warningMessage = "";
public errorMessage = "";
public showLoading: boolean = true;
// Variable to specify requests with either collectedFrom or hostedBy
public paramsForSearchLink = {};
public resultParamsForSearchLink = {};
// Metrics tab variables
public metricsClicked: boolean;
public viewsFrameUrl: string;
public downloadsFrameUrl: string;
public totalViews: number;
public totalDownloads: number;
public pageViews: number;
// Statistics tab variables
public statsClicked: boolean = false;
public docsTimelineUrl: string;
public docsTypesUrl: string;
public docsFunderUrl: string;
public dataProjectsUrl: string;
public pubsProjectsUrl: string;
@ViewChild('statisticsModal') statisticsModal;
@ViewChild('relatedDatasourcesModal') relatedDatasourcesModal;
// Variables for publications, research data, projects, content providers, related content providers tabs
public fetchPublications: FetchResearchResults;
public fetchDatasets: FetchResearchResults;
public fetchSoftware: FetchResearchResults;
public fetchOrps: FetchResearchResults;
public fetchProjects: FetchProjects;
public fetchDataproviders: FetchDataproviders;
public fetchAggregatorsPublications: FetchResearchResults;
public fetchAggregatorsDatasets: FetchResearchResults;
public fetchAggregatorsSoftware: FetchResearchResults;
public fetchAggregatorsOrps: FetchResearchResults;
public fetchAggregatorsResults: FetchResearchResults;
public searchNumber: number = 5;
public aggregationStatusIsInitialized: boolean = false;
public loadingRelatedDatasources: boolean = true;
// Active tab variable for responsiveness - show tabs only if main request is completed
public activeTab: string = "";
public showTabs: boolean = false;
public firstTab: string = "";
public _numberOfTabs: number = 0;
public tabsAreInitialized: boolean = false;
public routerHelper: RouterHelper = new RouterHelper();
public errorCodes: ErrorCodes = new ErrorCodes();
public pageContents = null;
public divContents = null;
// 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 reloadProjects: boolean = true;
private reloadDataproviders: boolean = true;
private reloadRelatedDatasources: boolean = true;
// Organizations variables for view more/less functionality
public thresholdOrganizations: number = 20;
public showNumOrganizations: number = 20;
// Subjects variables for view more/less functionality
public thresholdSubjects: number = 20;
public showNumSubjects: number = 20;
// Description variables for view more/less functionality
public thresholdDescription: number = 670;
public showNumDescription: number = 670;
public indexUpdateDate: Date;
public showFeedback: boolean = false;
public feedbackFields: string [] = ['Name', 'Organizations', 'Country', 'Other'];
sub: any;
piwiksub: any;
subInfo: any;
relatedDatasourcesSub: any;
properties: EnvProperties = properties;
constructor(private _dataproviderService: DataProviderService,
private _piwikService: PiwikService,
private route: ActivatedRoute,
private _meta: Meta,
private _title: Title,
private _router: Router,
private _searchResearchResultsService: SearchResearchResultsService,
private _searchProjectsService: SearchProjectsService,
private _searchDataprovidersService: SearchDataprovidersService,
private seoService: SEOService,
private helper: HelperService,
private _location: Location,
private indexInfoService: IndexInfoService) {
this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
this.fetchProjects = new FetchProjects(this._searchProjectsService);
this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
}
ngOnInit() {
if (typeof document !== 'undefined') {
this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
if (lastIndexUpdate) {
this.indexUpdateDate = new Date(lastIndexUpdate);
} else if (this.properties.lastIndexUpdate) {
this.indexUpdateDate = new Date(this.properties.lastIndexUpdate);
}
});
}
//this.getDivContents();
this.getPageContents();
this.updateUrl(this.properties.baseLink + this._router.url);
this.sub = this.route.queryParams.subscribe(data => {
this.updateTitle("Content provider");
this.updateDescription("");
this.datasourceId = data['datasourceId'];
if (this.datasourceId && StringUtils.isOpenAIREID(this.datasourceId)) {
this.initializeValues();
this.getDataProviderInfo(this.datasourceId);
} else {
this.showLoading = false;
this._router.navigate(['/error'], {
queryParams: {
"page": this._location.path(true),
"page_type": "dataprovider"
}
});
}
HelperFunctions.scroll();
});
}
public initializeValues() {
this._numberOfTabs = 0;
this.tabsAreInitialized = false;
this.dataProviderInfo = null;
this.aggregationStatusIsInitialized = false;
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
this.fetchProjects.searchUtils.totalResults = 0;
this.fetchDataproviders.searchUtils.status = this.errorCodes.LOADING;
this.fetchDataproviders.searchUtils.totalResults = 0;
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
this.fetchPublications.searchUtils.totalResults = 0;
this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
this.fetchDatasets.searchUtils.totalResults = 0;
this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
this.fetchSoftware.searchUtils.totalResults = 0;
this.fetchOrps.searchUtils.status = this.errorCodes.LOADING;
this.fetchOrps.searchUtils.totalResults = 0;
this.statsClicked = false;
this.metricsClicked = false;
}
private getPageContents() {
this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.pageContents = contents;
})
}
private getDivContents() {
this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
this.divContents = contents;
})
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
}
if (this.piwiksub) {
this.piwiksub.unsubscribe();
}
if (this.subInfo) {
this.subInfo.unsubscribe();
}
if (this.relatedDatasourcesSub) {
this.relatedDatasourcesSub.unsubscribe();
}
}
private getDataProviderInfo(id: string) {
this.warningMessage = '';
this.errorMessage = "";
this.showLoading = true;
this.dataProviderInfo = null;
this.showTabs = false;
if (this.datasourceId == null || this.datasourceId == '') {
this.showLoading = false;
this.warningMessage = "No valid datasource id";
} else {
this.subInfo = this._dataproviderService.getDataproviderInfo(this.datasourceId, this.properties).subscribe(
data => {
this.dataProviderInfo = data;
this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this._router.url);
if (typeof document !== 'undefined') {
this.getDataProviderAggregationStatus(this.dataProviderInfo.originalId);
} else {
this.aggregationStatusIsInitialized = true;
}
if (typeof document !== 'undefined') {
this.initTabs();
}
this.showTabs = true;
this.updateTitle(this.dataProviderInfo.title.name);
this.updateDescription("Content provider, " + this.dataProviderInfo.title.name);
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
this.piwiksub = this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe();
}
this.showLoading = false;
// if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
// this.activeTab = this.dataProviderInfo.tabs[0].name;
// }
},
err => {
//console.log(err);
this.handleError("Error getting content provider for id: " + this.datasourceId, err);
if (err.status == 404) {
this._router.navigate(['/error'], {
queryParams: {
"page": this._location.path(true),
"page_type": "dataprovider"
}
});
}
this.errorMessage = 'No dataProvider found';
this.showLoading = false;
this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToDataProviders);
}
);
}
}
private getDataProviderAggregationStatus(originalId: string) {
this.subInfo = this._dataproviderService.getDataproviderAggregationStatus(originalId, this.properties).subscribe(
data => {
this.dataProviderInfo.aggregationStatus = data;
},
err => {
//console.log(err);
this.handleError("Error getting content provider aggregation status for id: " + this.datasourceId, err);
},
() => {
this.aggregationStatusIsInitialized = true;
}
);
}
private updateDescription(description: string) {
this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
}
private updateTitle(title: string) {
var _prefix = "";
// 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'");
}
private updateUrl(url: string) {
this._meta.updateTag({content: url}, "property='og:url'");
}
private initTabs() {
//if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
this.reloadPublications = true;
this.reloadDatasets = true;
this.reloadSoftware = true;
this.reloadOrps = true;
this.reloadProjects = true;
this.reloadDataproviders = true;
this.reloadRelatedDatasources = true;
this.statsClicked = false;
//this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
this.count(1, 0);
this.metricsClicked = false;
this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"dtsrcRepoViews","dtsrcName":"' + this.datasourceId + '","table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["column"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
/*this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"dtsrcOpenAIRETimeline", "dtsrcName":"'+this.datasourceId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"OpenAIRE","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]},{"query":"dtsrcRepoTimeline", "dtsrcName":"'+this.datasourceId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":[""],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column","column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true';
*/
this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"dtsrcRepoDownloads","dtsrcName":"' + this.datasourceId + '","table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["column"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
/*
this.downloadsFrameUrl = this.properties.framesAPIURL +'merge.php?com=query&data=[{"query":"dtsrcDownloadsTimeline","dtsrcName":"'+this.datasourceId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true';
*/
//if({"name": "Publications", "content": "publicationsTab"} in this.dataProviderInfo.tabs) {
//if(this.dataProviderInfo.tabs.some(function (tab) {
// return tab.name === 'Publications';
//})) {
// this.relatedDataprovidersResultsType = 'publications';
// this.fetchAggregatorsPublications = new FetchResearchResults(this._searchResearchResultsService);
// //} else {
// // this.relatedDataprovidersResultsType = 'datasets';
// this.fetchAggregatorsDatasets = new FetchResearchResults(this._searchResearchResultsService);
// //}
// this.fetchAggregatorsSoftware = new FetchResearchResults(this._searchResearchResultsService);
// this.fetchAggregatorsOrps = new FetchResearchResults(this._searchResearchResultsService);
this.fetchAggregatorsResults = new FetchResearchResults(this._searchResearchResultsService);
//}
// if (this.dataProviderInfo.resultsBy == "collectedFrom") {
// //this.paramsForSearchLink = "?collectedFrom="+this.datasourceId+"&co=and";
// this.paramsForSearchLink = this.routerHelper.createQueryParams(['f0', 'fv0'], ["collectedfromdatasourceid", this.datasourceId]);
// this.resultParamsForSearchLink = this.routerHelper.createQueryParams(['collectedFrom', 'cl', 'qf'], [this.datasourceId, 'and', 'false']);
// } else if (this.dataProviderInfo.resultsBy == "hostedBy") {
// //this.paramsForSearchLink = "?hostedBy="+this.datasourceId+"&ho=and";
// this.paramsForSearchLink = this.routerHelper.createQueryParams(['f0', 'fv0'], ["resulthostingdatasourceid", this.datasourceId]);
// this.resultParamsForSearchLink = this.routerHelper.createQueryParams(['hostedBy', 'hs', 'qf'], [this.datasourceId, 'and', 'false']);
// }
}
public getParamsForSearchLink(type: string = "") {
let resultsBy: string = "";
// if(this.dataProviderInfo.resultsBy == "collectedFrom") {
// resultsBy = "collectedfromdatasourceid"
// } else if (this.dataProviderInfo.resultsBy == "hostedBy") {
// resultsBy = "resulthostingdatasourceid";
// }
if (type) {
return this.routerHelper.createQueryParams(['f0', 'fv0', 'f1', 'fv1', 'type', 'qf', 'sortBy'], ["collectedfromdatasourceid", this.datasourceId, "resulthostingdatasourceid,or", this.datasourceId, type, "false", 'resultdateofacceptance,descending']);
} else {
return this.routerHelper.createQueryParams(['f0', 'fv0', 'f1', 'fv1'], ["collectedfromdatasourceid", this.datasourceId, "resulthostingdatasourceid,or", this.datasourceId]);
}
}
private count(page: number, size: number) {
//for (let i = 0; i < this.dataProviderInfo.tabs.length; i++) {
//let content: string = this.dataProviderInfo.tabs[i].content;
//if (content == 'publicationsTab') {
this.countPublications(page, size);
//} else if (content == 'datasetsTab') {
this.countDatasets(page, size);
//} else if (content == 'softwareTab') {
this.countSoftware(page, size);
//} else if (content == 'orpsTab') {
this.countOrps(page, size);
//} else if (content == 'projectsTab') {
this.countProjects(page, size);
//} else if (content == 'datasourcesTab') {
this.countDatasources(page, size);
//}// else if(content=='relatedDatasourcesTab') {
// this.countRelatedDatasources(page, size);
//}
//}
}
public search(content: string, page: number, size: number) {
if (content == 'publicationsTab') {
this.searchPublications(page, size);
} else if (content == 'datasetsTab') {
this.searchDatasets(page, size);
} else if (content == 'softwareTab') {
this.searchSoftware(page, size);
} else if (content == 'orpsTab') {
this.searchOrps(page, size);
} else if (content == 'projectsTab') {
this.searchProjects(page, size);
} else if (content == 'datasourcesTab') {
this.searchDatasources(page, size);
} else if (content == 'relatedDatasourcesTab') {
this.searchRelatedDatasources(1, 0);
} else if (content == 'metricsTab') {
this.metricsClicked = true;
} else if (content == 'statisticsTab') {
this.statsClicked = !this.statsClicked;
}
}
private searchPublications(page: number, size: number) {
if (this.reloadPublications &&
(this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
)
) {
this.fetchPublications.getResultsForDataproviders("publication", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
this.reloadPublications = false;
}
private countPublications(page: number, size: number) {
this.fetchPublications.getResultsForDataproviders("publication", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
private searchDatasets(page: number, size: number) {
if (this.reloadDatasets &&
(this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
)
) {
this.fetchDatasets.getResultsForDataproviders("dataset", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
this.reloadDatasets = false;
}
private countDatasets(page: number, size: number) {
this.fetchDatasets.getResultsForDataproviders("dataset", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
private searchSoftware(page: number, size: number) {
if (this.reloadSoftware &&
(this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
)
) {
this.fetchSoftware.getResultsForDataproviders("software", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
this.reloadSoftware = false;
}
private countSoftware(page: number, size: number) {
this.fetchSoftware.getResultsForDataproviders("software", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
private searchOrps(page: number, size: number) {
if (this.reloadOrps &&
(this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
)
) {
this.fetchOrps.getResultsForDataproviders("other", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
this.reloadOrps = false;
}
private countOrps(page: number, size: number) {
this.fetchOrps.getResultsForDataproviders("other", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
}
private searchProjects(page: number, size: number) {
if (this.reloadProjects &&
(this.fetchProjects.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchProjects.searchUtils.status == this.errorCodes.DONE && this.fetchProjects.searchUtils.totalResults > 0)
)
) {
this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
}
this.reloadProjects = false;
}
private countProjects(page: number, size: number) {
this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
}
private searchDatasources(page: number, size: number) {
if (this.reloadDataproviders &&
(this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE && this.fetchDataproviders.searchUtils.totalResults > 0)
)
) {
this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
}
this.reloadDataproviders = false;
}
private countDatasources(page: number, size: number) {
this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
}
private searchRelatedDatasources(page: number, size: number) {
// Currently no counting is done for this tab. Following condition is always false
// if (this.reloadRelatedDatasources &&
// (this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.LOADING ||
// this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE)
// &&
// (this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.LOADING ||
// this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE)
// &&
// (this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.LOADING ||
// this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE)
// &&
// (this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.LOADING ||
// this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE)
// ) {
// this.relatedDatasourcesSub = observableMerge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete, this.fetchAggregatorsSoftware.requestComplete, this.fetchAggregatorsOrps.requestComplete)
// .subscribe(
// data => {
// },
// err => {
// },
// () => {
// this.preprocessRelatedDatasources();
// }
// );
//
// this.fetchAggregatorsPublications.getAggregatorResults("publication", this.datasourceId, page, size, this.properties);
// this.fetchAggregatorsDatasets.getAggregatorResults("dataset", this.datasourceId, page, size, this.properties);
// this.fetchAggregatorsSoftware.getAggregatorResults("software", this.datasourceId, page, size, this.properties);
// this.fetchAggregatorsOrps.getAggregatorResults("other", this.datasourceId, page, size, this.properties);
if (this.reloadRelatedDatasources &&
(this.fetchAggregatorsResults.searchUtils.status == this.errorCodes.LOADING ||
(this.fetchAggregatorsResults.searchUtils.status == this.errorCodes.DONE && this.fetchAggregatorsResults.searchUtils.totalResults > 0)
)
) {
this.relatedDatasourcesSub = this.fetchAggregatorsResults.requestComplete.subscribe(
data => {
},
err => {
},
() => {
//this.preprocessRelatedDatasources();
this.dataProviderInfo.relatedDatasources = this.fetchAggregatorsResults.results;
this.loadingRelatedDatasources = false;
}
);
this.fetchAggregatorsResults.getAggregatorResults("results", this.datasourceId, page, size, this.properties);
} else {
this.loadingRelatedDatasources = false;
}
this.reloadRelatedDatasources = false;
}
private countRelatedDatasources(page: number, size: number) {
// this.fetchAggregatorsPublications.getAggregatorResults("publication", this.datasourceId, page, size, this.properties);
// this.fetchAggregatorsDatasets.getAggregatorResults("dataset", this.datasourceId, page, size, this.properties);
// this.fetchAggregatorsSoftware.getAggregatorResults("software", this.datasourceId, page, size, this.properties);
// this.fetchAggregatorsOrps.getAggregatorResults("other", this.datasourceId, page, size, this.properties);
this.fetchAggregatorsResults.getAggregatorResults("results", this.datasourceId, page, size, this.properties);
}
// private preprocessRelatedDatasources() {
// if (this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE ||
// this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE ||
// this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE ||
// this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE) {
// this.dataProviderInfo.relatedDatasources = new Map<string, { "name": string, "countPublications": string, "countDatasets": string, "countSoftware": string, "countOrps": string }>();
// }
// for (let result of this.fetchAggregatorsPublications.results) {
// if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
// this.dataProviderInfo.relatedDatasources.set(result.id, {
// "name": result.name,
// "countPublications": result.count,
// "countDatasets": "0",
// "countSoftware": "0",
// "countOrps": "0"
// });
// } else {
// this.dataProviderInfo.relatedDatasources.get(result.id).countPublications = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countPublications + result.count) + "";
// }
// }
//
// for (let result of this.fetchAggregatorsDatasets.results) {
// if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
// this.dataProviderInfo.relatedDatasources.set(result.id, {
// "name": result.name,
// "countPublications": "0",
// "countDatasets": result.count,
// "countSoftware": "0",
// "countOrps": "0"
// });
// } else {
// this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets + result.count) + "";
// }
// }
//
// for (let result of this.fetchAggregatorsSoftware.results) {
// if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
// this.dataProviderInfo.relatedDatasources.set(result.id, {
// "name": result.name,
// "countPublications": "0",
// "countDatasets": "0",
// "countSoftware": result.count,
// "countOrps": "0"
// });
// } else {
// this.dataProviderInfo.relatedDatasources.get(result.id).countSoftware = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countSoftware + result.count) + "";
// }
// }
//
// for (let result of this.fetchAggregatorsOrps.results) {
// if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
// this.dataProviderInfo.relatedDatasources.set(result.id, {
// "name": result.name,
// "countPublications": "0",
// "countDatasets": "0",
// "countSoftware": "0",
// "countOrps": result.count
// });
// } else {
// this.dataProviderInfo.relatedDatasources.get(result.id).countOrps = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countOrps + result.count) + "";
// }
// }
// this.loadingRelatedDatasources = false;
// }
public metricsResults($event) {
this.totalViews = $event.totalViews;
this.totalDownloads = $event.totalDownloads;
this.pageViews = $event.pageViews;
}
public get hasMetrics(): boolean {
return !(this.totalViews && this.totalDownloads && this.pageViews) || this.totalViews > 0 || this.totalDownloads > 0 || this.pageViews > 0;
}
public openStatistics() {
this.statsClicked = true;
this.statisticsModal.cancelButton = false;
this.statisticsModal.okButton = false;
this.statisticsModal.alertTitle = "Statistics of";
this.statisticsModal.open();
}
public openRelatedDatasources() {
this.searchRelatedDatasources(1, 0);
this.relatedDatasourcesModal.cancelButton = false;
this.relatedDatasourcesModal.okButton = false;
this.relatedDatasourcesModal.alertTitle = "Related content providers of";
this.relatedDatasourcesModal.open();
}
public scroll() {
HelperFunctions.scroll();
}
public removeUnknown(array: string[]): string[] {
return array.filter(value => value.toLowerCase() !== 'unknown');
}
private handleError(message: string, error) {
console.error("Content Provider Landing Page: " + message, error);
}
private getEntityName(entityType: string, plural: boolean, full: boolean): string {
if (entityType == "publication") {
return "publication" + (plural ? "s" : "");
} else if (entityType == "dataset") {
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
} else if (entityType == "software") {
return "software";
} else if (entityType == "other") {
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
} else if (entityType == "dataprovider") {
return (full ? ("content provider" + (plural ? "s" : "")) : "dataprovider" + (plural ? "s" : ""));
} else {
return entityType + (plural ? "s" : "");
}
}
public getResultPreview(result: SearchResult, type: string): ResultPreview {
return ResultPreview.searchResultConvert(result, type);
}
public onSelectActiveTab(activeTabId) {
if (this.activeTab != "activaTabId") { // tab really changed
if (activeTabId == 'summary') {
this.activeTab = 'summary';
} else if (activeTabId == 'publications') {
this.activeTab = 'publications';
this.searchPublications(1, this.searchNumber);
} else if (activeTabId == 'datasets') {
this.activeTab = 'datasets';
this.searchDatasets(1, this.searchNumber);
} else if (activeTabId == 'software') {
this.activeTab = 'software';
this.searchSoftware(1, this.searchNumber);
} else if (activeTabId == 'other') {
this.activeTab = "other";
this.searchOrps(1, this.searchNumber);
} else if (activeTabId == 'projects') {
this.activeTab = "projects";
this.searchProjects(1, this.searchNumber);
} else if (activeTabId == 'datasources') {
this.activeTab = "datasources";
this.searchDatasources(1, this.searchNumber);
} else if (activeTabId == 'relatedDatasources') {
this.activeTab = "relatedDatasources";
this.searchRelatedDatasources(1, this.searchNumber);
} else if (activeTabId == 'statistics') {
this.activeTab = 'statistics';
this.statsClicked = true;
}
}
}
public get hasAggregationStatusInfo(): boolean {
return (!!this.dataProviderInfo.aggregationStatus &&
((!!this.dataProviderInfo.aggregationStatus.fulltexts && parseInt(this.dataProviderInfo.aggregationStatus.fulltexts) != -1)
|| (!!this.dataProviderInfo.aggregationStatus.fundedContent && parseInt(this.dataProviderInfo.aggregationStatus.fundedContent) != -1)
|| !!this.dataProviderInfo.aggregationStatus.lastUpdateDate));
}
public get hasJournalInfo(): boolean {
return (!!this.dataProviderInfo.journal && (
!!this.dataProviderInfo.journal['journal'] || !!this.dataProviderInfo.journal['issn'] ||
!!this.dataProviderInfo.journal['lissn'] || !!this.dataProviderInfo.journal['eissn'] ||
!!this.dataProviderInfo.journal['volume'] || !!this.dataProviderInfo.journal['issue'] ||
!!this.dataProviderInfo.journal['start_page'] || !!this.dataProviderInfo.journal['end_page']));
//return true;
}
public get hasPrimaryInfo(): boolean {
return !!this.dataProviderInfo && (
!!this.dataProviderInfo.description ||
this.hasJournalInfo ||
//this.hasAggregationStatusInfo ||
!!this.dataProviderInfo.countries ||
(!!this.dataProviderInfo.subjects && this.dataProviderInfo.subjects.length > 0));
}
public get hasSecondaryInfo(): boolean {
return !!this.dataProviderInfo && (
(!!this.dataProviderInfo.organizations && this.dataProviderInfo.organizations.length > 0)
|| !!this.dataProviderInfo.oaiPmhURL || !!this.dataProviderInfo.openDoarId || !!this.dataProviderInfo.r3DataId
);
}
// public numberOfTabs(): number {
// if(this.tabsAreInitialized) {
// return this._numberOfTabs;
// }
//
// // if(!this.dataProviderInfo || !this.aggregationStatusIsInitialized
// // || 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.dataProviderInfo
// && 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) {
// this.tabsAreInitialized = true;
// }
//
// this._numberOfTabs = 0;
// //if (this.hasPrimaryInfo || this.hasSecondaryInfo) {
// this.firstTab = "summary";
// this._numberOfTabs++;
// //}
// if(this.fetchProjects.searchUtils.totalResults > 0) {
// /*if( this._numberOfTabs == 0) {
// this.firstTab = "projects";
// this.searchProjects(1, this.searchNumber);
// }*/
// this._numberOfTabs++;
// }
// if(this.fetchDataproviders.searchUtils.totalResults > 0) {
// /*if( this._numberOfTabs == 0) {
// this.firstTab = "datasources";
// this.searchDatasources(1, this.searchNumber);
// }*/
// this._numberOfTabs++;
// }
// if(this.fetchPublications.searchUtils.totalResults > 0 || this.fetchDatasets.searchUtils.totalResults > 0
// || this.fetchSoftware.searchUtils.totalResults > 0 || this.fetchOrps.searchUtils.totalResults > 0) {
// /*if( this._numberOfTabs == 0) {
// this.firstTab = "relatedDatasources";
// this.searchRelatedDatasources(1, this.searchNumber);
// }*/
// this._numberOfTabs += 2;
//
// if(this.fetchPublications.searchUtils.totalResults > 0) {
// this._numberOfTabs++;
// }
// if(this.fetchDatasets.searchUtils.totalResults > 0) {
// this._numberOfTabs++;
// }
// if(this.fetchSoftware.searchUtils.totalResults > 0) {
// this._numberOfTabs++;
// }
// if(this.fetchOrps.searchUtils.totalResults > 0) {
// this._numberOfTabs++;
// }
// }
// //this.activeTab = this.firstTab;
// //this.tabsAreInitialized = true;
// return this._numberOfTabs;
// }
}