#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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -82,5 +82,24 @@ export class ObjectGridComponent implements OnChanges, OnInit {
constructor(private cdRef: ChangeDetectorRef) { 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"> <p *ngIf="dso.findMetadata('dc.description.abstract')" class="item-abstract card-text">
{{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}</p> {{dso.findMetadata("dc.description.abstract") | dsTruncate:[200] }}</p>
</div>
<a [routerLink]="['/items/' + dso.id]" class="lead btn btn-primary viewButton">View</a> <a [routerLink]="['/items/' + dso.id]" class="lead btn btn-primary viewButton">View</a>
</div>
</div> </div>

View File

@@ -103,4 +103,23 @@ export class ObjectListComponent {
this.paginationChange.emit(event); 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);
}
} }