2016-01-31 20:37:51 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-06 00:48:41 +03:00
|
|
|
import { forwardRef, ViewChildren, QueryList } from '@angular/core';
|
2016-02-10 14:19:50 +03:00
|
|
|
|
2016-05-06 00:48:41 +03:00
|
|
|
import { RedocComponent, BaseComponent, SchemaManager } from '../base';
|
2016-01-31 20:37:51 +03:00
|
|
|
import JsonPointer from '../../utils/JsonPointer';
|
2016-05-06 00:48:41 +03:00
|
|
|
import { Tabs, Tab } from '../..//shared/components/index';
|
|
|
|
import { SchemaSample } from '../index';
|
|
|
|
import { PrismPipe } from '../../utils/pipes';
|
|
|
|
import { RedocEventsService } from '../../services/index';
|
2016-02-03 17:47:20 +03:00
|
|
|
|
2016-01-31 20:37:51 +03:00
|
|
|
@RedocComponent({
|
|
|
|
selector: 'request-samples',
|
|
|
|
templateUrl: './lib/components/RequestSamples/request-samples.html',
|
|
|
|
styleUrls: ['./lib/components/RequestSamples/request-samples.css'],
|
2016-05-06 00:48:41 +03:00
|
|
|
directives: [forwardRef(() =>SchemaSample), Tabs, Tab],
|
|
|
|
inputs: ['schemaPointer'],
|
|
|
|
pipes: [PrismPipe]
|
2016-01-31 20:37:51 +03:00
|
|
|
})
|
2016-05-06 00:48:41 +03:00
|
|
|
@Reflect.metadata('parameters', [[SchemaManager], [RedocEventsService], [new ViewChildren(Tabs), QueryList]])
|
|
|
|
export class RequestSamples extends BaseComponent {
|
|
|
|
constructor(schemaMgr, events, childQuery) {
|
2016-01-31 20:37:51 +03:00
|
|
|
super(schemaMgr);
|
2016-05-06 00:48:41 +03:00
|
|
|
childQuery.changes.subscribe(() => {
|
|
|
|
this.childTabs = childQuery.first;
|
2016-02-03 17:47:20 +03:00
|
|
|
});
|
2016-05-06 00:48:41 +03:00
|
|
|
this.events = events;
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.subscribeForEvents();
|
2016-02-03 17:47:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
changeLangNotify(lang) {
|
2016-05-06 00:48:41 +03:00
|
|
|
this.events.samplesLanguageChanged.next(lang);
|
2016-02-03 17:47:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
subscribeForEvents() {
|
2016-05-06 00:48:41 +03:00
|
|
|
this.events.samplesLanguageChanged.subscribe((sampleLang) => {
|
|
|
|
if (!this.childTabs) return;
|
|
|
|
this.childTabs.selectyByTitle(sampleLang);
|
2016-02-03 17:47:20 +03:00
|
|
|
});
|
2016-01-31 20:37:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
prepareModel() {
|
|
|
|
this.data = {};
|
2016-05-06 00:48:41 +03:00
|
|
|
this.data.schemaPointer = JsonPointer.join(this.schemaPointer, 'schema');
|
2016-01-31 20:37:51 +03:00
|
|
|
this.data.samples = this.componentSchema['x-code-samples'] || [];
|
|
|
|
}
|
|
|
|
}
|