Skip to content

Commit 67436d8

Browse files
authored
Merge pull request #253 from harunurhan/fix-252
add JSONSchema type
2 parents f723f5b + a3b924f commit 67436d8

39 files changed

+255
-190
lines changed

src/abstract-list-field/abstract-list-field.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { List } from 'immutable';
2525
import { AbstractFieldComponent } from '../abstract-field';
2626

2727
import { JsonStoreService, AppGlobalsService, PathUtilService } from '../shared/services';
28-
import { PathCache } from '../shared/interfaces';
28+
import { PathCache, JSONSchema } from '../shared/interfaces';
2929

3030
/**
3131
* Abstract component to share code of common operations of all array fields
@@ -36,7 +36,7 @@ import { PathCache } from '../shared/interfaces';
3636
export abstract class AbstractListFieldComponent extends AbstractFieldComponent {
3737

3838
values: List<any>;
39-
schema: Object;
39+
schema: JSONSchema;
4040
path: Array<any>;
4141
pathCache: PathCache = {};
4242

src/add-field-dropdown/add-field-dropdown.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<input [(ngModel)]="expression" placeholder="filter" (click)="$event.stopPropagation()">
66
</li>
77
<li class="divider dropdown-divider"></li>
8-
<li *ngFor="let key of schema | differentKeys:fields | filterByExpression:expression">
8+
<li *ngFor="let key of schema.properties | differentKeys:fields | filterByExpression:expression">
99
<a class="dropdown-item" href="javascript:void(0)" (click)="onFieldSelect(key)">{{key}}</a>
1010
</li>
1111
</ul>

src/add-field-dropdown/add-field-dropdown.component.spec.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ import { AddFieldDropdownComponent } from './add-field-dropdown.component';
2929
import { Ng2BootstrapModule } from 'ng2-bootstrap';
3030

3131
import { DifferentKeysPipe, FilterByExpressionPipe } from '../shared/pipes';
32-
3332
import { DomUtilService, EmptyValueService, PathUtilService, TabsUtilService } from '../shared/services';
33+
import { JSONSchema } from '../shared/interfaces';
3434

35-
const schemaProperties = {
36-
propA: {},
37-
propB: {},
38-
propNotInValueA: {},
39-
propNotInValueB: {}
35+
const testSchema: JSONSchema = {
36+
type: 'object',
37+
properties: {
38+
propA: { type: 'string' },
39+
propB: { type: 'string' },
40+
propNotInValueA: { type: 'string' },
41+
propNotInValueB: { type: 'string' }
42+
}
4043
};
4144
const fields = Set(['propA', 'propB']);
4245
const mockDifferentKeys = Set(['propNotInValueB', 'propNotInValueA']);
4346
const emptyValue = 'empty-value';
4447

4548
class MockEmptyValueService extends EmptyValueService {
46-
generateEmptyValue(schema: Object): any {
49+
generateEmptyValue(schema: JSONSchema): any {
4750
return emptyValue;
4851
}
4952
}
@@ -78,7 +81,7 @@ describe('AddFieldToObjectDropdownComponent', () => {
7881
fixture = TestBed.createComponent(AddFieldDropdownComponent);
7982
component = fixture.componentInstance;
8083
component.fields = fields;
81-
component.schema = schemaProperties;
84+
component.schema = testSchema;
8285
fixture.detectChanges();
8386

8487
nativeEl = fixture.nativeElement;

src/add-field-dropdown/add-field-dropdown.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Component, Input, Output, EventEmitter, ElementRef } from '@angular/cor
2525
import { Set } from 'immutable';
2626

2727
import { DomUtilService, EmptyValueService, PathUtilService } from '../shared/services';
28+
import { JSONSchema } from '../shared/interfaces';
2829

2930
@Component({
3031
selector: 'add-field-dropdown',
@@ -35,8 +36,7 @@ import { DomUtilService, EmptyValueService, PathUtilService } from '../shared/se
3536
})
3637
export class AddFieldDropdownComponent {
3738

38-
// 'propeties' of an object schema
39-
@Input() schema: Object;
39+
@Input() schema: JSONSchema;
4040
@Input() fields: Set<string>;
4141
@Input() pathString: string;
4242

@@ -50,7 +50,7 @@ export class AddFieldDropdownComponent {
5050
public pathUtilService: PathUtilService) { }
5151

5252
get disabled(): boolean {
53-
return Object.keys(this.schema).length === this.fields.size;
53+
return Object.keys(this.schema.properties).length === this.fields.size;
5454
}
5555

5656
onDropdownShown() {

src/add-new-element-button/add-new-element-button.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { List } from 'immutable';
44

55

66
import { DomUtilService, EmptyValueService, JsonStoreService, PathUtilService } from '../shared/services';
7+
import { JSONSchema } from '../shared/interfaces';
78

89
@Component({
910
selector: 'add-new-element-button',
@@ -16,15 +17,15 @@ import { DomUtilService, EmptyValueService, JsonStoreService, PathUtilService }
1617
export class AddNewElementButtonComponent {
1718

1819
@Input() path: Array<any>;
19-
@Input() schema: Object;
20+
@Input() schema: JSONSchema;
2021

2122
constructor(public domUtilService: DomUtilService,
2223
public emptyValueService: EmptyValueService,
2324
public jsonStoreService: JsonStoreService,
2425
public pathUtilService: PathUtilService) { }
2526

2627
addNewElement() {
27-
let itemSchema = this.schema['items'];
28+
let itemSchema = this.schema.items;
2829
let emptyValue = this.emptyValueService.generateEmptyValue(itemSchema);
2930
let values: List<any> = this.jsonStoreService.getIn(this.path) || List();
3031
this.jsonStoreService.setIn(this.path, values.push(emptyValue));

src/any-type-field/any-type-field.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from '@angular/core';
2828

2929
import { AppGlobalsService, ComponentTypeService } from '../shared/services';
30+
import { JSONSchema } from '../shared/interfaces';
3031

3132
/**
3233
* AnyFieldComponent
@@ -48,7 +49,7 @@ import { AppGlobalsService, ComponentTypeService } from '../shared/services';
4849
})
4950
export class AnyTypeFieldComponent {
5051

51-
@Input() schema: Object;
52+
@Input() schema: JSONSchema;
5253
@Input() path: Array<any>;
5354
@Input() value: any;
5455

@@ -60,6 +61,6 @@ export class AnyTypeFieldComponent {
6061
}
6162

6263
get isDisabled(): boolean {
63-
return this.schema && this.schema['disabled'] && !this.appGlobalsService.adminMode;
64+
return this.schema && this.schema.disabled && !this.appGlobalsService.adminMode;
6465
}
6566
}

src/complex-list-field/complex-list-field.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { AbstractListFieldComponent } from '../abstract-list-field';
3535

3636
import { AppGlobalsService, JsonStoreService, DomUtilService, PathUtilService } from '../shared/services';
3737

38-
import { LongListNavigatorConfig } from '../shared/interfaces';
38+
import { LongListNavigatorConfig, JSONSchema } from '../shared/interfaces';
3939

4040
@Component({
4141
selector: 'complex-list-field',
@@ -48,7 +48,7 @@ import { LongListNavigatorConfig } from '../shared/interfaces';
4848
export class ComplexListFieldComponent extends AbstractListFieldComponent implements OnChanges, OnInit {
4949

5050
@Input() values: List<Map<string, any>>;
51-
@Input() schema: Object;
51+
@Input() schema: JSONSchema;
5252
@Input() path: Array<any>;
5353

5454
paginatedIndices: Array<number>;
@@ -68,7 +68,7 @@ export class ComplexListFieldComponent extends AbstractListFieldComponent implem
6868
}
6969

7070
ngOnInit() {
71-
this.navigator = this.schema['longListNavigatorConfig'];
71+
this.navigator = this.schema.longListNavigatorConfig;
7272
if (this.navigator) {
7373
this.paginatedIndices = this.getIndicesForPage(this.currentPage);
7474
} else {

src/find-replace/find-replace.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { DomSanitizer } from '@angular/platform-browser';
2626
import { List, Map } from 'immutable';
2727

2828
import { FindReplaceAllService, JsonStoreService, ModalService } from '../shared/services';
29+
import { JSONSchema } from '../shared/interfaces';
2930

3031
@Component({
3132
selector: 'find-replace',
@@ -38,7 +39,7 @@ import { FindReplaceAllService, JsonStoreService, ModalService } from '../shared
3839
export class FindReplaceComponent {
3940

4041
@Input() path: Array<any>;
41-
@Input() schema: Object;
42+
@Input() schema: JSONSchema;
4243

4344
private replaced: List<any> | Map<string, any>;
4445

src/json-editor.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="row editor-container">
22
<div class="col-md-2 menu-container">
33
<tree-menu [record]="_record" [schema]="schema"></tree-menu>
4-
<add-field-dropdown [fields]="keys" [pathString]="''" (onFieldAdd)="onFieldAdd($event)" [schema]="schema.properties">Add field</add-field-dropdown>
4+
<add-field-dropdown [fields]="keys" [pathString]="''" (onFieldAdd)="onFieldAdd($event)" [schema]="schema">Add field</add-field-dropdown>
55
<div *ngIf="config.enableAdminModeSwitch" class="admin-mode" tooltip="Allows editing all fields (use with care)">
66
<input id="admin-mode-checkbox" type="checkbox" [(ngModel)]="appGlobalsService.adminMode" />
77
<label class="admin-mode" for="admin-mode-checkbox">Enable Admin Mode</label>

src/json-editor.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class JsonEditorComponent extends AbstractTrackerComponent implements OnI
6666

6767
@Input() config: JsonEditorConfig;
6868
@Input() record: Object;
69-
@Input() schema: Object;
69+
@Input() schema: any;
7070
@Input() errorMap: SchemaValidationErrors = {};
7171
@Input() templates: { [templateName: string]: TemplateRef<any> } = {};
7272

0 commit comments

Comments
 (0)