Use dropdown instead of buttons for discriminator switch

This commit is contained in:
Roman Hotsiy 2016-04-19 18:56:20 +03:00
parent 4c450e56b5
commit 4f2e1a29e6
2 changed files with 10 additions and 9 deletions

View File

@ -29,10 +29,10 @@
<div class="param-description" innerHtml="{{prop.description | marked}}"></div>
<div class="discriminator-info" *ngIf="prop.isDiscriminator">
<span>This field value determines the exact schema:</span>
<ul>
<li *ngFor="#derived of schema.derived"
(click)="selectDerived(derived)" [ngClass]="{active: derived.active}"> {{derived.name}} </li>
</ul>
<dropdown (change)="selectDerived($event)">
<option *ngFor="#derived of schema.derived; #i=index"
[value]="i">{{derived.name}}</option>
</dropdown>
</div>
</td>
</tr>

View File

@ -3,14 +3,14 @@
import {ElementRef} from 'angular2/core';
import {RedocComponent, BaseComponent, SchemaManager} from '../base';
import {Tabs, Tab} from '../../common/components/Tabs/tabs';
import {DropDown} from '../../common/components/DropDown/dropdown';
import JsonPointer from '../../utils/JsonPointer';
@RedocComponent({
selector: 'json-schema',
templateUrl: './lib/components/JsonSchema/json-schema.html',
styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
directives: [JsonSchema, Tabs, Tab],
directives: [JsonSchema, DropDown],
inputs: ['isArray', 'final', 'nestOdd', 'childFor']
})
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
@ -21,8 +21,9 @@ export default class JsonSchema extends BaseComponent {
this.final = false;
}
selectDerived(subClass) {
if (subClass.active) return;
selectDerived(subClassIdx) {
let subClass = this.schema.derived[subClassIdx];
if (!subClass || subClass.active) return;
this.schema.derived.forEach((subSchema) => {
subSchema.active = false;
});
@ -62,7 +63,7 @@ export default class JsonSchema extends BaseComponent {
}
this.schema = schema;
if (schema.derived.length) this.selectDerived(schema.derived[0]);
this.selectDerived(0);
}
prepareObjectPropertiesData(schema) {