update pipes
This commit is contained in:
parent
e1ebbb9ab2
commit
87b19da9a9
@ -19,5 +19,5 @@ export * from './lib/scrollbar';
|
||||
export * from './lib/caching';
|
||||
export * from './lib/users';
|
||||
export * from './lib/translations';
|
||||
export * from './lib/standalone';
|
||||
export * from './lib/pipes';
|
||||
export * from './lib/permissions';
|
||||
|
||||
@ -3,7 +3,6 @@ import { CommonModule } from '@angular/common';
|
||||
import { MatIconModule, MatIconRegistry } from '@angular/material/icon';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatLegacyProgressSpinnerModule as MatProgressSpinnerModule } from '@angular/material/legacy-progress-spinner';
|
||||
import { SortByPipe } from './sorting';
|
||||
import { CommonUiOptions, IqserAppConfig, ModuleOptions } from './utils';
|
||||
import { HiddenActionComponent, ToastComponent } from './shared';
|
||||
import { ConnectionStatusComponent, FullPageErrorComponent } from './error';
|
||||
@ -37,10 +36,8 @@ const matModules = [
|
||||
const modules = [IqserListingModule, IqserFiltersModule, IqserInputsModule, IqserScrollbarModule, IqserSkeletonModule, HttpClientModule];
|
||||
const components = [ConnectionStatusComponent, FullPageErrorComponent, HiddenActionComponent, ConfirmationDialogComponent, ToastComponent];
|
||||
|
||||
const pipes = [SortByPipe];
|
||||
|
||||
@NgModule({
|
||||
declarations: [...components, ...pipes],
|
||||
declarations: [...components],
|
||||
imports: [
|
||||
CommonModule,
|
||||
...matModules,
|
||||
@ -51,7 +48,7 @@ const pipes = [SortByPipe];
|
||||
IconButtonComponent,
|
||||
CircleButtonComponent,
|
||||
],
|
||||
exports: [...components, ...pipes, ...modules],
|
||||
exports: [...components, ...modules],
|
||||
providers: [
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { capitalize } from '../../utils';
|
||||
import { capitalize } from '../utils';
|
||||
|
||||
@Pipe({
|
||||
name: 'capitalize',
|
||||
@ -1,5 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { humanizeCamelCase } from '../../utils';
|
||||
import { humanizeCamelCase } from '../utils';
|
||||
|
||||
@Pipe({
|
||||
name: 'humanizeCamelCase',
|
||||
@ -1,5 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { humanize } from '../../utils';
|
||||
import { humanize } from '../utils';
|
||||
|
||||
@Pipe({
|
||||
name: 'humanize',
|
||||
4
src/lib/pipes/index.ts
Normal file
4
src/lib/pipes/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './log.pipe';
|
||||
export * from './humanize-camel-case.pipe';
|
||||
export * from './capitalize.pipe';
|
||||
export * from './humanize.pipe';
|
||||
21
src/lib/sorting/functions.ts
Normal file
21
src/lib/sorting/functions.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { SortingOrder, SortingOrders } from './models/sorting-order.type';
|
||||
import { KeysOf } from '../utils';
|
||||
import { orderBy } from 'lodash-es';
|
||||
|
||||
export function sort<T>(values: T[], order?: SortingOrder, column?: KeysOf<T>): T[] {
|
||||
if (!values || values.length <= 1 || !order) {
|
||||
return values;
|
||||
}
|
||||
|
||||
if (!column) {
|
||||
/** sort 1D array */
|
||||
const result = [...values].sort();
|
||||
return order === SortingOrders.asc ? result : result.reverse();
|
||||
}
|
||||
|
||||
return orderBy<T>(
|
||||
values,
|
||||
[(entity: T) => (typeof entity[column] === 'string' ? (entity[column] as unknown as string).toLowerCase() : entity[column])],
|
||||
[order],
|
||||
);
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
export * from './functions';
|
||||
export * from './sort-by.pipe';
|
||||
export * from './sorting.service';
|
||||
export * from './models/sorting-option.model';
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { SortingService } from './sorting.service';
|
||||
import { SortingOrder } from './models/sorting-order.type';
|
||||
import { KeysOf } from '../utils';
|
||||
import { sort } from './functions';
|
||||
|
||||
@Pipe({ name: 'sortBy' })
|
||||
@Pipe({ name: 'sortBy', standalone: true })
|
||||
export class SortByPipe implements PipeTransform {
|
||||
transform<T>(values: T[], order: SortingOrder, column: KeysOf<T>): T[] {
|
||||
return SortingService.sort(values, order, column);
|
||||
return sort(values, order, column);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { SortingOption } from './models/sorting-option.model';
|
||||
import { SortingOrder, SortingOrders } from './models/sorting-order.type';
|
||||
import { SortingOrders } from './models/sorting-order.type';
|
||||
import { KeysOf, shareDistinctLast } from '../utils';
|
||||
import { Id, IListable } from '../listing';
|
||||
import { orderBy } from 'lodash-es';
|
||||
import { sort } from './functions';
|
||||
|
||||
@Injectable()
|
||||
export class SortingService<T extends IListable<PrimaryKey>, PrimaryKey extends Id = T['id']> {
|
||||
@ -18,30 +18,12 @@ export class SortingService<T extends IListable<PrimaryKey>, PrimaryKey extends
|
||||
return this._sortingOption$.getValue();
|
||||
}
|
||||
|
||||
static sort<T>(values: T[], order?: SortingOrder, column?: KeysOf<T>): T[] {
|
||||
if (!values || values.length <= 1 || !order) {
|
||||
return values;
|
||||
}
|
||||
|
||||
if (!column) {
|
||||
/** sort 1D array */
|
||||
const result = [...values].sort();
|
||||
return order === SortingOrders.asc ? result : result.reverse();
|
||||
}
|
||||
|
||||
return orderBy<T>(
|
||||
values,
|
||||
[(entity: T) => (typeof entity[column] === 'string' ? (entity[column] as unknown as string).toLowerCase() : entity[column])],
|
||||
[order],
|
||||
);
|
||||
}
|
||||
|
||||
setSortingOption(value: SortingOption<T>): void {
|
||||
this._sortingOption$.next(value);
|
||||
}
|
||||
|
||||
defaultSort(values: T[]): T[] {
|
||||
return SortingService.sort(values, this.sortingOption?.order, this.sortingOption?.column);
|
||||
return sort(values, this.sortingOption?.order, this.sortingOption?.column);
|
||||
}
|
||||
|
||||
toggleSort(column: KeysOf<T>): void {
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
export * from './pipes/log.pipe';
|
||||
export * from './pipes/humanize-camel-case.pipe';
|
||||
export * from './pipes/capitalize.pipe';
|
||||
export * from './pipes/humanize.pipe';
|
||||
Loading…
x
Reference in New Issue
Block a user