Auto expand schema with one element

This commit is contained in:
Roman Hotsiy 2016-07-10 14:28:05 +03:00
parent ed2a5b46e1
commit 7618507cda
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
3 changed files with 8 additions and 4 deletions

View File

@ -42,6 +42,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
this.initComponent(compRef.instance);
this._renderer.setElementAttribute(compRef.location.nativeElement, 'class', this.location.element.nativeElement.className);
compRef.changeDetectorRef.detectChanges();
this.loaded = true;
return compRef;
}).catch(err => {
console.log(err);
@ -55,7 +56,6 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
if (this.pointer) {
this._loadAfterSelf();
}
this.loaded = true;
}
// cache JsonSchema view
@ -73,7 +73,8 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
return;
}
insertAfter($element.cloneNode(true), this.elementRef.nativeElement);
} );
this.loaded = true;
});
});
} else {
cache[this.pointer] = this._loadAfterSelf();

View File

@ -62,8 +62,8 @@
</tr>
<tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" [hidden]="!prop._pointer">
<td colspan="2">
<zippy #subSchema title="test" [headless]="true" (open)="lazySchema.load()">
<json-schema-lazy #lazySchema class="nested-schema" [pointer]="prop._pointer" [isArray]='prop._isArray'
<zippy #subSchema title="Expand" [headless]="true" (open)="lazySchema.load()" [visible]="autoExpand">
<json-schema-lazy #lazySchema [auto]="autoExpand" class="nested-schema" [pointer]="prop._pointer" [isArray]='prop._isArray'
[nestOdd]="!nestOdd" [isRequestSchema]="isRequestSchema">
</json-schema-lazy>
</zippy>

View File

@ -28,6 +28,7 @@ export class JsonSchema extends BaseComponent {
@Input() childFor: string;
@Input() isRequestSchema: boolean;
normalizer: SchemaNormalizer;
autoExpand = false;
constructor(specMgr:SpecManager, private _renderer: Renderer, private _elementRef: ElementRef) {
super(specMgr);
@ -100,6 +101,8 @@ export class JsonSchema extends BaseComponent {
}
return (propSchema && propSchema.type === 'object' && propSchema._pointer);
});
this.autoExpand = this.properties && this.properties.length === 1;
}
trackByIdx(index: number, item: any): number {