mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 11:33:04 +00:00
Implement component to switch between view modes
For now it allows to switch between list and grid views. Fixes https://github.com/DSpace/dspace-angular/issues/171
This commit is contained in:
@@ -81,6 +81,10 @@
|
|||||||
},
|
},
|
||||||
"results": {
|
"results": {
|
||||||
"title": "Search Results"
|
"title": "Search Results"
|
||||||
|
},
|
||||||
|
"view-switch": {
|
||||||
|
"show-list": "Show as list",
|
||||||
|
"show-grid": "Show as grid"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"loading": {
|
"loading": {
|
||||||
|
@@ -1,7 +1,13 @@
|
|||||||
import { SortOptions } from '../core/cache/models/sort-options.model';
|
import { SortOptions } from '../core/cache/models/sort-options.model';
|
||||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||||
|
|
||||||
|
export enum ViewMode {
|
||||||
|
List = 'list',
|
||||||
|
Grid = 'grid'
|
||||||
|
}
|
||||||
|
|
||||||
export class SearchOptions {
|
export class SearchOptions {
|
||||||
pagination?: PaginationComponentOptions;
|
pagination?: PaginationComponentOptions;
|
||||||
sort?: SortOptions;
|
sort?: SortOptions;
|
||||||
|
view?: ViewMode = ViewMode.List;
|
||||||
}
|
}
|
||||||
|
@@ -5,5 +5,6 @@
|
|||||||
[currentParams]="currentParams"
|
[currentParams]="currentParams"
|
||||||
[scopes]="scopeList?.payload">
|
[scopes]="scopeList?.payload">
|
||||||
</ds-search-form>
|
</ds-search-form>
|
||||||
|
<ds-view-mode-switch></ds-view-mode-switch>
|
||||||
<ds-search-results [searchResults]="results" [searchConfig]="searchOptions"></ds-search-results>
|
<ds-search-results [searchResults]="results" [searchConfig]="searchOptions"></ds-search-results>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -6,6 +6,7 @@ import { SearchResult } from './search-result.model';
|
|||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||||
import { SortOptions } from '../core/cache/models/sort-options.model';
|
import { SortOptions } from '../core/cache/models/sort-options.model';
|
||||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||||
|
import { ViewModeSwitchComponent } from '../shared/view-mode-switch/view-mode-switch.component';
|
||||||
import { SearchOptions } from './search-options.model';
|
import { SearchOptions } from './search-options.model';
|
||||||
import { CommunityDataService } from '../core/data/community-data.service';
|
import { CommunityDataService } from '../core/data/community-data.service';
|
||||||
import { isNotEmpty } from '../shared/empty.util';
|
import { isNotEmpty } from '../shared/empty.util';
|
||||||
|
@@ -13,6 +13,8 @@ import { ItemSearchResult } from '../../object-list/search-result-list-element/i
|
|||||||
import { SearchFilterConfig } from './search-filter-config.model';
|
import { SearchFilterConfig } from './search-filter-config.model';
|
||||||
import { FilterType } from './filter-type.model';
|
import { FilterType } from './filter-type.model';
|
||||||
import { FacetValue } from './facet-value.model';
|
import { FacetValue } from './facet-value.model';
|
||||||
|
import { ViewMode } from '../../+search-page/search-options.model';
|
||||||
|
import { Router, NavigationExtras } from '@angular/router';
|
||||||
|
|
||||||
function shuffle(array: any[]) {
|
function shuffle(array: any[]) {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
@@ -76,7 +78,9 @@ export class SearchService {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
constructor(private itemDataService: ItemDataService) {
|
constructor(
|
||||||
|
private itemDataService: ItemDataService,
|
||||||
|
private router: Router) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,4 +196,13 @@ export class SearchService {
|
|||||||
Observable.of(values)
|
Observable.of(values)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setViewMode(viewMode: ViewMode) {
|
||||||
|
const navigationExtras: NavigationExtras = {
|
||||||
|
queryParams: {view: viewMode},
|
||||||
|
queryParamsHandling: 'merge'
|
||||||
|
};
|
||||||
|
|
||||||
|
this.router.navigate(['/search'], navigationExtras);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@ import { ThumbnailComponent } from '../thumbnail/thumbnail.component';
|
|||||||
import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component';
|
import { SearchResultListElementComponent } from '../object-list/search-result-list-element/search-result-list-element.component';
|
||||||
import { SearchFormComponent } from './search-form/search-form.component';
|
import { SearchFormComponent } from './search-form/search-form.component';
|
||||||
import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component';
|
import { WrapperListElementComponent } from '../object-list/wrapper-list-element/wrapper-list-element.component';
|
||||||
|
import { ViewModeSwitchComponent } from './view-mode-switch/view-mode-switch.component';
|
||||||
|
|
||||||
const MODULES = [
|
const MODULES = [
|
||||||
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
|
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
|
||||||
@@ -61,7 +62,8 @@ const COMPONENTS = [
|
|||||||
PaginationComponent,
|
PaginationComponent,
|
||||||
SearchFormComponent,
|
SearchFormComponent,
|
||||||
ThumbnailComponent,
|
ThumbnailComponent,
|
||||||
WrapperListElementComponent
|
WrapperListElementComponent,
|
||||||
|
ViewModeSwitchComponent
|
||||||
];
|
];
|
||||||
|
|
||||||
const ENTRY_COMPONENTS = [
|
const ENTRY_COMPONENTS = [
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
<div class="btn-group" data-toggle="buttons">
|
||||||
|
<a routerLink="."
|
||||||
|
[queryParams]="{view: 'list'}"
|
||||||
|
queryParamsHandling="merge"
|
||||||
|
(click)="switchViewTo(viewModeEnum.List)"
|
||||||
|
routerLinkActive="active"
|
||||||
|
class="btn btn-secondary">
|
||||||
|
<i class="fa fa-list" title="{{'search.view-switch.show-list' | translate}}"></i>
|
||||||
|
</a>
|
||||||
|
<a routerLink="."
|
||||||
|
[queryParams]="{view: 'grid'}"
|
||||||
|
queryParamsHandling="merge"
|
||||||
|
(click)="switchViewTo(viewModeEnum.Grid)"
|
||||||
|
routerLinkActive="active"
|
||||||
|
class="btn btn-secondary">
|
||||||
|
<i class="fa fa-th-large" title="{{'search.view-switch.show-grid' | translate}}"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
@@ -0,0 +1 @@
|
|||||||
|
@import '../../../styles/variables.scss';
|
@@ -0,0 +1,20 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { ViewMode } from '../../+search-page/search-options.model';
|
||||||
|
import { SearchService } from './../../+search-page/search-service/search.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component to switch between list and grid views.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-view-mode-switch',
|
||||||
|
styleUrls: ['./view-mode-switch.component.scss'],
|
||||||
|
templateUrl: './view-mode-switch.component.html'
|
||||||
|
})
|
||||||
|
export class ViewModeSwitchComponent {
|
||||||
|
constructor(private searchService: SearchService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
switchViewTo(viewMode: ViewMode) {
|
||||||
|
this.searchService.setViewMode(viewMode);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user