#150 SortOptions config fixing

This commit is contained in:
Jonas Van Goolen
2017-10-31 13:28:48 +01:00
parent a704157c1f
commit 17f839f9e1
10 changed files with 66 additions and 28 deletions

View File

@@ -1,11 +1,10 @@
<ng-container *ngVar="(subCollectionsRDObs | async) as subCollectionsRD">
<div *ngIf="subCollectionsRD?.hasSucceeded" @fadeIn>
<h2>{{'community.sub-collection-list.head' | translate}}</h2>
<ul>
<ds-viewable-collection [objects]="subCollectionsRD?.payload">
</ds-viewable-collection>
</ul>
</div>
<ds-error *ngIf="subCollectionsRD?.hasFailed" message="{{'error.sub-collections' | translate}}"></ds-error>
<div *ngIf="subCollectionsRD?.hasSucceeded " @fadeIn>
<h2>{{'community.sub-collection-list.head' | translate}}</h2>
<ul>
<ds-viewable-collection [objects]="subCollectionsRD?.payload"
[sortConfig]="sortConfig"></ds-viewable-collection>
</ul>
</div><ds-error *ngIf="subCollectionsRD?.hasFailed" message="{{'error.sub-collections' | translate}}"></ds-error>
<ds-loading *ngIf="subCollectionsRD?.isLoading" message="{{'loading.sub-collections' | translate}}"></ds-loading>
</ng-container>

View File

@@ -4,8 +4,8 @@
<p class="lead">{{'home.top-level-communities.help' | translate}}</p>
<ds-viewable-collection
[config]="config"
[sortConfig]="sortConfig"
[objects]="communitiesRD"
(paginationChange)="updatePage($event)">
</ds-viewable-collection>
</div>

View File

@@ -30,7 +30,7 @@
</button>
</div>
<ds-search-results [searchResults]="resultsRDObs | async"
[searchConfig]="searchOptions"></ds-search-results>
[searchConfig]="searchOptions" [sortConfig]="sortConfig"></ds-search-results>
</div>
</div>
</div>

View File

