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

View File

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

View File

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