mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
45621: finished facet branch - changed decrease to reset
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
<a class="float-left" *ngIf="filterValues.length > (facetCount | async)"
|
<a class="float-left" *ngIf="filterValues.length > (facetCount | async)"
|
||||||
(click)="showMore()">{{"search.filters.filter.show-more"
|
(click)="showMore()">{{"search.filters.filter.show-more"
|
||||||
| translate}}</a>
|
| translate}}</a>
|
||||||
<a class="float-right" *ngIf="(currentPage | async) > 1" (click)="showLess()">{{"search.filters.filter.show-less"
|
<a class="float-right" *ngIf="(currentPage | async) > 1" (click)="showFirstPageOnly()">{{"search.filters.filter.show-less"
|
||||||
| translate}}</a>
|
| translate}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -55,8 +55,10 @@ describe('SearchFacetFilterComponent', () => {
|
|||||||
getQueryParamsWithout: (paramName: string, filterValue: string) => '',
|
getQueryParamsWithout: (paramName: string, filterValue: string) => '',
|
||||||
getPage: (paramName: string) => page,
|
getPage: (paramName: string) => page,
|
||||||
/* tslint:disable:no-empty */
|
/* tslint:disable:no-empty */
|
||||||
increasePage: (filterName: string) => {},
|
incrementPage: (filterName: string) => {
|
||||||
decreasePage: (filterName: string) => {},
|
},
|
||||||
|
resetPage: (filterName: string) => {
|
||||||
|
},
|
||||||
/* tslint:enable:no-empty */
|
/* tslint:enable:no-empty */
|
||||||
searchLink: '/search',
|
searchLink: '/search',
|
||||||
}
|
}
|
||||||
@@ -156,12 +158,23 @@ describe('SearchFacetFilterComponent', () => {
|
|||||||
|
|
||||||
describe('when the showMore method is called', () => {
|
describe('when the showMore method is called', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(filterService, 'increasePage');
|
spyOn(filterService, 'incrementPage');
|
||||||
comp.showMore();
|
comp.showMore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call increasePage on the filterService with the correct filter parameter name', () => {
|
it('should call incrementPage on the filterService with the correct filter parameter name', () => {
|
||||||
expect(filterService.increasePage).toHaveBeenCalledWith(mockFilterConfig.name)
|
expect(filterService.incrementPage).toHaveBeenCalledWith(mockFilterConfig.name)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the showFirstPageOnly method is called', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(filterService, 'resetPage');
|
||||||
|
comp.showFirstPageOnly();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call resetPage on the filterService with the correct filter parameter name', () => {
|
||||||
|
expect(filterService.resetPage).toHaveBeenCalledWith(mockFilterConfig.name)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -57,11 +57,11 @@ export class SearchFacetFilterComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showMore() {
|
showMore() {
|
||||||
this.filterService.increasePage(this.filterConfig.name);
|
this.filterService.incrementPage(this.filterConfig.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
showLess() {
|
showFirstPageOnly() {
|
||||||
this.filterService.decreasePage(this.filterConfig.name);
|
this.filterService.resetPage(this.filterConfig.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentPage(): Observable<number> {
|
getCurrentPage(): Observable<number> {
|
||||||
|
@@ -17,7 +17,8 @@ export const SearchFilterActionTypes = {
|
|||||||
INITIAL_EXPAND: type('dspace/search-filter/INITIAL_EXPAND'),
|
INITIAL_EXPAND: type('dspace/search-filter/INITIAL_EXPAND'),
|
||||||
TOGGLE: type('dspace/search-filter/TOGGLE'),
|
TOGGLE: type('dspace/search-filter/TOGGLE'),
|
||||||
DECREMENT_PAGE: type('dspace/search-filter/DECREMENT_PAGE'),
|
DECREMENT_PAGE: type('dspace/search-filter/DECREMENT_PAGE'),
|
||||||
INCREMENT_PAGE: type('dspace/search-filter/INCREMENT_PAGE')
|
INCREMENT_PAGE: type('dspace/search-filter/INCREMENT_PAGE'),
|
||||||
|
RESET_PAGE: type('dspace/search-filter/RESET_PAGE')
|
||||||
};
|
};
|
||||||
|
|
||||||
export class SearchFilterAction implements Action {
|
export class SearchFilterAction implements Action {
|
||||||
@@ -55,4 +56,8 @@ export class SearchFilterDecrementPageAction extends SearchFilterAction {
|
|||||||
export class SearchFilterIncrementPageAction extends SearchFilterAction {
|
export class SearchFilterIncrementPageAction extends SearchFilterAction {
|
||||||
type = SearchFilterActionTypes.INCREMENT_PAGE;
|
type = SearchFilterActionTypes.INCREMENT_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SearchFilterResetPageAction extends SearchFilterAction {
|
||||||
|
type = SearchFilterActionTypes.RESET_PAGE;
|
||||||
|
}
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
@@ -4,7 +4,7 @@ import {
|
|||||||
SearchFilterInitialCollapseAction,
|
SearchFilterInitialCollapseAction,
|
||||||
SearchFilterInitialExpandAction,
|
SearchFilterInitialExpandAction,
|
||||||
SearchFilterToggleAction,
|
SearchFilterToggleAction,
|
||||||
SearchFilterDecrementPageAction
|
SearchFilterDecrementPageAction, SearchFilterResetPageAction
|
||||||
} from './search-filter.actions';
|
} from './search-filter.actions';
|
||||||
import { filterReducer } from './search-filter.reducer';
|
import { filterReducer } from './search-filter.reducer';
|
||||||
|
|
||||||
@@ -154,4 +154,12 @@ describe('filterReducer', () => {
|
|||||||
const newState = filterReducer(state, action);
|
const newState = filterReducer(state, action);
|
||||||
expect(newState[filterName1].page).toEqual(1);
|
expect(newState[filterName1].page).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reset the page to 1 for the specified filter in response to the RESET_PAGE action', () => {
|
||||||
|
const state = {};
|
||||||
|
state[filterName1] = { filterCollapsed: true, page: 20 };
|
||||||
|
const action = new SearchFilterResetPageAction(filterName1);
|
||||||
|
const newState = filterReducer(state, action);
|
||||||
|
expect(newState[filterName1].page).toEqual(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -77,6 +77,15 @@ export function filterReducer(state = initialState, action: SearchFilterAction):
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
case SearchFilterActionTypes.RESET_PAGE: {
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
[action.filterName]: {
|
||||||
|
filterCollapsed: state[action.filterName].filterCollapsed,
|
||||||
|
page: 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case SearchFilterActionTypes.TOGGLE: {
|
case SearchFilterActionTypes.TOGGLE: {
|
||||||
|
@@ -4,7 +4,8 @@ import { Store } from '@ngrx/store';
|
|||||||
import {
|
import {
|
||||||
SearchFilterCollapseAction, SearchFilterDecrementPageAction, SearchFilterExpandAction,
|
SearchFilterCollapseAction, SearchFilterDecrementPageAction, SearchFilterExpandAction,
|
||||||
SearchFilterIncrementPageAction,
|
SearchFilterIncrementPageAction,
|
||||||
SearchFilterInitialCollapseAction, SearchFilterInitialExpandAction, SearchFilterToggleAction
|
SearchFilterInitialCollapseAction, SearchFilterInitialExpandAction, SearchFilterResetPageAction,
|
||||||
|
SearchFilterToggleAction
|
||||||
} from './search-filter.actions';
|
} from './search-filter.actions';
|
||||||
import { SearchFiltersState } from './search-filter.reducer';
|
import { SearchFiltersState } from './search-filter.reducer';
|
||||||
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
|
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
|
||||||
@@ -95,7 +96,7 @@ describe('SearchFilterService', () => {
|
|||||||
|
|
||||||
describe('when the decreasePage method is triggered', () => {
|
describe('when the decreasePage method is triggered', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service.decreasePage(mockFilterConfig.name);
|
service.decrementPage(mockFilterConfig.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
|
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
|
||||||
@@ -106,7 +107,7 @@ describe('SearchFilterService', () => {
|
|||||||
|
|
||||||
describe('when the increasePage method is triggered', () => {
|
describe('when the increasePage method is triggered', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service.increasePage(mockFilterConfig.name);
|
service.incrementPage(mockFilterConfig.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('SearchFilterCollapseAction should be dispatched to the store', () => {
|
it('SearchFilterCollapseAction should be dispatched to the store', () => {
|
||||||
@@ -115,6 +116,17 @@ describe('SearchFilterService', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when the resetPage method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
service.resetPage(mockFilterConfig.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('SearchFilterDecrementPageAction should be dispatched to the store', () => {
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(new SearchFilterResetPageAction(mockFilterConfig.name));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('when the expand method is triggered', () => {
|
describe('when the expand method is triggered', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service.expand(mockFilterConfig.name);
|
service.expand(mockFilterConfig.name);
|
||||||
|
@@ -7,7 +7,7 @@ import {
|
|||||||
SearchFilterDecrementPageAction, SearchFilterExpandAction,
|
SearchFilterDecrementPageAction, SearchFilterExpandAction,
|
||||||
SearchFilterIncrementPageAction,
|
SearchFilterIncrementPageAction,
|
||||||
SearchFilterInitialCollapseAction,
|
SearchFilterInitialCollapseAction,
|
||||||
SearchFilterInitialExpandAction,
|
SearchFilterInitialExpandAction, SearchFilterResetPageAction,
|
||||||
SearchFilterToggleAction
|
SearchFilterToggleAction
|
||||||
} from './search-filter.actions';
|
} from './search-filter.actions';
|
||||||
import { hasValue, } from '../../../shared/empty.util';
|
import { hasValue, } from '../../../shared/empty.util';
|
||||||
@@ -91,13 +91,17 @@ export class SearchFilterService {
|
|||||||
this.store.dispatch(new SearchFilterInitialExpandAction(filterName));
|
this.store.dispatch(new SearchFilterInitialExpandAction(filterName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public decreasePage(filterName: string): void {
|
public decrementPage(filterName: string): void {
|
||||||
this.store.dispatch(new SearchFilterDecrementPageAction(filterName));
|
this.store.dispatch(new SearchFilterDecrementPageAction(filterName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public increasePage(filterName: string): void {
|
public incrementPage(filterName: string): void {
|
||||||
this.store.dispatch(new SearchFilterIncrementPageAction(filterName));
|
this.store.dispatch(new SearchFilterIncrementPageAction(filterName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public resetPage(filterName: string): void {
|
||||||
|
this.store.dispatch(new SearchFilterResetPageAction(filterName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterByNameSelector(name: string): MemoizedSelector<SearchFiltersState, SearchFilterState> {
|
function filterByNameSelector(name: string): MemoizedSelector<SearchFiltersState, SearchFilterState> {
|
||||||
|
Reference in New Issue
Block a user