[Trunk | Library]: claimResultSearchForm.component & directLinking.component & search.component: Merge methods for research results (since they are now merged in one common service & component).

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57084 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2019-09-16 09:34:49 +00:00
parent e7d0ef876f
commit fc3e2f9b19
3 changed files with 76 additions and 147 deletions

View File

@ -271,46 +271,29 @@ export class ClaimResultSearchFormComponent {
this.totalOpenaireCount = 0;
}
if (type == "dataset") {
this._searchResearchResultsService.search("dataset", this.createOpenaireQueryParams(), (mainResults && page==1 ?this.openaireRefineFieldsQuery:null), (mainResults?page:1), (mainResults?size:0), "", (mainResults && page==1 ?this.openaireRefineFields:[]), this.properties).subscribe(
data => {
this.setOpenaireResults(data, mainResults, page, type);
},
err => {
this.setOpenaireResultsError(mainResults, term, err);
}
);
this.searchResearchResults("dataset", term, size, page, mainResults, type);
} else if (type == "software") {
this._searchResearchResultsService.search("software", this.createOpenaireQueryParams(), (mainResults && page==1 ?this.openaireRefineFieldsQuery:null), (mainResults?page:1), (mainResults?size:0), "", (mainResults && page==1 ?this.openaireRefineFields:[]), this.properties).subscribe(
data => {
this.setOpenaireResults(data, mainResults, page, type);
},
err => {
this.setOpenaireResultsError(mainResults, term, err);
}
);
this.searchResearchResults("software", term, size, page, mainResults, type);
} else if (type == "other") {
this._searchResearchResultsService.search("other", this.createOpenaireQueryParams(), (mainResults && page==1 ?this.openaireRefineFieldsQuery:null), (mainResults?page:1), (mainResults?size:0), "", (mainResults && page==1 ?this.openaireRefineFields:[]), this.properties).subscribe(
data => {
this.setOpenaireResults(data, mainResults, page, type);
},
err => {
this.setOpenaireResultsError(mainResults, term, err);
}
);
this.searchResearchResults("other", term, size, page, mainResults, type);
} else {
this._searchResearchResultsService.search("publication", this.createOpenaireQueryParams(), (mainResults && page==1 ?this.openaireRefineFieldsQuery:null), (mainResults?page:1), (mainResults?size:0), "", (mainResults && page==1 ?this.openaireRefineFields:[]), this.properties).subscribe(
data => {
this.setOpenaireResults(data, mainResults, page, type);
},
err => {
this.setOpenaireResultsError(mainResults, term, err);
}
);
this.searchResearchResults("publication", term, size, page, mainResults, type);
}
}
public searchResearchResults(resultType: string, term: string, size: number, page: number, mainResults: boolean, type) {
this._searchResearchResultsService.search(resultType, this.createOpenaireQueryParams(), (mainResults && page==1 ?this.openaireRefineFieldsQuery:null), (mainResults?page:1), (mainResults?size:0), "", (mainResults && page==1 ?this.openaireRefineFields:[]), this.properties).subscribe(
data => {
this.setOpenaireResults(data, mainResults, page, type);
},
err => {
this.setOpenaireResultsError(mainResults, term, err);
}
);
}
public setOpenaireResults(data, mainResults: boolean, page, type) {
if (data != null) {
if (mainResults) {

View File

@ -8,6 +8,7 @@ import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySear
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
import {LinkingGenericComponent} from "../linking/linkingGeneric.component";
import {ClaimResultSearchFormComponent} from "../claim-utils/claimResultSearchForm.component";
import {enterView} from "@angular/core/src/render3/state";
@Component({
@ -71,13 +72,13 @@ export class DirectLinkingComponent {
// this.linkType = "project";
this.getProjectById(this.id);
} else if (this.type == "publication") {
this.getPublicationById(this.id);
this.getResearchResultById("publication", this.id);
} else if (this.type == "dataset") {
this.getDatasetById(this.id);
this.getResearchResultById("dataset", this.id);
} else if (this.type == "software") {
this.getSoftwareById(this.id);
this.getResearchResultById("software", this.id);
} else if (this.type == "orp") {
this.getOrpById(this.id);
this.getResearchResultById("other", this.id);
} else {
this.validInput = this.isValidInput(null);
}
@ -133,51 +134,14 @@ export class DirectLinkingComponent {
});
}
getPublicationById(id: string) {
this.sub = this._searchResearchResultsService.searchById("publication", id, this.properties).subscribe(data => {
this.createClaimEntity(data, "publication");
getResearchResultById(resultType: string, id: string) {
this.sub = this._searchResearchResultsService.searchById(resultType, id, this.properties).subscribe(data => {
this.createClaimEntity(data, resultType);
},
err => {
this.validInput = this.isValidInput(null);
//console.log("An error occured")
this.handleError("Error getting publication by id: " + id, err);
});
}
getDatasetById(id: string) {
this.sub = this._searchResearchResultsService.searchById("dataset", id, this.properties).subscribe(
data => {
this.createClaimEntity(data, "dataset");
},
err => {
this.validInput = this.isValidInput(null);
//console.log("An error occured")
this.handleError("Error getting research data by id: " + id, err);
});
}
getSoftwareById(id: string) {
this.sub = this._searchResearchResultsService.searchById("software", id, this.properties).subscribe(
data => {
this.createClaimEntity(data, "software");
},
err => {
this.validInput = this.isValidInput(null);
//console.log("An error occured")
this.handleError("Error getting software by id: " + id, err);
});
}
getOrpById(id: string) {
this.sub = this._searchResearchResultsService.searchById("other", id, this.properties).subscribe(
data => {
this.createClaimEntity(data, "other");
},
err => {
this.validInput = this.isValidInput(null);
//console.log("An error occured")
this.handleError("Error getting other research product by id: " + id, err);
this.handleError("Error getting "+this.getEntityName(resultType, false, true)+" by id: " + id, err);
});
}
@ -212,4 +176,16 @@ export class DirectLinkingComponent {
private handleError(message: string, error) {
console.error("Direct Linking 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");
}
}
}

View File

@ -25,6 +25,7 @@ import {EnvProperties} from '../../utils/properties/env-properties';
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
import {StringUtils} from '../../utils/string-utils.class';
import {SearchCustomFilter} from "../searchUtils/searchUtils.class";
import {Observable} from "rxjs";
@Component({
changeDetection: ChangeDetectionStrategy.Default,
@ -257,7 +258,7 @@ export class SearchComponent {
public searchPublications() {
this.activeTab = "publications";
this.advancedSearchLink = "/search/advanced/publications";
this.advancedSearchLink = this.properties.searchLinkToAdvancedPublications;//"/search/advanced/publications";
if (this.reloadPublications &&
this.fetchPublications.searchUtils.status != this.errorCodes.NONE /*&&
this.fetchPublications.searchUtils.status != this.errorCodes.ERROR*/) {
@ -269,7 +270,7 @@ export class SearchComponent {
public searchDatasets() {
this.activeTab = "research data";
this.advancedSearchLink = "/search/advanced/datasets";
this.advancedSearchLink = this.properties.searchLinkToAdvancedDatasets;//"/search/advanced/datasets";
if (this.reloadDatasets &&
this.fetchDatasets.searchUtils.status != this.errorCodes.NONE /*&&
this.fetchDatasets.searchUtils.status != this.errorCodes.ERROR*/) {
@ -282,7 +283,7 @@ export class SearchComponent {
public searchSoftware() {
this.activeTab = "software";
this.advancedSearchLink = "/search/advanced/software";
this.advancedSearchLink = this.properties.searchLinkToAdvancedSoftware;//"/search/advanced/software";
if (this.reloadSoftware
&& this.fetchSoftware.searchUtils.status != this.errorCodes.NONE/* &&
( this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
@ -295,7 +296,7 @@ export class SearchComponent {
public searchOrps() {
this.activeTab = "other research products";
this.advancedSearchLink = "/search/advanced/other";
this.advancedSearchLink = this.properties.searchLinkToAdvancedOrps;//"/search/advanced/other";
if (this.reloadOrps &&
this.fetchOrps.searchUtils.status != this.errorCodes.NONE /*&&
this.fetchOrps.searchUtils.status != this.errorCodes.ERROR*/) {
@ -307,7 +308,7 @@ export class SearchComponent {
public searchProjects() {
this.activeTab = "projects";
this.advancedSearchLink = "/search/advanced/projects";
this.advancedSearchLink = this.properties.searchLinkToAdvancedProjects;//"/search/advanced/projects";
if (this.reloadProjects &&
this.fetchProjects.searchUtils.status != this.errorCodes.NONE /*&&
this.fetchProjects.searchUtils.status != this.errorCodes.ERROR*/) {
@ -319,7 +320,7 @@ export class SearchComponent {
public searchDataProviders() {
this.activeTab = "content providers";
this.advancedSearchLink = "/search/advanced/dataproviders";
this.advancedSearchLink = this.properties.searchLinkToAdvancedDataProviders;//"/search/advanced/dataproviders";
if (this.reloadDataproviders &&
this.fetchDataproviders.searchUtils.status != this.errorCodes.NONE /*&&
this.fetchDataproviders.searchUtils.status != this.errorCodes.ERROR*/) {
@ -331,7 +332,7 @@ export class SearchComponent {
public searchOrganizations() {
this.activeTab = "organizations";
this.advancedSearchLink = "/search/advanced/organizations";
this.advancedSearchLink = this.properties.searchLinkToAdvancedOrganizations;//"/search/advanced/organizations";
if (this.reloadOrganizations &&
this.fetchOrganizations.searchUtils.status != this.errorCodes.NONE /*&&
this.fetchOrganizations.searchUtils.status != this.errorCodes.ERROR*/) {
@ -382,81 +383,22 @@ export class SearchComponent {
this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
this.fetchPublications.results = [];
this.subPub = this._searchResearchResultsService.numOfSearchResults("publication", this.keyword, this.properties, refineParams).subscribe(
data => {
this.fetchPublications.searchUtils.totalResults = data;
this.fetchPublications.searchUtils.status = this.errorCodes.DONE;
if (this.fetchPublications.searchUtils.totalResults == 0) {
this.fetchPublications.searchUtils.status = this.errorCodes.NONE;
}
},
err => {
//console.log(err);
this.handleError("Error getting number of Publications", err);
this.fetchPublications.searchUtils.status = this.errorCodes.ERROR;
}
);
this.subPub = this.numOfSearchResults("publication", this.fetchPublications, refineParams);
}
if (this.activeTab != "research data" && this.showDatasets) {
this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
this.fetchDatasets.results = [];
this.subData = this._searchResearchResultsService.numOfSearchResults("dataset", this.keyword, this.properties, refineParams).subscribe(
data => {
this.fetchDatasets.searchUtils.totalResults = data;
this.fetchDatasets.searchUtils.status = this.errorCodes.DONE;
if (this.fetchDatasets.searchUtils.totalResults == 0) {
this.fetchDatasets.searchUtils.status = this.errorCodes.NONE;
}
},
err => {
//console.log(err);
this.handleError("Error getting number of Research Data", err);
this.fetchDatasets.searchUtils.status = this.errorCodes.ERROR;
}
);
this.subData = this.numOfSearchResults("dataset", this.fetchDatasets, refineParams);
}
if (this.activeTab != "software" && this.showSoftware) {
this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
this.fetchSoftware.results = [];
this.subSoftware = this._searchResearchResultsService.numOfSearchResults("software", this.keyword, this.properties, refineParams).subscribe(
data => {
this.fetchSoftware.searchUtils.totalResults = data;
this.fetchSoftware.searchUtils.status = this.errorCodes.DONE;
if (this.fetchSoftware.searchUtils.totalResults == 0) {
this.fetchSoftware.searchUtils.status = this.errorCodes.NONE;
}
},
err => {
this.handleError("Error getting number of Software", err);
/*console.log(err);
if(err.status == '404') {
this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_FOUND;
} else if(err.status == '500') {
this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
} else {
this.fetchSoftware.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
}*/
this.fetchSoftware.searchUtils.status = this.errorCodes.ERROR;
}
);
this.subSoftware = this.numOfSearchResults("software", this.fetchSoftware, refineParams);
}
if (this.activeTab != "other research products" && this.showOrps) {
this.fetchOrps.searchUtils.status = this.errorCodes.LOADING;
this.fetchOrps.results = [];
this.subOrps = this._searchResearchResultsService.numOfSearchResults("other", this.keyword, this.properties, refineParams).subscribe(
data => {
this.fetchOrps.searchUtils.totalResults = data;
this.fetchOrps.searchUtils.status = this.errorCodes.DONE;
if (this.fetchOrps.searchUtils.totalResults == 0) {
this.fetchOrps.searchUtils.status = this.errorCodes.NONE;
}
},
err => {
//console.log(err);
this.handleError("Error getting number of Other Research Products", err);
this.fetchOrps.searchUtils.status = this.errorCodes.ERROR;
}
);
this.subOrps = this.numOfSearchResults("other", this.fetchOrps, refineParams);
}
if (this.activeTab != "projects" && this.showProjects) {
this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
@ -503,6 +445,22 @@ export class SearchComponent {
}
private numOfSearchResults(resultType: string, fetchClass: FetchResearchResults, refineParams): Observable<any> {
return this._searchResearchResultsService.numOfSearchResults(resultType, this.keyword, this.properties, refineParams).subscribe(
data => {
fetchClass.searchUtils.totalResults = data;
fetchClass.searchUtils.status = this.errorCodes.DONE;
if (fetchClass.searchUtils.totalResults == 0) {
fetchClass.searchUtils.status = this.errorCodes.NONE;
}
},
err => {
this.handleError("Error getting number of "+this.getEntityName(resultType, true, true), err);
fetchClass.searchUtils.status = this.errorCodes.ERROR;
}
);
}
private reloadTabs() {
this.reloadPublications = true;
this.reloadDatasets = true;
@ -523,4 +481,16 @@ export class SearchComponent {
private handleError(message: string, error) {
console.error("General Search 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");
}
}
}