|
|
|
@ -14,64 +14,41 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, forwardRef, Input, OnInit } from '@angular/core'; |
|
|
|
import { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
|
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'; |
|
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
|
import { RateLimits, rateLimitsArrayToHtml } from './rate-limits.models'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-rate-limits-text', |
|
|
|
templateUrl: './rate-limits-text.component.html', |
|
|
|
styleUrls: ['./rate-limits-text.component.scss'], |
|
|
|
providers: [ |
|
|
|
{ |
|
|
|
provide: NG_VALUE_ACCESSOR, |
|
|
|
useExisting: forwardRef(() => RateLimitsTextComponent), |
|
|
|
multi: true |
|
|
|
} |
|
|
|
] |
|
|
|
styleUrls: ['./rate-limits-text.component.scss'] |
|
|
|
}) |
|
|
|
export class RateLimitsTextComponent implements ControlValueAccessor, OnInit { |
|
|
|
export class RateLimitsTextComponent implements OnChanges { |
|
|
|
|
|
|
|
@Input() |
|
|
|
disabled: boolean; |
|
|
|
|
|
|
|
noRateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set'); |
|
|
|
|
|
|
|
public rateLimitsText: string; |
|
|
|
|
|
|
|
private propagateChange = (v: any) => { }; |
|
|
|
|
|
|
|
constructor(private dialog: MatDialog, |
|
|
|
private fb: FormBuilder, |
|
|
|
private translate: TranslateService) { |
|
|
|
} |
|
|
|
|
|
|
|
registerOnChange(fn: any): void { |
|
|
|
this.propagateChange = fn; |
|
|
|
} |
|
|
|
rateLimitsArray: Array<RateLimits>; |
|
|
|
|
|
|
|
registerOnTouched(fn: any): void { |
|
|
|
} |
|
|
|
@Input() |
|
|
|
disabled: boolean; |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
} |
|
|
|
rateLimitsText: string; |
|
|
|
|
|
|
|
setDisabledState(isDisabled: boolean): void { |
|
|
|
this.disabled = isDisabled; |
|
|
|
} |
|
|
|
constructor(private translate: TranslateService) {} |
|
|
|
|
|
|
|
writeValue(value: Array<RateLimits>): void { |
|
|
|
this.updateText(value); |
|
|
|
ngOnChanges(changes: SimpleChanges): void { |
|
|
|
for (const propName of Object.keys(changes)) { |
|
|
|
if (propName === 'rateLimitsArray') { |
|
|
|
const change = changes[propName]; |
|
|
|
this.updateView(change.currentValue); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private updateText(value: Array<RateLimits>) { |
|
|
|
if (value && value.length) { |
|
|
|
private updateView(value: Array<RateLimits>): void { |
|
|
|
if (value?.length) { |
|
|
|
this.rateLimitsText = rateLimitsArrayToHtml(this.translate, value); |
|
|
|
} else { |
|
|
|
this.rateLimitsText = this.noRateLimitsText; |
|
|
|
this.rateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|