mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Merge pull request #169 from LotteHofstede/w2p-44835_mock-search-service-filters
Added facet/filter methods to the mock search service
This commit is contained in:
@@ -4,7 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { CommunityDataService } from '../core/data/community-data.service';
|
import { CommunityDataService } from '../core/data/community-data.service';
|
||||||
import { SearchPageComponent } from './search-page.component';
|
import { SearchPageComponent } from './search-page.component';
|
||||||
import { SearchService } from './search.service';
|
import { SearchService } from './search-service/search.service';
|
||||||
import { Community } from '../core/shared/community.model';
|
import { Community } from '../core/shared/community.model';
|
||||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { SearchService } from './search.service';
|
import { SearchService } from './search-service/search.service';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
import { RemoteData } from '../core/data/remote-data';
|
||||||
import { SearchResult } from './search-result.model';
|
import { SearchResult } from './search-result.model';
|
||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||||
@@ -57,8 +57,8 @@ export class SearchPageComponent implements OnInit, OnDestroy {
|
|||||||
this.currentParams = params;
|
this.currentParams = params;
|
||||||
this.query = params.query || '';
|
this.query = params.query || '';
|
||||||
this.scope = params.scope;
|
this.scope = params.scope;
|
||||||
const page = +params.page || this.searchOptions.pagination.currentPage;
|
const page = +params.page || this.searchOptions.pagination.currentPage;
|
||||||
const pageSize = +params.pageSize || this.searchOptions.pagination.pageSize;
|
const pageSize = +params.pageSize || this.searchOptions.pagination.pageSize;
|
||||||
const sortDirection = +params.sortDirection || this.searchOptions.sort.direction;
|
const sortDirection = +params.sortDirection || this.searchOptions.sort.direction;
|
||||||
const pagination = Object.assign({},
|
const pagination = Object.assign({},
|
||||||
this.searchOptions.pagination,
|
this.searchOptions.pagination,
|
||||||
|
@@ -11,7 +11,7 @@ import { SearchResultsComponent } from './search-results/search-results.componen
|
|||||||
import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component';
|
import { ItemSearchResultListElementComponent } from '../object-list/search-result-list-element/item-search-result/item-search-result-list-element.component';
|
||||||
import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component';
|
import { CollectionSearchResultListElementComponent } from '../object-list/search-result-list-element/collection-search-result/collection-search-result-list-element.component';
|
||||||
import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component';
|
import { CommunitySearchResultListElementComponent } from '../object-list/search-result-list-element/community-search-result/community-search-result-list-element.component';
|
||||||
import { SearchService } from './search.service';
|
import { SearchService } from './search-service/search.service';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
7
src/app/+search-page/search-service/facet-value.model.ts
Normal file
7
src/app/+search-page/search-service/facet-value.model.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
export class FacetValue {
|
||||||
|
|
||||||
|
value: string;
|
||||||
|
count: number;
|
||||||
|
search: string;
|
||||||
|
}
|
5
src/app/+search-page/search-service/filter-type.model.ts
Normal file
5
src/app/+search-page/search-service/filter-type.model.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export enum FilterType {
|
||||||
|
text,
|
||||||
|
range,
|
||||||
|
hierarchy
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
import { FilterType } from './filter-type.model';
|
||||||
|
|
||||||
|
export class SearchFilterConfig {
|
||||||
|
|
||||||
|
name: string;
|
||||||
|
type: FilterType;
|
||||||
|
hasFacets: boolean;
|
||||||
|
isOpenByDefault: boolean;
|
||||||
|
/**
|
||||||
|
* Name of this configuration that can be used in a url
|
||||||
|
* @returns Parameter name
|
||||||
|
*/
|
||||||
|
get paramName(): string {
|
||||||
|
return 'f.' + this.name;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,19 +1,18 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { SearchResult } from '../search-result.model';
|
||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
import { ItemDataService } from '../../core/data/item-data.service';
|
||||||
import { Item } from '../core/shared/item.model';
|
import { PageInfo } from '../../core/shared/page-info.model';
|
||||||
import { ItemSearchResult } from '../object-list/search-result-list-element/item-search-result/item-search-result.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
import { Metadatum } from '../core/shared/metadatum.model';
|
import { SearchOptions } from '../search-options.model';
|
||||||
import { PageInfo } from '../core/shared/page-info.model';
|
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
import { Metadatum } from '../../core/shared/metadatum.model';
|
||||||
import { SearchOptions } from './search-options.model';
|
import { Item } from '../../core/shared/item.model';
|
||||||
import { SearchResult } from './search-result.model';
|
import { ItemSearchResult } from '../../object-list/search-result-list-element/item-search-result/item-search-result.model';
|
||||||
|
import { SearchFilterConfig } from './search-filter-config.model';
|
||||||
import { ItemDataService } from '../core/data/item-data.service';
|
import { FilterType } from './filter-type.model';
|
||||||
|
import { FacetValue } from './facet-value.model';
|
||||||
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
|
||||||
|
|
||||||
function shuffle(array: any[]) {
|
function shuffle(array: any[]) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
@@ -46,6 +45,37 @@ export class SearchService {
|
|||||||
'<em>The QSAR DataBank (QsarDB) repository</em>',
|
'<em>The QSAR DataBank (QsarDB) repository</em>',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
config: SearchFilterConfig[] = [
|
||||||
|
Object.assign(new SearchFilterConfig(),
|
||||||
|
{
|
||||||
|
name: 'scope',
|
||||||
|
type: FilterType.hierarchy,
|
||||||
|
hasFacets: true,
|
||||||
|
isOpenByDefault: true
|
||||||
|
}),
|
||||||
|
Object.assign(new SearchFilterConfig(),
|
||||||
|
{
|
||||||
|
name: 'author',
|
||||||
|
type: FilterType.text,
|
||||||
|
hasFacets: true,
|
||||||
|
isOpenByDefault: false
|
||||||
|
}),
|
||||||
|
Object.assign(new SearchFilterConfig(),
|
||||||
|
{
|
||||||
|
name: 'date',
|
||||||
|
type: FilterType.range,
|
||||||
|
hasFacets: true,
|
||||||
|
isOpenByDefault: false
|
||||||
|
}),
|
||||||
|
Object.assign(new SearchFilterConfig(),
|
||||||
|
{
|
||||||
|
name: 'subject',
|
||||||
|
type: FilterType.text,
|
||||||
|
hasFacets: false,
|
||||||
|
isOpenByDefault: false
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
constructor(private itemDataService: ItemDataService) {
|
constructor(private itemDataService: ItemDataService) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -116,4 +146,50 @@ export class SearchService {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getConfig(): RemoteData<SearchFilterConfig[]> {
|
||||||
|
const requestPending = Observable.of(false);
|
||||||
|
const responsePending = Observable.of(false);
|
||||||
|
const isSuccessful = Observable.of(true);
|
||||||
|
const errorMessage = Observable.of(undefined);
|
||||||
|
const statusCode = Observable.of('200');
|
||||||
|
const returningPageInfo = Observable.of(new PageInfo());
|
||||||
|
return new RemoteData(
|
||||||
|
Observable.of('https://dspace7.4science.it/dspace-spring-rest/api/search'),
|
||||||
|
requestPending,
|
||||||
|
responsePending,
|
||||||
|
isSuccessful,
|
||||||
|
errorMessage,
|
||||||
|
statusCode,
|
||||||
|
returningPageInfo,
|
||||||
|
Observable.of(this.config)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFacetValuesFor(searchFilterConfigName: string): RemoteData<FacetValue[]> {
|
||||||
|
const values: FacetValue[] = [];
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const value = searchFilterConfigName + ' ' + (i + 1);
|
||||||
|
values.push({
|
||||||
|
value: value,
|
||||||
|
count: Math.floor(Math.random() * 20) + 20 * (5 - i), // make sure first results have the highest (random) count
|
||||||
|
search: 'https://dspace7.4science.it/dspace-spring-rest/api/search?f.' + searchFilterConfigName + '=' + encodeURI(value)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const requestPending = Observable.of(false);
|
||||||
|
const responsePending = Observable.of(false);
|
||||||
|
const isSuccessful = Observable.of(true);
|
||||||
|
const errorMessage = Observable.of(undefined);
|
||||||
|
const statusCode = Observable.of('200');
|
||||||
|
const returningPageInfo = Observable.of(new PageInfo());
|
||||||
|
return new RemoteData(
|
||||||
|
Observable.of('https://dspace7.4science.it/dspace-spring-rest/api/search'),
|
||||||
|
requestPending,
|
||||||
|
responsePending,
|
||||||
|
isSuccessful,
|
||||||
|
errorMessage,
|
||||||
|
statusCode,
|
||||||
|
returningPageInfo,
|
||||||
|
Observable.of(values)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user