Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pipe to sort #414

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/chains/chains.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ChainsComponent implements AfterViewInit, OnDestroy, OnInit {
dtOptions: DataTables.Settings = {};

chains: Chain[];
columns = []
columns = [];

constructor(private environmentsService: EnvironmentsService,
private chainsService: ChainsService,
Expand Down
2 changes: 1 addition & 1 deletion src/app/files/files.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<a *ngIf="subDir.length > 0" (click)="exploreParentDirectory()" href="javascript:void(0)" class="btn btn-secondary btn-sm">{{'FILE.EXPLORE_UP' | translate}}</a>
</td>
</tr>
<tr *ngFor="let remotefile of remoteFiles">
<tr *ngFor="let remotefile of remoteFiles | sortBy:'asc':'name'">
<td class="align-middle">
{{remotefile.name}}
</td>
Expand Down
7 changes: 5 additions & 2 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {YesNoPipe} from './yesno.pipe';
import {ToastComponent} from './toast/toast.component';
import {HasAnyRoleDirective} from './has-any-role/has-any-role.directive';
import {ShowHideColumnComponent} from './show-hide-column/show-hide-column.component';
import {SortByPipe} from './sort.pipe';

@NgModule({
imports: [
Expand Down Expand Up @@ -63,7 +64,8 @@ import {ShowHideColumnComponent} from './show-hide-column/show-hide-column.compo
AvatarPipe,
YesNoPipe,
ToastComponent,
ShowHideColumnComponent
ShowHideColumnComponent,
SortByPipe
],
exports: [
CommonModule,
Expand All @@ -86,7 +88,8 @@ import {ShowHideColumnComponent} from './show-hide-column/show-hide-column.compo
AvatarPipe,
YesNoPipe,
ToastComponent,
ShowHideColumnComponent
ShowHideColumnComponent,
SortByPipe
],
providers: [
DatePipe,
Expand Down
23 changes: 23 additions & 0 deletions src/app/shared/sort.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Pipe, PipeTransform} from '@angular/core';
import {orderBy} from 'lodash';

@Pipe({name: 'sortBy'})
export class SortByPipe implements PipeTransform {

transform(value: any[], order = '', column: string = ''): any[] {
if (!value || order === '' || !order) {
return value;
} // no array
if (value.length <= 1) {
return value;
} // array with only one item
if (!column || column === '') {
if (order === 'asc') {
return value.sort();
} else {
return value.sort().reverse();
}
} // sort 1d array
return orderBy(value, [column], [order]);
}
}