openaire-library/deposit/searchResultsInDeposit.comp...

120 lines
4.9 KiB
TypeScript
Raw Normal View History

import {Component, Input} from '@angular/core';
import {SearchResult} from '../utils/entities/searchResult';
import {ErrorCodes} from '../utils/properties/errorCodes';
import {RouterHelper} from '../utils/routerHelper.class';
import{EnvProperties} from '../utils/properties/env-properties';
import {ZenodoCommunitiesService} from "../connect/zenodoCommunities/zenodo-communities.service";
import {CommunityService} from "../connect/community/community.service";
import {SearchZenodoCommunitiesService} from "../connect/zenodoCommunities/searchZenodoCommunities.service";
import {ZenodoInformationClass} from "./utils/zenodoInformation.class";
import {FetchZenodoInformation} from "../../deposit/utils/fetchZenodoInformation.class";
import {ConnectHelper} from "../connect/connectHelper";
import {PiwikHelper} from "../../utils/piwikHelper";
import {ActivatedRoute} from "@angular/router";
@Component({
selector: 'deposit-result',
templateUrl:'searchResultsInDeposit.component.html'
})
export class SearchResultsInDepositComponent {
@Input() results: SearchResult[];
@Input() status: number;
@Input() type: string;
@Input() showLoading: boolean = false;
@Input() showSubjects: boolean = false;
@Input() showOrganizations: boolean = true;
@Input() custom_class: string = "search-results";
@Input() properties:EnvProperties;
public urlParam: string;
public linkToAdvancedSearchPage: string;
public errorCodes:ErrorCodes = new ErrorCodes();
public routerHelper:RouterHelper = new RouterHelper();
public errorMessage: string = "No results found";
public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
fetchZenodoInformation: FetchZenodoInformation;
constructor (private route: ActivatedRoute,
private _ΖenodoCommunitieService: ZenodoCommunitiesService,
private _communityService: CommunityService,
private _searchZenodoCommunitiesService: SearchZenodoCommunitiesService) {
this.fetchZenodoInformation = new FetchZenodoInformation(this._ΖenodoCommunitieService, this._searchZenodoCommunitiesService);
}
ngOnInit() {
if(this.type == "publication") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedPublications;
this.urlParam = "articleId";
} else if(this.type == "dataset") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedDatasets;
this.urlParam = "datasetId";
} else if(this.type == "software") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedSoftware;
this.urlParam = "softwareId";
} else if(this.type == "other") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedOrps;
this.urlParam = "orpId";
} else if(this.type == "project") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedProjects;
this.urlParam = "projectId";
} else if(this.type == "organization") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedOrganizations;
this.urlParam = "organizationId";
} else if(this.type == "dataprovider") {
this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedDataProviders;
this.urlParam = "datasourceId";
}
this.route.queryParams.subscribe(params => {
let communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
if (!communityId) {
communityId = params['communityId'];
}
if (communityId) {
if (communityId != null && communityId != '') {
this._communityService.getCommunity(this.properties, this.properties.communityAPI + communityId).subscribe(
community => {
var community = community;
var masterZenodoCommunityId = community.zenodoCommunity;
if (masterZenodoCommunityId) {
this.zenodoInformation.shareInZenodoUrl = this.properties.shareInZenodoPage+communityId;
//this.fetchZenodoInformation.getZenodoCommunityNameAndUrlById(masterZenodoCommunityId, this.properties, this.zenodoInformation);
} else {
this.zenodoInformation.url = this.properties.zenodo;
this.zenodoInformation.name = "Zenodo";
}
//this.fetchZenodoInformation.searchNumberOfZCommunities(communityId, this.properties, this.zenodoInformation);
},
error => {
this.handleError("Error getting community with id: " + communityId, error);
}
);
}
}
if (!this.zenodoInformation.shareInZenodoUrl) {
this.zenodoInformation.url = this.properties.zenodo;
}
if (!this.zenodoInformation.name) {
this.zenodoInformation.name = "Zenodo";
}
});
}
public quote(params: string):string {
return '"'+params+'"';
}
private handleError(message: string, error) {
console.error("search Results in Deposit page: "+message, error);
}
}