diff --git a/apps/dsp-app/src/app/main/services/sorting.service.spec.ts b/apps/dsp-app/src/app/main/services/sorting.service.spec.ts index d43bcec767..f8510208f4 100644 --- a/apps/dsp-app/src/app/main/services/sorting.service.spec.ts +++ b/apps/dsp-app/src/app/main/services/sorting.service.spec.ts @@ -144,36 +144,6 @@ describe('SortingService', () => { }, ]); }); - - it('should return an array sorted by lastname reversed', () => { - const sorted = service.keySortByAlphabetical( - data, - 'lastname', - true - ); - expect(sorted).toEqual([ - { - firstname: 'Mickey', - lastname: 'Mouse', - creator: 'Walt Disney', - }, - { - firstname: 'Gaston', - lastname: 'Lagaffe', - creator: 'André Franquin', - }, - { - firstname: 'Gyro', - lastname: 'Gearloose', - creator: 'Carl Barks', - }, - { - firstname: 'Charlie', - lastname: 'Brown', - creator: 'Charles M. Schulz', - }, - ]); - }); }); describe('Sort an array of ReadProject', () => { @@ -208,15 +178,5 @@ describe('SortingService', () => { expect(sorted).toEqual([project1, project2, project3, project4]); }); - - it('should sort an array of ReadProject by "longname" reversed', () => { - const sorted = service.keySortByAlphabetical( - projects, - 'longname', - true - ); - - expect(sorted).toEqual([project4, project3, project2, project1]); - }); }); }); diff --git a/apps/dsp-app/src/app/main/services/sorting.service.ts b/apps/dsp-app/src/app/main/services/sorting.service.ts index 697f31fa58..ab3943f605 100644 --- a/apps/dsp-app/src/app/main/services/sorting.service.ts +++ b/apps/dsp-app/src/app/main/services/sorting.service.ts @@ -14,33 +14,46 @@ export class SortingService { } /** - * compares value by value and sorts in alphabetical order using the provided key - * optionally, you can have the array returned to you in reversed order by setting the reversed parameter to 'true' + * compares value by value and sorts in alphabetical order using the provided first key, in case the comparison + * of the values results in zero the second key is used if provided. */ keySortByAlphabetical( value: Array, - sortKey: keyof T, - reversed = false + firstSortKey: keyof T, + secondSortKey?: keyof T ): Array { const sortedArray = value.slice(); sortedArray.sort((a: T, b: T) => { if ( - String(a[sortKey]).toLowerCase() < - String(b[sortKey]).toLowerCase() + String(a[firstSortKey]).toLowerCase() < + String(b[firstSortKey]).toLowerCase() ) { return -1; } else if ( - String(a[sortKey]).toLowerCase() > - String(b[sortKey]).toLowerCase() + String(a[firstSortKey]).toLowerCase() > + String(b[firstSortKey]).toLowerCase() ) { return 1; } else { - return 0; + if (secondSortKey) { + if ( + String(a[secondSortKey]).toLowerCase() < + String(b[secondSortKey]).toLowerCase() + ) { + return -1; + } else if ( + String(a[secondSortKey]).toLowerCase() > + String(b[secondSortKey]).toLowerCase() + ) { + return 1; + } else { + return 0; + } + } else { + return 0 + } } }); - if (reversed) { - sortedArray.reverse(); - } return sortedArray; } } diff --git a/apps/dsp-app/src/app/workspace/resource/properties/properties.component.ts b/apps/dsp-app/src/app/workspace/resource/properties/properties.component.ts index e41365453c..d36c015862 100644 --- a/apps/dsp-app/src/app/workspace/resource/properties/properties.component.ts +++ b/apps/dsp-app/src/app/workspace/resource/properties/properties.component.ts @@ -63,6 +63,7 @@ import { ValueOperationEventService, } from '../services/value-operation-event.service'; import { ValueService } from '../services/value.service'; +import { SortingService } from '@dsp-app/src/app/main/services/sorting.service'; // object of property information from ontology class, properties and property values export interface PropertyInfoValues { @@ -177,7 +178,8 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { private _valueOperationEventService: ValueOperationEventService, private _valueService: ValueService, private _componentCommsService: ComponentCommunicationEventService, - private _projectService: ProjectService + private _projectService: ProjectService, + private _sortingService: SortingService, ) {} ngOnInit(): void { @@ -672,7 +674,11 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy { .subscribe( (response: ReadResourceSequence) => { if (response.resources.length > 0) { - this.incomingLinkResources = response.resources; + this.incomingLinkResources = this._sortingService.keySortByAlphabetical( + response.resources, + "resourceClassLabel", + "label" + ); } this.loading = false; },