• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipsesource / jsonforms / 3813777547

pending completion
3813777547

push

github

GitHub
Bump json5 and rollup-plugin-vue in /packages/vue2/vue2-vanilla

109 of 177 branches covered (61.58%)

296 of 355 relevant lines covered (83.38%)

13.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.86
/packages/angular-material/src/controls/autocomplete.renderer.ts
1
/*
2
  The MIT License
3
  
4
  Copyright (c) 2017-2019 EclipseSource Munich
5
  https://github.com/eclipsesource/jsonforms
6
  
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
  of this software and associated documentation files (the "Software"), to deal
9
  in the Software without restriction, including without limitation the rights
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
  copies of the Software, and to permit persons to whom the Software is
12
  furnished to do so, subject to the following conditions:
13
  
14
  The above copyright notice and this permission notice shall be included in
15
  all copies or substantial portions of the Software.
16
  
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
  THE SOFTWARE.
24
*/
25
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
26
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
27
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
28
import {
29
  Actions,
30
  composeWithUi,
31
  ControlElement,
32
  isEnumControl,
33
  OwnPropsOfControl,
34
  RankedTester,
35
  rankWith
36
} from '@jsonforms/core';
37
import { Observable } from 'rxjs';
38
import { map } from 'rxjs/operators';
39
import { startWith } from 'rxjs/operators';
40

41
/**
42
 * To use this component you will need to add your own tester:
43
 * <pre><code>
44
 * ...
45
 * export const AutocompleteControlRendererTester: RankedTester = rankWith(2, isEnumControl);
46
 * ...
47
 * </code></pre>
48
 * Add the tester and renderer to JSONForms registry:
49
 * <pre><code>
50
 * ...
51
 * { tester: AutocompleteControlRendererTester, renderer: AutocompleteControlRenderer },
52
 * ...
53
 * </code></pre>
54
 * Furthermore you need to update your module.
55
 * <pre><code>
56
 * ...
57
 * imports: [JsonFormsAngularMaterialModule, MatAutocompleteModule],
58
 * declarations: [AutocompleteControlRenderer],
59
 * entryComponents: [AutocompleteControlRenderer]
60
 * ...
61
 * </code></pre>
62
 *
63
 */
64
@Component({
65
  selector: 'AutocompleteControlRenderer',
66
  template: `
67
    <mat-form-field fxFlex [fxHide]="hidden">
68
      <mat-label>{{ label }}</mat-label>
69
      <input
70
        matInput
71
        type="text"
72
        (change)="onChange($event)"
73
        [id]="id"
74
        [formControl]="form"
75
        [matAutocomplete]="auto"
76
        (keydown)="updateFilter($event)"
77
        (focus)="focused = true" 
78
        (focusout)="focused = false"
79
      />
80
      <mat-autocomplete
81
        autoActiveFirstOption
82
        #auto="matAutocomplete"
83
        (optionSelected)="onSelect($event)"
84
      >
85
        <mat-option
86
          *ngFor="let option of filteredOptions | async"
87
          [value]="option"
88
        >
89
          {{ option }}
90
        </mat-option>
91
      </mat-autocomplete>
92
      <mat-hint *ngIf="shouldShowUnfocusedDescription() || focused">{{ description }}</mat-hint>
93
      <mat-error>{{ error }}</mat-error>
94
    </mat-form-field>
95
  `,
96
  changeDetection: ChangeDetectionStrategy.OnPush
97
})
98
export class AutocompleteControlRenderer extends JsonFormsControl {
1✔
99
  @Input() options: string[];
1✔
100
  filteredOptions: Observable<string[]>;
101
  shouldFilter: boolean;
102

103
  constructor(jsonformsService: JsonFormsAngularService) {
104
    super(jsonformsService);
11!
105
  }
106
  getEventValue = (event: any) => event.target.value;
11✔
107

108
  ngOnInit() {
22✔
109
    super.ngOnInit();
22✔
110
    this.shouldFilter = false;
22✔
111
    this.filteredOptions = this.form.valueChanges.pipe(
22✔
112
      startWith(''),
113
      map(val => this.filter(val))
40✔
114
    );
115
  }
116

117
  updateFilter(event: any) {
1✔
118
    // ENTER
119
    if (event.keyCode === 13) {
×
120
      this.shouldFilter = false;
×
121
    } else {
122
      this.shouldFilter = true;
×
123
    }
124
  }
125

126
  onSelect(ev: MatAutocompleteSelectedEvent) {
1✔
127
    const path = composeWithUi(this.uischema as ControlElement, this.path);
×
128
    this.shouldFilter = false;
×
129
    this.jsonFormsService.updateCore(Actions.update(path, () => ev.option.value));
×
130
    this.triggerValidation();
×
131
  }
132

133
  filter(val: string): string[] {
40✔
134
    return (this.options || this.scopedSchema.enum || []).filter(
40!
135
      option =>
136
        !this.shouldFilter ||
120!
137
        !val ||
138
        option.toLowerCase().indexOf(val.toLowerCase()) === 0
139
    );
140
  }
141
  protected getOwnProps(): OwnPropsOfAutoComplete {
1✔
142
    return {
32✔
143
      ...super.getOwnProps(),
144
      options: this.options
145
    };
146
  }
147
}
1✔
148

149
export const enumControlTester: RankedTester = rankWith(2, isEnumControl);
1✔
150

151
interface OwnPropsOfAutoComplete extends OwnPropsOfControl {
152
  options: string[];
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc