Skip to content
Snippets Groups Projects
Commit 0a737203 authored by Matthieu Benoist's avatar Matthieu Benoist
Browse files

other licence initialization problem

parent 9354bf96
No related branches found
No related tags found
1 merge request!144other licence initialization problem
......@@ -17,7 +17,7 @@ import { notificationMessages } from '../i18n/traductions';
// Function used by APP_INITIALIZER before the app start: init user info / statut (expect a promise)
export function initUserService(authService: UserService, notificationService: NotificationService) {
return (): Promise<any> => {
return new Promise((resolve, reject) => {
return new Promise<void>((resolve, reject) => {
authService.initializeService().pipe(timeout(3000)).subscribe(
() => {
resolve();
......@@ -37,7 +37,7 @@ export function initUserService(authService: UserService, notificationService: N
export function initAppConfig(appConfigService: AppConfigService) {
return (): Promise<any> => {
return new Promise((resolve, reject) => {
return new Promise<void>((resolve, reject) => {
appConfigService.load();
resolve();
});
......
......@@ -52,8 +52,6 @@ export class ResultsComponent implements OnInit, OnDestroy {
ngOnInit() {
console.log(`Titre vaut : ${ pageTitles.datasets }.`);
console.log(pageTitles);
// Set the title and description for the research page
this._meta.updateTag({ name: 'description', content: metaDescription.research });
......@@ -94,12 +92,23 @@ export class ResultsComponent implements OnInit, OnDestroy {
// If there are parameters, we extract them to set the ESoptions for a news search.
private manageUrlParameters(params) {
this._datasetResearchService.resetActiveAggregations();
//this._datasetResearchService.resetActiveAggregations();
if (params && Object.keys(params).length > 0) {
this.hasParams = true;
// We need to make an initial request to get the aggregations and subaggregations
this.urlSearch(params);
}
else {
//reset filters recorded when there are not get parameters
this._datasetResearchService.triggerSearchChange();
this._researchUrlService.reset();
}
}
urlSearch(params) {
this._datasetResearchService.resetActiveAggregations();
this._datasetResearchService.getResults().subscribe(() => {
// Create the ESOptions
const options = this._researchUrlService.getOptionsFromParameters(params);
this._datasetResearchService.elasticSearchOptions.setElasticsearchOptions(options);
......@@ -153,12 +162,6 @@ export class ResultsComponent implements OnInit, OnDestroy {
this._datasetResearchService.triggerSearchChange();
});
}
else {
//reset filters recorded when there are not get parameters
this._datasetResearchService.triggerSearchChange();
this._researchUrlService.reset();
}
}
ngOnDestroy() {
this.searchChangeSub.unsubscribe();
......
......@@ -41,6 +41,7 @@ export class DatasetResearchService {
this._resultsCount = [];
}
/**
* Get results from elasticsearch (can be Datasets or Articles).
* Options: filter by query string and pagination
......@@ -49,43 +50,6 @@ export class DatasetResearchService {
this._pendingRequests += 1;
return this._elasticsearchService.getAllEntities(this._elasticsearchOptions).pipe(
map((e) => {
// Set results count
if (this._elasticsearchOptions.shouldAggregateResultCount) {
this._resultsCount = [];
const countScopes = e.aggregations['count_by_scope'].buckets;
let countDatasets = 0;
countScopes.forEach((bucket) => {
if (scopesResearch.datasets.elasticType.includes(bucket.key)) {
countDatasets += bucket.count.value;
} else {
this._resultsCount.push({
scopeKey: bucket.key,
count: bucket.count.value,
});
}
});
// Datasets scope (datasets + non geographic datasets + series)
this._resultsCount.push({
scopeKey: scopesResearch.datasets.key,
count: countDatasets,
});
// All scope
const countAll = this._resultsCount.reduce((acc, obj) => {
const count = obj.scopeKey !== (scopesResearch.page.key&&scopesResearch.post.key) ? acc + obj.count : 0;
return count;
// tslint:disable-next-line:align
}, 0);
this._resultsCount.push({
scopeKey: scopesResearch.all.key,
count: countAll,
});
}
// Matomo tracking
this.angulartics2Piwik.eventTrack('trackSiteSearch', { keyword: this.searchString });
if (this._elasticsearchOptions.shouldAggregateFilters) {
// Get the aggregations that will be used to display the filters
let aggregations = (e.hits.hits) ? e.aggregations : [];
......@@ -161,13 +125,6 @@ export class DatasetResearchService {
}
});
}
this._elasticsearchOptions.shouldAggregateFilters = true;
this._elasticsearchOptions.shouldAggregateResultCount = false;
this._elasticsearchOptions.fromAutocompletion = false;
// Notify that data have been reloaded
this._datasetsReloadedSubject.next();
this._pendingRequests -= 1;
const results: any = [];
......@@ -217,6 +174,50 @@ export class DatasetResearchService {
});
// Set results count
this._resultsCount = [];
const countScopes = e.aggregations['count_by_scope'].buckets;
let countDatasets = 0;
countScopes.forEach((bucket) => {
if (scopesResearch.datasets.elasticType.includes(bucket.key)) {
countDatasets += bucket.count.value;
} else {
this._resultsCount.push({
scopeKey: bucket.key,
count: bucket.count.value,
});
}
});
// Datasets scope (datasets + non geographic datasets + series)
this._resultsCount.push({
scopeKey: scopesResearch.datasets.key,
count: countDatasets,
});
// All scope
const countAll = this._resultsCount.reduce((acc, obj) => {
const count = obj.scopeKey !== (scopesResearch.page.key&&scopesResearch.post.key) ? acc + obj.count : 0;
return count;
// tslint:disable-next-line:align
}, 0);
this._resultsCount.push({
scopeKey: scopesResearch.all.key,
count: countAll,
});
// Matomo tracking
this.angulartics2Piwik.eventTrack('trackSiteSearch', { keyword: this.searchString });
this._elasticsearchOptions.shouldAggregateFilters = true;
this._elasticsearchOptions.shouldAggregateResultCount = false;
this._elasticsearchOptions.fromAutocompletion = false;
// Notify that data have been reloaded
this._datasetsReloadedSubject.next();
this._pendingRequests -= 1;
return results;
}),
catchError(
......@@ -257,6 +258,9 @@ export class DatasetResearchService {
}
}
}
if (!hasAlreadyOtherLicenses) {
this._searchChangeSubject.next();
}
return aggregations;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment