redoc/lib/components/RequestSamples/request-samples.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-01-31 20:37:51 +03:00
'use strict';
2016-10-23 20:18:42 +03:00
import { Component, ViewChildren, QueryList, Input,
ChangeDetectionStrategy, OnInit, HostBinding, ElementRef, NgZone } from '@angular/core';
2016-10-23 20:18:42 +03:00
import { Subject } from 'rxjs/Subject';
2016-08-22 12:12:13 +03:00
import { BaseComponent, SpecManager } from '../base';
2016-01-31 20:37:51 +03:00
import JsonPointer from '../../utils/JsonPointer';
2016-08-22 12:12:13 +03:00
import { Tabs } from '../../shared/components/index';
import { AppStateService, ScrollService } from '../../services/index';
2016-02-03 17:47:20 +03:00
2016-08-22 12:12:13 +03:00
@Component({
2016-01-31 20:37:51 +03:00
selector: 'request-samples',
templateUrl: './request-samples.html',
styleUrls: ['./request-samples.css'],
2016-08-22 12:12:13 +03:00
changeDetection: ChangeDetectionStrategy.OnPush
2016-01-31 20:37:51 +03:00
})
2016-08-28 21:46:10 +03:00
export class RequestSamples extends BaseComponent implements OnInit {
2016-08-22 12:12:13 +03:00
@Input() pointer:string;
@Input() schemaPointer:string;
@ViewChildren(Tabs) childQuery:QueryList<Tabs>;
@HostBinding('attr.hidden') hidden;
2016-08-22 12:12:13 +03:00
childTabs: Tabs;
2016-10-23 20:18:42 +03:00
selectedLang: Subject<any>;
samples: Array<any>;
constructor(
specMgr:SpecManager,
public appState:AppStateService,
private scrollService: ScrollService,
private el: ElementRef,
private zone: NgZone
) {
super(specMgr);
2016-06-06 19:32:20 +03:00
2016-10-23 20:18:42 +03:00
this.selectedLang = this.appState.samplesLanguage;
2016-05-06 00:48:41 +03:00
}
2016-02-03 17:47:20 +03:00
changeLangNotify(lang) {
let relativeScrollPos = this.scrollService.relativeScrollPos(this.el.nativeElement);
2016-10-23 20:18:42 +03:00
this.selectedLang.next(lang);
// do scroll in the end of VM turn to have it seamless
let subscription = this.zone.onMicrotaskEmpty.subscribe(() => {
this.scrollService.scrollTo(this.el.nativeElement, relativeScrollPos);
subscription.unsubscribe();
});
2016-02-03 17:47:20 +03:00
}
init() {
this.schemaPointer = this.schemaPointer ? JsonPointer.join(this.schemaPointer, 'schema') : null;
this.samples = this.componentSchema['x-code-samples'] || [];
if (!this.schemaPointer && !this.samples.length) this.hidden = true;
2016-01-31 20:37:51 +03:00
}
2016-08-28 21:46:10 +03:00
ngOnInit() {
this.preinit();
}
2016-01-31 20:37:51 +03:00
}