@vgip/meta-ui 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.eslintrc.json +57 -0
  2. package/karma.conf.js +35 -0
  3. package/ng-package.json +10 -0
  4. package/package.json +3 -15
  5. package/src/lib/common/fieldNormalizer/boolean.ts +11 -0
  6. package/src/lib/common/fieldNormalizer/datetime.ts +8 -0
  7. package/src/lib/common/fieldNormalizer/index.ts +171 -0
  8. package/src/lib/common/fieldNormalizer/number.ts +13 -0
  9. package/src/lib/common/fieldNormalizer/options.ts +48 -0
  10. package/src/lib/common/fieldNormalizer/radio.ts +29 -0
  11. package/src/lib/common/fieldNormalizer/reference.ts +32 -0
  12. package/src/lib/common/fieldNormalizer/richtext.ts +15 -0
  13. package/src/lib/common/fieldNormalizer/string.ts +23 -0
  14. package/src/lib/common/fieldNormalizer/text.ts +17 -0
  15. package/src/lib/common/fieldNormalizer/uniqueNameFilter.ts +21 -0
  16. package/src/lib/common/metaAutofocus.directive.ts +31 -0
  17. package/src/lib/common/metaContext.resolver.ts +25 -0
  18. package/src/lib/common/metaIcons.pipe.spec.ts +15 -0
  19. package/src/lib/common/metaIcons.pipe.ts +29 -0
  20. package/src/lib/common/metaModel.pipe.ts +19 -0
  21. package/src/lib/common/metaNormalizer.ts +366 -0
  22. package/src/lib/common/metaStripHtml.pipe.ts +18 -0
  23. package/src/lib/common/utils/colorThemes.ts +86 -0
  24. package/src/lib/common/utils/indexedDbStore/index.ts +244 -0
  25. package/src/lib/common/utils/indexedDbStore/indexedDbStore.spec.ts +149 -0
  26. package/src/lib/common/utils/relativeTimeBuilder.ts +49 -0
  27. package/src/lib/common/utils/resourceCardLabel.ts +25 -0
  28. package/src/lib/common/utils/smartProp.spec.ts +24 -0
  29. package/src/lib/common/utils/smartProp.ts +28 -0
  30. package/src/lib/common/utils/templateBuilder.ts +99 -0
  31. package/src/lib/field.scss +207 -0
  32. package/src/lib/fieldAbstract.ts +327 -0
  33. package/src/lib/fieldBoolean/index.ts +55 -0
  34. package/src/lib/fieldBoolean/style.scss +22 -0
  35. package/src/lib/fieldBoolean/test.spec.ts +43 -0
  36. package/src/lib/fieldBoolean/view.html +30 -0
  37. package/src/lib/fieldComposite/index.ts +86 -0
  38. package/src/lib/fieldComposite/style.scss +6 -0
  39. package/src/lib/fieldComposite/test.spec.ts +43 -0
  40. package/src/lib/fieldComposite/view.html +9 -0
  41. package/src/lib/fieldDatetime/index.ts +359 -0
  42. package/src/lib/fieldDatetime/style.scss +81 -0
  43. package/src/lib/fieldDatetime/test.spec.ts +43 -0
  44. package/src/lib/fieldDatetime/view.html +26 -0
  45. package/src/lib/fieldHidden/index.ts +15 -0
  46. package/src/lib/fieldHidden/view.html +0 -0
  47. package/src/lib/fieldInput/index.ts +477 -0
  48. package/src/lib/fieldInput/style.scss +128 -0
  49. package/src/lib/fieldInput/test.spec.ts +43 -0
  50. package/src/lib/fieldInput/view.html +81 -0
  51. package/src/lib/fieldList/index.ts +73 -0
  52. package/src/lib/fieldList/style.scss +26 -0
  53. package/src/lib/fieldList/test.spec.ts +43 -0
  54. package/src/lib/fieldList/view.html +25 -0
  55. package/src/lib/fieldRadio/index.ts +93 -0
  56. package/src/lib/fieldRadio/style.scss +32 -0
  57. package/src/lib/fieldRadio/test.spec.ts +43 -0
  58. package/src/lib/fieldRadio/view.html +24 -0
  59. package/src/lib/fieldReference/index.ts +871 -0
  60. package/src/lib/fieldReference/style.scss +273 -0
  61. package/src/lib/fieldReference/test.spec.ts +44 -0
  62. package/src/lib/fieldReference/view.html +163 -0
  63. package/src/lib/fieldRichtext/index.ts +98 -0
  64. package/src/lib/fieldRichtext/quill.scss +6 -0
  65. package/src/lib/fieldRichtext/style.scss +87 -0
  66. package/src/lib/fieldRichtext/test.spec.ts +43 -0
  67. package/src/lib/fieldRichtext/view.html +17 -0
  68. package/src/lib/fieldSelect/index.ts +597 -0
  69. package/src/lib/fieldSelect/style.scss +165 -0
  70. package/src/lib/fieldSelect/test.spec.ts +44 -0
  71. package/src/lib/fieldSelect/view.html +128 -0
  72. package/src/lib/fieldText/index.ts +86 -0
  73. package/src/lib/fieldText/style.scss +24 -0
  74. package/src/lib/fieldText/test.spec.ts +43 -0
  75. package/src/lib/fieldText/view.html +23 -0
  76. package/src/lib/fieldUnknown/index.ts +15 -0
  77. package/src/lib/fieldUnknown/test.spec.ts +34 -0
  78. package/src/lib/fieldUnknown/view.html +9 -0
  79. package/src/lib/index.ts +127 -0
  80. package/src/lib/layout/index.ts +255 -0
  81. package/src/lib/layout/style.scss +67 -0
  82. package/src/lib/layout/view.html +45 -0
  83. package/src/lib/metaField/index.ts +133 -0
  84. package/src/lib/metaField/test.spec.ts +32 -0
  85. package/src/lib/refDialog/index.ts +157 -0
  86. package/src/lib/refDialog/style.scss +154 -0
  87. package/src/lib/refDialog/view.html +24 -0
  88. package/src/lib/resource/index.ts +559 -0
  89. package/src/lib/resource/style.scss +132 -0
  90. package/src/lib/resource/view.html +70 -0
  91. package/src/lib/resourceCard/index.ts +44 -0
  92. package/src/lib/resourceCard/style.scss +7 -0
  93. package/src/lib/resourceCard/view.html +14 -0
  94. package/src/lib/services/metaContext/index.ts +61 -0
  95. package/src/lib/services/metaMsg/index.ts +84 -0
  96. package/src/lib/services/metaReference/index.ts +98 -0
  97. package/src/lib/services/metaResource/index.ts +163 -0
  98. package/src/lib/services/metaResource/metaHttpClient.ts +76 -0
  99. package/src/lib/services/metaResource/metaResource.spec.ts +24 -0
  100. package/src/lib/services/metaTracker/index.ts +38 -0
  101. package/src/lib/services/resourceDrafts/index.ts +81 -0
  102. package/src/lib/services/resourceDrafts/resourceDrafts.spec.ts +24 -0
  103. package/src/lib/styles.scss +13 -0
  104. package/src/public-api.ts +5 -0
  105. package/src/test.ts +17 -0
  106. package/tsconfig.lib.json +25 -0
  107. package/tsconfig.lib.prod.json +9 -0
  108. package/tsconfig.spec.json +17 -0
  109. package/fesm2022/vgip-meta-ui.mjs +0 -6079
  110. package/fesm2022/vgip-meta-ui.mjs.map +0 -1
  111. package/index.d.ts +0 -709
