diff --git a/src/app/core/cache/models/sort-options.model.ts b/src/app/core/cache/models/sort-options.model.ts index dff65c3d35..27d45139e5 100644 --- a/src/app/core/cache/models/sort-options.model.ts +++ b/src/app/core/cache/models/sort-options.model.ts @@ -4,6 +4,8 @@ export enum SortDirection { } export class SortOptions { - field: string = "id"; - direction: SortDirection = SortDirection.Ascending + + constructor (public field: string = "name", public direction : SortDirection = SortDirection.Ascending) { + + } } diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 4b52ef7d97..36dd88ca44 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -37,8 +37,9 @@ export abstract class DataService args.push(`scope=${options.scopeID}`); } - if (hasValue(options.currentPage)) { - args.push(`page=${options.currentPage}`); + if (hasValue(options.currentPage) && typeof options.currentPage === "number") { + /* TODO: this is a temporary fix for the pagination start index (0 or 1) discrepancy between the rest and the frontend respectively */ + args.push(`page=${options.currentPage - 1}`); } if (hasValue(options.elementsPerPage)) { diff --git a/src/app/home/top-level-community-list/top-level-community-list.component.ts b/src/app/home/top-level-community-list/top-level-community-list.component.ts index f884960f6b..d54e8f5797 100644 --- a/src/app/home/top-level-community-list/top-level-community-list.component.ts +++ b/src/app/home/top-level-community-list/top-level-community-list.component.ts @@ -1,9 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; import { RemoteData } from "../../core/data/remote-data"; import { ItemDataService } from "../../core/data/item-data.service"; import { Item } from "../../core/shared/item.model"; import { PaginationComponentOptions } from "../../shared/pagination/pagination-component-options.model"; -import { SortOptions } from "../../core/cache/models/sort-options.model"; +import { SortOptions, SortDirection } from "../../core/cache/models/sort-options.model"; @Component({ selector: 'ds-top-level-community-list', @@ -16,7 +16,8 @@ export class TopLevelCommunityListComponent implements OnInit { sortConfig : SortOptions; constructor( - private cds: ItemDataService + private cds: ItemDataService, + private ref: ChangeDetectorRef ) { this.universalInit(); } @@ -26,35 +27,37 @@ export class TopLevelCommunityListComponent implements OnInit { } ngOnInit(): void { - this.topLevelCommunities = this.cds.findAll(); this.config = new PaginationComponentOptions(); - this.config.id = "top-level-pagination" + this.config.id = "top-level-pagination"; this.config.pageSizeOptions = [ 5, 10, 20, 40, 60, 80, 100 ]; - + this.config.pageSize = 4; this.sortConfig = new SortOptions(); + + this.updateResults(); } - onPageChange(currentPage): void { + onPageChange(currentPage: number): void { this.config.currentPage = currentPage; this.updateResults(); } - onPageSizeChange(elementsPerPage): void { + onPageSizeChange(elementsPerPage: number): void { this.config.pageSize = elementsPerPage; this.updateResults(); } - onSortDirectionChange(sortDirection): void { - this.sortConfig.direction = sortDirection; + onSortDirectionChange(sortDirection: SortDirection): void { + this.sortConfig = new SortOptions(this.sortConfig.field, sortDirection); this.updateResults(); } - onSortFieldChange(field): void { - this.sortConfig.field = field; + onSortFieldChange(field: string): void { + this.sortConfig = new SortOptions(field, this.sortConfig.direction); this.updateResults(); } updateResults() { this.topLevelCommunities = this.cds.findAll({ currentPage: this.config.currentPage, elementsPerPage: this.config.pageSize, sort: this.sortConfig }); + this.ref.detectChanges(); } } diff --git a/src/app/object-list/object-list.component.html b/src/app/object-list/object-list.component.html index 8d81b4003e..79ce61f5fe 100644 --- a/src/app/object-list/object-list.component.html +++ b/src/app/object-list/object-list.component.html @@ -1,6 +1,8 @@ ; @Input() config : PaginationComponentOptions; @Input() sortConfig : SortOptions; + @Input() hideGear : boolean = false; + @Input() hidePagerWhenSinglePage : boolean = true; pageInfo : Observable; - @Output() pageChange = new EventEmitter(); - @Output() pageSizeChange = new EventEmitter(); - @Output() sortDirectionChange = new EventEmitter(); - @Output() sortFieldChange = new EventEmitter(); + /** + * An event fired when the page is changed. + * Event's payload equals to the newly selected page. + */ + @Output() pageChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the page wsize is changed. + * Event's payload equals to the newly selected page size. + */ + @Output() pageSizeChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort direction is changed. + * Event's payload equals to the newly selected sort direction. + */ + @Output() sortDirectionChange: EventEmitter = new EventEmitter(); + + /** + * An event fired when the sort field is changed. + * Event's payload equals to the newly selected sort field. + */ + @Output() sortFieldChange: EventEmitter = new EventEmitter(); data: any = {}; constructor() { diff --git a/src/app/shared/pagination/pagination.component.html b/src/app/shared/pagination/pagination.component.html index 021d42620b..0e5347a699 100644 --- a/src/app/shared/pagination/pagination.component.html +++ b/src/app/shared/pagination/pagination.component.html @@ -1,4 +1,4 @@ -
+
{{ 'pagination.showing.label' | translate }} @@ -20,7 +20,7 @@ -