Attach controler to schemas with subschemas

This commit is contained in:
Roman Hotsiy 2016-06-29 19:07:18 +03:00
parent 7a73ba2ce5
commit 46a44f3f6c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
3 changed files with 11 additions and 6 deletions

View File

@ -41,7 +41,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
componentFactory, null, contextInjector, null); componentFactory, null, contextInjector, null);
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.markForCheck(); compRef.changeDetectorRef.detectChanges();
return compRef; return compRef;
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
@ -68,7 +68,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
// skip caching view with tabs inside (discriminator) // skip caching view with tabs inside (discriminator)
// as it needs attached controller // as it needs attached controller
if (compRef.instance.hasDescendants) { if (compRef.instance.hasDescendants || compRef.instance._hasSubSchemas) {
this._loadAfterSelf(); this._loadAfterSelf();
return; return;
} }
@ -85,6 +85,10 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
} }
ngAfterViewInit() { ngAfterViewInit() {
if (this.optionsService.options.disableLazySchemas) {
this._loadAfterSelf();
return;
}
if (!this.auto) return; if (!this.auto) return;
this.loadCached(); this.loadCached();
} }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { Input, Renderer, ElementRef } from '@angular/core'; import { Input, Renderer, ElementRef, forwardRef } from '@angular/core';
import { RedocComponent, BaseComponent, SpecManager } from '../base'; import { RedocComponent, BaseComponent, SpecManager } from '../base';
import { DropDown } from '../../shared/components/index'; import { DropDown } from '../../shared/components/index';
@ -12,13 +12,14 @@ import { Zippy } from '../../shared/components/Zippy/zippy';
selector: 'json-schema', selector: 'json-schema',
templateUrl: './json-schema.html', templateUrl: './json-schema.html',
styleUrls: ['./json-schema.css'], styleUrls: ['./json-schema.css'],
directives: [JsonSchema, DropDown, JsonSchemaLazy, Zippy], directives: [JsonSchema, DropDown, forwardRef(() => JsonSchemaLazy), Zippy],
detect: true detect: true
}) })
export class JsonSchema extends BaseComponent { export class JsonSchema extends BaseComponent {
schema: any; schema: any;
activeDescendant:any = {}; activeDescendant:any = {};
hasDescendants: boolean = false; hasDescendants: boolean = false;
_hasSubSchemas: boolean = false;
@Input() isArray: boolean; @Input() isArray: boolean;
@Input() final: boolean = false; @Input() final: boolean = false;
@Input() nestOdd: boolean; @Input() nestOdd: boolean;
@ -85,6 +86,8 @@ export class JsonSchema extends BaseComponent {
} }
this.initDescendants(); this.initDescendants();
this._hasSubSchemas = this.schema._properties && this.schema._properties.some(
propSchema => propSchema.type === 'object' && propSchema._pointer);
} }
trackByName(index: number, item: any): string { trackByName(index: number, item: any): string {

View File

@ -15,8 +15,6 @@
<header *ngIf="response.headers"> <header *ngIf="response.headers">
Response Schema Response Schema
</header> </header>
<json-schema *ngIf="response.schema && options.disableLazySchemas" class="schema type" pointer="{{response.pointer}}/schema">
</json-schema>
<json-schema-lazy #lazySchema pointer="{{response.schema ? response.pointer + '/schema' : null}}"> <json-schema-lazy #lazySchema pointer="{{response.schema ? response.pointer + '/schema' : null}}">
</json-schema-lazy> </json-schema-lazy>
</zippy> </zippy>