Skip to content

Commit

Permalink
adapt alphabetical sorting into existing sort service
Browse files Browse the repository at this point in the history
  • Loading branch information
basak-akan committed Jul 20, 2023
1 parent a947dc3 commit bd113ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/main/webapp/app/lecture/lecture.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,7 @@ export class LectureComponent implements OnInit {
}

sortRows() {
//Sort alphabetically for title and description
if (this.predicate === 'title')
this.filteredLectures = this.filteredLectures.sort((a: Lecture, b: Lecture) => (this.ascending ? a.title!.localeCompare(b.title!) : b.title!.localeCompare(a.title!)));
else if (this.predicate === 'description')
this.filteredLectures.sort((a: Lecture, b: Lecture) =>
this.ascending ? (a.description || '').localeCompare(b.description || '') : (b.description || '').localeCompare(a.description || ''),
);
else this.sortService.sortByProperty(this.filteredLectures, this.predicate, this.ascending);
this.sortService.sortByProperty(this.filteredLectures, this.predicate, this.ascending);
}

private loadAll() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/webapp/app/shared/service/sort.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export class SortService {
}

private static compareBasic(valueA: any, valueB: any) {
if (valueA === valueB) {
if (typeof valueA === 'string' && typeof valueB === 'string') {
return valueA.localeCompare(valueB);
} else if (valueA === valueB) {
return 0;
} else {
return valueA < valueB ? -1 : 1;
Expand Down

0 comments on commit bd113ac

Please sign in to comment.