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 { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS } from './plugins/config/config.plugin';
import { ForDirective } from './directives/for.directive'; import { ForDirective } from './directives/for.directive';
import { AbstractNgModelComponent } from './abstracts/ng-model.component'; import { AbstractNgModelComponent } from './abstracts/ng-model.component';
import { SortDirective } from './directives/sort.directive'; import { TableSortDirective } from './directives/table-sort.directive';
@NgModule({ @NgModule({
imports: [ imports: [
@ -47,7 +47,7 @@ import { SortDirective } from './directives/sort.directive';
EllipsisDirective, EllipsisDirective,
ForDirective, ForDirective,
FormSubmitDirective, FormSubmitDirective,
SortDirective, TableSortDirective,
LocalizationPipe, LocalizationPipe,
SortPipe, SortPipe,
PermissionDirective, PermissionDirective,
@ -70,7 +70,7 @@ import { SortDirective } from './directives/sort.directive';
FormSubmitDirective, FormSubmitDirective,
LocalizationPipe, LocalizationPipe,
SortPipe, SortPipe,
SortDirective, TableSortDirective,
PermissionDirective, PermissionDirective,
VisibilityDirective, VisibilityDirective,
InputEventDebounceDirective, 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 './for.directive';
export * from './form-submit.directive'; export * from './form-submit.directive';
export * from './permission.directive'; export * from './permission.directive';
export * from './table-sort.directive';
export * from './visibility.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'; import clone from 'just-clone';
export type SortOrder = 'asc' | 'desc'; export type SortOrder = 'asc' | 'desc';
@Injectable()
@Pipe({ @Pipe({
name: 'abpSort', name: 'abpSort',
}) })

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

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

Loading…
Cancel
Save