diff --git a/lib/components/Method/method.ts b/lib/components/Method/method.ts
index 82332307..977f7a1d 100644
--- a/lib/components/Method/method.ts
+++ b/lib/components/Method/method.ts
@@ -1,10 +1,24 @@
'use strict';
-import { Input, Component, OnInit, ChangeDetectionStrategy, ElementRef } from '@angular/core';
+import { Input, HostBinding, Component, OnInit, ChangeDetectionStrategy, ElementRef } from '@angular/core';
import JsonPointer from '../../utils/JsonPointer';
import { BaseComponent, SpecManager } from '../base';
import { SchemaHelper } from '../../services/schema-helper.service';
import { OptionsService } from '../../services/';
+
+interface MethodInfo {
+ apiUrl: string;
+ httpMethod: string;
+ path: string;
+ info: {
+ tags: string[];
+ description: string;
+ };
+ bodyParam: any;
+ summary: any;
+ anchor: any;
+}
+
@Component({
selector: 'method',
templateUrl: './method.html',
@@ -12,35 +26,47 @@ import { OptionsService } from '../../services/';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Method extends BaseComponent implements OnInit {
- @Input() pointer:string;
- @Input() tag:string;
- @Input() posInfo: any;
+ @Input() pointer :string;
+ @Input() parentTagId :string;
- hidden = true;
+ @HostBinding('attr.operation-id') operationId;
- method:any;
+ private method: MethodInfo;
- constructor(specMgr:SpecManager, private optionsService: OptionsService, private el: ElementRef) {
+ constructor(specMgr:SpecManager, private optionsService: OptionsService) {
super(specMgr);
}
init() {
- this.method = {};
- if (this.optionsService.options.hideHostname) {
- this.method.apiUrl = this.specMgr.basePath;
+ this.operationId = this.componentSchema.operationId;
+
+ this.method = {
+ httpMethod: JsonPointer.baseName(this.pointer),
+ path: JsonPointer.baseName(this.pointer, 2),
+ info: {
+ description: this.componentSchema.description,
+ tags: this.filterMainTags(this.componentSchema.tags)
+ },
+ bodyParam: this.findBodyParam(),
+ summary: SchemaHelper.methodSummary(this.componentSchema),
+ apiUrl: this.getBaseUrl(),
+ anchor: this.buildAnchor()
+ };
+ }
+
+ buildAnchor() {
+ if (this.operationId) {
+ return 'operation/' + encodeURIComponent(this.componentSchema.operationId);
} else {
- this.method.apiUrl = this.specMgr.apiUrl;
+ return this.parentTagId + encodeURIComponent(this.pointer);
}
- this.method.httpMethod = JsonPointer.baseName(this.pointer);
- this.method.path = JsonPointer.baseName(this.pointer, 2);
- this.method.info = this.componentSchema;
- this.method.info.tags = this.filterMainTags(this.method.info.tags);
- this.method.bodyParam = this.findBodyParam();
- this.method.summary = SchemaHelper.methodSummary(this.componentSchema);
- if (this.componentSchema.operationId) {
- this.method.anchor = 'operation/' + encodeURIComponent(this.componentSchema.operationId);
+ }
+
+ getBaseUrl():string {
+ if (this.optionsService.options.hideHostname) {
+ return this.specMgr.basePath;
} else {
- this.method.anchor = this.tag + encodeURIComponent(this.pointer);
+ return this.specMgr.apiUrl;
}
}
@@ -56,14 +82,6 @@ export class Method extends BaseComponent implements OnInit {
return bodyParam;
}
- show(res) {
- if (res) {
- this.el.nativeElement.firstElementChild.removeAttribute('hidden');
- } else {
- this.el.nativeElement.firstElementChild.setAttribute('hidden', 'hidden');
- }
- }
-
ngOnInit() {
this.preinit();
}
diff --git a/lib/components/MethodsList/methods-list.html b/lib/components/MethodsList/methods-list.html
index f80a471d..18a833c8 100644
--- a/lib/components/MethodsList/methods-list.html
+++ b/lib/components/MethodsList/methods-list.html
@@ -4,8 +4,8 @@
-
+
diff --git a/lib/components/MethodsList/methods-list.ts b/lib/components/MethodsList/methods-list.ts
index 3db51eb8..9542bf51 100644
--- a/lib/components/MethodsList/methods-list.ts
+++ b/lib/components/MethodsList/methods-list.ts
@@ -1,7 +1,7 @@
'use strict';
import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { BaseComponent, SpecManager } from '../base';
-import { SchemaHelper } from '../../services/index';
+import { MenuService } from '../../services/index';
@Component({
selector: 'methods-list',
@@ -14,18 +14,19 @@ export class MethodsList extends BaseComponent implements OnInit {
tags:Array = [];
- constructor(specMgr:SpecManager) {
+ constructor(specMgr:SpecManager, private menu: MenuService) {
super(specMgr);
}
init() {
- let flatMenuItems = SchemaHelper.flatMenu(SchemaHelper.buildMenuTree(this.specMgr.schema));
+ let flatMenuItems = this.menu.flatItems;
this.tags = [];
let emptyTag = {
name: '',
items: []
}
flatMenuItems.forEach(menuItem => {
+ // skip items that are not bound to swagger tags/methods
if (!menuItem.metadata) return;
if (menuItem.metadata.type === 'tag') {
diff --git a/lib/components/SideMenu/side-menu-items.scss b/lib/components/SideMenu/side-menu-items.scss
index f59ce73c..db89e9ac 100644
--- a/lib/components/SideMenu/side-menu-items.scss
+++ b/lib/components/SideMenu/side-menu-items.scss
@@ -53,7 +53,7 @@
}
}
-.menu-item-level-0 {
+.menu-item-level-1 {
> .menu-item-header {
font-family: $headers-font, $headers-font-family;
font-weight: $light;
@@ -61,7 +61,7 @@
text-transform: uppercase;
}
- > .menu-item-header:hover,
+ > .menu-item-header:not(.disabled):hover,
&.active > .menu-item-header {
color: $primary-color;
background: $side-menu-active-bg-color;
@@ -71,7 +71,7 @@
}
}
-.menu-item-level-1 {
+.menu-item-level-2 {
> .menu-item-header {
padding-left: 2*$side-menu-item-hpadding;
}
diff --git a/lib/components/SideMenu/side-menu.ts b/lib/components/SideMenu/side-menu.ts
index fc3d1925..c46fcca9 100644
--- a/lib/components/SideMenu/side-menu.ts
+++ b/lib/components/SideMenu/side-menu.ts
@@ -69,9 +69,17 @@ export class SideMenu extends BaseComponent implements OnInit, OnDestroy {
}
changed(item) {
- if (item) {
- this.activeCatCaption = item.name || '';
- this.activeItemCaption = item.parent && item.parent.name || '';
+ if (!item) {
+ this.activeCatCaption = '';
+ this.activeItemCaption = '';
+ return;
+ }
+ if (item.parent) {
+ this.activeItemCaption = item.name;
+ this.activeCatCaption = item.parent.name;
+ } else {
+ this.activeCatCaption = item.name;
+ this.activeItemCaption = '';
}
//safari doesn't update bindings if not run changeDetector manually :(
@@ -88,12 +96,10 @@ export class SideMenu extends BaseComponent implements OnInit, OnDestroy {
}
activateAndScroll(item) {
- if (this.mobileMode()) {
+ if (this.mobileMode) {
this.toggleMobileNav();
}
- //if (!this.flatItems[idx].ready) return; // TODO: move inside next statement
-
this.menuService.activate(item.flatIdx);
this.menuService.scrollToActive();
}
@@ -111,7 +117,7 @@ export class SideMenu extends BaseComponent implements OnInit, OnDestroy {
};
}
- mobileMode() {
+ get mobileMode() {
return this.$mobileNav.clientHeight > 0;
}
diff --git a/lib/services/menu.service.ts b/lib/services/menu.service.ts
index 3bd5f88e..e4fd784d 100644
--- a/lib/services/menu.service.ts
+++ b/lib/services/menu.service.ts
@@ -15,53 +15,45 @@ import * as slugify from 'slugify';
const CHANGE = {
NEXT : 1,
BACK : -1,
- INITIAL : 0
};
@Injectable()
export class MenuService {
-
changed: EventEmitter = new EventEmitter();
- ready: BehaviorSubject = new BehaviorSubject(false);
- items: Array