1
|
import {Component, ViewChild} from '@angular/core';
|
2
|
import {Subscription} from 'rxjs';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
import {Location} from '@angular/common';
|
5
|
import {Meta, Title} from '@angular/platform-browser';
|
6
|
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
|
7
|
import {SearchDataprovidersService} from '../openaireLibrary/services/searchDataproviders.service';
|
8
|
import {SearchProjectsService} from '../openaireLibrary/services/searchProjects.service';
|
9
|
import {SearchOrganizationsService} from '../openaireLibrary/services/searchOrganizations.service';
|
10
|
import {RefineFieldResultsService} from '../openaireLibrary/services/refineFieldResults.service';
|
11
|
import {SearchFields} from '../openaireLibrary/utils/properties/searchFields';
|
12
|
|
13
|
import {RouterHelper} from '../openaireLibrary/utils/routerHelper.class';
|
14
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
15
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
16
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
17
|
import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
|
18
|
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
|
19
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
20
|
import {Filter} from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
|
21
|
import {AggregatorInfo, PortalAggregators} from "../utils/aggregators";
|
22
|
import {SearchCustomFilter} from "../openaireLibrary/searchPages/searchUtils/searchUtils.class";
|
23
|
import {properties} from "../../environments/environment";
|
24
|
import {portalProperties} from "../../environments/environment-aggregator";
|
25
|
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
|
26
|
import {ConnectHelper} from "../openaireLibrary/connect/connectHelper";
|
27
|
import {NumbersComponent} from "../openaireLibrary/sharedComponents/numbers/numbers.component";
|
28
|
|
29
|
@Component({
|
30
|
selector: 'home',
|
31
|
templateUrl: 'home.component.html',
|
32
|
})
|
33
|
export class HomeComponent {
|
34
|
public keyword:string = "";
|
35
|
|
36
|
public searchFields:SearchFields = new SearchFields();
|
37
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
38
|
public routerHelper:RouterHelper = new RouterHelper();
|
39
|
showPublications: boolean = portalProperties.entities.publication.isEnabled;
|
40
|
showDatasets: boolean = portalProperties.entities.dataset.isEnabled;
|
41
|
showSoftware: boolean = portalProperties.entities.software.isEnabled;
|
42
|
showOrp: boolean = portalProperties.entities.other.isEnabled;
|
43
|
showOrganizations: boolean = portalProperties.entities.organization.isEnabled;
|
44
|
showProjects: boolean = portalProperties.entities.project.isEnabled;
|
45
|
showDataProviders: boolean = portalProperties.entities.datasource.isEnabled;
|
46
|
properties: EnvProperties = properties;
|
47
|
public readMore: boolean = false;
|
48
|
|
49
|
subs: Subscription[] = [];
|
50
|
|
51
|
resultsQuickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = {
|
52
|
filter: null,
|
53
|
selected: true,
|
54
|
filterId: "resultbestaccessright",
|
55
|
value: "Open Access"
|
56
|
};
|
57
|
selectedEntity = "all";
|
58
|
selectedEntitySimpleUrl;
|
59
|
selectedEntityAdvancedUrl;
|
60
|
resultTypes:Filter = {values:[],filterId:"type", countSelectedValues: 0, filterType: 'checkbox', originalFilterId: "", valueIsExact: true, title: "Result Types",filterOperator:"or"};
|
61
|
public pageContents = null;
|
62
|
customFilter:SearchCustomFilter= null;
|
63
|
aggregatorId;
|
64
|
aggregator:AggregatorInfo;
|
65
|
@ViewChild('numbersComponent', { static: true }) numbersComponent: NumbersComponent;
|
66
|
|
67
|
constructor (
|
68
|
private route: ActivatedRoute,
|
69
|
private _router: Router,
|
70
|
private _searchResearchResultsService: SearchResearchResultsService,
|
71
|
private _searchDataprovidersService: SearchDataprovidersService,
|
72
|
private _searchProjectsService: SearchProjectsService,
|
73
|
private _searchOrganizationsService: SearchOrganizationsService,
|
74
|
private _refineFieldResultsService:RefineFieldResultsService,
|
75
|
private location: Location, private _piwikService:PiwikService,
|
76
|
private config: ConfigurationService, private _meta: Meta, private _title: Title, private seoService: SEOService,
|
77
|
private helper: HelperService
|
78
|
) {
|
79
|
this.aggregatorId = ConnectHelper.getCommunityFromDomain(properties.domain);
|
80
|
this.aggregator = PortalAggregators.getFilterInfoByMenuId(this.aggregatorId);
|
81
|
this.customFilter = PortalAggregators.getSearchCustomFilterByAggregator(this.aggregator);
|
82
|
let description = "OpenAIRE Explore: Over 100M of research deduplicated, 170K research software, 11M research data. One of the largest open scholarly records collection worldwide.";
|
83
|
let title = "OpenAIRE - Explore| " +this.aggregator.title;
|
84
|
|
85
|
this._title.setTitle(title);
|
86
|
this._meta.updateTag({content:description},"name='description'");
|
87
|
this._meta.updateTag({content:description},"property='og:description'");
|
88
|
this._meta.updateTag({content:title},"property='og:title'");
|
89
|
|
90
|
|
91
|
}
|
92
|
|
93
|
private getPageContents() {
|
94
|
this.subs.push(this.helper.getPageHelpContents(this.properties, 'openaire', this._router.url).subscribe(contents => {
|
95
|
this.pageContents = contents;
|
96
|
}));
|
97
|
}
|
98
|
|
99
|
public ceil(num: number) {
|
100
|
return Math.ceil(num);
|
101
|
}
|
102
|
|
103
|
public ngOnInit() {
|
104
|
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink+this._router.url, false);
|
105
|
this.getPageContents();
|
106
|
if(this.properties!=null){
|
107
|
var url = this.properties.domain + this.properties.baseLink+this._router.url;
|
108
|
this._meta.updateTag({content:url},"property='og:url'");
|
109
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
110
|
this.subs.push(this._piwikService.trackView(this.properties, "OpenAIRE").subscribe());
|
111
|
}
|
112
|
|
113
|
//this.config.getCommunityInformation(this.properties, this.properties.adminToolsCommunity ).subscribe(data => {
|
114
|
this.subs.push(this.config.communityInformationState.subscribe(data => {
|
115
|
if(data) {
|
116
|
var showEntity = {};
|
117
|
for (var i = 0; i < data['entities'].length; i++) {
|
118
|
|
119
|
showEntity["" + data['entities'][i]["pid"] + ""] = data['entities'][i]["isEnabled"];
|
120
|
}
|
121
|
this.showPublications = !!showEntity["publication"];
|
122
|
this.showDatasets = !!showEntity["dataset"];
|
123
|
this.showSoftware = !!showEntity["software"];
|
124
|
this.showOrp = !!showEntity["orp"];
|
125
|
this.showProjects = !!showEntity["project"];
|
126
|
this.showDataProviders = !!showEntity["datasource"];
|
127
|
this.showOrganizations = !!showEntity["organization"];
|
128
|
if(this.showPublications){
|
129
|
this.resultTypes.values.push({name: "Publications" , id:"publications",selected:true, number:0});
|
130
|
}
|
131
|
if(this.showDatasets){
|
132
|
this.resultTypes.values.push({name: "Research data" , id:"datasets",selected:true, number:0});
|
133
|
}
|
134
|
if(this.showSoftware){
|
135
|
this.resultTypes.values.push({name: "Software" , id:"software",selected:true, number:0});
|
136
|
}
|
137
|
if(this.showOrp){
|
138
|
this.resultTypes.values.push({name: "Other research products" , id:"other",selected:true, number:0});
|
139
|
}
|
140
|
this.numbersComponent.init(false, false, this.showPublications, this.showDatasets,
|
141
|
this.showSoftware, this.showOrp, this.showProjects, this.showDataProviders,
|
142
|
StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId ))));
|
143
|
}
|
144
|
},
|
145
|
error => {
|
146
|
this.handleError("Error getting community information", error);
|
147
|
}
|
148
|
));
|
149
|
}
|
150
|
|
151
|
}
|
152
|
public ngOnDestroy() {
|
153
|
for (let sub of this.subs) {
|
154
|
sub.unsubscribe();
|
155
|
}
|
156
|
}
|
157
|
|
158
|
private handleError(message: string, error) {
|
159
|
console.error("Home Page: "+message, error);
|
160
|
}
|
161
|
entityChanged($event){
|
162
|
this.selectedEntity = $event.entity;
|
163
|
this.selectedEntitySimpleUrl = $event.simpleUrl;
|
164
|
this.selectedEntityAdvancedUrl = $event.advancedUrl;
|
165
|
}
|
166
|
goTo(simple:boolean){
|
167
|
let url = (simple)?this.selectedEntitySimpleUrl:this.selectedEntityAdvancedUrl;
|
168
|
let parameterNames = [];
|
169
|
let parameterValues = [];
|
170
|
if (this.selectedEntity == "result") {
|
171
|
if (this.resultTypes) {
|
172
|
let values = [];
|
173
|
for(let value of this.resultTypes.values){
|
174
|
if (value.selected) {
|
175
|
values.push(value.id);
|
176
|
}
|
177
|
}
|
178
|
if (values.length > 0 && values.length !=4) {
|
179
|
parameterNames.push("type");
|
180
|
parameterValues.push(values.join(","));
|
181
|
}
|
182
|
if (this.resultsQuickFilter) {
|
183
|
parameterNames.push("qf");
|
184
|
parameterValues.push("" + this.resultsQuickFilter.selected);
|
185
|
}
|
186
|
}
|
187
|
}else if(this.selectedEntity == "all"){
|
188
|
if (this.resultsQuickFilter) {
|
189
|
parameterNames.push("qf");
|
190
|
parameterValues.push("true");
|
191
|
}
|
192
|
}
|
193
|
if(this.keyword.length > 0) {
|
194
|
parameterNames.push("fv0");
|
195
|
parameterValues.push(this.keyword);
|
196
|
parameterNames.push("f0");
|
197
|
parameterValues.push("q");
|
198
|
}
|
199
|
if(this.customFilter){
|
200
|
parameterNames.push(this.customFilter.queryFieldName);
|
201
|
parameterValues.push(this.customFilter.valueId);
|
202
|
parameterNames.push("cf");
|
203
|
parameterValues.push("true");
|
204
|
}
|
205
|
this._router.navigate([url], {queryParams: this.routerHelper.createQueryParams(parameterNames, parameterValues)});
|
206
|
}
|
207
|
getQueryParamsForAdvancedSearch(entity){
|
208
|
let params = {};
|
209
|
if (entity == "result") {
|
210
|
if (this.resultsQuickFilter) {
|
211
|
params["qf"] = "" + this.resultsQuickFilter.selected;
|
212
|
}
|
213
|
}
|
214
|
if(this.keyword.length > 0) {
|
215
|
params["fv0"] = "" + this.keyword;
|
216
|
params["f0"] = "q";
|
217
|
}
|
218
|
if(this.customFilter){
|
219
|
params = this.customFilter.getParameters(params);
|
220
|
}
|
221
|
return params;
|
222
|
}
|
223
|
}
|