Browse Source

feat(tenant-management): replace abp-table in tenants.component with ngx-datatable

pull/4216/head
mehmet-erim 6 years ago
parent
commit
1fae3a9d58
  1. 153
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html
  2. 41
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

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

@ -18,99 +18,88 @@
</div> </div>
</div> </div>
</div> </div>
<div class="card-body"> <div class="card-body">
<div id="data-tables-table-filter" class="data-tables-filter"> <div id="data-tables-table-filter" class="data-tables-filter">
<label <div class="input-group">
><input <input
type="search" type="search"
class="form-control form-control-sm" class="form-control"
[placeholder]="'AbpUi::PagerSearch' | abpLocalization" [placeholder]="'AbpUi::PagerSearch' | abpLocalization"
(input.debounce)="onSearch($event.target.value)" [(ngModel)]="list.filter"
/></label> />
</div>
</div> </div>
<abp-table
*ngIf="[150, 0] as columnWidths" <ngx-datatable
[abpLoading]="loading" [rows]="data$ | async"
[abpLoadingDelay]="500" [loadingIndicator]="list.isLoading$ | async"
[abpTableSort]="{ key: sortKey, order: sortOrder }" [externalSorting]="true"
[colgroupTemplate]="tableColGroup" (sort)="sort($event)"
[headerTemplate]="tableHeader" [externalPaging]="true"
[bodyTemplate]="tableBody" [count]="totalCount$ | async"
[value]="data$ | async" [offset]="list.page - 1"
[abpTableSort]="{ key: sortKey, order: sortOrder }" [limit]="list.maxResultCount"
[rows]="pageQuery.maxResultCount" (page)="list.page = $event.offset + 1"
[totalRecords]="totalCount$ | async" [headerHeight]="50"
[scrollable]="true" [footerHeight]="50"
(pageChange)="onPageChange($event)" columnMode="force"
rowHeight="auto"
class="material"
> >
<ng-template #tableColGroup> <ngx-datatable-column
<colgroup> [name]="'AbpIdentity::Actions' | abpLocalization"
<col *ngFor="let width of columnWidths" [ngStyle]="{ 'width.px': width || undefined }" /> [maxWidth]="150"
</colgroup> [sortable]="false"
</ng-template> >
<ng-template #tableHeader let-columns> <ng-template let-row="row" ngx-datatable-cell-template>
<tr> <div ngbDropdown container="body" class="d-inline-block">
<th>{{ 'AbpTenantManagement::Actions' | abpLocalization }}</th> <button
<th (click)="sortOrderIcon.sort('name')"> class="btn btn-primary btn-sm dropdown-toggle"
{{ 'AbpTenantManagement::TenantName' | abpLocalization }} data-toggle="dropdown"
<abp-sort-order-icon aria-haspopup="true"
#sortOrderIcon ngbDropdownToggle
sortKey="name"
[(selectedSortKey)]="sortKey"
[(order)]="sortOrder"
> >
</abp-sort-order-icon> <i class="fa fa-cog mr-1"></i>{{ 'AbpTenantManagement::Actions' | abpLocalization }}
</th> </button>
</tr> <div ngbDropdownMenu>
</ng-template> <button
<ng-template #tableBody let-data> *abpPermission="'AbpTenantManagement.Tenants.Update'"
<tr> ngbDropdownItem
<td class="text-center"> (click)="editTenant(row.id)"
<div ngbDropdown container="body" class="d-inline-block"> >
{{ 'AbpTenantManagement::Edit' | abpLocalization }}
</button>
<button
*abpPermission="'AbpTenantManagement.Tenants.ManageConnectionStrings'"
ngbDropdownItem
(click)="onEditConnectionString(row.id)"
>
{{ 'AbpTenantManagement::Permission:ManageConnectionStrings' | abpLocalization }}
</button>
<button
*abpPermission="'AbpTenantManagement.Tenants.ManageFeatures'"
ngbDropdownItem
(click)="openFeaturesModal(row.id)"
>
{{ 'AbpTenantManagement::Permission:ManageFeatures' | abpLocalization }}
</button>
<button <button
class="btn btn-primary btn-sm dropdown-toggle" *abpPermission="'AbpTenantManagement.Tenants.Delete'"
data-toggle="dropdown" ngbDropdownItem
aria-haspopup="true" (click)="delete(row.id, row.name)"
ngbDropdownToggle
> >
<i class="fa fa-cog mr-1"></i>{{ 'AbpTenantManagement::Actions' | abpLocalization }} {{ 'AbpTenantManagement::Delete' | abpLocalization }}
</button> </button>
<div ngbDropdownMenu>
<button
*abpPermission="'AbpTenantManagement.Tenants.Update'"
ngbDropdownItem
(click)="editTenant(data.id)"
>
{{ 'AbpTenantManagement::Edit' | abpLocalization }}
</button>
<button
*abpPermission="'AbpTenantManagement.Tenants.ManageConnectionStrings'"
ngbDropdownItem
(click)="onEditConnectionString(data.id)"
>
{{ 'AbpTenantManagement::Permission:ManageConnectionStrings' | abpLocalization }}
</button>
<button
*abpPermission="'AbpTenantManagement.Tenants.ManageFeatures'"
ngbDropdownItem
(click)="openFeaturesModal(data.id)"
>
{{ 'AbpTenantManagement::Permission:ManageFeatures' | abpLocalization }}
</button>
<button
*abpPermission="'AbpTenantManagement.Tenants.Delete'"
ngbDropdownItem
(click)="delete(data.id, data.name)"
>
{{ 'AbpTenantManagement::Delete' | abpLocalization }}
</button>
</div>
</div> </div>
</td> </div>
<td>{{ data.name }}</td> </ng-template>
</tr> </ngx-datatable-column>
</ng-template> <ngx-datatable-column
</abp-table> [name]="'AbpTenantManagement::TenantName' | abpLocalization"
prop="name"
></ngx-datatable-column>
</ngx-datatable>
</div> </div>
</div> </div>

