UNPKG

ngx-bit

Version:

A flexible NG-ZORRO helper library

386 lines (371 loc) 12.5 kB
import { Directive, HostListener, Input, EventEmitter, Output, NgModule } from '@angular/core'; import { BitService, BitConfig } from 'ngx-bit'; import { NzColDirective } from 'ng-zorro-antd/grid'; import { FormGroupDirective, FormGroupName, NgModel } from '@angular/forms'; import { switchMap, map } from 'rxjs/operators'; import { NzSwitchComponent } from 'ng-zorro-antd/switch'; import { NzMessageService } from 'ng-zorro-antd/message'; import { NzUploadComponent } from 'ng-zorro-antd/upload'; import { HttpClient } from '@angular/common/http'; class BitBackDirective { constructor(bit) { this.bit = bit; } onClick() { this.bit.back(); } } BitBackDirective.decorators = [ { type: Directive, args: [{ selector: '[bitBack]' },] } ]; BitBackDirective.ctorParameters = () => [ { type: BitService } ]; BitBackDirective.propDecorators = { onClick: [{ type: HostListener, args: ['click',] }] }; class BitColDirective { constructor(nzColDirective, config) { this.nzColDirective = nzColDirective; this.config = config; } ngOnInit() { if (!this.config.col.hasOwnProperty(this.bitCol)) { return; } const col = this.config.col[this.bitCol]; this.nzColDirective.nzXs = col.hasOwnProperty('nzXs') ? col.nzXs : null; this.nzColDirective.nzSm = col.hasOwnProperty('nzSm') ? col.nzSm : null; this.nzColDirective.nzMd = col.hasOwnProperty('nzMd') ? col.nzMd : null; this.nzColDirective.nzLg = col.hasOwnProperty('nzLg') ? col.nzLg : null; this.nzColDirective.nzXl = col.hasOwnProperty('nzXl') ? col.nzXl : null; this.nzColDirective.nzXXl = col.hasOwnProperty('nzXXl') ? col.nzXXl : null; this.nzColDirective.setHostClassMap(); } } BitColDirective.decorators = [ { type: Directive, args: [{ selector: '[bitCol]' },] } ]; BitColDirective.ctorParameters = () => [ { type: NzColDirective }, { type: BitConfig } ]; BitColDirective.propDecorators = { bitCol: [{ type: Input }] }; class BitFormSubmitDirective { constructor(form) { this.form = form; this.bitFormSubmit = new EventEmitter(); } ngOnInit() { this.form.ngSubmit.subscribe(_ => { const controls = this.form.control.controls; for (const key in controls) { if (controls.hasOwnProperty(key)) { controls[key].markAsDirty(); controls[key].updateValueAndValidity(); } } this.bitFormSubmit.emit(this.form.value); }); } } BitFormSubmitDirective.decorators = [ { type: Directive, args: [{ selector: 'form[bitFormSubmit]' },] } ]; BitFormSubmitDirective.ctorParameters = () => [ { type: FormGroupDirective } ]; BitFormSubmitDirective.propDecorators = { bitFormSubmit: [{ type: Output }] }; class BitHistoryDirective { constructor(bit) { this.bit = bit; } onClick() { this.bit.history(this.bitHistory); } } BitHistoryDirective.decorators = [ { type: Directive, args: [{ selector: '[bitHistory]' },] } ]; BitHistoryDirective.ctorParameters = () => [ { type: BitService } ]; BitHistoryDirective.propDecorators = { bitHistory: [{ type: Input }], onClick: [{ type: HostListener, args: ['click',] }] }; class BitI18nUpdateDirective { constructor(bit, formGroupName) { this.bit = bit; this.formGroupName = formGroupName; } ngOnInit() { this.changes = this.formGroupName.valueChanges.subscribe((value) => { const emptyI18n = []; for (const ID in value) { if (value.hasOwnProperty(ID)) { if (!value[ID]) { emptyI18n.push(ID); } } } Reflect.set(this.bit.i18nTooltip, this.formGroupName.name, emptyI18n); }); } ngOnDestroy() { this.changes.unsubscribe(); } } BitI18nUpdateDirective.decorators = [ { type: Directive, args: [{ selector: '[formGroupName][bitI18nUpdate]' },] } ]; BitI18nUpdateDirective.ctorParameters = () => [ { type: BitService }, { type: FormGroupName } ]; class BitOpenDirective { constructor(bit) { this.bit = bit; } onClick() { this.bit.open(this.bitOpen, this.extras); } } BitOpenDirective.decorators = [ { type: Directive, args: [{ selector: '[bitOpen]' },] } ]; BitOpenDirective.ctorParameters = () => [ { type: BitService } ]; BitOpenDirective.propDecorators = { bitOpen: [{ type: Input }], extras: [{ type: Input }], onClick: [{ type: HostListener, args: ['click',] }] }; class BitSearchChangeDirective { constructor(model) { this.model = model; this.after = new EventEmitter(); } ngOnInit() { this.model.update.pipe(switchMap(_ => this.bitSearchChange.afterSearch())).subscribe(_ => { this.after.emit(true); }); } } BitSearchChangeDirective.decorators = [ { type: Directive, args: [{ selector: '[bitSearchChange]' },] } ]; BitSearchChangeDirective.ctorParameters = () => [ { type: NgModel } ]; BitSearchChangeDirective.propDecorators = { bitSearchChange: [{ type: Input }], after: [{ type: Output }] }; class BitSearchClearDirective { constructor() { this.after = new EventEmitter(); } onClick() { this.bitSearchClear.clearSearch(this.reset).subscribe(() => { this.after.emit(true); }); } } BitSearchClearDirective.decorators = [ { type: Directive, args: [{ selector: 'button[bitSearchClear]' },] } ]; BitSearchClearDirective.propDecorators = { bitSearchClear: [{ type: Input }], reset: [{ type: Input }], after: [{ type: Output }], onClick: [{ type: HostListener, args: ['click',] }] }; class BitSearchStartDirective { constructor() { this.after = new EventEmitter(); } onenter(el) { if (el.tagName.toLowerCase() !== 'input') { return; } this.afterSearch(); } onclick(el) { if (el.tagName.toLowerCase() === 'input') { return; } this.afterSearch(); } afterSearch() { this.bitSearchStart.afterSearch().subscribe(() => { this.after.emit(true); }); } } BitSearchStartDirective.decorators = [ { type: Directive, args: [{ selector: '[bitSearchStart]' },] } ]; BitSearchStartDirective.propDecorators = { bitSearchStart: [{ type: Input }], after: [{ type: Output }], onenter: [{ type: HostListener, args: ['keydown.enter', ['$event.target'],] }], onclick: [{ type: HostListener, args: ['click', ['$event.target'],] }] }; class BitStatusChangeDirective { constructor(nzSwitchComponent, bit, message) { this.bit = bit; this.message = message; this.bitControl = false; this.response = new EventEmitter(); nzSwitchComponent.nzControl = true; } onclick() { this.bitStatusChange.subscribe(res => { if (!res.error) { this.message.success(this.bit.l.StatusSuccess); } else { if (!this.bitControl) { this.message.error(this.bit.l.StatusError); } else { this.response.emit(res); } } }); } } BitStatusChangeDirective.decorators = [ { type: Directive, args: [{ selector: 'nz-switch[bitStatusChange]' },] } ]; BitStatusChangeDirective.ctorParameters = () => [ { type: NzSwitchComponent }, { type: BitService }, { type: NzMessageService } ]; BitStatusChangeDirective.propDecorators = { bitStatusChange: [{ type: Input }], bitControl: [{ type: Input }], response: [{ type: Output }], onclick: [{ type: HostListener, args: ['click',] }] }; class BitUploadDirective { constructor(config, http, nzUploadComponent) { nzUploadComponent.nzSize = !config.api.uploadSize ? 5120 : config.api.uploadSize; nzUploadComponent.nzShowUploadList = false; if (config.api.uploadStorage === 'default') { nzUploadComponent.nzAction = config.url.api + config.api.upload; nzUploadComponent.nzWithCredentials = config.api.withCredentials; return; } nzUploadComponent.nzAction = config.api.upload; nzUploadComponent.nzData = (file) => { const url = config.url.api + config.api.uploadFetchSigned; return http.request(config.api.uploadFetchSignedMethod, url, { withCredentials: config.api.withCredentials }).pipe(map((res) => { const sep = file.name.split('.'); const ext = sep.length > 1 ? '.' + sep.pop().toLowerCase() : ''; file.key = res.filename + ext; switch (config.api.uploadStorage) { case 'oss': return { key: file.key, policy: res.option.policy, OSSAccessKeyId: res.option.access_key_id, Signature: res.option.signature }; case 'obs': return { key: file.key, policy: res.option.policy, AccessKeyId: res.option.access_key_id, signature: res.option.signature }; case 'cos': return { key: file.key, policy: res.option.policy, 'q-sign-algorithm': res.option.sign_algorithm, 'q-ak': res.option.ak, 'q-key-time': res.option.key_time, 'q-signature': res.option.signature }; } })); }; } } BitUploadDirective.decorators = [ { type: Directive, args: [{ selector: 'nz-upload[bitUpload]' },] } ]; BitUploadDirective.ctorParameters = () => [ { type: BitConfig }, { type: HttpClient }, { type: NzUploadComponent } ]; class BitDirectiveModule { } BitDirectiveModule.decorators = [ { type: NgModule, args: [{ declarations: [ BitBackDirective, BitColDirective, BitFormSubmitDirective, BitHistoryDirective, BitI18nUpdateDirective, BitOpenDirective, BitSearchChangeDirective, BitSearchClearDirective, BitSearchStartDirective, BitStatusChangeDirective, BitUploadDirective ], exports: [ BitBackDirective, BitColDirective, BitFormSubmitDirective, BitHistoryDirective, BitI18nUpdateDirective, BitOpenDirective, BitSearchChangeDirective, BitSearchClearDirective, BitSearchStartDirective, BitStatusChangeDirective, BitUploadDirective ] },] } ]; /** * Generated bundle index. Do not edit. */ export { BitBackDirective, BitColDirective, BitDirectiveModule, BitFormSubmitDirective, BitHistoryDirective, BitI18nUpdateDirective, BitOpenDirective, BitSearchChangeDirective, BitSearchClearDirective, BitSearchStartDirective, BitStatusChangeDirective, BitUploadDirective }; //# sourceMappingURL=ngx-bit-directive.js.map