diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 2270e7a..308884d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,6 +1,6 @@ --- name: Bug report -about: Create a report to help us improve +about: Use this template to report actual bugs. If you are looking for general help, please post a discussion. title: '' labels: '' assignees: '' diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index c93ed8f..9224985 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -23,6 +23,7 @@ import { SetupComponent } from './setup/setup.component'; import { TorrentStatusPipe } from './torrent-status.pipe'; import { TorrentTableComponent } from './torrent-table/torrent-table.component'; import { TorrentComponent } from './torrent/torrent.component'; +import { SortPipe } from './sort.pipe'; curray(); @@ -42,6 +43,7 @@ curray(); DecodeURIPipe, ProfileComponent, Nl2BrPipe, + SortPipe, ], imports: [ BrowserModule, diff --git a/client/src/app/sort.pipe.ts b/client/src/app/sort.pipe.ts new file mode 100644 index 0000000..10e88ed --- /dev/null +++ b/client/src/app/sort.pipe.ts @@ -0,0 +1,22 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'sort', +}) +export class SortPipe implements PipeTransform { + transform(array: any[], field: string, order: 'asc' | 'desc' = 'asc'): any[] { + if (!Array.isArray(array)) { + return []; + } + const sortedArray = array.sort((a, b) => { + if (a[field] < b[field]) { + return -1; + } else if (a[field] > b[field]) { + return 1; + } else { + return 0; + } + }); + return order === 'asc' ? sortedArray : sortedArray.reverse(); + } +} diff --git a/client/src/app/torrent-table/torrent-table.component.html b/client/src/app/torrent-table/torrent-table.component.html index a1e0b10..42ed4d1 100644 --- a/client/src/app/torrent-table/torrent-table.component.html +++ b/client/src/app/torrent-table/torrent-table.component.html @@ -13,18 +13,18 @@ [checked]="selectedTorrents.length > 0 && selectedTorrents.length === torrents.length" /> -