mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #1821 from atmire/SearchEvents-bugfix
Search events bug-fix
This commit is contained in:
@@ -25,6 +25,7 @@ import { PaginationService } from '../../pagination/pagination.service';
|
|||||||
import { SearchConfigurationService } from './search-configuration.service';
|
import { SearchConfigurationService } from './search-configuration.service';
|
||||||
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
||||||
import { RequestEntry } from '../../data/request-entry.model';
|
import { RequestEntry } from '../../data/request-entry.model';
|
||||||
|
import { Angulartics2 } from 'angulartics2';
|
||||||
|
|
||||||
@Component({ template: '' })
|
@Component({ template: '' })
|
||||||
class DummyComponent {
|
class DummyComponent {
|
||||||
@@ -57,6 +58,7 @@ describe('SearchService', () => {
|
|||||||
{ provide: DSpaceObjectDataService, useValue: {} },
|
{ provide: DSpaceObjectDataService, useValue: {} },
|
||||||
{ provide: PaginationService, useValue: {} },
|
{ provide: PaginationService, useValue: {} },
|
||||||
{ provide: SearchConfigurationService, useValue: searchConfigService },
|
{ provide: SearchConfigurationService, useValue: searchConfigService },
|
||||||
|
{ provide: Angulartics2, useValue: {} },
|
||||||
SearchService
|
SearchService
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -124,6 +126,7 @@ describe('SearchService', () => {
|
|||||||
{ provide: DSpaceObjectDataService, useValue: {} },
|
{ provide: DSpaceObjectDataService, useValue: {} },
|
||||||
{ provide: PaginationService, useValue: paginationService },
|
{ provide: PaginationService, useValue: paginationService },
|
||||||
{ provide: SearchConfigurationService, useValue: searchConfigService },
|
{ provide: SearchConfigurationService, useValue: searchConfigService },
|
||||||
|
{ provide: Angulartics2, useValue: {} },
|
||||||
SearchService
|
SearchService
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@@ -33,6 +33,7 @@ import { SearchConfigurationService } from './search-configuration.service';
|
|||||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||||
import { RestRequest } from '../../data/rest-request.model';
|
import { RestRequest } from '../../data/rest-request.model';
|
||||||
import { BaseDataService } from '../../data/base/base-data.service';
|
import { BaseDataService } from '../../data/base/base-data.service';
|
||||||
|
import { Angulartics2 } from 'angulartics2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A limited data service implementation for the 'discover' endpoint
|
* A limited data service implementation for the 'discover' endpoint
|
||||||
@@ -96,6 +97,7 @@ export class SearchService implements OnDestroy {
|
|||||||
private dspaceObjectService: DSpaceObjectDataService,
|
private dspaceObjectService: DSpaceObjectDataService,
|
||||||
private paginationService: PaginationService,
|
private paginationService: PaginationService,
|
||||||
private searchConfigurationService: SearchConfigurationService,
|
private searchConfigurationService: SearchConfigurationService,
|
||||||
|
private angulartics2: Angulartics2,
|
||||||
) {
|
) {
|
||||||
this.searchDataService = new SearchDataService();
|
this.searchDataService = new SearchDataService();
|
||||||
}
|
}
|
||||||
@@ -320,6 +322,37 @@ export class SearchService implements OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send search event to rest api using angularitics
|
||||||
|
* @param config Paginated search options used
|
||||||
|
* @param searchQueryResponse The response objects of the performed search
|
||||||
|
*/
|
||||||
|
trackSearch(config: PaginatedSearchOptions, searchQueryResponse: SearchObjects<DSpaceObject>) {
|
||||||
|
const filters: { filter: string, operator: string, value: string, label: string; }[] = [];
|
||||||
|
const appliedFilters = searchQueryResponse.appliedFilters || [];
|
||||||
|
for (let i = 0, filtersLength = appliedFilters.length; i < filtersLength; i++) {
|
||||||
|
const appliedFilter = appliedFilters[i];
|
||||||
|
filters.push(appliedFilter);
|
||||||
|
}
|
||||||
|
this.angulartics2.eventTrack.next({
|
||||||
|
action: 'search',
|
||||||
|
properties: {
|
||||||
|
searchOptions: config,
|
||||||
|
page: {
|
||||||
|
size: config.pagination.size, // same as searchQueryResponse.page.elementsPerPage
|
||||||
|
totalElements: searchQueryResponse.pageInfo.totalElements,
|
||||||
|
totalPages: searchQueryResponse.pageInfo.totalPages,
|
||||||
|
number: config.pagination.currentPage, // same as searchQueryResponse.page.currentPage
|
||||||
|
},
|
||||||
|
sort: {
|
||||||
|
by: config.sort.field,
|
||||||
|
order: config.sort.direction
|
||||||
|
},
|
||||||
|
filters: filters,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} The base path to the search page
|
* @returns {string} The base path to the search page
|
||||||
*/
|
*/
|
||||||
|
@@ -1,2 +1 @@
|
|||||||
<ds-themed-search></ds-themed-search>
|
<ds-themed-search [trackStatistics]="true"></ds-themed-search>
|
||||||
<ds-search-tracker></ds-search-tracker>
|
|
||||||
|
@@ -140,6 +140,11 @@ export class SearchComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
@Input() showScopeSelector = true;
|
@Input() showScopeSelector = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not to track search statistics by sending updates to the rest api
|
||||||
|
*/
|
||||||
|
@Input() trackStatistics = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current configuration used during the search
|
* The current configuration used during the search
|
||||||
*/
|
*/
|
||||||
@@ -360,9 +365,14 @@ export class SearchComponent implements OnInit {
|
|||||||
followLink<Item>('accessStatus', { isOptional: true, shouldEmbed: environment.item.showAccessStatuses })
|
followLink<Item>('accessStatus', { isOptional: true, shouldEmbed: environment.item.showAccessStatuses })
|
||||||
).pipe(getFirstCompletedRemoteData())
|
).pipe(getFirstCompletedRemoteData())
|
||||||
.subscribe((results: RemoteData<SearchObjects<DSpaceObject>>) => {
|
.subscribe((results: RemoteData<SearchObjects<DSpaceObject>>) => {
|
||||||
if (results.hasSucceeded && results.payload?.page?.length > 0) {
|
if (results.hasSucceeded) {
|
||||||
|
if (this.trackStatistics) {
|
||||||
|
this.service.trackSearch(searchOptions, results.payload);
|
||||||
|
}
|
||||||
|
if (results.payload?.page?.length > 0) {
|
||||||
this.resultFound.emit(results.payload);
|
this.resultFound.emit(results.payload);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.resultsRD$.next(results);
|
this.resultsRD$.next(results);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ import { ListableObject } from '../object-collection/shared/listable-object.mode
|
|||||||
templateUrl: '../theme-support/themed.component.html',
|
templateUrl: '../theme-support/themed.component.html',
|
||||||
})
|
})
|
||||||
export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
|
export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
|
||||||
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'useCachedVersionIfAvailable', 'inPlaceSearch', 'linkType', 'paginationId', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showSidebar', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'resultFound', 'deselectObject', 'selectObject'];
|
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'useCachedVersionIfAvailable', 'inPlaceSearch', 'linkType', 'paginationId', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showSidebar', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'resultFound', 'deselectObject', 'selectObject', 'trackStatistics'];
|
||||||
|
|
||||||
@Input() configurationList: SearchConfigurationOption[] = [];
|
@Input() configurationList: SearchConfigurationOption[] = [];
|
||||||
|
|
||||||
@@ -57,6 +57,8 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
|
|||||||
|
|
||||||
@Input() showScopeSelector = true;
|
@Input() showScopeSelector = true;
|
||||||
|
|
||||||
|
@Input() trackStatistics = false;
|
||||||
|
|
||||||
@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter<SearchObjects<DSpaceObject>>();
|
@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter<SearchObjects<DSpaceObject>>();
|
||||||
|
|
||||||
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
|
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
|
||||||
|
Reference in New Issue
Block a user