mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[AAE-936] injecting external settings for amount widget (#5389)
* injecting external settings for amount widget * undo form changes
This commit is contained in:
parent
deb2a0082f
commit
c7c1d76510
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { FormFieldModel } from './../core/form-field.model';
|
import { FormFieldModel } from './../core/form-field.model';
|
||||||
import { AmountWidgetComponent } from './amount.widget';
|
import { AmountWidgetComponent, ADF_AMOUNT_SETTINGS } from './amount.widget';
|
||||||
import { setupTestBed } from '../../../../testing/setupTestBed';
|
import { setupTestBed } from '../../../../testing/setupTestBed';
|
||||||
import { CoreModule } from '../../../../core.module';
|
import { CoreModule } from '../../../../core.module';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
@ -77,3 +77,38 @@ describe('AmountWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('AmountWidgetComponent settings', () => {
|
||||||
|
let widget: AmountWidgetComponent;
|
||||||
|
let fixture: ComponentFixture<AmountWidgetComponent>;
|
||||||
|
|
||||||
|
setupTestBed({
|
||||||
|
imports: [
|
||||||
|
NoopAnimationsModule,
|
||||||
|
CoreModule.forRoot()
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: ADF_AMOUNT_SETTINGS,
|
||||||
|
useValue: {
|
||||||
|
showReadonlyPlaceholder: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(AmountWidgetComponent);
|
||||||
|
|
||||||
|
widget = fixture.componentInstance;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display placeholder via injected settings', () => {
|
||||||
|
const field: any = {
|
||||||
|
readOnly: true,
|
||||||
|
placeholder: 'some placeholder'
|
||||||
|
};
|
||||||
|
widget.field = field;
|
||||||
|
expect(widget.placeholder).toBe('some placeholder');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -17,10 +17,16 @@
|
|||||||
|
|
||||||
/* tslint:disable:component-selector */
|
/* tslint:disable:component-selector */
|
||||||
|
|
||||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, OnInit, ViewEncapsulation, InjectionToken, Inject, Optional } from '@angular/core';
|
||||||
import { FormService } from './../../../services/form.service';
|
import { FormService } from './../../../services/form.service';
|
||||||
import { baseHost , WidgetComponent } from './../widget.component';
|
import { baseHost , WidgetComponent } from './../widget.component';
|
||||||
|
|
||||||
|
export interface AmountWidgetSettings {
|
||||||
|
showReadonlyPlaceholder: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ADF_AMOUNT_SETTINGS = new InjectionToken<AmountWidgetSettings>('adf-amount-settings');
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'amount-widget',
|
selector: 'amount-widget',
|
||||||
templateUrl: './amount.widget.html',
|
templateUrl: './amount.widget.html',
|
||||||
@ -31,20 +37,32 @@ import { baseHost , WidgetComponent } from './../widget.component';
|
|||||||
export class AmountWidgetComponent extends WidgetComponent implements OnInit {
|
export class AmountWidgetComponent extends WidgetComponent implements OnInit {
|
||||||
|
|
||||||
static DEFAULT_CURRENCY: string = '$';
|
static DEFAULT_CURRENCY: string = '$';
|
||||||
|
private showPlaceholder = true;
|
||||||
|
|
||||||
currency: string = AmountWidgetComponent.DEFAULT_CURRENCY;
|
currency: string = AmountWidgetComponent.DEFAULT_CURRENCY;
|
||||||
|
|
||||||
get placeholder(): string {
|
get placeholder(): string {
|
||||||
return !this.field.readOnly ? this.field.placeholder : '';
|
return this.showPlaceholder ? this.field.placeholder : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(public formService: FormService) {
|
constructor(
|
||||||
|
public formService: FormService,
|
||||||
|
@Inject(ADF_AMOUNT_SETTINGS)
|
||||||
|
@Optional()
|
||||||
|
private settings: AmountWidgetSettings
|
||||||
|
) {
|
||||||
super(formService);
|
super(formService);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.field && this.field.currency) {
|
if (this.field) {
|
||||||
this.currency = this.field.currency;
|
if (this.field.currency) {
|
||||||
|
this.currency = this.field.currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.field.readOnly) {
|
||||||
|
this.showPlaceholder = this.settings && this.settings.showReadonlyPlaceholder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user