Default value : [
{
key: 'id',
type: 'string',
templateOptions: {
placeholder: 'FED987',
label: gettext('ID'),
required: true,
pattern: '(0x){0,1}[0-9A-F]+(h){0,1}'
},
validation: {
messages: {
pattern: gettext('Must be a valid hexadecimal number.')
}
}
},
{
key: 'pac',
type: 'string',
templateOptions: {
placeholder: 'FEDCBA9876543210',
label: gettext('PAC'),
required: true,
pattern: '^([a-fA-F0-9]{16})$'
},
validation: {
messages: {
pattern: gettext('Must be a valid 16 digit hexadecimal number.')
}
}
},
{
key: 'connection',
type: 'typeahead',
templateOptions: {
label: gettext('Connection'),
required: true,
c8yForOptions: this.connections$,
displayProperty: 'name',
valueProperties: ['name']
}
},
{
key: 'contract',
type: 'typeahead',
templateOptions: {
label: gettext('Contract'),
required: true,
placeholder: 'Free contract_25',
displayProperty: 'name',
valueProperties: ['id'],
description: gettext('Only active contracts with free slots are displayed.')
},
hooks: {
onInit: field => {
const connectionControl = field.form.get('connection');
connectionControl.valueChanges
.pipe(
takeUntil(this.unsubscribe$),
mergeMap(({ name }) => this.getContracts$(name))
)
.subscribe(
profiles => {
field.templateOptions.c8yForOptions = of(profiles);
field.formControl.setValue(null);
},
error => {
field.form.get('contract').setErrors({ contract: true });
field.validators.contract.message = error.message;
}
);
}
},
validators: {
contract: {
expression: (control: AbstractControl) => {
return control.status === 'VALID';
},
message: () => ''
}
}
},
{
key: 'deviceType',
type: 'typeahead',
templateOptions: {
label: gettext('Device protocol'),
required: true,
c8yForOptions: this.protocols$,
displayProperty: 'name',
valueProperties: ['id', 'name']
}
},
{
key: 'productCertificate',
type: 'string',
templateOptions: {
placeholder: 'P_001F_EDCB_01',
label: gettext('Product certificate key'),
pattern: 'P_[0-9A-F]{4}_[0-9A-F]{4}_[0-9A-F]{2}',
description: gettext(
'If no product certificate key is specified, the device is considered a prototype.'
)
},
validation: {
messages: {
pattern: (_error, _field: FormlyFieldConfig) =>
this.translateService.instant(
gettext('Must be a valid product certificate key, for example, {{ example }}'),
{ example: 'P_001F_EDCB_01' }
)
}
}
}
]
|