Browse Source

Merge pull request #1601 from abpframework/feature/event-modifier-directives

Feature/event modifier directives
pull/1606/head
Yasin Aydın 7 years ago
committed by GitHub
parent
commit
81d1358a08
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. 26
      npm/ng-packs/packages/core/src/lib/directives/debounce.directive.ts
  3. 21
      npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts
  4. 2
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.html
  5. 30
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  6. 2
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.html
  7. 18
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts
  8. 2
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.html
  9. 14
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

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

@ -20,6 +20,8 @@ import { SessionState } from './states/session.state';
import { getInitialData } from './utils/initial-utils'; import { getInitialData } from './utils/initial-utils';
import { EllipsisDirective } from './directives/ellipsis.directive'; import { EllipsisDirective } from './directives/ellipsis.directive';
import { AutofocusDirective } from './directives/autofocus.directive'; import { AutofocusDirective } from './directives/autofocus.directive';
import { InputEventDebounceDirective } from './directives/debounce.directive';
import { ClickEventStopPropagationDirective } from './directives/stop-propagation.directive';
@NgModule({ @NgModule({
imports: [ imports: [
@ -40,6 +42,8 @@ import { AutofocusDirective } from './directives/autofocus.directive';
LocalizationPipe, LocalizationPipe,
PermissionDirective, PermissionDirective,
VisibilityDirective, VisibilityDirective,
InputEventDebounceDirective,
ClickEventStopPropagationDirective,
], ],
exports: [ exports: [
CommonModule, CommonModule,
@ -54,7 +58,9 @@ import { AutofocusDirective } from './directives/autofocus.directive';
LocalizationPipe, LocalizationPipe,
PermissionDirective, PermissionDirective,
VisibilityDirective, VisibilityDirective,
InputEventDebounceDirective,
LocalizationPipe, LocalizationPipe,
ClickEventStopPropagationDirective,
], ],
providers: [LocalizationPipe], providers: [LocalizationPipe],
entryComponents: [RouterOutletComponent, DynamicLayoutComponent], entryComponents: [RouterOutletComponent, DynamicLayoutComponent],

26
npm/ng-packs/packages/core/src/lib/directives/debounce.directive.ts

@ -0,0 +1,26 @@
import { Directive, Output, Renderer2, ElementRef, OnInit, EventEmitter, Input } from '@angular/core';
import { fromEvent } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { takeUntilDestroy } from '@ngx-validate/core';
@Directive({
selector: '[input.debounce]',
})
export class InputEventDebounceDirective implements OnInit {
@Input() debounce: number = 300;
@Output('input.debounce') debounceEvent = new EventEmitter<Event>();
constructor(private renderer: Renderer2, private el: ElementRef) {}
ngOnInit(): void {
fromEvent(this.el.nativeElement, 'input')
.pipe(
debounceTime(this.debounce),
takeUntilDestroy(this),
)
.subscribe((event: Event) => {
this.debounceEvent.emit(event);
});
}
}

21
npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts

@ -0,0 +1,21 @@
import { Directive, ElementRef, EventEmitter, OnInit, Output, Renderer2 } from '@angular/core';
import { fromEvent } from 'rxjs';
import { takeUntilDestroy } from '@ngx-validate/core';
@Directive({
selector: '[click.stop]',
})
export class ClickEventStopPropagationDirective implements OnInit {
@Output('click.stop') stopPropEvent = new EventEmitter<MouseEvent>();
constructor(private renderer: Renderer2, private el: ElementRef) {}
ngOnInit(): void {
fromEvent(this.el.nativeElement, 'click')
.pipe(takeUntilDestroy(this))
.subscribe((event: MouseEvent) => {
event.stopPropagation();
this.stopPropEvent.emit(event);
});
}
}

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

@ -18,7 +18,7 @@
type="search" type="search"
class="form-control form-control-sm" class="form-control form-control-sm"
[placeholder]="'AbpUi::PagerSearch' | abpLocalization" [placeholder]="'AbpUi::PagerSearch' | abpLocalization"
(input)="search$.next($event.target.value)" (input.debounce)="onSearch($event.target.value)"
/></label> /></label>
</div> </div>
<p-table <p-table

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

@ -1,25 +1,25 @@
import { Component, TemplateRef, ViewChild, OnInit } from '@angular/core'; import { ABP } from '@abp/ng.core';
import { Select, Store } from '@ngxs/store'; import { ConfirmationService, Toaster } from '@abp/ng.theme.shared';
import { Observable, Subject } from 'rxjs'; import { Component, TemplateRef, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { IdentityState } from '../../states/identity.state'; import { Select, Store } from '@ngxs/store';
import { Identity } from '../../models/identity'; import { Observable } from 'rxjs';
import { debounceTime, finalize, pluck } from 'rxjs/operators';
import { import {
IdentityUpdateRole,
IdentityAddRole, IdentityAddRole,
IdentityDeleteRole, IdentityDeleteRole,
IdentityGetRoleById, IdentityGetRoleById,
IdentityGetRoles, IdentityGetRoles,
IdentityUpdateRole,
} from '../../actions/identity.actions'; } from '../../actions/identity.actions';
import { pluck, debounceTime, finalize } from 'rxjs/operators'; import { Identity } from '../../models/identity';
import { ConfirmationService, Toaster } from '@abp/ng.theme.shared'; import { IdentityState } from '../../states/identity.state';
import { ABP } from '@abp/ng.core';
@Component({ @Component({
selector: 'abp-roles', selector: 'abp-roles',
templateUrl: './roles.component.html', templateUrl: './roles.component.html',
}) })
export class RolesComponent implements OnInit { export class RolesComponent {
@Select(IdentityState.getRoles) @Select(IdentityState.getRoles)
data$: Observable<Identity.RoleItem[]>; data$: Observable<Identity.RoleItem[]>;
@ -42,18 +42,14 @@ export class RolesComponent implements OnInit {
loading: boolean = false; loading: boolean = false;
search$ = new Subject<string>();
@ViewChild('modalContent', { static: false }) @ViewChild('modalContent', { static: false })
modalContent: TemplateRef<any>; modalContent: TemplateRef<any>;
constructor(private confirmationService: ConfirmationService, private fb: FormBuilder, private store: Store) {} constructor(private confirmationService: ConfirmationService, private fb: FormBuilder, private store: Store) {}
ngOnInit() { onSearch(value) {
this.search$.pipe(debounceTime(300)).subscribe(value => { this.pageQuery.filter = value;
this.pageQuery.filter = value; this.get();
this.get();
});
} }
createForm() { createForm() {

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

@ -24,7 +24,7 @@
type="search" type="search"
class="form-control form-control-sm" class="form-control form-control-sm"
[placeholder]="'AbpUi::PagerSearch' | abpLocalization" [placeholder]="'AbpUi::PagerSearch' | abpLocalization"
(input)="search$.next($event.target.value)" (input.debounce)="onSearch($event.target.value)"
/></label> /></label>
</div> </div>
<p-table <p-table

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

@ -1,10 +1,10 @@
import { ABP } from '@abp/ng.core'; import { ABP } from '@abp/ng.core';
import { ConfirmationService, Toaster } from '@abp/ng.theme.shared'; import { ConfirmationService, Toaster } from '@abp/ng.theme.shared';
import { Component, OnInit, TemplateRef, TrackByFunction, ViewChild } from '@angular/core'; import { Component, TemplateRef, TrackByFunction, ViewChild } from '@angular/core';
import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Select, Store } from '@ngxs/store'; import { Select, Store } from '@ngxs/store';
import { combineLatest, Observable, Subject } from 'rxjs'; import { combineLatest, Observable } from 'rxjs';
import { debounceTime, filter, map, pluck, take, finalize } from 'rxjs/operators'; import { filter, finalize, map, pluck, take } from 'rxjs/operators';
import snq from 'snq'; import snq from 'snq';
import { import {
IdentityAddUser, IdentityAddUser,
@ -20,7 +20,7 @@ import { IdentityState } from '../../states/identity.state';
selector: 'abp-users', selector: 'abp-users',
templateUrl: './users.component.html', templateUrl: './users.component.html',
}) })
export class UsersComponent implements OnInit { export class UsersComponent {
@Select(IdentityState.getUsers) @Select(IdentityState.getUsers)
data$: Observable<Identity.UserItem[]>; data$: Observable<Identity.UserItem[]>;
@ -50,8 +50,6 @@ export class UsersComponent implements OnInit {
loading: boolean = false; loading: boolean = false;
search$ = new Subject<string>();
trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index; trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index;
get roleGroups(): FormGroup[] { get roleGroups(): FormGroup[] {
@ -60,11 +58,9 @@ export class UsersComponent implements OnInit {
constructor(private confirmationService: ConfirmationService, private fb: FormBuilder, private store: Store) {} constructor(private confirmationService: ConfirmationService, private fb: FormBuilder, private store: Store) {}
ngOnInit() { onSearch(value) {
this.search$.pipe(debounceTime(300)).subscribe(value => { this.pageQuery.filter = value;
this.pageQuery.filter = value; this.get();
this.get();
});
} }
buildForm() { buildForm() {

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

@ -27,7 +27,7 @@
type="search" type="search"
class="form-control form-control-sm" class="form-control form-control-sm"
[placeholder]="'AbpUi::PagerSearch' | abpLocalization" [placeholder]="'AbpUi::PagerSearch' | abpLocalization"
(input)="search$.next($event.target.value)" (input.debounce)="onSearch($event.target.value)"
/></label> /></label>
</div> </div>
<p-table <p-table

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

@ -1,6 +1,6 @@
import { ABP } from '@abp/ng.core'; import { ABP } from '@abp/ng.core';
import { ConfirmationService, Toaster } from '@abp/ng.theme.shared'; import { ConfirmationService, Toaster } from '@abp/ng.theme.shared';
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; import { Component, 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, Subject } from 'rxjs'; import { Observable, Subject } from 'rxjs';
@ -25,7 +25,7 @@ type SelectedModalContent = {
selector: 'abp-tenants', selector: 'abp-tenants',
templateUrl: './tenants.component.html', templateUrl: './tenants.component.html',
}) })
export class TenantsComponent implements OnInit { export class TenantsComponent {
@Select(TenantManagementState.get) @Select(TenantManagementState.get)
data$: Observable<ABP.BasicItem[]>; data$: Observable<ABP.BasicItem[]>;
@ -52,8 +52,6 @@ export class TenantsComponent implements OnInit {
loading: boolean = false; loading: boolean = false;
search$ = new Subject<string>();
get useSharedDatabase(): boolean { get useSharedDatabase(): boolean {
return this.defaultConnectionStringForm.get('useSharedDatabase').value; return this.defaultConnectionStringForm.get('useSharedDatabase').value;
} }
@ -75,11 +73,9 @@ export class TenantsComponent implements OnInit {
private store: Store, private store: Store,
) {} ) {}
ngOnInit() { onSearch(value) {
this.search$.pipe(debounceTime(300)).subscribe(value => { this.pageQuery.filter = value;
this.pageQuery.filter = value; this.get();
this.get();
});
} }
private createTenantForm() { private createTenantForm() {

Loading…
Cancel
Save