Browse Source

update: some upgrade enhancements for the identity

pull/25690/head
sumeyye 4 months ago
parent
commit
0295f5a29b
  1. 8
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html
  2. 25
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  3. 16
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.html
  4. 31
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

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

@ -9,7 +9,11 @@
</div> </div>
</div> </div>
<abp-modal [(visible)]="isModalVisible" [busy]="modalBusy"> <abp-modal
[visible]="isModalVisible()"
(visibleChange)="isModalVisible.set($event)"
[busy]="modalBusy()"
>
<ng-template #abpHeader> <ng-template #abpHeader>
<h3>{{ (selected?.id ? 'AbpIdentity::Edit' : 'AbpIdentity::NewRole') | abpLocalization }}</h3> <h3>{{ (selected?.id ? 'AbpIdentity::Edit' : 'AbpIdentity::NewRole') | abpLocalization }}</h3>
</ng-template> </ng-template>
@ -37,7 +41,7 @@
inputs: { inputs: {
providerName: { value: 'R' }, providerName: { value: 'R' },
providerKey: { value: providerKey }, providerKey: { value: providerKey },
visible: { value: visiblePermissions, twoWay: true }, visible: { value: visiblePermissions(), twoWay: true },
hideBadges: { value: true }, hideBadges: { value: true },
}, },
outputs: { visibleChange: onVisiblePermissionChange }, outputs: { visibleChange: onVisiblePermissionChange },

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

