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

eclipsesource / jsonforms / 4078973452

pending completion
4078973452

Pull #2089

github

GitHub
Merge 02bf9f9a8 into 1b22f55dc
Pull Request #2089: Bump http-cache-semantics and lerna

110 of 179 branches covered (61.45%)

297 of 357 relevant lines covered (83.19%)

13.76 hits per line

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

27.66
/packages/angular-material/src/layouts/array-layout.renderer.ts
1
/*
2
  The MIT License
3

4
  Copyright (c) 2017-2020 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 {
26
  ChangeDetectionStrategy,
27
  Component,
28
  OnDestroy,
29
  OnInit
30
} from '@angular/core';
31
import { JsonFormsAngularService, JsonFormsAbstractControl } from '@jsonforms/angular';
32
import {
33
  ArrayLayoutProps,
34
  createDefaultValue,
35
  findUISchema,
36
  isObjectArrayWithNesting,
37
  JsonFormsState,
38
  mapDispatchToArrayControlProps,
39
  mapStateToArrayLayoutProps,
40
  OwnPropsOfRenderer,
41
  Paths,
42
  RankedTester,
43
  rankWith,
44
  setReadonly,
45
  StatePropsOfArrayLayout,
46
  UISchemaElement,
47
  UISchemaTester,
48
  unsetReadonly
49
} from '@jsonforms/core';
50

51
@Component({
52
  selector: 'app-array-layout-renderer',
53
  template: `
54
    <div fxLayout="column" fxLayoutGap="16px" [fxHide]="hidden">
55
      <div [ngClass]="'array-layout-toolbar'">
56
        <h2 [ngClass]="['mat-h2', 'array-layout-title']">{{ label }}</h2>
57
        <span fxFlex></span>
58
        <mat-icon
59
          *ngIf="this.error?.length"
60
          color="warn"
61
          matBadge="{{ this.error.split('\n').length }}"
62
          matBadgeColor="warn"
63
          matTooltip="{{ this.error }}"
64
          matTooltipClass="error-message-tooltip"
65
          >
66
            error_outline
67
        </mat-icon>
68
        <span fxFlex></span>
69
        <button
70
          mat-button
71
          matTooltip="{{ this.addTooltip }}"
72
          [disabled]="!isEnabled()"
73
          (click)="add()"
74
          attr.aria-label="{{ this.addAriaLabel }}"
75
        >
76
          <mat-icon>add</mat-icon>
77
        </button>
78
      </div>
79
      <p *ngIf="noData">{{ this.noDataMessage }}</p>
80
      <div
81
        *ngFor="
82
          let item of [].constructor(data);
83
          let idx = index;
84
          trackBy: trackByFn;
85
          last as last;
86
          first as first
87
        "
88
      >
89
        <mat-card>
90
          <mat-card-content>
91
            <jsonforms-outlet [renderProps]="getProps(idx)"></jsonforms-outlet>
92
          </mat-card-content>
93
          <mat-card-actions *ngIf="isEnabled()">
94
          <button
95
              *ngIf="uischema?.options?.showSortButtons"
96
              class="item-up"
97
              mat-button
98
              [disabled]="first"
99
              (click)="up(idx)"
100
              attr.aria-label="{{ this.upAriaLabel }}"
101
              matTooltip="{{ this.upTooltip }}"
102
              matTooltipPosition="right"
103
            >
104
              <mat-icon>arrow_upward</mat-icon>
105
            </button>
106
            <button
107
              *ngIf="uischema?.options?.showSortButtons"
108
              class="item-down"
109
              mat-button
110
              [disabled]="last"
111
              (click)="down(idx)"
112
              attr.aria-label="{{ this.downAriaLabel }}"
113
              matTooltip="{{ this.downTooltip }}"
114
              matTooltipPosition="right"
115
            >
116
              <mat-icon>arrow_downward</mat-icon>
117
            </button>
118
            <button
119
              mat-button
120
              color="warn"
121
              (click)="remove(idx)"
122
              attr.aria-label="{{ this.removeAriaLabel }}"
123
              matTooltip="{{ this.removeTooltip }}"
124
              matTooltipPosition="right"
125
            >
126
              <mat-icon>delete</mat-icon>
127
            </button>
128
          </mat-card-actions>
129
        </mat-card>
130
      </div>
131
    </div>
132
  `,
133
  styles: [
134
    `.array-layout-toolbar {
135
       display: flex;
136
       align-items: center;
137
      }
138
      .array-layout-title {
139
        margin: 0;
140
      }
141
      ::ng-deep .error-message-tooltip {
142
        white-space: pre-line;
143
      }
144
      `
145
  ],
146
  changeDetection: ChangeDetectionStrategy.OnPush
147
})
148
export class ArrayLayoutRenderer
1✔
149
  extends JsonFormsAbstractControl<StatePropsOfArrayLayout>
1✔
150
  implements OnInit, OnDestroy {
151
  addTooltip: string;
152
  addAriaLabel: string;
153
  noDataMessage: string;
154
  removeTooltip: string;
155
  removeAriaLabel: string;
156
  upTooltip: string;
157
  upAriaLabel: string;
158
  downTooltip: string;
159
  downAriaLabel:string;
160
  noData: boolean;
161
  addItem: (path: string, value: any) => () => void;
162
  moveItemUp: (path: string, index: number) => () => void;
163
  moveItemDown: (path: string, index: number) => () => void;
164
  removeItems: (path: string, toDelete: number[]) => () => void;
165
  uischemas: {
166
    tester: UISchemaTester;
167
    uischema: UISchemaElement;
168
  }[];
169
  constructor(jsonFormsService: JsonFormsAngularService) {
170
    super(jsonFormsService);
×
171
  }
172
  mapToProps(state: JsonFormsState): StatePropsOfArrayLayout {
1✔
173
    const props = mapStateToArrayLayoutProps(state, this.getOwnProps());
×
174
    return { ...props };
×
175
  }
176
  remove(index: number): void {
1✔
177
    this.removeItems(this.propsPath, [index])();
×
178
  }
179
  add(): void {
1✔
180
    this.addItem(this.propsPath, createDefaultValue(this.scopedSchema))();
×
181
  }
182
  up(index: number): void {
1✔
183
    this.moveItemUp(this.propsPath, index)();
×
184
  }
185
  down(index: number): void {
1✔
186
    this.moveItemDown(this.propsPath, index)();
×
187
  }
188
  ngOnInit() {
1✔
189
    super.ngOnInit();
×
190
    const { addItem, removeItems, moveUp, moveDown } = mapDispatchToArrayControlProps(
×
191
      this.jsonFormsService.updateCore.bind(this.jsonFormsService)
192
    );
193
    this.addItem = addItem;
×
194
    this.moveItemUp = moveUp;
×
195
    this.moveItemDown = moveDown;
×
196
    this.removeItems = removeItems;
×
197
  }
198
  mapAdditionalProps(props: ArrayLayoutProps) {
1✔
199
    this.noData = !props.data || props.data === 0;
×
200
    this.uischemas = props.uischemas;
×
201
    this.addTooltip = `Add to ${this.label}`;
×
202
    this.addAriaLabel = `Add to ${this.label} button`;
×
203
    this.upAriaLabel = `Move ${this.label} up`;
×
204
    this.downAriaLabel = `Move ${this.label} down`;
×
205
    this.removeTooltip = `Delete`;
×
206
    this.removeAriaLabel = `Delete button`;
×
207
    this.noDataMessage = `No data`;
×
208
  }
209
  getProps(index: number): OwnPropsOfRenderer {
1✔
210
    const uischema = findUISchema(
×
211
      this.uischemas,
212
      this.scopedSchema,
213
      this.uischema.scope,
214
      this.propsPath,
215
      undefined,
216
      this.uischema,
217
      this.rootSchema
218
    );
219
    if (this.isEnabled()) {
×
220
      unsetReadonly(uischema);
×
221
    } else {
222
      setReadonly(uischema);
×
223
    }
224
    return {
×
225
      schema: this.scopedSchema,
226
      path: Paths.compose(this.propsPath, `${index}`),
227
      uischema
228
    };
229
  }
230
  trackByFn(index: number) {
1✔
231
    return index;
×
232
  }
233
}
1✔
234

235
export const ArrayLayoutRendererTester: RankedTester = rankWith(
1✔
236
  4,
237
  isObjectArrayWithNesting
238
);
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