-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the add definition dialog is now a component - much nicer
- Loading branch information
1 parent
0381112
commit d03e4f7
Showing
9 changed files
with
220 additions
and
135 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
...end/app/studio/pages/apis/{apiId}/editor/components/dialogs/add-definition.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!-- Add Definition Dialog --> | ||
<div> | ||
<div bsModal #addDefinitionModal="bs-modal" class="modal fade" id="addDefinitionModal" tabindex="-1" role="dialog" | ||
aria-labelledby="addDefinitionModalLabel" role="dialog" aria-hidden="true" *ngIf="isOpen()" | ||
(onShown)="addDefinitionInput.focus()" (onHidden)="close()"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" (click)="addDefinitionModal.hide()"> | ||
<span class="pficon pficon-close"></span> | ||
</button> | ||
<h4 class="modal-title" id="addDefinitionModalLabel">Add Definition</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<p>Enter a new definition name below and then click Add.</p> | ||
<form id="adddef-form" class="form-horizontal" #addDefinitionForm="ngForm" data-dismiss="modal"> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label" for="definitionName">Name</label> | ||
<div class="col-sm-10"> | ||
<input #addDefinitionInput name="definitionName" type="text" id="definitionName" class="form-control" | ||
placeholder="Enter a Definition Name" | ||
required [(ngModel)]="name"> | ||
</div> | ||
</div> | ||
<div class="section example-section"> | ||
<div class="section-header"> | ||
<a class="collapsed" data-toggle="collapse" data-target="#example-section-body"> | ||
<span class="section-label">FROM EXAMPLE (optional)</span> | ||
</a> | ||
</div> | ||
<div class="section-body collapse" id="example-section-body"> | ||
<div class="explanation"> | ||
Input a JSON formatted sample below and we'll do our best to initialize the Definition's schema | ||
based on the example. | ||
</div> | ||
<div class="example"> | ||
<ace-editor #exampleEditor | ||
[theme]="'eclipse'" | ||
[mode]="'json'" | ||
[durationBeforeCallback]="350" | ||
(textChanged)="setExampleDefinition($event)" | ||
style="position: relative; height: 200px; border: 1px solid #ccc; width: 100%"></ace-editor> | ||
<button class="btn btn-default btn-xs" type="button" | ||
[disabled]="!isExampleDefinitionFormattable()" (click)="formatExampleDefinition()"> | ||
<span class="fa fa-fw fa-indent"></span> | ||
<span>Format</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-primary" data-dismiss="modal" (click)="add()" | ||
[disabled]="!addDefinitionForm.form.valid || !isExampleDefinitionValid()">Add</button> | ||
<button type="button" class="btn btn-default" data-dismiss="modal" (click)="cancel()">Cancel</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
...end/app/studio/pages/apis/{apiId}/editor/components/dialogs/add-definition.component.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.example-section .example button { | ||
margin-top: 5px; | ||
} |
145 changes: 145 additions & 0 deletions
145
...t-end/app/studio/pages/apis/{apiId}/editor/components/dialogs/add-definition.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* @license | ||
* Copyright 2017 JBoss Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {Component, Output, EventEmitter, ViewChild, ViewChildren, QueryList} from "@angular/core"; | ||
import {ModalDirective} from "ng2-bootstrap"; | ||
import {AceEditorDirective} from "ng2-ace-editor"; | ||
|
||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: "add-definition-dialog", | ||
templateUrl: "add-definition.component.html", | ||
styleUrls: ["add-definition.component.css"] | ||
}) | ||
export class AddDefinitionDialogComponent { | ||
|
||
@Output() onAdd: EventEmitter<any> = new EventEmitter<any>(); | ||
|
||
@ViewChildren("addDefinitionModal") addDefinitionModal: QueryList<ModalDirective>; | ||
@ViewChildren("exampleEditor") exampleEditor: QueryList<AceEditorDirective>; | ||
|
||
protected _isOpen: boolean = false; | ||
|
||
protected name: string = ""; | ||
|
||
protected example: string = ""; | ||
protected exampleValid: boolean = true; | ||
protected exampleFormattable: boolean = false; | ||
|
||
/** | ||
* Called to open the dialog. | ||
*/ | ||
public open(): void { | ||
console.info("Opening the Add Definition dialog!"); | ||
this._isOpen = true; | ||
this.addDefinitionModal.changes.subscribe( thing => { | ||
if (this.addDefinitionModal.first) { | ||
this.addDefinitionModal.first.show(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Called to close the dialog. | ||
*/ | ||
public close(): void { | ||
this._isOpen = false; | ||
this.name = ""; | ||
this.example = ""; | ||
this.exampleValid = false; | ||
this.exampleFormattable = false; | ||
} | ||
|
||
/** | ||
* Called when the user clicks "add". | ||
*/ | ||
protected add(): void { | ||
let data: any = { | ||
name: this.name, | ||
example: this.example | ||
}; | ||
this.onAdd.emit(data); | ||
this.cancel(); | ||
} | ||
|
||
/** | ||
* Called when the user clicks "cancel". | ||
*/ | ||
protected cancel(): void { | ||
this.addDefinitionModal.first.hide(); | ||
} | ||
|
||
/** | ||
* Returns true if the dialog is open. | ||
* @return {boolean} | ||
*/ | ||
public isOpen(): boolean { | ||
return this._isOpen; | ||
} | ||
|
||
/** | ||
* Called when the user changes the example definition in the Add Definition modal dialog. | ||
* @param definition | ||
*/ | ||
public setExampleDefinition(definition: string): void { | ||
this.example = definition; | ||
if (this.example === "") { | ||
this.exampleValid = true; | ||
this.exampleFormattable = false; | ||
} else { | ||
try { | ||
JSON.parse(this.example); | ||
this.exampleValid = true; | ||
this.exampleFormattable = true; | ||
} catch (e) { | ||
this.exampleValid = false; | ||
this.exampleFormattable = false; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if it's possible to format the example definition (it must be non-null and | ||
* syntactically valid). | ||
* @return {boolean} | ||
*/ | ||
public isExampleDefinitionFormattable(): boolean { | ||
return this.exampleFormattable; | ||
} | ||
|
||
/** | ||
* Returns true if the example definition added by the user in the Add Definition modal | ||
* dialog is valid (syntactically). | ||
* @return {boolean} | ||
*/ | ||
public isExampleDefinitionValid(): boolean { | ||
return this.exampleValid; | ||
} | ||
|
||
/** | ||
* Called to format the example definition. | ||
*/ | ||
public formatExampleDefinition(): void { | ||
if (this.exampleEditor.first) { | ||
let jsObj: any = JSON.parse(this.example); | ||
let nsrcStr: string = JSON.stringify(jsObj, null, 4); | ||
this.exampleEditor.first.setText(nsrcStr); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.