Dataprovider landing: 'Related Content Providers' tab requests for both Publication and Research Data - observer added in fetch functions to preprocess when requests are over

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@48845 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2017-08-22 07:00:22 +00:00
parent 81d7666b34
commit 0b8fb9da6f
5 changed files with 187 additions and 70 deletions

View File

@ -152,9 +152,10 @@
</organizationsTab>
<!--*ngIf=" tab.content=='relatedDatasourcesTab'"-->
<relatedDatasourcesTab *ngIf="activeTab=='Related Content Providers'"
[dataproviderId]="id"
[fetchResults]="fetchResultsAggregators"
[type]="relatedDataprovidersResultsType">
[dataproviderId]="datasourceId"
[fetchPublications]="fetchAggregatorsPublications"
[fetchDatasets]="fetchAggregatorsDatasets">
<!--[type]="relatedDataprovidersResultsType"-->
</relatedDatasourcesTab>
<!-- *ngIf=" tab.content=='statisticsTab' && statsClicked"-->

View File

@ -62,7 +62,8 @@ export class DataProviderComponent {
public fetchDatasets: FetchDatasets;
public fetchProjects: FetchProjects;
public fetchDataproviders: FetchDataproviders;
public fetchResultsAggregators: any;
public fetchAggregatorsPublications: FetchPublications;
public fetchAggregatorsDatasets: FetchDatasets;
// Active tab variable for responsiveness - show tabs only if main request is completed
public activeTab: string = "";
@ -254,15 +255,15 @@ export class DataProviderComponent {
this.pubsProjectsUrl ='https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"dtsrcProjPubs","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "bar", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Publications"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
//if({"name": "Publications", "content": "publicationsTab"} in this.dataProviderInfo.tabs) {
if(this.dataProviderInfo.tabs.some(function (tab) {
return tab.name === 'Publications';
})) {
this.relatedDataprovidersResultsType = 'publications';
this.fetchResultsAggregators = new FetchPublications(this._searchPublicationsService);
} else {
this.relatedDataprovidersResultsType = 'datasets';
this.fetchResultsAggregators = new FetchDatasets(this._searchDatasetsService);
}
//if(this.dataProviderInfo.tabs.some(function (tab) {
// return tab.name === 'Publications';
//})) {
// this.relatedDataprovidersResultsType = 'publications';
this.fetchAggregatorsPublications = new FetchPublications(this._searchPublicationsService);
//} else {
// this.relatedDataprovidersResultsType = 'datasets';
this.fetchAggregatorsDatasets = new FetchDatasets(this._searchDatasetsService);
//}
}
if(this.dataProviderInfo.resultsBy == "collectedFrom") {
//this.paramsForSearchLink = "?collectedFrom="+this.datasourceId+"&co=and";
@ -311,75 +312,81 @@ export class DataProviderComponent {
}
private searchPublications(page: number, size: number) {
if(this.reloadPublications) {
this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
}
if(this.fetchPublications.searchUtils.status == this.errorCodes.NONE) {
this.reloadPublications = false;
}
if(this.reloadPublications) {
this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
}
this.reloadPublications = false;
}
private countPublications(page: number, size: number) {
this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
if(this.fetchPublications.searchUtils.totalResults == 0) {
this.reloadPublications = false;
}
this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
}
private searchDatasets(page: number, size: number) {
if(this.reloadDatasets) {
this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
}
if(this.fetchDatasets.searchUtils.status == this.errorCodes.NONE) {
this.reloadDatasets = false;
}
if(this.reloadDatasets) {
this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
}
this.reloadDatasets = false;
}
private countDatasets(page: number, size: number) {
this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
if(this.fetchDatasets.searchUtils.totalResults == 0) {
this.reloadDatasets = false;
}
this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
}
private searchProjects(page: number, size: number) {
if(this.reloadProjects) {
this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
}
if(this.fetchProjects.searchUtils.status == this.errorCodes.NONE) {
this.reloadProjects = false;
}
if(this.reloadProjects) {
this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
}
this.reloadProjects = false;
}
private countProjects(page: number, size: number) {
this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
if(this.fetchProjects.searchUtils.totalResults == 0) {
this.reloadProjects = false;
}
this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
}
private searchDatasources(page: number, size: number) {
if(this.reloadDataproviders) {
this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
}
if(this.fetchDataproviders.searchUtils.status == this.errorCodes.NONE) {
this.reloadDataproviders = false;
}
if(this.reloadDataproviders) {
this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
}
this.reloadDataproviders = false;
}
private countDatasources(page: number, size: number) {
this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
if(this.fetchDataproviders.searchUtils.totalResults == 0) {
this.reloadDataproviders = false;
}
this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
}
private searchRelatedDatasources(page: number, size: number) {
if(this.reloadRelatedDatasources) {
this.fetchResultsAggregators.getAggregatorResults(this.datasourceId, page, size);
}
if(this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.NONE
&& this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.NONE) {
this.reloadRelatedDatasources = false;
}
if(this.reloadRelatedDatasources) {
this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size);
this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size);
}
this.reloadRelatedDatasources = false;
}
private countRelatedDatasources(page: number, size: number) {
this.fetchResultsAggregators.getAggregatorResults(this.datasourceId, page, size);
if(this.fetchResultsAggregators.searchUtils.totalResults == 0) {
this.reloadRelatedDatasources = false;
}
this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size);
this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size);
}
public metricsResults($event) {

View File

@ -5,20 +5,32 @@ import { FetchDatasets } from '../../utils/fetchEntitiesClasses/fetchDatasets.cl
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
import {RouterHelper} from '../../utils/routerHelper.class';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'relatedDatasourcesTab',
template: `
<div *ngIf="fetchResults.searchUtils.status == errorCodes.NONE" class="uk-alert uk-alert-primary uk-animation-fade" role="alert">No related content providers available</div>
<div *ngIf="fetchResults.searchUtils.status == errorCodes.ERROR" class="uk-alert uk-alert-warning uk-animation-fade" role="alert">An Error Occured</div>
<div *ngIf="fetchResults.searchUtils.status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger uk-animation-fade" role="alert">Service not available</div>
<div *ngIf="fetchResults.searchUtils.status == errorCodes.LOADING" class="uk-animation-fade uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading"></div>
<div *ngIf="fetchPublications.searchUtils.status == errorCodes.NONE && fetchDatasets.searchUtils.status == errorCodes.NONE"
class="uk-alert uk-alert-primary uk-animation-fade" role="alert">
No related content providers available
</div>
<div *ngIf="fetchPublications.searchUtils.status == errorCodes.ERROR && fetchDatasets.searchUtils.status == errorCodes.ERROR"
class="uk-alert uk-alert-warning uk-animation-fade" role="alert">
An Error Occured
</div>
<!--div *ngIf="fetchPublications.searchUtils.status == errorCodes.NOT_AVAILABLE && fetchDatasets.searchUtils.status == errorCodes.NOT_AVAILABLE"
class="uk-alert uk-alert-danger uk-animation-fade" role="alert">
Service not available
</div-->
<div *ngIf="fetchPublications.searchUtils.status == errorCodes.LOADING || fetchDatasets.searchUtils.status == errorCodes.LOADING"
class="uk-animation-fade uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="Loading">
</div>
<!--div *ngIf="fetchResults.results.length == 0" class = "uk-alert">
No related content providers available
</div-->
<div *ngIf="fetchResults.results.length > 0">
<div *ngIf="fetchPublications.searchUtils.status == errorCodes.DONE || fetchDatasets.searchUtils.status == errorCodes.DONE">
<table class="uk-table uk-table-striped">
<thead>
<tr>
@ -27,22 +39,41 @@ import {RouterHelper} from '../../utils/routerHelper.class';
</tr>
</thead>
<tbody>
<ng-container *ngIf="!results && fetchResults">
<tr *ngFor="let item of fetchResults.results">
<td class="uk-text-center">
<!--a href="{{item.url}}"-->
<a [queryParams]="{datasourceId: item.id}" routerLinkActive="router-link-active" routerLink="/search/dataprovider">
<!--a href="{{searchLinkToDataProvider}}{{item.id}}"-->
{{item.name}}
</a>
</td>
<td class="uk-text-center">
<!--a href="{{linkToSearchPublications}}{{item.id}}&ho=and&collectedFrom={{dataproviderId}}&co=and"-->
<a [queryParams]="routerHelper.createQueryParams(['hostedBy', 'ho', 'collectedFrom', 'co'], [item.id, 'and', dataproviderId, 'and'])"
routerLinkActive="router-link-active" [routerLink]="linkToSearchResults">
{{item.count}}
</a>
</td>
</tr>
</ng-container>
<ng-container *ngIf="results">
<tr *ngFor="let id of results.keys()">
<td class="uk-text-center">
<a [queryParams]="{datasourceId: id}" routerLinkActive="router-link-active" routerLink="/search/dataprovider">
{{results.get(id).name}}
</a>
</td>
<td class="uk-text-center">
<a [queryParams]="routerHelper.createQueryParams(['hostedBy', 'ho', 'collectedFrom', 'co'], [id, 'and', dataproviderId, 'and'])"
routerLinkActive="router-link-active" [routerLink]="linkToSearchPublications">
{{results.get(key).countPublications}}
</a> / <a [queryParams]="routerHelper.createQueryParams(['hostedBy', 'ho', 'collectedFrom', 'co'], [id, 'and', dataproviderId, 'and'])"
routerLinkActive="router-link-active" [routerLink]="linkToSearchResearchData">
{{results.get(key).countDatasets}}
</a>
</td>
</tr>
</ng-container>
</tbody>
</table>
</div>
@ -50,33 +81,90 @@ import {RouterHelper} from '../../utils/routerHelper.class';
})
export class RelatedDatasourcesTabComponent {
@Input() type: string;
//@Input() type: string;
@Input() dataproviderId: string;
@Input() fetchResults : any;
@Input() fetchPublications : FetchPublications;
@Input() fetchDatasets : FetchDatasets;
public linkToSearchResults: string = "";
public type: string;
public linkToSearchResults: string;
public fetchResults: any;
public results: Map<string, {"name": string, "countPublications": string, "countDatasets": string}>;
public linkToSearchPublications: string = "";
public linkToSearchResearchData: string = "";
//public searchLinkToDataProvider: string = "";
public routerHelper:RouterHelper = new RouterHelper();
public errorCodes:ErrorCodes = new ErrorCodes();
public sub: any;
//public queryParams: string[] = [];
//public queryParamsIds: string[] = [];
constructor () {}
ngOnInit() {
if(this.type == "publications") {
this.linkToSearchResults = OpenaireProperties.getLinkToAdvancedSearchPublications();//+"?&hostedBy=";//+ +"&ho=and&collectedFrom="+ +"&co=and";
} else {
this.linkToSearchResults = OpenaireProperties.getLinkToAdvancedSearchDatasets();
}
//if(this.type == "publications") {
this.linkToSearchPublications = OpenaireProperties.getLinkToAdvancedSearchPublications();//+"?&hostedBy=";//+ +"&ho=and&collectedFrom="+ +"&co=and";
//} else {
this.linkToSearchResearchData = OpenaireProperties.getLinkToAdvancedSearchDatasets();
//}
//this.searchLinkToDataProvider = OpenaireProperties.getsearchLinkToDataProvider();
/*queryParams.push("hostedBy");
queryParams.push("ho");
queryParams.push("collectedFrom");
queryParams.push("co");
queryParamsIds.push()*/
this.sub = Observable.merge(this.fetchPublications.requestComplete, this.fetchDatasets.requestComplete)
.subscribe(
data => {
if((this.fetchPublications.results.length > 0 && this.fetchDatasets.results.length > 0)
|| (this.fetchPublications.results.length > 0 && this.fetchDatasets.searchUtils.status == this.errorCodes.ERROR)
|| (this.fetchPublications.searchUtils.status == this.errorCodes.ERROR && this.fetchDatasets.results.length > 0)) {
this.results = new Map<string, {"name": string, "countPublications": string, "countDatasets": string}>();
for(let result of this.fetchPublications.results) {
if(!this.results.has(result.id)) {
this.results.set(result.id, {"name": result.name, "countPublications": result.count, "countDatasets": "0"});
} else {
if(this.fetchPublications.searchUtils.status == this.errorCodes.ERROR) {
this.results.get(result.id).countPublications = "-";
} else {
this.results.get(result.id).countPublications = parseInt(this.results.get(result.id).countPublications) + result.count;
}
}
}
for(let result of this.fetchDatasets.results) {
if(!this.results.has(result.id)) {
this.results.set(result.id, {"name": result.name, "countPublications": "0", "countDatasets": result.count});
} else {
if(this.fetchDatasets.searchUtils.status == this.errorCodes.ERROR) {
this.results.get(result.id).countDatasets = "-";
} else {
this.results.get(result.id).countDatasets = parseInt(this.results.get(result.id).countDatasets) + result.count;
}
}
}
this.type = "Publications / Research Data"
} else if(this.fetchPublications.results.length > 0) {
this.fetchResults = this.fetchPublications;
this.type = "Publications";
this.linkToSearchResults = this.linkToSearchPublications;
} else {
this.fetchResults = this.fetchDatasets;
this.type = "Research Data";
this.linkToSearchResults = this.linkToSearchResearchData;
}
}
);
}
ngOnDestroy() {}
ngOnDestroy() {
if(this.sub) {
this.sub.unsubscribe();
}
}
}

View File

@ -2,9 +2,13 @@ import {SearchDatasetsService} from '../../services/searchDatasets.service';
import { ErrorCodes} from '../../utils/properties/openaireProperties';
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
import {DOI} from '../../utils/string-utils.class';
import { Observable } from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
export class FetchDatasets{
public results =[];
public requestComplete: Observable<boolean>;
private observer: Observer<boolean>;
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
private sub: any;
@ -179,12 +183,18 @@ public getResultsForDataproviders(id:string, resultsFrom:string, page: number, s
}
public getAggregatorResults(id:string, page: number, size: number){
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING;
this.requestComplete = new Observable<boolean>(observer => this.observer = observer);
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING;
this.subResults = this._searchDatasetsService.searchAggregators(id, '&fq=collectedfromdatasourceid exact "'+id+'"',"&refine=true&fields=resulthostingdatasource" , page, size).subscribe(
data => {
this.results = data;
this.searchUtils.totalResults = this.results.length;
this.observer.next(true);
//console.info("TRUE dataset!!!");
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.DONE;
@ -193,6 +203,7 @@ public getAggregatorResults(id:string, page: number, size: number){
}
},
err => {
this.observer.next(false);
console.log(err);
//TODO check erros (service not available, bad request)
// if( ){

View File

@ -4,10 +4,13 @@ import {ErrorCodes} from '../../utils/properties/openaireProperties';
import {SearchFields} from '../../utils/properties/searchFields';
import {SearchUtilsClass } from '../../searchPages/searchUtils/searchUtils.class';
import {DOI} from '../../utils/string-utils.class';
import { Observable } from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
export class FetchPublications {
public results =[];
public requestComplete: Observable<boolean>;
private observer: Observer<boolean>;
// public filters =[];
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
// public baseUrl:string = "";
@ -165,6 +168,8 @@ public getResultsForDataproviders(id:string, resultsFrom:string, page: number, s
}
public getAggregatorResults(id:string, page: number, size: number){
this.requestComplete = new Observable<boolean>(observer => this.observer = observer);
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.LOADING;
@ -173,6 +178,10 @@ public getAggregatorResults(id:string, page: number, size: number){
this.results = data;
this.searchUtils.totalResults = this.results.length;
//this.requestComplete = Observable.of(true);//new Observable(observer => observer = "true");
//console.info("TRUE publication!!!");
this.observer.next(true);
var errorCodes:ErrorCodes = new ErrorCodes();
this.searchUtils.status = errorCodes.DONE;
if(this.searchUtils.totalResults == 0 ){
@ -180,6 +189,7 @@ public getAggregatorResults(id:string, page: number, size: number){
}
},
err => {
this.observer.next(false);
console.log(err);
//TODO check erros (service not available, bad request)
// if( ){