From 17e7bf9fd8898860f7d705a1fcbc60aa1e610c2e Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sun, 23 Oct 2016 20:18:42 +0300 Subject: [PATCH] Refactor + minor fixes/optimizations --- lib/components/ApiInfo/api-info.spec.ts | 2 +- lib/components/ApiInfo/api-info.ts | 2 +- lib/components/ApiLogo/api-logo.spec.ts | 2 +- lib/components/JsonSchema/json-schema-lazy.ts | 26 ++-- lib/components/JsonSchema/json-schema.spec.ts | 2 +- lib/components/Method/method.spec.ts | 2 +- .../MethodsList/methods-list.spec.ts | 2 +- lib/components/Redoc/redoc.html | 6 +- lib/components/Redoc/redoc.spec.ts | 119 +----------------- lib/components/Redoc/redoc.ts | 96 +++++++------- .../RequestSamples/request-samples.ts | 15 +-- .../security-definitions.html | 2 + .../security-definitions.scss | 28 +++++ .../security-definitions.ts | 25 ++++ lib/components/SideMenu/side-menu.spec.ts | 2 +- lib/components/SideMenu/side-menu.ts | 1 - lib/components/base.spec.ts | 2 +- lib/components/base.ts | 2 +- lib/components/index.ts | 5 +- lib/index.ts | 4 +- lib/redoc.module.ts | 17 +-- lib/services/app-state.service.ts | 11 ++ lib/services/clipboard.service.ts | 3 +- lib/services/events.service.ts | 8 -- lib/services/hash.service.spec.ts | 21 ++-- lib/services/hash.service.ts | 39 +++--- lib/services/index.ts | 2 +- lib/services/menu.service.spec.ts | 17 +-- lib/services/menu.service.ts | 4 +- lib/services/schema-helper.serivce.spec.ts | 2 +- lib/services/schema-helper.service.ts | 2 +- .../schema-normalizer.service.spec.ts | 2 +- lib/services/schema-normalizer.service.ts | 2 +- lib/services/scroll.service.ts | 6 +- lib/utils/browser-update.js | 10 -- lib/utils/custom-error-handler.ts | 12 ++ lib/utils/helpers.js | 103 --------------- lib/utils/index.ts | 1 + lib/utils/{SpecManager.ts => spec-manager.ts} | 22 +++- tests/spec-bundle.js | 11 +- tests/unit/SpecManager.spec.ts | 2 +- 41 files changed, 251 insertions(+), 391 deletions(-) create mode 100644 lib/components/SecurityDefinitions/security-definitions.html create mode 100644 lib/components/SecurityDefinitions/security-definitions.scss create mode 100644 lib/components/SecurityDefinitions/security-definitions.ts create mode 100644 lib/services/app-state.service.ts delete mode 100644 lib/services/events.service.ts delete mode 100644 lib/utils/browser-update.js create mode 100644 lib/utils/custom-error-handler.ts delete mode 100644 lib/utils/helpers.js create mode 100644 lib/utils/index.ts rename lib/utils/{SpecManager.ts => spec-manager.ts} (91%) diff --git a/lib/components/ApiInfo/api-info.spec.ts b/lib/components/ApiInfo/api-info.spec.ts index 7f5bf1c8..4d0e6612 100644 --- a/lib/components/ApiInfo/api-info.spec.ts +++ b/lib/components/ApiInfo/api-info.spec.ts @@ -11,7 +11,7 @@ import { } from '@angular/core/testing'; import { ApiInfo } from './api-info'; -import { SpecManager } from '../../utils/SpecManager'; +import { SpecManager } from '../../utils/spec-manager'; describe('Redoc components', () => { describe('ApiInfo Component', () => { diff --git a/lib/components/ApiInfo/api-info.ts b/lib/components/ApiInfo/api-info.ts index 9847210a..00a301c6 100644 --- a/lib/components/ApiInfo/api-info.ts +++ b/lib/components/ApiInfo/api-info.ts @@ -12,7 +12,7 @@ import { OptionsService, MenuService } from '../../services/index'; export class ApiInfo extends BaseComponent implements OnInit { info: any = {}; specUrl: String; - constructor(specMgr:SpecManager, private optionsService:OptionsService, private menuServ: MenuService) { + constructor(specMgr:SpecManager, private optionsService: OptionsService) { super(specMgr); } diff --git a/lib/components/ApiLogo/api-logo.spec.ts b/lib/components/ApiLogo/api-logo.spec.ts index e4ba00c0..5ef98c1f 100644 --- a/lib/components/ApiLogo/api-logo.spec.ts +++ b/lib/components/ApiLogo/api-logo.spec.ts @@ -10,7 +10,7 @@ import { } from '@angular/core/testing'; import { ApiLogo } from './api-logo'; -import { SpecManager } from '../../utils/SpecManager'; +import { SpecManager } from '../../utils/spec-manager'; describe('Redoc components', () => { diff --git a/lib/components/JsonSchema/json-schema-lazy.ts b/lib/components/JsonSchema/json-schema-lazy.ts index 80dc3f63..4cfe9143 100644 --- a/lib/components/JsonSchema/json-schema-lazy.ts +++ b/lib/components/JsonSchema/json-schema-lazy.ts @@ -5,7 +5,7 @@ import { Component, ElementRef, ViewContainerRef, OnDestroy, Input, import { JsonSchema } from './json-schema'; import { OptionsService } from '../../services/options.service'; -import { SpecManager } from '../../utils/SpecManager'; +import { SpecManager } from '../../utils/spec-manager'; var cache = {}; @@ -38,7 +38,7 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { var componentFactory = this.resolver.resolveComponentFactory(JsonSchema); let contextInjector = this.location.parentInjector; let compRef = this.location.createComponent(componentFactory, null, contextInjector, null); - this.initComponent(compRef.instance); + this.projectComponentInputs(compRef.instance); this._renderer.setElementAttribute(compRef.location.nativeElement, 'class', this.location.element.nativeElement.className); compRef.changeDetectorRef.detectChanges(); this.loaded = true; @@ -58,24 +58,22 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit { this.pointer = this.normalizePointer(); if (cache[this.pointer]) { let compRef = cache[this.pointer]; - setTimeout( ()=> { - let $element = compRef.location.nativeElement; + let $element = compRef.location.nativeElement; - // skip caching view with descendant schemas - // as it needs attached controller - if (!this.disableLazy && (compRef.instance.hasDescendants || compRef.instance._hasSubSchemas)) { - this._loadAfterSelf(); - return; - } - insertAfter($element.cloneNode(true), this.elementRef.nativeElement); - this.loaded = true; - }); + // skip caching view with descendant schemas + // as it needs attached controller + if (!this.disableLazy && (compRef.instance.hasDescendants || compRef.instance._hasSubSchemas)) { + this._loadAfterSelf(); + return; + } + insertAfter($element.cloneNode(true), this.elementRef.nativeElement); + this.loaded = true; } else { cache[this.pointer] = this._loadAfterSelf(); } } - initComponent(instance:JsonSchema) { + projectComponentInputs(instance:JsonSchema) { Object.assign(instance, this); } diff --git a/lib/components/JsonSchema/json-schema.spec.ts b/lib/components/JsonSchema/json-schema.spec.ts index d2c8f697..53b77cad 100644 --- a/lib/components/JsonSchema/json-schema.spec.ts +++ b/lib/components/JsonSchema/json-schema.spec.ts @@ -10,7 +10,7 @@ import { getChildDebugElement } from '../../../tests/helpers'; import { JsonSchema } from './json-schema'; -import { SpecManager } from '../../utils/SpecManager';; +import { SpecManager } from '../../utils/spec-manager';; describe('Redoc components', () => { beforeEach(() => { diff --git a/lib/components/Method/method.spec.ts b/lib/components/Method/method.spec.ts index c5e80d15..c35508a0 100644 --- a/lib/components/Method/method.spec.ts +++ b/lib/components/Method/method.spec.ts @@ -10,7 +10,7 @@ import { import { getChildDebugElement } from '../../../tests/helpers'; import { Method } from './method'; -import { SpecManager } from '../../utils/SpecManager';; +import { SpecManager } from '../../utils/spec-manager';; describe('Redoc components', () => { beforeEach(() => { diff --git a/lib/components/MethodsList/methods-list.spec.ts b/lib/components/MethodsList/methods-list.spec.ts index e552d2d2..ca59e157 100644 --- a/lib/components/MethodsList/methods-list.spec.ts +++ b/lib/components/MethodsList/methods-list.spec.ts @@ -11,7 +11,7 @@ import { getChildDebugElement } from '../../../tests/helpers'; import { MethodsList } from './methods-list'; -import { SpecManager } from '../../utils/SpecManager'; +import { SpecManager } from '../../utils/spec-manager'; describe('Redoc components', () => { beforeEach(() => { diff --git a/lib/components/Redoc/redoc.html b/lib/components/Redoc/redoc.html index 8df000b0..11e8c3d7 100644 --- a/lib/components/Redoc/redoc.html +++ b/lib/components/Redoc/redoc.html @@ -1,4 +1,8 @@ -
+
+

Oops... ReDoc failed to render this spec

+
{{_error.message}}
+
+