Browse Source

Merge pull request #1875 from abpframework/refactor/sort

Refactor/sort
pull/1879/head
Mehmet Erim 7 years ago
committed by GitHub
parent
commit
be0da79788
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 1
      npm/ng-packs/packages/core/src/lib/directives/index.ts
  3. 12
      npm/ng-packs/packages/core/src/lib/directives/sort.directive.ts
  4. 29
      npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts
  5. 3
      npm/ng-packs/packages/core/src/lib/pipes/sort.pipe.ts
  6. 10
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html
  7. 26
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.html
  8. 18
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html

6
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -27,7 +27,7 @@ import { getInitialData, localeInitializer } from './utils/initial-utils';
import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS } from './plugins/config/config.plugin';
import { ForDirective } from './directives/for.directive';
import { AbstractNgModelComponent } from './abstracts/ng-model.component';
import { SortDirective } from './directives/sort.directive';
import { TableSortDirective } from './directives/table-sort.directive';
@NgModule({
imports: [
@ -47,7 +47,7 @@ import { SortDirective } from './directives/sort.directive';
EllipsisDirective,
ForDirective,
FormSubmitDirective,
SortDirective,
TableSortDirective,
LocalizationPipe,
SortPipe,
PermissionDirective,
@ -70,7 +70,7 @@ import { SortDirective } from './directives/sort.directive';
FormSubmitDirective,
LocalizationPipe,
SortPipe,
SortDirective,
TableSortDirective,
PermissionDirective,
VisibilityDirective,
InputEventDebounceDirective,

1
npm/ng-packs/packages/core/src/lib/directives/index.ts

@ -3,4 +3,5 @@ export * from './ellipsis.directive';
export * from './for.directive';
export * from './form-submit.directive';
export * from './permission.directive';
export * from './table-sort.directive';
export * from './visibility.directive';

12
npm/ng-packs/packages/core/src/lib/directives/sort.directive.ts

@ -1,12 +0,0 @@
import { Directive, ElementRef, Input, Optional, Self } from '@angular/core';
import { Table } from 'primeng/table';
@Directive({
selector: '[abpSort]',
})
export class SortDirective {
constructor(private elementRef: ElementRef, @Optional() @Self() table: Table) {
console.warn(elementRef);
setInterval(() => console.warn(table.value), 1000);
}
}

29
npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts

@ -0,0 +1,29 @@
import { Directive, Input, Optional, Self, SimpleChanges, OnChanges } from '@angular/core';
import { Table } from 'primeng/table';
import { SortPipe, SortOrder } from '../pipes/sort.pipe';
export interface TableSortOptions {
key: string;
order: SortOrder;
}
@Directive({
selector: '[abpTableSort]',
providers: [SortPipe],
})
export class TableSortDirective implements OnChanges {
@Input()
abpTableSort: TableSortOptions;
@Input()
value: any[] = [];
constructor(@Optional() @Self() private table: Table, private sortPipe: SortPipe) {}
ngOnChanges({ value, abpTableSort }: SimpleChanges) {
if (value || abpTableSort) {
this.abpTableSort = this.abpTableSort || ({} as TableSortOptions);
this.table.value = this.sortPipe.transform(this.value, this.abpTableSort.order, this.abpTableSort.key);
}
}
}

3
npm/ng-packs/packages/core/src/lib/pipes/sort.pipe.ts

@ -1,8 +1,9 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Pipe, PipeTransform, Injectable } from '@angular/core';
import clone from 'just-clone';
export type SortOrder = 'asc' | 'desc';
@Injectable()
@Pipe({
name: 'abpSort',
})

10
npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html

@ -24,7 +24,8 @@
</div>
<p-table
*ngIf="[130, 200] as columnWidths"
[value]="data$ | async | abpSort: sortOrder:sortKey"
[value]="data$ | async"
[abpTableSort]="{ key: sortKey, order: sortOrder }"
[lazy]="true"
[lazyLoadOnInit]="false"
[paginator]="true"
@ -129,8 +130,5 @@
</ng-template>
</abp-modal>
<abp-permission-management
[(visible)]="visiblePermissions"
providerName="Role"
[providerKey]="providerKey"
></abp-permission-management>
<abp-permission-management [(visible)]="visiblePermissions" providerName="Role" [providerKey]="providerKey">
</abp-permission-management>

26
npm/ng-packs/packages/identity/src/lib/components/users/users.component.html

@ -29,9 +29,9 @@
/></label>
</div>
<p-table
abpSort
*ngIf="[130, 200, 200, 200] as columnWidths"
[value]="data$ | async | abpSort: sortOrder:sortKey"
[value]="data$ | async"
[abpTableSort]="{ key: sortKey, order: sortOrder }"
[lazy]="true"
[lazyLoadOnInit]="false"
[paginator]="true"
@ -60,12 +60,8 @@
<th>{{ 'AbpIdentity::Actions' | abpLocalization }}</th>
<th pResizableColumn (click)="sortOrderIcon.sort('userName')">
{{ 'AbpIdentity::UserName' | abpLocalization }}
<abp-sort-order-icon
#sortOrderIcon
key="userName"
[(selectedKey)]="sortKey"
[(order)]="sortOrder"
></abp-sort-order-icon>
<abp-sort-order-icon #sortOrderIcon key="userName" [(selectedKey)]="sortKey" [(order)]="sortOrder">
</abp-sort-order-icon>
</th>
<th pResizableColumn (click)="sortOrderIcon.sort('email')">
{{ 'AbpIdentity::EmailAddress' | abpLocalization }}
@ -73,11 +69,8 @@
</th>
<th pResizableColumn (click)="sortOrderIcon.sort('phoneNumber')">
{{ 'AbpIdentity::PhoneNumber' | abpLocalization }}
<abp-sort-order-icon
key="phoneNumber"
[(selectedKey)]="sortKey"
[(order)]="sortOrder"
></abp-sort-order-icon>
<abp-sort-order-icon key="phoneNumber" [(selectedKey)]="sortKey" [(order)]="sortOrder">
</abp-sort-order-icon>
</th>
</tr>
</ng-template>
@ -223,8 +216,5 @@
</ng-template>
</abp-modal>
<abp-permission-management
[(visible)]="visiblePermissions"
providerName="User"
[providerKey]="providerKey"
></abp-permission-management>
<abp-permission-management [(visible)]="visiblePermissions" providerName="User" [providerKey]="providerKey">
</abp-permission-management>

18
npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html

@ -31,7 +31,8 @@
</div>
<p-table
*ngIf="[130, 200] as columnWidths"
[value]="data$ | async | abpSort: sortOrder:sortKey"
[value]="data$ | async"
[abpTableSort]="{ key: sortKey, order: sortOrder }"
[lazy]="true"
[lazyLoadOnInit]="false"
[paginator]="true"
@ -60,12 +61,8 @@
<th>{{ 'AbpTenantManagement::Actions' | abpLocalization }}</th>
<th pResizableColumn (click)="sortOrderIcon.sort('name')">
{{ 'AbpTenantManagement::TenantName' | abpLocalization }}
<abp-sort-order-icon
#sortOrderIcon
key="name"
[(selectedKey)]="sortKey"
[(order)]="sortOrder"
></abp-sort-order-icon>
<abp-sort-order-icon #sortOrderIcon key="name" [(selectedKey)]="sortKey" [(order)]="sortOrder">
</abp-sort-order-icon>
</th>
</tr>
</ng-template>
@ -180,8 +177,5 @@
</form>
</ng-template>
<abp-feature-management
[(visible)]="visibleFeatures"
providerName="Tenant"
[providerKey]="providerKey"
></abp-feature-management>
<abp-feature-management [(visible)]="visibleFeatures" providerName="Tenant" [providerKey]="providerKey">
</abp-feature-management>

Loading…
Cancel
Save