@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,86 @@
1
+ import { Component, OnInit, DoCheck } from '@angular/core';
2
+ import { FieldAbstract } from '../fieldAbstract';
3
+
4
+ @Component({
5
+ templateUrl: './view.html',
6
+ styleUrls: ['./style.scss'],
7
+ standalone: false
8
+ })
9
+ export class FieldComposite extends FieldAbstract implements OnInit, DoCheck {
10
+ // @Input() meta: any;
11
+ // @Input() parent: any;
12
+ value: any;
13
+ private invisible;
14
+
15
+ get isRow() {
16
+ return this.meta.subtype !== 'column';
17
+ }
18
+
19
+ get fields() {
20
+ return (this.meta.fields || []).map((f) => {
21
+ if (f.type === 'textarea') { // no textareas inside composite (use string)
22
+ delete f.type;
23
+ }
24
+ return f;
25
+ });
26
+ }
27
+
28
+ ngOnInit() {
29
+ // super.ngOnInit()
30
+ let nestedFieldsRegex: RegExp;
31
+ if (this.meta.name) {
32
+ this.scope += `${this.meta.name}_`;
33
+ this.value = this.parent[this.meta.name] || {};
34
+ nestedFieldsRegex = new RegExp(`^${this.meta.name}\\.(.*)`);
35
+ Object.defineProperty(this.parent, this.meta.name, {
36
+ set: (value) => {
37
+ if (value) {
38
+ for (const v of Object.keys(value)) {
39
+ this.value[v] = value[v];
40
+ }
41
+ }
42
+ },
43
+ get: () => {
44
+ if (JSON.stringify(this.value) !== '{}') {
45
+ return this.value;
46
+ }
47
+ },
48
+ enumerable: this.sendToServer,
49
+ configurable: true
50
+ });
51
+ for (const f of this.meta.fields) {
52
+ if (this.isRow) {
53
+ if (f.type === 'text') {
54
+ f.type = 'string';
55
+ }
56
+ }
57
+ const nestedFieldMatch = (f.name || '').match(nestedFieldsRegex);
58
+ if (nestedFieldMatch) {
59
+ f.name = nestedFieldMatch[1]; // for VGIS V2 backward compatibility normalize name with dotted syntax
60
+ }
61
+ }
62
+ } else {
63
+ this.value = this.parent;
64
+ }
65
+ }
66
+
67
+ ngDoCheck(): void {
68
+ if (typeof (this.invisible) !== 'undefined') {
69
+ if (this.invisible !== this.meta.$invisible) {
70
+ if (this.meta.$invisible === false) {
71
+ if (typeof (this.meta.name) !== 'undefined') {
72
+ this.parent[this.meta.name] = this.value;
73
+ }
74
+ }
75
+ this.invisible = this.meta.$invisible;
76
+ }
77
+ } else {
78
+ this.invisible = this.meta.$invisible;
79
+ }
80
+ }
81
+
82
+ onValueChange(): void {
83
+ this.onChange.emit(this.value);
84
+ }
85
+
86
+ }
@@ -0,0 +1,6 @@
1
+ div > vgip-meta-field {
2
+ display: none;
3
+ &.shown {
4
+ display: initial;
5
+ }
6
+ }
@@ -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:55: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 { FieldComposite } from '../fieldComposite';
14
+
15
+ describe('FieldComposite', () => {
16
+ let component: FieldComposite;
17
+ let fixture: ComponentFixture<FieldComposite>;
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(FieldComposite);
34
+ component = fixture.componentInstance;
35
+ component.parent = {};
36
+ component.meta = { fields: [{ name: 'f2' }] };
37
+ fixture.detectChanges();
38
+ });
39
+
40
+ it('should create', () => {
41
+ expect(component).toBeTruthy();
42
+ });
43
+ });
@@ -0,0 +1,9 @@
1
+ <div [ngClass]="{ 'Vlt-grid Vlt-grid--narrow': isRow }">
2
+ <ng-container *ngFor='let field of fields'>
3
+ <div style='margin: 0;' [ngClass]="{ 'Vlt-col': isRow, 'Vlt-col--1of3': isRow && fields.length > 3 }" *ngIf="!field.$invisible">
4
+ <vgip-meta-field *ngIf='!meta.$invisible' [ngClass]="{ shown: !field.$invisible}" [index]='index' [scope]='scope' [meta]='field'
5
+ [parent]='value' [integrationCode]='integrationCode' [resourceType]='resourceType' [preview]='preview' (onChange)='onValueChange()'
6
+ theme='inherit'></vgip-meta-field>
7
+ </div>
8
+ </ng-container>
9
+ </div>
@@ -0,0 +1,359 @@
1
+ /*
2
+ * @Author: Alexander.Vangelov@vonage.com
3
+ * @Date: 2020-04-18 18:05:46
4
+ * @Last Modified by: Alexander.Vangelov@vonage.com
5
+ * @Last Modified time: 2020-04-18 21:09:16
6
+ */
7
+
8
+ import { Component, OnInit } from '@angular/core';
9
+ import { ControlContainer, NgForm } from '@angular/forms';
10
+
11
+ import { FieldAbstract } from '../fieldAbstract';
12
+ import { relativeTimeBuilder } from '../common/utils/relativeTimeBuilder';
13
+
14
+ @Component({
15
+ templateUrl: './view.html',
16
+ styleUrls: ['./style.scss'],
17
+ viewProviders: [{ provide: ControlContainer, useExisting: NgForm }],
18
+ standalone: false
19
+ })
20
+ export class FieldDatetime extends FieldAbstract implements OnInit {
21
+ input: any;
22
+ dropdown: any;
23
+ activeSuggestionIndex: number;
24
+ value: any;
25
+ type: string;
26
+ placeholder = 'dd/mm/yyyy';
27
+
28
+ get suggestions() {
29
+ return this.meta.suggestions || [];
30
+ }
31
+
32
+ ngOnInit() {
33
+ this.validationAttributes = ['required', 'min', 'max', 'step'];
34
+ this.type = this.meta.type;
35
+ if (this.meta.type === 'datetime') {
36
+ this.type = 'datetime-local';
37
+ this.placeholder += ' --:-- --';
38
+ } else if (this.meta.type === 'time') {
39
+ this.placeholder = '--:-- --';
40
+ }
41
+ const origValue = this.parent[this.meta.name];
42
+ Object.defineProperty(this.parent, this.meta.name, {
43
+ set: (value) => {
44
+ if (value) {
45
+ if (['datetime', 'date', 'datetime-local'].indexOf(this.meta.type || this.meta.subtype) !== -1 && value) {
46
+ try {
47
+ let date: Date;
48
+ if ((typeof (value) === 'number')) {
49
+ date = new Date(parseInt(value as any, 10));
50
+ if ('date' === (this.meta.type || this.meta.subtype)) {
51
+ date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
52
+ }
53
+ } else {
54
+ if ('date' === (this.meta.type || this.meta.subtype)) {
55
+ date = new Date(Date.parse(value));
56
+ } else {
57
+ date = new Date(Date.parse(`${value}Z`) + (new Date().getTimezoneOffset() * 60000));
58
+ }
59
+ }
60
+ switch (this.meta.type || this.meta.subtype) {
61
+ case 'datetime-local':
62
+ case 'datetime': {
63
+ this.model = `${date.getFullYear()}-${('00' + (date.getMonth() + 1)).slice(-2)}-${('00' + date.getDate()).slice(-2)}`;
64
+ this.model += `T${('00' + date.getHours()).slice(-2)}:${('00' + date.getMinutes()).slice(-2)}`;
65
+ break;
66
+ }
67
+ case 'date': {
68
+ this.model = date.toISOString().split('T')[0];
69
+ break;
70
+ }
71
+ }
72
+ if (this.meta.valueType === 'isostring') {
73
+ this.value = date.toISOString();
74
+ } else if (this.meta.valueType === 'string') {
75
+ if ((this.meta.type || this.meta.subtype) === 'date') {
76
+ this.value = date.toISOString().split('T')[0];
77
+ } else {
78
+ this.value = date.toISOString();
79
+ }
80
+ } else {
81
+ if ((this.meta.type || this.meta.subtype) === 'date') {
82
+ date.setFullYear(date.getUTCFullYear());
83
+ date.setMonth(date.getUTCMonth());
84
+ date.setDate(date.getUTCDate());
85
+ date.setMinutes(0);
86
+ date.setHours(0);
87
+ date.setSeconds(0);
88
+ date.setMilliseconds(0);
89
+ this.value = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).getTime();
90
+ } else {
91
+ this.value = date.getTime();
92
+ }
93
+ }
94
+ } catch (e) {
95
+ console.error('Date parse error', e.message, `"${value}"`, `(${typeof (value)})`);
96
+ }
97
+ } else if ('time' === (this.meta.type || this.meta.subtype)) {
98
+ try {
99
+ let date: Date;
100
+ if (typeof (value) === 'number') {
101
+ date = new Date(parseInt(value as any, 10));
102
+ if (value < 86400000) {
103
+ date = new Date(date.getTime() + (date.getTimezoneOffset() * 60000));
104
+ }
105
+ } else {
106
+ date = new Date(
107
+ Date.parse(new Date().toISOString().replace(/T.*Z/, `T${value}Z`)) + (new Date().getTimezoneOffset() * 60000)
108
+ );
109
+ }
110
+ this.model = date.toTimeString().split(' ')[0];
111
+ if (this.meta.valueType === 'isostring') {
112
+ this.value = date.toISOString();
113
+ } else {
114
+ date.setFullYear(1970);
115
+ date.setMonth(0);
116
+ date.setDate(1);
117
+ date.setMilliseconds(0);
118
+ if (this.meta.valueType === 'string') {
119
+ this.value = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().split('T')[1].substring(0,8);
120
+ } else {
121
+ this.value = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).getTime();
122
+ }
123
+ }
124
+ } catch (e) {
125
+ console.error('Date parse error', e.message, `"${value}"`, `(${typeof (value)})`);
126
+ }
127
+ }
128
+ } else {
129
+ delete this.model;
130
+ delete this.value;
131
+ }
132
+ this.meta.$optional = this.isOptional;
133
+ },
134
+ get: () => this.value,
135
+ enumerable: this.sendToServer,
136
+ configurable: true
137
+ });
138
+ if (typeof(origValue) !== 'undefined') {
139
+ this.parent[this.meta.name] = origValue;
140
+ }
141
+ const d = this.meta.default || this.meta.defaultValue;
142
+ if (d && typeof(this.model) === 'undefined') {
143
+ const defaultValue = ((typeof (d) === 'string') || (typeof (d) === 'number')) ? d : (d.id || d.value);
144
+ if (defaultValue || defaultValue === 0) {
145
+ if (/^(date|time)/.test(this.meta.type || this.meta.subtype) && typeof(defaultValue) === 'string') {
146
+ this.parent[this.meta.name] = relativeTimeBuilder(this.meta.type || this.meta.subtype, defaultValue, this.validations.step);
147
+ } else {
148
+ this.parent[this.meta.name] = defaultValue;
149
+ }
150
+ }
151
+ }
152
+ if (typeof(this.meta.auto) === 'object') {
153
+ Object.keys(this.meta.auto || {}).filter(n => ['gt', 'lt'].indexOf(n) !== -1).map(v => this.setupLogicalValidation(v));
154
+ }
155
+ }
156
+
157
+ onActivated(ev) {
158
+ this.input = ev.srcElement;
159
+ if (!this.dropdown) {
160
+ this.dropdown = ev.srcElement.parentNode.parentNode;
161
+ }
162
+ this.showDropdown();
163
+ }
164
+
165
+ clear(ev?) {
166
+ delete this.model;
167
+ this.onModelChange(this.model);
168
+ if (ev) {
169
+ ev.preventDefault();
170
+ ev.stopPropagation();
171
+ return false;
172
+ }
173
+ }
174
+
175
+ onBlur(ev) {
176
+ let internalControl = false;
177
+ if (ev.relatedTarget) {
178
+ if (!this.elementRef.nativeElement.contains(ev.relatedTarget)) {
179
+ this.dismissDropdown();
180
+ } else {
181
+ internalControl = true;
182
+ }
183
+ }
184
+ if (this.keyListenerActive && !internalControl) {
185
+ this.input.removeEventListener('keydown', this.keydown);
186
+ setTimeout(() => {
187
+ if (!this.keyListenerActive) {
188
+ document.removeEventListener('click', this.clickout);
189
+ }
190
+ }, 400);
191
+ delete this.keyListenerActive;
192
+ }
193
+ }
194
+
195
+ onSuggestionSelect(ev, suggestion) {
196
+ if (!suggestion) {
197
+ return;
198
+ }
199
+ ev.preventDefault();
200
+ ev.stopPropagation();
201
+ this.focus();
202
+ this.dismissDropdown();
203
+ this.model = suggestion;
204
+ this.onModelChange(suggestion);
205
+ }
206
+
207
+ dismissDropdown(event?) {
208
+ if (event) {
209
+ this.focus();
210
+ }
211
+ if (this.dropdown) {
212
+ this.dropdown.classList.remove('Vlt-dropdown--expanded');
213
+ }
214
+ }
215
+
216
+ private ensureDropdownIsVisible() {
217
+ setTimeout(() => {
218
+ const holder = this.dropdown.closest('.Vlt-card__content, .Vlt-modal__content');
219
+ if (holder) {
220
+ const el = this.elementRef.nativeElement.querySelector('.Vlt-dropdown__panel');
221
+ const elRect = el.getBoundingClientRect();
222
+ const holderRect = holder.getBoundingClientRect();
223
+ if (holderRect.top + holderRect.height < elRect.top + elRect.height) {
224
+ el.scrollIntoView({ block: 'end' });
225
+ }
226
+ }
227
+ }, 400);
228
+ }
229
+
230
+ private showDropdown() {
231
+ if (this.meta.suggestions?.length) {
232
+ this.dropdown.classList.add('Vlt-dropdown--expanded');
233
+ this.ensureDropdownIsVisible();
234
+ }
235
+ if (!this.keyListenerActive) {
236
+ this.input.addEventListener('keydown', this.keydown);
237
+ setTimeout(() => {
238
+ document.addEventListener('click', this.clickout);
239
+ }, 200);
240
+ this.keyListenerActive = true;
241
+ if (this.parent[this.meta.name]) {
242
+ for (let suggestionIndex = 0; suggestionIndex < (this.meta.suggestions || []).length; suggestionIndex++) {
243
+ if (this.meta.suggestions[suggestionIndex] === this.parent[this.meta.name]) {
244
+ this.activeSuggestionIndex = suggestionIndex;
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ private clickout = (event) => {
252
+ if (event.target.className === 'Vlt-dropdown__link' && this.elementRef.nativeElement.contains(event.target)) {
253
+ this.focus();
254
+ // this.dismissDropdown();
255
+ // this.parent[this.meta.name] = event.target.textContent;
256
+
257
+ } else if (event.target !== this.input && event.target.className !== 'Vlt-dropdown__title') {
258
+ this.dismissDropdown();
259
+ } else {
260
+ this.focus();
261
+ }
262
+ };
263
+
264
+ private keydown = (event) => {
265
+ switch (event.key) {
266
+ case 'ArrowDown': {
267
+ if (['datetime', 'time', 'date', 'datetime-local'].indexOf(this.meta.type || this.meta.subtype) !== -1) {
268
+ break;
269
+ }
270
+ this.showDropdown();
271
+ event.preventDefault();
272
+ if (typeof (this.activeSuggestionIndex) === 'undefined') {
273
+ this.activeSuggestionIndex = 0;
274
+ } else {
275
+ this.activeSuggestionIndex++;
276
+ if (this.activeSuggestionIndex >= this.suggestions.length) {
277
+ this.activeSuggestionIndex = 0;
278
+ }
279
+ }
280
+ break;
281
+ }
282
+ case 'ArrowUp': {
283
+ if (['datetime', 'time', 'date', 'datetime-local'].indexOf(this.meta.type || this.meta.subtype) !== -1) {
284
+ break;
285
+ }
286
+ this.showDropdown();
287
+ event.preventDefault();
288
+ if (typeof (this.activeSuggestionIndex) === 'undefined') {
289
+ this.activeSuggestionIndex = this.suggestions.length - 1;
290
+ } else {
291
+ this.activeSuggestionIndex--;
292
+ if (this.activeSuggestionIndex < 0) {
293
+ this.activeSuggestionIndex = this.suggestions.length - 1;
294
+ }
295
+ }
296
+ break;
297
+ }
298
+ case 'Space':
299
+ case 'Enter': {
300
+ if (typeof (this.activeSuggestionIndex) !== 'undefined') {
301
+ event.preventDefault();
302
+ event.stopPropagation();
303
+ this.onSuggestionSelect(event, this.suggestions[this.activeSuggestionIndex]);
304
+ delete this.activeSuggestionIndex;
305
+ }
306
+ break;
307
+ }
308
+ case 'Escape': {
309
+ event.preventDefault();
310
+ event.stopPropagation();
311
+ this.dismissDropdown();
312
+ break;
313
+ }
314
+ }
315
+ };
316
+
317
+
318
+ private autoSetValue(againstTimestamp, v, cfg) {
319
+ const compareValue = relativeTimeBuilder(this.meta.type, cfg.offset, this.validations.step, againstTimestamp);
320
+ if (this.model) {
321
+ const currentValue = new Date(this.model).getTime();
322
+ let isInvalid: boolean;
323
+ if (v === 'gt') {
324
+ isInvalid = compareValue > currentValue;
325
+ } else if (v === 'lt') {
326
+ isInvalid = currentValue > compareValue;
327
+ }
328
+ if (isInvalid) {
329
+ this.parent[this.meta.name] = compareValue;
330
+ }
331
+ } else {
332
+ this.parent[this.meta.name] = compareValue;
333
+ }
334
+ }
335
+
336
+ private setupLogicalValidation(v: string) {
337
+ const cfg = this.meta.auto[v];
338
+ if (typeof(cfg.against) === 'string') {
339
+ let againstValue = this.parent[cfg.against];
340
+ try {
341
+ let againstTimestamp = Date.parse(`${againstValue}Z`) + (new Date().getTimezoneOffset() * 60000);
342
+ if (againstValue) {
343
+ this.autoSetValue(againstTimestamp, v, cfg);
344
+ }
345
+ this.parentChangeSubject.subscribe((value) => {
346
+ if (value && value.hasOwnProperty(cfg.against)) {
347
+ againstValue = value[cfg.against];
348
+ if (againstValue) {
349
+ againstTimestamp = Date.parse(`${againstValue}Z`) + (new Date().getTimezoneOffset() * 60000);
350
+ this.autoSetValue(againstTimestamp, v, cfg);
351
+ }
352
+ }
353
+ });
354
+ } catch (e) {
355
+ if ((window as any).scDebug) console.error(e);
356
+ }
357
+ }
358
+ }
359
+ }
@@ -0,0 +1,81 @@
1
+ .Vlt-form__element--big {
2
+ &.Vlt-form__element--error {
3
+ input.main, .Vlt-composite__append button {
4
+ background: var(--vgip-meta-input-bg-color);
5
+ border-color: #f25a6b;
6
+ box-shadow: none;
7
+ }
8
+ }
9
+ }
10
+
11
+ @-moz-document url-prefix() {
12
+ .Vlt-composite__append.right-actions {
13
+ right: 10px !important;
14
+ }
15
+ }
16
+
17
+ .Vlt-composite__append.right-actions {
18
+ position: absolute;
19
+ top: 5px;
20
+ right: 10px;
21
+ cursor: pointer;
22
+ @media screen and (-webkit-min-device-pixel-ratio:0) and (min-resolution:.001dpcm) {
23
+ right: 53px;
24
+ }
25
+ .Vlt-composite__append--icon {
26
+ width: 36px;
27
+ outline: none;
28
+ position: initial;
29
+ display: inline-block;
30
+ svg {
31
+ height: 14px;
32
+ width: 14px;
33
+ }
34
+ }
35
+ .Vlt-composite__append--icon:hover svg, .Vlt-composite__append--icon:focus svg {
36
+ fill: #2c2d30;
37
+ }
38
+ }
39
+
40
+ .vgip-disable .Vlt-composite__append{
41
+ cursor: not-allowed;
42
+ pointer-events: none;
43
+ }
44
+
45
+ :host-context {
46
+ ::ng-deep {
47
+ input::-webkit-calendar-picker-indicator {
48
+ height: 48px;
49
+ width: 51px;
50
+ margin-top: -15px;
51
+ margin-right: -15px;
52
+ padding: 0 2px 0 0;
53
+ cursor: pointer;
54
+ color: transparent;
55
+ background-origin: content-box;
56
+ background-size: initial;
57
+ background-repeat: no-repeat;
58
+ background-position: center;
59
+ opacity: 1;
60
+ visibility: visible;
61
+ background-image: var(--vgip-meta-date-icon)
62
+ }
63
+ input::-webkit-calendar-picker-indicator:hover {
64
+ background-color: var(--vgip-meta-input-action-hover-bg-color);
65
+ }
66
+ input[type='time']::-webkit-calendar-picker-indicator {
67
+ background-image: var(--vgip-meta-time-icon)
68
+ }
69
+ input[readonly]::-webkit-calendar-picker-indicator {
70
+ visibility: visible;
71
+ }
72
+ input:enabled:read-write:-webkit-any(:focus,:hover)::-webkit-clear-button {
73
+ opacity: 0;
74
+ pointer-events: none;
75
+ }
76
+ input:enabled:read-write:-webkit-any(:focus,:hover)::-webkit-inner-spin-button {
77
+ opacity: 0;
78
+ pointer-events: none;
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,43 @@
1
+ /*
2
+ * @Author: Alexander.Vangelov@vonage.com
3
+ * @Date: 2020-04-18 18:10:03
4
+ * @Last Modified by: Alexander.Vangelov@vonage.com
5
+ * @Last Modified time: 2020-04-18 18:10:03
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 { FieldDatetime } from '.';
14
+
15
+ describe('FieldDatetime', () => {
16
+ let component: FieldDatetime;
17
+ let fixture: ComponentFixture<FieldDatetime>;
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(FieldDatetime);
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,26 @@
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'>{{model}}</div>
4
+ </div>
5
+ <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), 'has-value': f.value, active: keyListenerActive }">
6
+ <div class="Vlt-input" [ngClass]="{'vgip-disable': disabled}">
7
+ <label class='wrapper'>
8
+ <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]="type" [placeholder]="placeholder" (click)='onActivated($event)' (focus)='onActivated($event)' (blur)='onBlur($event)'/>
9
+ <label class='Vlt-truncate'>{{meta.label || meta.name}}<span *ngIf='validations.required' class='Vlt-red'>*</span></label> <!-- eslint-disable-line @angular-eslint/template/label-has-associated-control -->
10
+ </label>
11
+ <div class='Vlt-composite__append right-actions'>
12
+ <a href='#' *ngIf='model' class="Vlt-composite__append--icon" (click)='clear($event)' tabindex='0'>
13
+ <div class="Vlt-composite__icon">
14
+ <svg><use xlink:href="volta/volta-icons.svg#Vlt-icon-cross"/></svg>
15
+ </div>
16
+ </a>
17
+ </div>
18
+ </div>
19
+ <small *ngIf='f.invalid && ((f | metaModel)._parent.submitted || ((f | metaModel ).touched && keyListenerActive))' class="Vlt-form__element__error">
20
+ <span *ngIf="f.errors.required">Required.&nbsp;</span>
21
+ <span *ngIf="f.errors.min">Must be later than {{validations.min}}.&nbsp;</span>
22
+ <span *ngIf="f.errors.max">Must be no later than {{validations}}.&nbsp;</span>
23
+ <span *ngIf="f.errors.custom">{{f.errors.custom}}&nbsp;</span>
24
+ </small>
25
+ <small *ngIf='meta.hint' class="Vlt-form__element__hint">{{meta.hint}}</small>
26
+ </div>
@@ -0,0 +1,15 @@
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-15 13:04:01
6
+ */
7
+
8
+ import { Component } from '@angular/core';
9
+ import { FieldAbstract } from '../fieldAbstract';
10
+
11
+ @Component({
12
+ templateUrl: './view.html',
13
+ standalone: false
14
+ })
15
+ export class FieldHidden extends FieldAbstract {}
File without changes