mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 05:06:16 -08:00
feat: add sorting button for VOD and series
This commit is contained in:
1 parent
35d83149eb
commit
81cbc1e5d6
10 files changed
+111
-15
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { Injectable, Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'sortBy',
|
||||
standalone: true,
|
||||
})
|
||||
@Injectable()
|
||||
export class SortPipe implements PipeTransform {
|
||||
transform(array: any[], sortType: string): any {
|
||||
if (!array || !sortType) {
|
||||
return array;
|
||||
}
|
||||
return array.sort((a, b) => {
|
||||
if (sortType === 'date') {
|
||||
return parseInt(b.added) - parseInt(a.added);
|
||||
} else if (sortType === 'rating') {
|
||||
const ratingA = isNaN(parseFloat(a.rating)) ? 0 : parseFloat(a.rating);
|
||||
const ratingB = isNaN(parseFloat(b.rating)) ? 0 : parseFloat(b.rating);
|
||||
return ratingB - ratingA;
|
||||
} else if (sortType === 'alpha') {
|
||||
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user