Add sorting on the interface.
This commit is contained in:
parent
acb57dc1ea
commit
ba94039b24
5 changed files with 41 additions and 10 deletions
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
name: Bug report
|
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: ''
|
title: ''
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import { SetupComponent } from './setup/setup.component';
|
||||||
import { TorrentStatusPipe } from './torrent-status.pipe';
|
import { TorrentStatusPipe } from './torrent-status.pipe';
|
||||||
import { TorrentTableComponent } from './torrent-table/torrent-table.component';
|
import { TorrentTableComponent } from './torrent-table/torrent-table.component';
|
||||||
import { TorrentComponent } from './torrent/torrent.component';
|
import { TorrentComponent } from './torrent/torrent.component';
|
||||||
|
import { SortPipe } from './sort.pipe';
|
||||||
|
|
||||||
curray();
|
curray();
|
||||||
|
|
||||||
|
|
@ -42,6 +43,7 @@ curray();
|
||||||
DecodeURIPipe,
|
DecodeURIPipe,
|
||||||
ProfileComponent,
|
ProfileComponent,
|
||||||
Nl2BrPipe,
|
Nl2BrPipe,
|
||||||
|
SortPipe,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
|
|
||||||
22
client/src/app/sort.pipe.ts
Normal file
22
client/src/app/sort.pipe.ts
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,18 +13,18 @@
|
||||||
[checked]="selectedTorrents.length > 0 && selectedTorrents.length === torrents.length"
|
[checked]="selectedTorrents.length > 0 && selectedTorrents.length === torrents.length"
|
||||||
/>
|
/>
|
||||||
</th>
|
</th>
|
||||||
<th>Name</th>
|
<th (click)="sort('rdName')">Name</th>
|
||||||
<th>Category</th>
|
<th (click)="sort('category')">Category</th>
|
||||||
<th>Priority</th>
|
<th (click)="sort('priority')">Priority</th>
|
||||||
<th>Seeders</th>
|
<th (click)="sort('rdSeeders')">Seeders</th>
|
||||||
<th>Files</th>
|
<th (click)="sort('files.length')">Files</th>
|
||||||
<th>Downloads</th>
|
<th (click)="sort('downloads.length')">Downloads</th>
|
||||||
<th>Size</th>
|
<th (click)="sort('rdSize')">Size</th>
|
||||||
<th>Status</th>
|
<th (click)="sort('status')">Status</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let torrent of torrents; trackBy: trackByMethod">
|
<tr *ngFor="let torrent of torrents | sort: sortProperty : sortDirection; trackBy: trackByMethod">
|
||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ export class TorrentTableComponent implements OnInit {
|
||||||
public torrents: Torrent[] = [];
|
public torrents: Torrent[] = [];
|
||||||
public selectedTorrents: string[] = [];
|
public selectedTorrents: string[] = [];
|
||||||
public error: string;
|
public error: string;
|
||||||
|
public sortProperty = 'rdName';
|
||||||
|
public sortDirection: 'asc' | 'desc' = 'asc';
|
||||||
|
|
||||||
public isDeleteModalActive: boolean;
|
public isDeleteModalActive: boolean;
|
||||||
public deleteError: string;
|
public deleteError: string;
|
||||||
|
|
@ -58,6 +60,11 @@ export class TorrentTableComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sort(property: string): void {
|
||||||
|
this.sortProperty = property;
|
||||||
|
this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
|
||||||
|
}
|
||||||
|
|
||||||
public openTorrent(torrentId: string): void {
|
public openTorrent(torrentId: string): void {
|
||||||
this.router.navigate([`/torrent/${torrentId}`]);
|
this.router.navigate([`/torrent/${torrentId}`]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue