Merge pull request #1637 from abpframework/refactor/button-component

Refactor/button component
pull/1639/head
Yasin Aydın 6 years ago committed by GitHub
commit 2c8cff7355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,4 @@
import { StartLoader, StopLoader } from '@abp/ng.core';
import { Component, Input, OnInit } from '@angular/core';
import { Actions, ofActionSuccessful } from '@ngxs/store';
import { filter } from 'rxjs/operators';
import { Component, Input } from '@angular/core';
@Component({
selector: 'abp-button',
@ -11,7 +8,7 @@ import { filter } from 'rxjs/operators';
</button>
`,
})
export class ButtonComponent implements OnInit {
export class ButtonComponent {
@Input()
buttonClass: string = 'btn btn-primary';
@ -27,47 +24,7 @@ export class ButtonComponent implements OnInit {
@Input()
disabled: boolean = false;
@Input()
requestType: string | string[];
@Input()
requestURLContainSearchValue: string;
get icon(): string {
return `${this.loading ? 'fa fa-spin fa-spinner' : this.iconClass || 'd-none'}`;
}
constructor(private actions: Actions) {}
ngOnInit(): void {
if (this.requestType || this.requestURLContainSearchValue) {
this.actions
.pipe(
ofActionSuccessful(StartLoader, StopLoader),
filter((event: StartLoader | StopLoader) => {
let condition = true;
if (this.requestType) {
if (!Array.isArray(this.requestType)) this.requestType = [this.requestType];
condition =
condition &&
this.requestType.findIndex(type => type.toLowerCase() === event.payload.method.toLowerCase()) > -1;
}
if (condition && this.requestURLContainSearchValue) {
condition =
condition &&
event.payload.url.toLowerCase().indexOf(this.requestURLContainSearchValue.toLowerCase()) > -1;
}
return condition;
}),
)
.subscribe(() => {
setTimeout(() => {
this.loading = !this.loading;
}, 0);
});
}
}
}

Loading…
Cancel
Save