Browse Source

feat(identity): implement ngx-datatable and list service to roles.component

pull/4216/head
mehmet-erim 6 years ago
parent
commit
f96b8028df
  1. 138
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html
  2. 32
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts

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

@ -19,90 +19,70 @@
</div> </div>
</div> </div>
<div class="card-body"> <div class="">
<abp-table <ngx-datatable
*ngIf="[150, 0] as columnWidths" [rows]="data$ | async"
[abpLoading]="loading" [loadingIndicator]="list.isLoading$ | async"
[abpLoadingDelay]="500" [externalSorting]="true"
[abpTableSort]="{ key: sortKey, order: sortOrder }" (sort)="onSort($event)"
[colgroupTemplate]="tableColGroup" [externalPaging]="true"
[headerTemplate]="tableHeader" [count]="totalCount$ | async"
[bodyTemplate]="tableBody" [offset]="list.page - 1"
[value]="data$ | async" [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> <ng-template let-value="value" ngx-datatable-cell-template>
<tr> <div ngbDropdown container="body" class="d-inline-block">
<th>{{ 'AbpIdentity::Actions' | abpLocalization }}</th> <button
<th (click)="sortOrderIcon.sort('name')"> class="btn btn-primary btn-sm dropdown-toggle"
{{ 'AbpIdentity::RoleName' | abpLocalization }} data-toggle="dropdown"
<abp-sort-order-icon aria-haspopup="true"
#sortOrderIcon ngbDropdownToggle
sortKey="name" >
[(selectedSortKey)]="sortKey" <i class="fa fa-cog mr-1"></i>{{ 'AbpIdentity::Actions' | abpLocalization }}
[(order)]="sortOrder" </button>
></abp-sort-order-icon> <div ngbDropdownMenu>
</th>
</tr>
</ng-template>
<ng-template #tableBody let-data>
<tr>
<td class="text-center">
<div ngbDropdown container="body" class="d-inline-block">
<button <button
class="btn btn-primary btn-sm dropdown-toggle" *abpPermission="'AbpIdentity.Roles.Update'"
data-toggle="dropdown" ngbDropdownItem
aria-haspopup="true" (click)="edit(value.id)"
ngbDropdownToggle
> >
<i class="fa fa-cog mr-1"></i>{{ 'AbpIdentity::Actions' | abpLocalization }} {{ 'AbpIdentity::Edit' | abpLocalization }}
</button>
<button
*abpPermission="'AbpIdentity.Roles.ManagePermissions'"
ngbDropdownItem
(click)="openPermissionsModal(value.name)"
>
{{ 'AbpIdentity::Permissions' | abpLocalization }}
</button>
<button
*ngIf="!value.isStatic"
[abpPermission]="'AbpIdentity.Roles.Delete'"
ngbDropdownItem
(click)="delete(value.id, value.name)"
>
{{ 'AbpIdentity::Delete' | abpLocalization }}
</button> </button>
<div ngbDropdownMenu>
<button
*abpPermission="'AbpIdentity.Roles.Update'"
ngbDropdownItem
(click)="edit(data.id)"
>
{{ 'AbpIdentity::Edit' | abpLocalization }}
</button>
<button
*abpPermission="'AbpIdentity.Roles.ManagePermissions'"
ngbDropdownItem
(click)="openPermissionsModal(data.name)"
>
{{ 'AbpIdentity::Permissions' | abpLocalization }}
</button>
<button
*ngIf="!data.isStatic"
[abpPermission]="'AbpIdentity.Roles.Delete'"
ngbDropdownItem
(click)="delete(data.id, data.name)"
>
{{ 'AbpIdentity::Delete' | abpLocalization }}
</button>
</div>
</div> </div>
</td> </div>
<td> </ng-template>
{{ data.name </ngx-datatable-column>
}}<span *ngIf="data.isDefault" class="badge badge-pill badge-success ml-1">{{ <ngx-datatable-column
'AbpIdentity::DisplayName:IsDefault' | abpLocalization [name]="'AbpIdentity::RoleName' | abpLocalization"
}}</span> prop="name"
<span *ngIf="data.isPublic" class="badge badge-pill badge-info ml-1">{{ ></ngx-datatable-column>
'AbpIdentity::DisplayName:IsPublic' | abpLocalization </ngx-datatable>
}}</span>
</td>
</tr>
</ng-template>
</abp-table>
</div> </div>
</div> </div>

32
npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts

@ -1,5 +1,6 @@
import { ABP } from '@abp/ng.core'; import { ListService } from '@abp/ng.core';
import { ConfirmationService, Confirmation } from '@abp/ng.theme.shared'; import { ePermissionManagementComponents } from '@abp/ng.permission-management';
import { Confirmation, ConfirmationService } from '@abp/ng.theme.shared';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Select, Store } from '@ngxs/store'; import { Select, Store } from '@ngxs/store';
@ -14,11 +15,11 @@ import {
} from '../../actions/identity.actions'; } from '../../actions/identity.actions';
import { Identity } from '../../models/identity'; import { Identity } from '../../models/identity';
import { IdentityState } from '../../states/identity.state'; import { IdentityState } from '../../states/identity.state';
import { ePermissionManagementComponents } from '@abp/ng.permission-management';
@Component({ @Component({
selector: 'abp-roles', selector: 'abp-roles',
templateUrl: './roles.component.html', templateUrl: './roles.component.html',
providers: [ListService],
}) })
export class RolesComponent implements OnInit { export class RolesComponent implements OnInit {
@Select(IdentityState.getRoles) @Select(IdentityState.getRoles)
@ -37,16 +38,10 @@ export class RolesComponent implements OnInit {
providerKey: string; providerKey: string;
pageQuery: ABP.PageQueryParams = { maxResultCount: 10 };
loading = false; loading = false;
modalBusy = false; modalBusy = false;
sortOrder = '';
sortKey = '';
permissionManagementKey = ePermissionManagementComponents.PermissionManagement; permissionManagementKey = ePermissionManagementComponents.PermissionManagement;
@ViewChild('formRef', { static: false, read: ElementRef }) @ViewChild('formRef', { static: false, read: ElementRef })
@ -57,6 +52,7 @@ export class RolesComponent implements OnInit {
}; };
constructor( constructor(
public readonly list: ListService,
private confirmationService: ConfirmationService, private confirmationService: ConfirmationService,
private fb: FormBuilder, private fb: FormBuilder,
private store: Store, private store: Store,
@ -126,18 +122,8 @@ export class RolesComponent 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 GetRoles(query))).subscribe();
this.store
.dispatch(new GetRoles(this.pageQuery))
.pipe(finalize(() => (this.loading = false)))
.subscribe();
} }
onClickSaveButton() { onClickSaveButton() {
@ -152,4 +138,10 @@ export class RolesComponent implements OnInit {
this.visiblePermissions = true; this.visiblePermissions = true;
}, 0); }, 0);
} }
onSort(event) {
const { prop, dir } = event.sorts[0];
this.list.sortKey = prop;
this.list.sortOrder = dir;
}
} }

Loading…
Cancel
Save