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

View File

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