@@ -0,0 +1,81 @@
1
+ <div class='vgip-meta-field-preview' *ngIf='preview && model'>
2
+ <div class='vgip-meta-field-label' [title]='meta.label || meta.name'>{{meta.label || meta.name}}</div>
3
+ <div class='vgip-meta-field-value __gu'>
4
+ <a *ngIf="isPhoneNumber; else elseBlock" href='#' (click)="click2dial($event)" class="Vlt-text-link" aria-label='Dial'>
5
+ <svg class="Vlt-icon Vlt-icon--smaller" style="margin-top: -3px;">
6
+ <use xlink:href="volta/volta-icons.svg#Vlt-icon-phone-full" />
7
+ </svg>
8
+ {{model}}
9
+ </a>
10
+ <ng-template #elseBlock>{{model}}</ng-template>
11
+ </div>
12
+ </div>
13
+ <div *ngIf='!preview' class="Vlt-form__element Vlt-form__element--big" [ngClass]="{'Vlt-form__element--error': f.invalid && ((f | metaModel)._parent.submitted || (f | metaModel ).touched), 'multiple': multiple, 'has-value': f.value, active: keyListenerActive }">
14
+ <div *ngIf='multiple' class='items-container'>
15
+ <div *ngIf='model' class='badges-container keep-focus' (click)='focus()'> <!-- eslint-disable-line -->
16
+ <div *ngFor='let item of model' class="Vlt-badge Vlt-badge--transparent Vlt-badge--app Vlt-badge--large keep-focus">
17
+ {{item}}
18
+ <button class="Vlt-badge__dismiss keep-focus" (click)='remove($event, item)'></button> <!-- eslint-disable-line @angular-eslint/template/elements-content -->
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <div class="Vlt-input Vlt-dropdown" style='display: block;' [ngClass]="{'vgip-disable': disabled}">
23
+ <label class='wrapper'>
24
+ <input class='main model' [pattern]="validations.pattern ? validations.pattern.value || validations.pattern : null" [required]='validations.required' [minlength]='validations.minlength' [maxlength]='validations.maxlength' [min]='validations.min' [max]='validations.max' [step]='validations.step' [disabled]='disabled' [readonly]="readonly" [(ngModel)]='model' (ngModelChange)="onModelChange($event)" #f='ngModel' [name]='name' [type]="multiple ? 'hidden' : (logicalSubtype || meta.subtype || 'text')" placeholder=" " (click)='onActivated($event)' (focus)='onActivated($event)' (blur)='onBlur($event)'/>
25
+ <input *ngIf='multiple' class='main' [pattern]="validations.pattern ? validations.pattern.value || validations.pattern : null" [minlength]='validations.minlength' [maxlength]='validations.maxlength' [min]='validations.min' [max]='validations.max' [(ngModel)]='addText' [ngModelOptions]="{ standalone: true }" [type]="logicalSubtype || meta.subtype || 'text'" [disabled]='disabled' [readonly]='readonly' placeholder="+Add" (keydown.enter)='onAdd($event)' (click)='onActivated($event)' (focus)='onActivated($event)' (blur)='onBlur($event)'/>
26
+ <label class='Vlt-truncate'>{{meta.label || meta.name}}<span *ngIf='validations.required' class='Vlt-red'>*</span>&nbsp;<span class='Vlt-black' *ngIf='model && multiple'>({{model.length}})</span></label> <!-- eslint-disable-line @angular-eslint/template/label-has-associated-control -->
27
+ </label>
28
+ <div class='Vlt-composite__append right-actions'>
29
+ <a href='#' *ngIf='model && showClear' class="Vlt-composite__append--icon" (click)='clear($event)'>
30
+ <div class="Vlt-composite__icon">
31
+ <svg><use xlink:href="volta/volta-icons.svg#Vlt-icon-cross"/></svg>
32
+ </div>
33
+ </a>
34
+ </div>
35
+ <!-- <div *ngIf="!meta.subtype || meta.subtype == 'text'" class="Vlt-composite__append Vlt-composite__append--icon" style='bottom: 7px; right: 10px; padding: 3px; width: initial; height: initial; cursor: pointer;'>
36
+ <div *ngIf="!meta.type || meta.type === 'string'" class="Vlt-composite__icon" (click)='textToSpeech()'>
37
+ <svg><use xlink:href="volta/volta-icons.svg#Vlt-icon-microphone"/></svg>
38
+ </div>
39
+ </div> -->
40
+ <div *ngIf="suggestions.length" class="Vlt-dropdown__panel">
41
+ <div class="Vlt-dropdown__panel__content Vlt-dropdown__panel__content--scroll-area suggestions">
42
+ <!-- <div class="Vlt-dropdown__title" style='padding-left: 13px;'>
43
+ Suggestions
44
+ <div class="Vlt-dropdown__close Vlt-white" (click)='dismissDropdown($event)'>
45
+ <svg class='Vlt-icon Vlt-icon--small'><use xlink:href="volta/volta-icons.svg#Vlt-icon-cross"/></svg>
46
+ </div>
47
+ </div> -->
48
+ <div class="Vlt-dropdown__block"></div>
49
+ <div *ngIf='dropdown' class="Vlt-dropdown__scroll">
50
+ <a href='#' [ngClass]="{ 'Vlt-dropdown__link--selected': (activeSuggestionIndex === i) }" (click)='onSuggestionSelect($event, suggestion)' *ngFor='let suggestion of suggestions; let i = index' class="Vlt-dropdown__link" style='padding: 0;'>
51
+ <div *ngIf='multiple' class="Vlt-checkbox" style='width: 100%;'>
52
+ <label [title]='suggestion.label || suggestion'>
53
+ <span class="Vlt-checkbox__button">
54
+ <input type="checkbox" [checked]='model && model.indexOf(suggestion) !== -1'/>
55
+ <span class="Vlt-checkbox__icon"></span>
56
+ </span>
57
+ {{suggestion.label || suggestion}}
58
+ </label>
59
+ </div>
60
+ <div *ngIf='!multiple' style='padding: 12px 20px;'>
61
+ {{suggestion.label || suggestion}}
62
+ </div>
63
+ </a>
64
+ </div>
65
+ <div *ngIf='!multiple' class="Vlt-dropdown__block"></div>
66
+ <div *ngIf='multiple' class="Vlt-dropdown__block Vlt-dropdown__block--nowrap" style='padding: 8px 16px 16px;'>
67
+ <button (click)='clear($event)' type='button' class="Vlt-btn Vlt-btn--secondary Vlt-btn--app Vlt-btn--small Vlt-btn--outline">Clear all</button>
68
+ <button (click)='dismissDropdown($event)' type='button' class="Vlt-btn Vlt-btn--secondary Vlt-btn--app Vlt-btn--small">Done</button>
69
+ </div>
70
+ </div>
71
+ </div>
72
+ </div>
73
+ <small *ngIf='f.invalid && ((f | metaModel)._parent.submitted || ((f | metaModel ).touched && keyListenerActive))' class="Vlt-form__element__error">
74
+ <span *ngIf="f.errors.required">Required.&nbsp;</span>
75
+ <span *ngIf="f.errors.minlength">Must be longer than {{validations.minlength}} characters.&nbsp;</span>
76
+ <span *ngIf="f.errors.maxlength">Must be lest than {{validations.maxlength}} characters.&nbsp;</span>
77
+ <span *ngIf="f.errors.pattern">{{ validations.pattern.text || "Should match '"+validations.pattern+"' pattern." }}.&nbsp;</span>
78
+ <span *ngIf="f.errors.custom">{{f.errors.custom}}&nbsp;</span>
79
+ </small>
80
+ <small *ngIf='meta.hint' class="Vlt-form__element__hint">{{meta.hint}}</small>
81
+ </div>
@@ -0,0 +1,73 @@
1
+ import { Component, OnInit } from '@angular/core';
2
+ import { FieldAbstract } from '../fieldAbstract';
3
+ import { ControlContainer, NgForm } from '@angular/forms';
4
+
5
+ @Component({
6
+ templateUrl: './view.html',
7
+ styleUrls: ['./style.scss'],
8
+ viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
9
+ standalone: false
10
+ })
11
+ export class FieldList extends FieldAbstract implements OnInit {
12
+ items: Array<any> = [];
13
+ value: any;
14
+
15
+ get list() {
16
+ return this.meta.list || this.meta.reference;
17
+ }
18
+
19
+ get cloneList() {
20
+ return JSON.parse(JSON.stringify(this.list));
21
+ }
22
+
23
+ ngOnInit() {
24
+ this.scope += (typeof(this.index) === 'undefined') ? `${this.meta.name}_` : `${this.meta.name}[${this.index}]_`;
25
+ const origValue = this.parent[this.meta.name];
26
+ Object.defineProperty(this.parent, this.meta.name, {
27
+ set: (value) => {
28
+ this.model = [];
29
+ if (value && value.length) {
30
+ for (const i of value) {
31
+ if (this.model.indexOf(i) === -1) {
32
+ this.model.push(i);
33
+ }
34
+ }
35
+ }
36
+ this.value = this.model;
37
+ this.meta.$optional = this.isOptional;
38
+ },
39
+ get: () => this.value,
40
+ enumerable: true,
41
+ configurable: true
42
+ });
43
+ if (origValue) {
44
+ this.parent[this.meta.name] = origValue;
45
+ }
46
+ if (!this.model && this.validations.min) {
47
+ for (let i = 0; i < this.validations.min; i++) {
48
+ this.add();
49
+ }
50
+ }
51
+ }
52
+
53
+ add() {
54
+ if (!this.model) {
55
+ this.model = [];
56
+ }
57
+ if (!this.validations.max || (this.validations.max > this.model.length)) {
58
+ this.model.push({});
59
+ this.value = this.model;
60
+ }
61
+ this.onChange.emit(this.model);
62
+ }
63
+
64
+ remove(itemIndex) {
65
+ this.model.splice(itemIndex, 1);
66
+ this.value = this.model;
67
+ this.onChange.emit(this.model);
68
+ }
69
+
70
+ onChildChange() {
71
+ this.onChange.emit(this.model);
72
+ }
73
+ }
@@ -0,0 +1,26 @@
1
+ .Vlt-btn--link:not([disabled]) {
2
+ svg {
3
+ fill: #e84545;
4
+ }
5
+ &:hover svg {
6
+ fill: #de1c1c;
7
+ }
8
+ }
9
+ .item-add-button {
10
+ background-color: var(--vgip-meta-input-action-hover-bg-color);
11
+ color: var(--vgip-meta-input-color);
12
+ svg {
13
+ fill: var(--vgip-meta-input-color);
14
+ }
15
+ &:hover {
16
+ transform: scale(1.02);
17
+ box-shadow: inset 0 0 0 1px var(--vgip-meta-input-active-border-color);
18
+ }
19
+ }
20
+
21
+ .item-remove-button {
22
+ border: 0;
23
+ &:disabled {
24
+ cursor: not-allowed;
25
+ }
26
+ }
@@ -0,0 +1,43 @@
1
+ /*
2
+ * @Author: Alexander.Vangelov@vonage.com
3
+ * @Date: 2019-09-19 17:35:19
4
+ * @Last Modified by: Alexander.Vangelov@vonage.com
5
+ * @Last Modified time: 2022-01-19 08:54:10
6
+ */
7
+
8
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
9
+ import { NgForm } from '@angular/forms';
10
+
11
+ import { MetaModule } from '..';
12
+
13
+ import { FieldList } from '../fieldList';
14
+
15
+ describe('FieldList', () => {
16
+ let component: FieldList;
17
+ let fixture: ComponentFixture<FieldList>;
18
+
19
+ beforeEach(waitForAsync(() => {
20
+ TestBed.configureTestingModule({
21
+ declarations: [],
22
+ imports: [
23
+ MetaModule
24
+ ],
25
+ providers: [
26
+ { provide: NgForm, useValue: new NgForm([], []) }
27
+ ]
28
+ })
29
+ .compileComponents();
30
+ }));
31
+
32
+ beforeEach(() => {
33
+ fixture = TestBed.createComponent(FieldList);
34
+ component = fixture.componentInstance;
35
+ component.parent = {};
36
+ component.meta = { name: 'f1', list: [ { name: 'f2' }] };
37
+ fixture.detectChanges();
38
+ });
39
+
40
+ it('should create', () => {
41
+ expect(component).toBeTruthy();
42
+ });
43
+ });
@@ -0,0 +1,25 @@
1
+ <div *ngIf='true' class="Vlt-form__element" [ngClass]="{ 'Vlt-form__element--error': (f | metaModel)._parent.submitted && f.invalid }">
2
+ <label class="Vlt-label">{{meta.label || meta.name}} ({{(model || []).length}})<span *ngIf='validations.required' class='Vlt-red'>*</span></label> <!-- eslint-disable-line @angular-eslint/template/label-has-associated-control -->
3
+ <small style='margin-bottom: 4px;' *ngIf='meta.hint' class="Vlt-form__element__hint">{{meta.hint}}</small>
4
+ <input class='model' type='hidden' [required]='validations.required' [(ngModel)]='model' #f='ngModel' [name]='name' />
5
+ <ng-container *ngIf='model'>
6
+ <div *ngFor='let item of model; let i = index;' style='display: flex; border-bottom: 1px solid var(--vgip-meta-separator-color);'>
7
+ <vgip-meta-field style='flex: 1;' [index]='i' [scope]='scope' [meta]='cloneList' [parent]='item' [integrationCode]='integrationCode' [resourceType]='meta.resourceType || resourceType' theme='inherit' [preview]='preview' (onChange)='onChildChange()'></vgip-meta-field>
8
+ <vgip-meta-field *ngIf='meta.selectable' [meta]="{ name: meta.selectable.name, label: ' ', type: 'radio', options: [ { id: meta.selectable.value, label: meta.selectable.label } ] }" [parent]='item' [integrationCode]='integrationCode' theme='inherit' style='margin-left: 12px; margin-top: 12px; margin-right: -12px;' (onChange)='onChildChange()'></vgip-meta-field>
9
+ <div *ngIf='!preview' style='padding-left: 12px; margin-top: 3px;'>
10
+ <button type='button' (click)='remove(i)' class="Vlt-btn Vlt-btn--link item-remove-button" [disabled]='model.length === (validations.min || 0)' aria-label='Remove'>
11
+ <svg><use xlink:href="volta/volta-icons.svg#Vlt-icon-bin"/></svg>
12
+ </button>
13
+ </div>
14
+ </div>
15
+ </ng-container>
16
+ <button *ngIf='!preview && (!validations.max || !model || model.length < validations.max)' style='width: 100%;' type='button' (click)='add()' class="Vlt-btn Vlt-btn--small Vlt-btn--tertiary Vlt-btn--app Vlt-btn--no-focus item-add-button" [disabled]='validations.max && model && model.length === validations.max'>
17
+ <svg><use xlink:href="volta/volta-icons.svg#Vlt-icon-plus"/></svg>{{list.label}}
18
+ </button>
19
+ <small *ngIf='(f | metaModel)._parent.submitted && f.invalid' class="Vlt-form__element__error">
20
+ <span *ngIf="f.errors.required">Required</span>
21
+ <span *ngIf="f.errors.maxlength">Length can not exceed {{validations.maxlength}} characters</span>
22
+ <span *ngIf="f.errors.custom">{{f.errors.custom}}&nbsp;</span>
23
+ </small>
24
+ <small *ngIf='meta.helpText' class="Vlt-form__element__hint">{{meta.helpText}}</small>
25
+ </div>
@@ -0,0 +1,93 @@
1
+ /*
2
+ * @Author: Alexander.Vangelov@vonage.com
3
+ * @Date: 2019-09-19 17:35:19
4
+ * @Last Modified by: Alexander.Vangelov@vonage.com
5
+ * @Last Modified time: 2020-03-26 12:56:38
6
+ */
7
+
8
+ import { Component, OnInit } from '@angular/core';
9
+ import { ControlContainer, NgForm } from '@angular/forms';
10
+
11
+ import { FieldAbstract } from '../fieldAbstract';
12
+
13
+ @Component({
14
+ templateUrl: './view.html',
15
+ styleUrls: ['./style.scss'],
16
+ viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
17
+ standalone: false
18
+ })
19
+
20
+ export class FieldRadio extends FieldAbstract implements OnInit {
21
+ // @Input() meta: any;
22
+ value: any;
23
+
24
+ get options() {
25
+ return this.meta.options || this.meta.picklist;
26
+ }
27
+
28
+ ngOnInit() {
29
+ this.validationAttributes = ['required'];
30
+ const origValue = this.parent[this.meta.name];
31
+ Object.defineProperty(this.parent, this.meta.name, {
32
+ set: (value) => {
33
+ if (value) {
34
+ for (const o of this.options) {
35
+ if ((value.id || value) === (o.id || o.value || o.name || o)) {
36
+ this.model = o;
37
+ this.value = this.modelToValue(o, this.meta.valueType);
38
+ break;
39
+ }
40
+ }
41
+ } else {
42
+ delete this.model;
43
+ delete this.value;
44
+ }
45
+ this.meta.$optional = this.isOptional;
46
+ },
47
+ get: () => this.value,
48
+ enumerable: this.sendToServer,
49
+ configurable: true
50
+ });
51
+
52
+ if (origValue) {
53
+ this.parent[this.meta.name] = origValue;
54
+ }
55
+
56
+ if (this.default && !this.model) {
57
+ setTimeout(() => {
58
+ this.parent[this.meta.name] = this.meta.valueType === 'object' ? this.default : (this.default.id || this.default);
59
+ setTimeout(() => {
60
+ this.onModelChange(this.model);
61
+ }, 0);
62
+ }, 0);
63
+ }
64
+ }
65
+
66
+ onOptionChange(model) {
67
+ this.model = model;
68
+ this.onModelChange(this.model);
69
+ }
70
+
71
+ onActivated(ev) {
72
+ if (!this.keyListenerActive) {
73
+ ev.srcElement.addEventListener('keydown', this.keydown);
74
+ }
75
+ }
76
+
77
+ onBlur(ev) {
78
+ if (this.keyListenerActive) {
79
+ ev.srcElement.removeEventListener('keydown', this.keydown);
80
+ }
81
+ }
82
+
83
+ private keydown = (event) => {
84
+ switch (event.key) {
85
+ case 'Backspace': {
86
+ event.preventDefault();
87
+ event.stopPropagation();
88
+ this.clear();
89
+ break;
90
+ }
91
+ }
92
+ };
93
+ }
@@ -0,0 +1,32 @@
1
+ .Vlt-form__element {
2
+ padding-bottom: 4px;
3
+ }
4
+ .Vlt-form__element__hint {
5
+ margin-top: 4px;
6
+ }
7
+ .Vlt-form__element__error {
8
+ margin-top: 4px;
9
+ }
10
+ .Vlt-radio--inline {
11
+ margin-bottom: 4px;
12
+ }
13
+
14
+ .Vlt-radio {
15
+ .Vlt-radio__icon {
16
+ border-color: var(--vgip-meta-input-border-color);
17
+ }
18
+ &:hover {
19
+ .Vlt-radio__icon {
20
+ border-color: var(--vgip-meta-input-active-border-color);
21
+ }
22
+ }
23
+ input:checked ~ .Vlt-radio__icon {
24
+ border-color: var(--vgip-meta-input-active-border-color);
25
+ &:after {
26
+ background: var(--vgip-meta-input-active-border-color);
27
+ }
28
+ }
29
+ input:focus + .Vlt-radio__icon, input:active + .Vlt-radio__icon {
30
+ background: var(--vgip-meta-input-bg-color)
31
+ }
32
+ }
@@ -0,0 +1,43 @@
1
+ /*
2
+ * @Author: Alexander.Vangelov@vonage.com
3
+ * @Date: 2019-09-19 17:35:19
4
+ * @Last Modified by: Alexander.Vangelov@vonage.com
5
+ * @Last Modified time: 2019-11-13 14:58:27
6
+ */
7
+
8
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
9
+ import { NgForm } from '@angular/forms';
10
+
11
+ import { MetaModule } from '..';
12
+
13
+ import { FieldRadio } from '.';
14
+
15
+ describe('FieldInput', () => {
16
+ let component: FieldRadio;
17
+ let fixture: ComponentFixture<FieldRadio>;
18
+
19
+ beforeEach(waitForAsync(() => {
20
+ TestBed.configureTestingModule({
21
+ declarations: [],
22
+ imports: [
23
+ MetaModule
24
+ ],
25
+ providers: [
26
+ { provide: NgForm, useValue: new NgForm([], []) }
27
+ ]
28
+ })
29
+ .compileComponents();
30
+ }));
31
+
32
+ beforeEach(() => {
33
+ fixture = TestBed.createComponent(FieldRadio);
34
+ component = fixture.componentInstance;
35
+ component.parent = {};
36
+ component.meta = { name: 'f1' };
37
+ fixture.detectChanges();
38
+ });
39
+
40
+ it('should create', () => {
41
+ expect(component).toBeTruthy();
42
+ });
43
+ });
@@ -0,0 +1,24 @@
1
+ <div class='vgip-meta-field-preview' *ngIf='preview && model'>
2
+ <div class='vgip-meta-field-label' [title]='meta.label || meta.name'>{{meta.label || meta.name}}</div>
3
+ <div class='vgip-meta-field-value __gu'>
4
+ {{ model.label || model }}
5
+ </div>
6
+ </div>
7
+ <div *ngIf='!preview' class="Vlt-form__element" [ngClass]="{ 'Vlt-form__element--error': f && f.invalid && ((f | metaModel)._parent.submitted || (f | metaModel ).touched) }">
8
+ <label class="Vlt-label">{{meta.label || meta.name}}<span *ngIf='validations.required' class='Vlt-red'>*</span></label> <!-- eslint-disable-line @angular-eslint/template/label-has-associated-control -->
9
+ <input class='model' type='hidden' [required]='validations.required' [(ngModel)]='model' #f='ngModel' [name]='name' />
10
+ <fieldset *ngFor='let option of options' class="Vlt-radio Vlt-radio--inline">
11
+ <label style='cursor: pointer;'>
12
+ <span class="Vlt-radio__button">
13
+ <input class='main' (change)='onOptionChange(option)' type="radio" [checked]='option === model' [value]='option' [name]='name' (focus)='onActivated($event)' (blur)='onBlur($event)'/>
14
+ <span class="Vlt-radio__icon"></span>
15
+ </span>
16
+ <span style='white-space: nowrap;'>{{option.label || option}}</span>
17
+ </label>
18
+ </fieldset>
19
+ <small *ngIf='f && f.invalid && ((f | metaModel)._parent.submitted || (f | metaModel ).touched)' class="Vlt-form__element__error">
20
+ <span *ngIf="f.errors.required">Required.&nbsp;</span>
21
+ <span *ngIf="f.errors.custom">{{f.errors.custom}}&nbsp;</span>
22
+ </small>
23
+ <small *ngIf='meta.hint' class="Vlt-form__element__hint">{{meta.hint}}</small>
24
+ </div>