diff --git a/src/app/process-page/overview/process-overview.component.html b/src/app/process-page/overview/process-overview.component.html index 11f28bd290..b1181c3606 100644 --- a/src/app/process-page/overview/process-overview.component.html +++ b/src/app/process-page/overview/process-overview.component.html @@ -15,10 +15,12 @@ [getInfoValueMethod]="processOverviewService.timeCreated"/> diff --git a/src/app/process-page/overview/process-overview.component.ts b/src/app/process-page/overview/process-overview.component.ts index d3f55dbb67..6d9cea1777 100644 --- a/src/app/process-page/overview/process-overview.component.ts +++ b/src/app/process-page/overview/process-overview.component.ts @@ -13,7 +13,7 @@ import { ProcessBulkDeleteService } from './process-bulk-delete.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../shared/empty.util'; import { DSONameService } from '../../core/breadcrumbs/dso-name.service'; -import { ProcessOverviewService } from './process-overview.service'; +import { ProcessOverviewService, ProcessSortField } from './process-overview.service'; import { ProcessStatus } from '../processes/process-status.model'; @Component({ @@ -25,7 +25,9 @@ import { ProcessStatus } from '../processes/process-status.model'; */ export class ProcessOverviewComponent implements OnInit, OnDestroy { + // Enums are redeclared here so they can be used in the template protected readonly ProcessStatus = ProcessStatus; + protected readonly ProcessSortField = ProcessSortField; /** * List of all processes diff --git a/src/app/process-page/overview/process-overview.service.ts b/src/app/process-page/overview/process-overview.service.ts index 762376c85a..1d71e0d1fc 100644 --- a/src/app/process-page/overview/process-overview.service.ts +++ b/src/app/process-page/overview/process-overview.service.ts @@ -9,6 +9,18 @@ import { RequestParam } from '../../core/cache/models/request-param.model'; import { ProcessStatus } from '../processes/process-status.model'; import { DatePipe } from '@angular/common'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; +import { SortOptions, SortDirection } from '../../core/cache/models/sort-options.model'; + +/** + * The sortable fields for processes + * See [the endpoint documentation]{@link https://github.com/DSpace/RestContract/blob/main/processes-endpoint.md#search-processes-by-property} + * for details. + */ +export enum ProcessSortField { + creationTime = 'creationTime', + startTime = 'startTime', + endTime = 'endTime', +} /** * Service to manage the processes displayed in the @@ -58,13 +70,16 @@ export class ProcessOverviewService { /** * Map the provided paginationOptions to FindListOptions * @param paginationOptions the PaginationComponentOptions to map + * @param sortField the field on which the processes are sorted */ - getFindListOptions(paginationOptions: PaginationComponentOptions): FindListOptions { + getFindListOptions(paginationOptions: PaginationComponentOptions, sortField: ProcessSortField): FindListOptions { + let sortOptions = new SortOptions(sortField, SortDirection.DESC); return Object.assign( new FindListOptions(), { currentPage: paginationOptions.currentPage, elementsPerPage: paginationOptions.pageSize, + sort: sortOptions, } ); } diff --git a/src/app/process-page/overview/table/process-overview-table.component.ts b/src/app/process-page/overview/table/process-overview-table.component.ts index cbf475386c..2386480413 100644 --- a/src/app/process-page/overview/table/process-overview-table.component.ts +++ b/src/app/process-page/overview/table/process-overview-table.component.ts @@ -5,7 +5,7 @@ import { RemoteData } from '../../../core/data/remote-data'; import { PaginatedList } from '../../../core/data/paginated-list.model'; import { Process } from '../../processes/process.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; -import { ProcessOverviewService } from '../process-overview.service'; +import { ProcessOverviewService, ProcessSortField } from '../process-overview.service'; import { ProcessBulkDeleteService } from '../process-bulk-delete.service'; import { EPersonDataService } from '../../../core/eperson/eperson-data.service'; import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; @@ -40,6 +40,13 @@ export class ProcessOverviewTableComponent implements OnInit { */ @Input() processStatus: ProcessStatus; + /** + * The field on which the processes in this table are sorted + * {@link ProcessSortField.creationTime} by default as every single process has a creation time, + * but not every process has a start or end time + */ + @Input() sortField: ProcessSortField = ProcessSortField.creationTime; + /** * Whether to use auto refresh for the processes shown in this table. */ @@ -118,7 +125,7 @@ export class ProcessOverviewTableComponent implements OnInit { .pipe( // Map the paginationOptions to findListOptions map((paginationOptions: PaginationComponentOptions) => - this.processOverviewService.getFindListOptions(paginationOptions)), + this.processOverviewService.getFindListOptions(paginationOptions, this.sortField)), // Use the findListOptions to retrieve the relevant processes every interval switchMap((findListOptions: FindListOptions) => this.processOverviewService.getProcessesByProcessStatus(