41
npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

@ -1,6 +1,7 @@
import { ABP } from '@abp/ng.core'; import { ABP, ListService } from '@abp/ng.core';
import { ConfirmationService, Confirmation, getPasswordValidators } from '@abp/ng.theme.shared'; import { eFeatureManagementComponents } from '@abp/ng.feature-management';
import { Component, OnInit, TemplateRef, ViewChild, ChangeDetectorRef } from '@angular/core'; import { Confirmation, ConfirmationService, getPasswordValidators } from '@abp/ng.theme.shared';
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Select, Store } from '@ngxs/store'; import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
@ -14,7 +15,6 @@ import {
} from '../../actions/tenant-management.actions'; } from '../../actions/tenant-management.actions';
import { TenantManagementService } from '../../services/tenant-management.service'; import { TenantManagementService } from '../../services/tenant-management.service';
import { TenantManagementState } from '../../states/tenant-management.state'; import { TenantManagementState } from '../../states/tenant-management.state';
import { eFeatureManagementComponents } from '@abp/ng.feature-management';
interface SelectedModalContent { interface SelectedModalContent {
type: 'saveConnStr' | 'saveTenant'; type: 'saveConnStr' | 'saveTenant';
@ -25,6 +25,7 @@ interface SelectedModalContent {
@Component({ @Component({
selector: 'abp-tenants', selector: 'abp-tenants',
templateUrl: './tenants.component.html', templateUrl: './tenants.component.html',
providers: [ListService],
}) })
export class TenantsComponent implements OnInit { export class TenantsComponent implements OnInit {
@Select(TenantManagementState.get) @Select(TenantManagementState.get)
@ -51,16 +52,8 @@ export class TenantsComponent implements OnInit {
_useSharedDatabase: boolean; _useSharedDatabase: boolean;
pageQuery: ABP.PageQueryParams = { maxResultCount: 10 };
loading = false;
modalBusy = false; modalBusy = false;
sortOrder = '';
sortKey = '';
featureManagementKey = eFeatureManagementComponents.FeatureManagement; featureManagementKey = eFeatureManagementComponents.FeatureManagement;
get hasSelectedTenant(): boolean { get hasSelectedTenant(): boolean {
@ -106,6 +99,7 @@ export class TenantsComponent implements OnInit {
}; };
constructor( constructor(
public readonly list: ListService,
private confirmationService: ConfirmationService, private confirmationService: ConfirmationService,
private tenantService: TenantManagementService, private tenantService: TenantManagementService,
private fb: FormBuilder, private fb: FormBuilder,
@ -116,11 +110,6 @@ export class TenantsComponent implements OnInit {
this.get(); this.get();
} }
onSearch(value: string) {
this.pageQuery.filter = value;
this.get();
}
private createTenantForm() { private createTenantForm() {
const tenantForm = this.fb.group({ const tenantForm = this.fb.group({
name: [this.selected.name || '', [Validators.required, Validators.maxLength(256)]], name: [this.selected.name || '', [Validators.required, Validators.maxLength(256)]],
@ -262,18 +251,8 @@ export class TenantsComponent implements OnInit {
}); });
} }
onPageChange(page: number) {
this.pageQuery.skipCount = (page - 1) * this.pageQuery.maxResultCount;
this.get();
}
get() { get() {
this.loading = true; this.list.hookToQuery(query => this.store.dispatch(new GetTenants(query))).subscribe();
this.store
.dispatch(new GetTenants(this.pageQuery))
.pipe(finalize(() => (this.loading = false)))
.subscribe();
} }
onSharedDatabaseChange(value: boolean) { onSharedDatabaseChange(value: boolean) {
@ -295,4 +274,10 @@ export class TenantsComponent implements OnInit {
this.visibleFeatures = true; this.visibleFeatures = true;
}, 0); }, 0);
} }
sort(data) {
const { prop, dir } = data.sorts[0];
this.list.sortKey = prop;
this.list.sortOrder = dir;
}
} }

Loading…
Cancel
Save