@ -1,4 +1,4 @@
import { Component, inject, Injector } from '@angular/core'; import { Component, inject, Injector, signal, ChangeDetectionStrategy } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop'; import { toSignal } from '@angular/core/rxjs-interop';
import { ReactiveFormsModule, UntypedFormGroup } from '@angular/forms'; import { ReactiveFormsModule, UntypedFormGroup } from '@angular/forms';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
@ -35,6 +35,7 @@ import { PageComponent } from '@abp/ng.components/page';
import { eIdentityComponents } from '../../enums/components'; import { eIdentityComponents } from '../../enums/components';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'abp-roles', selector: 'abp-roles',
templateUrl: './roles.component.html', templateUrl: './roles.component.html',
providers: [ providers: [
@ -70,16 +71,20 @@ export class RolesComponent {
this.list.hookToQuery(query => this.service.getList(query)), this.list.hookToQuery(query => this.service.getList(query)),
{ initialValue: { items: [], totalCount: 0 } as PagedResultDto<IdentityRoleDto> }, { initialValue: { items: [], totalCount: 0 } as PagedResultDto<IdentityRoleDto> },
); );
form!: UntypedFormGroup; form!: UntypedFormGroup;
selected?: IdentityRoleDto; selected?: IdentityRoleDto;
isModalVisible!: boolean;
visiblePermissions = false; readonly isModalVisible = signal(false);
readonly visiblePermissions = signal(false);
providerKey?: string; providerKey?: string;
modalBusy = false; readonly modalBusy = signal(false);
permissionManagementKey = ePermissionManagementComponents.PermissionManagement; permissionManagementKey = ePermissionManagementComponents.PermissionManagement;
onVisiblePermissionChange = (event: boolean) => { onVisiblePermissionChange = (event: boolean) => {
this.visiblePermissions = event; this.visiblePermissions.set(event);
}; };
buildForm() { buildForm() {
@ -89,7 +94,7 @@ export class RolesComponent {
openModal() { openModal() {
this.buildForm(); this.buildForm();
this.isModalVisible = true; this.isModalVisible.set(true);
} }
add() { add() {
@ -106,16 +111,16 @@ export class RolesComponent {
save() { save() {
if (!this.form.valid) return; if (!this.form.valid) return;
this.modalBusy = true; this.modalBusy.set(true);
const { id } = this.selected || {}; const { id } = this.selected || {};
(id (id
? this.service.update(id, { ...this.selected, ...this.form.value }) ? this.service.update(id, { ...this.selected, ...this.form.value })
: this.service.create(this.form.value) : this.service.create(this.form.value)
) )
.pipe(finalize(() => (this.modalBusy = false))) .pipe(finalize(() => this.modalBusy.set(false)))
.subscribe(() => { .subscribe(() => {
this.isModalVisible = false; this.isModalVisible.set(false);
this.toasterService.success('AbpUi::SavedSuccessfully'); this.toasterService.success('AbpUi::SavedSuccessfully');
this.list.get(); this.list.get();
}); });
@ -139,7 +144,7 @@ export class RolesComponent {
openPermissionsModal(providerKey: string) { openPermissionsModal(providerKey: string) {
this.providerKey = providerKey; this.providerKey = providerKey;
setTimeout(() => { setTimeout(() => {
this.visiblePermissions = true; this.visiblePermissions.set(true);
}, 0); }, 0);
} }

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

@ -20,7 +20,11 @@
</div> </div>
</div> </div>
<abp-modal [(visible)]="isModalVisible" [busy]="modalBusy"> <abp-modal
[visible]="isModalVisible()"
(visibleChange)="isModalVisible.set($event)"
[busy]="modalBusy()"
>
<ng-template #abpHeader> <ng-template #abpHeader>
<h3>{{ (selected?.id ? 'AbpIdentity::Edit' : 'AbpIdentity::NewUser') | abpLocalization }}</h3> <h3>{{ (selected?.id ? 'AbpIdentity::Edit' : 'AbpIdentity::NewUser') | abpLocalization }}</h3>
</ng-template> </ng-template>
@ -44,14 +48,14 @@
*abpReplaceableTemplate="{ *abpReplaceableTemplate="{
inputs: { inputs: {
checkboxId: { value: 'roles-' + i }, checkboxId: { value: 'roles-' + i },
label: { value: roles[i].name }, label: { value: roles()[i].name },
formControl: { value: roleGroup.get(roles[i].name!), twoWay: true }, formControl: { value: roleGroup.get(roles()[i].name!), twoWay: true },
}, },
componentKey: inputKey, componentKey: inputKey,
}" }"
[checkboxId]="'roles-' + i" [checkboxId]="'roles-' + i"
[formControlName]="roles[i].name!" [formControlName]="roles()[i].name!"
[label]="roles[i].name" [label]="roles()[i].name"
/> />
</div> </div>
} }
@ -83,7 +87,7 @@
inputs: { inputs: {
providerName: { value: 'U' }, providerName: { value: 'U' },
providerKey: { value: providerKey }, providerKey: { value: providerKey },
visible: { value: visiblePermissions, twoWay: true }, visible: { value: visiblePermissions(), twoWay: true },
}, },
outputs: { visibleChange: onVisiblePermissionChange }, outputs: { visibleChange: onVisiblePermissionChange },
componentKey: permissionManagementKey, componentKey: permissionManagementKey,

31
npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

@ -36,9 +36,11 @@ import {
Component, Component,
inject, inject,
Injector, Injector,
signal,
TemplateRef, TemplateRef,
TrackByFunction, TrackByFunction,
viewChild, viewChild,
ChangeDetectionStrategy,
} from '@angular/core'; } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop'; import { toSignal } from '@angular/core/rxjs-interop';
import { import {
@ -56,6 +58,7 @@ import { NgbDropdownModule, NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxValidateCoreModule } from '@ngx-validate/core'; import { NgxValidateCoreModule } from '@ngx-validate/core';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'abp-users', selector: 'abp-users',
templateUrl: './users.component.html', templateUrl: './users.component.html',
providers: [ providers: [
@ -109,15 +112,15 @@ export class UsersComponent {
selectedUserRoles?: IdentityRoleDto[]; selectedUserRoles?: IdentityRoleDto[];
roles?: IdentityRoleDto[]; readonly roles = signal<IdentityRoleDto[]>([]);
visiblePermissions = false; readonly visiblePermissions = signal(false);
providerKey?: string; providerKey?: string;
isModalVisible?: boolean; readonly isModalVisible = signal(false);
modalBusy = false; readonly modalBusy = signal(false);
permissionManagementKey = ePermissionManagementComponents.PermissionManagement; permissionManagementKey = ePermissionManagementComponents.PermissionManagement;
@ -128,7 +131,7 @@ export class UsersComponent {
trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index; trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index;
onVisiblePermissionChange = (event: boolean) => { onVisiblePermissionChange = (event: boolean) => {
this.visiblePermissions = event; this.visiblePermissions.set(event);
}; };
get roleGroups(): UntypedFormGroup[] { get roleGroups(): UntypedFormGroup[] {
@ -140,12 +143,12 @@ export class UsersComponent {
this.form = generateFormFromProps(data); this.form = generateFormFromProps(data);
this.service.getAssignableRoles().subscribe(({ items }) => { this.service.getAssignableRoles().subscribe(({ items }) => {
this.roles = items; this.roles.set(items);
if (this.roles) { if (items?.length) {
this.form.addControl( this.form.addControl(
'roleNames', 'roleNames',
this.fb.array( this.fb.array(
this.roles.map(role => items.map(role =>
this.fb.group({ this.fb.group({
[role.name as string]: [ [role.name as string]: [
this.selected?.id this.selected?.id
@ -163,7 +166,7 @@ export class UsersComponent {
openModal() { openModal() {
this.selectedTab = 'user-info'; this.selectedTab = 'user-info';
this.buildForm(); this.buildForm();
this.isModalVisible = true; this.isModalVisible.set(true);
} }
add() { add() {
@ -186,8 +189,8 @@ export class UsersComponent {
} }
save() { save() {
if (!this.form.valid || this.modalBusy) return; if (!this.form.valid || this.modalBusy()) return;
this.modalBusy = true; this.modalBusy.set(true);
const { roleNames = [] } = this.form.value; const { roleNames = [] } = this.form.value;
const mappedRoleNames = const mappedRoleNames =
@ -205,9 +208,9 @@ export class UsersComponent {
}) })
: this.service.create({ ...this.form.value, roleNames: mappedRoleNames }) : this.service.create({ ...this.form.value, roleNames: mappedRoleNames })
) )
.pipe(finalize(() => (this.modalBusy = false))) .pipe(finalize(() => this.modalBusy.set(false)))
.subscribe(() => { .subscribe(() => {
this.isModalVisible = false; this.isModalVisible.set(false);
this.toasterService.success('AbpUi::SavedSuccessfully'); this.toasterService.success('AbpUi::SavedSuccessfully');
this.list.get(); this.list.get();
}); });
@ -238,7 +241,7 @@ export class UsersComponent {
this.providerKey = providerKey; this.providerKey = providerKey;
this.entityDisplayName = entityDisplayName; this.entityDisplayName = entityDisplayName;
setTimeout(() => { setTimeout(() => {
this.visiblePermissions = true; this.visiblePermissions.set(true);
}, 0); }, 0);
} }
} }

Loading…
Cancel
Save