@@ -6,7 +6,7 @@ import { RemoteData } from '../core/data/remote-data';
import { Community } from '../core/shared/community.model';
import { DSpaceObject } from '../core/shared/dspace-object.model';
import { isNotEmpty } from '../shared/empty.util';
import { SearchOptions } from './search-options.model';
import { SearchOptions,ViewMode } from './search-options.model';
import { SearchResult } from './search-result.model';
import { SearchService } from './search-service/search.service';
import { pushInOut } from '../shared/animations/push';
@@ -36,6 +36,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
resultsRDObs: Observable<RemoteData<Array<SearchResult<DSpaceObject>>>>;
currentParams = {};
searchOptions: SearchOptions;
sortConfig: SortOptions;
scopeListRDObs: Observable<RemoteData<Community[]>>;
isMobileView: Observable<boolean>;
@@ -58,15 +59,15 @@ export class SearchPageComponent implements OnInit, OnDestroy {
// TODO Update to accommodate view switcher
this.route.queryParams.map((params) => {
if (isNotEmpty(params.view) && params.view == 'grid') {
if (isNotEmpty(params.view) && params.view == ViewMode.Grid) {
pagination.pageSize = 12;
}
});
const sort: SortOptions = new SortOptions();
this.sortConfig=sort;
this.searchOptions = this.service.searchOptions;
}
ngOnInit(): void {

View File

@@ -3,6 +3,7 @@ import { RemoteData } from '../../core/data/remote-data';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { fadeIn, fadeInOut } from '../../shared/animations/fade';
import { SearchOptions } from '../search-options.model';
import { SortOptions } from '../../core/cache/models/sort-options.model';
import { SearchResult } from '../search-result.model';
/**
@@ -21,4 +22,5 @@ import { SearchResult } from '../search-result.model';
export class SearchResultsComponent {
@Input() searchResults: RemoteData<Array<SearchResult<DSpaceObject>>>;
@Input() searchConfig: SearchOptions;
@Input() sortConfig: SortOptions;
}

View File

@@ -1,13 +1,13 @@
<ds-object-list [config]="config"
[sortConfig]="sortConfig"
[objects]="objects"
*ngIf="getViewMode()=='list'">
*ngIf="getViewMode()===viewModeEnum.List">
</ds-object-list>
<ds-object-grid [config]="config"
[sortConfig]="sortConfig"
[objects]="objects"
*ngIf="getViewMode()=='grid'">
*ngIf="getViewMode()===viewModeEnum.Grid">
</ds-object-grid>

View File

@@ -11,10 +11,12 @@ import { PageInfo } from '../core/shared/page-info.model';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { SortDirection } from '../core/cache/models/sort-options.model';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { ListableObject } from './shared/listable-object.model';
import { ViewMode } from '../+search-page/search-options.model';
import { hasValue, isNotEmpty } from '../shared/empty.util';
@Component({
selector: 'ds-viewable-collection',
styleUrls: ['./object-collection.component.scss'],
@@ -24,6 +26,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit {
@Input() objects: RemoteData<ListableObject[]>;
@Input() config?: PaginationComponentOptions;
@Input() sortConfig: SortOptions;
pageInfo: Observable<PageInfo>;
/**
@@ -52,7 +55,8 @@ export class ObjectCollectionComponent implements OnChanges, OnInit {
*/
@Output() sortFieldChange: EventEmitter<string> = new EventEmitter<string>();
data: any = {};
defaultViewMode: string ='list';
currentMode: ViewMode = ViewMode.List;
viewModeEnum = ViewMode;
ngOnChanges(changes: SimpleChanges) {
if (changes.objects && !changes.objects.isFirstChange()) {
@@ -60,6 +64,7 @@ export class ObjectCollectionComponent implements OnChanges, OnInit {
}
}
ngOnInit(): void {
this.pageInfo = this.objects.pageInfo;
}
@@ -74,22 +79,15 @@ export class ObjectCollectionComponent implements OnChanges, OnInit {
private router: Router) {
}
getViewMode(): string {
// TODO Update to accommodate view switcher
getViewMode(): ViewMode {
this.route.queryParams.map((params) => {
if (isNotEmpty(params.view) && hasValue(params.view)) {
return params.view;
} else {
return this.defaultViewMode;
this.currentMode= params.view;
}
});
return this.defaultViewMode;
return this.currentMode;
}
setViewMode(viewMode: string) {
this.defaultViewMode = viewMode;
}
onPageChange(event) {
this.pageChange.emit(event);
}

View File

@@ -82,5 +82,24 @@ export class ObjectGridComponent implements OnChanges, OnInit {
constructor(private cdRef: ChangeDetectorRef) {
}
onPageChange(event) {
this.pageChange.emit(event);
}
onPageSizeChange(event) {
this.pageSizeChange.emit(event);
}
onSortDirectionChange(event) {
this.sortDirectionChange.emit(event);
}
onSortFieldChange(event) {
this.sortFieldChange.emit(event);
}
onPaginationChange(event) {
this.paginationChange.emit(event);
}
}

View File

@@ -20,8 +20,8 @@
<p *ngIf="dso.findMetadata('dc.description.abstract')" class="item-abstract card-text">
{{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}</p>
<a [routerLink]="['/items/' + dso.id]" class="lead btn btn-primary viewButton">View</a>
</div>
<a [routerLink]="['/items/' + dso.id]" class="lead btn btn-primary viewButton">View</a>
</div>

View File

@@ -103,4 +103,23 @@ export class ObjectListComponent {
this.paginationChange.emit(event);
}
onPageChange(event) {
this.pageChange.emit(event);
}
onPageSizeChange(event) {
this.pageSizeChange.emit(event);
}
onSortDirectionChange(event) {
this.sortDirectionChange.emit(event);
}
onSortFieldChange(event) {
this.sortFieldChange.emit(event);
}
onPaginationChange(event) {
this.paginationChange.emit(event);
}
}