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