Skip to content

Commit b28fd2d

Browse files
committed
fixed some issues with source editing de-selecting the item in the master panel
1 parent bcda2e6 commit b28fd2d

File tree

8 files changed

+67
-9
lines changed

8 files changed

+67
-9
lines changed

front-end/app/studio/pages/apis/{apiId}/editor/_components/forms/definition-form.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ export class DefinitionFormComponent extends SourceFormComponent<Oas20Definition
113113
this.onDeselect.emit(true);
114114
}
115115

116+
public formType(): string {
117+
return "definition";
118+
}
119+
116120
public enableSourceMode(): void {
117121
this.sourceNode = this.definition;
118122
super.enableSourceMode();

front-end/app/studio/pages/apis/{apiId}/editor/_components/forms/operation-form.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
<button class="btn btn-default btn-xs" [disabled]="!canFormatSource()" (click)="formatSource()"><span class="fa fa-fw fa-indent"></span> <span>Format</span></button>
3737
<button class="btn btn-default btn-xs" [disabled]="!canRevertSource()" (click)="revertSource()"><span class="fa fa-fw fa-undo"></span> <span>Revert</span></button>
3838
<button class="btn btn-primary btn-xs" [disabled]="!canSaveSource()" (click)="saveSource()"><span class="pficon pficon-save"></span> <span>Save</span></button>
39+
<button class="btn btn-default btn-xs" (click)="toggleSourceFormat()">
40+
<span class="fa fa-fw fa-code"></span>
41+
<span *ngIf="sourceFormat() === 'yaml'">As JSON</span>
42+
<span *ngIf="sourceFormat() === 'json'">As YAML</span>
43+
</button>
3944
</div>
4045
<div class="detail-content" style="position: relative" *ngIf="isSourceMode()">
4146
<ace-editor #sourceEditor

front-end/app/studio/pages/apis/{apiId}/editor/_components/forms/operation-form.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ export class OperationFormComponent extends SourceFormComponent<Oas20Operation>
550550
this.onCommand.emit(command);
551551
}
552552

553+
public formType(): string {
554+
return "operation";
555+
}
556+
553557
public enableSourceMode(): void {
554558
this.sourceNode = this.operation;
555559
super.enableSourceMode();

front-end/app/studio/pages/apis/{apiId}/editor/_components/forms/path-form.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<button class="btn btn-default btn-xs" [disabled]="!canFormatSource()" (click)="formatSource()"><span class="fa fa-fw fa-indent"></span> <span>Format</span></button>
2929
<button class="btn btn-default btn-xs" [disabled]="!canRevertSource()" (click)="revertSource()"><span class="fa fa-fw fa-undo"></span> <span>Revert</span></button>
3030
<button class="btn btn-primary btn-xs" [disabled]="!canSaveSource()" (click)="saveSource()"><span class="pficon pficon-save"></span> <span>Save</span></button>
31+
<button class="btn btn-default btn-xs" (click)="toggleSourceFormat()">
32+
<span class="fa fa-fw fa-code"></span>
33+
<span *ngIf="sourceFormat() === 'yaml'">As JSON</span>
34+
<span *ngIf="sourceFormat() === 'json'">As YAML</span>
35+
</button>
3136
</div>
3237
<div class="detail-content" style="position: relative" *ngIf="isSourceMode()">
3338
<ace-editor #sourceEditor

front-end/app/studio/pages/apis/{apiId}/editor/_components/forms/path-form.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
DeleteAllParameters, DeleteNodeCommand, DeleteParameterCommand,
2727
DeletePathCommand
2828
} from "../../_commands/delete.command";
29-
import {SourceFormComponent} from "./source-form.base";
29+
import {NodeSelectionEvent, SourceFormComponent} from "./source-form.base";
3030
import {ReplacePathItemCommand} from "../../_commands/replace.command";
3131
import {ModelUtils} from "../../_util/model.util";
3232
import {
@@ -58,7 +58,6 @@ export class PathFormComponent extends SourceFormComponent<Oas20PathItem> {
5858
return this._path;
5959
}
6060

61-
@Output() onOperationSelected: EventEmitter<string> = new EventEmitter<string>();
6261
@Output() onDeselect: EventEmitter<boolean> = new EventEmitter<boolean>();
6362

6463
@ViewChild("addQueryParamDialog") public addQueryParamDialog: AddQueryParamDialogComponent;
@@ -178,7 +177,7 @@ export class PathFormComponent extends SourceFormComponent<Oas20PathItem> {
178177
}
179178

180179
public selectOperation(operation: Oas20Operation): void {
181-
this.onOperationSelected.emit(operation.method());
180+
this.onNodeSelected.emit(new NodeSelectionEvent(operation, "operation"));
182181
}
183182

184183
public createOperation(operationType: string): void {
@@ -285,6 +284,10 @@ export class PathFormComponent extends SourceFormComponent<Oas20PathItem> {
285284
this.onCommand.emit(command);
286285
}
287286

287+
public formType(): string {
288+
return "path";
289+
}
290+
288291
public enableSourceMode(): void {
289292
this.sourceNode = this.path;
290293
super.enableSourceMode();

front-end/app/studio/pages/apis/{apiId}/editor/_components/forms/source-form.base.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ import {AceEditorDirective} from "ng2-ace-editor";
2626
import {ObjectUtils} from "../../_util/object.util";
2727
import * as YAML from "yamljs";
2828

29+
30+
export class NodeSelectionEvent {
31+
public node: OasNode;
32+
public type: string;
33+
34+
constructor(node: OasNode, type: string) {
35+
this.node = node;
36+
this.type = type;
37+
}
38+
}
39+
2940
/**
3041
* Base class for all forms that support a "Source" tab.
3142
*/
@@ -34,6 +45,7 @@ export abstract class SourceFormComponent<T extends OasNode> {
3445
private static library: OasLibraryUtils = new OasLibraryUtils();
3546

3647
@Output() onCommand: EventEmitter<ICommand> = new EventEmitter<ICommand>();
48+
@Output() onNodeSelected: EventEmitter<NodeSelectionEvent> = new EventEmitter<NodeSelectionEvent>();
3749

3850
private _mode: string = "design";
3951
private _sourceFormat: string = "yaml";
@@ -64,15 +76,20 @@ export abstract class SourceFormComponent<T extends OasNode> {
6476

6577
public source(): string {
6678
if (this._sourceFormat === "yaml") {
67-
return YAML.stringify(this.sourceJs(), 100, 2);
79+
return YAML.stringify(this.sourceJs(), 100, 4);
6880
} else {
6981
return JSON.stringify(this.sourceJs(), null, 4);
7082
}
7183
}
7284

7385
public updateSource(newSource: any): void {
7486
try {
75-
let newJsObject: any = YAML.parse(newSource);
87+
let newJsObject: any;
88+
if (this.sourceFormat() === "yaml") {
89+
newJsObject = YAML.parse(newSource);
90+
} else {
91+
newJsObject = JSON.parse(newSource);
92+
}
7693
let currentJsObj: any = this.sourceJs();
7794
this._source.dirty = !ObjectUtils.objectEquals(currentJsObj, newJsObject);
7895
this._source.value = SourceFormComponent.library.readNode(newJsObject, this.createEmptyNodeForSource());
@@ -108,12 +125,15 @@ export abstract class SourceFormComponent<T extends OasNode> {
108125
public saveSource(): void {
109126
let command: ICommand = this.createReplaceNodeCommand(<T>this._source.value);
110127
this.onCommand.emit(command);
128+
this.onNodeSelected.emit(new NodeSelectionEvent(<T>this._source.value, this.formType()));
111129
this.sourceNode = this._source.value;
112130
this._source.dirty = false;
113131
this._source.value = null;
114132
this._source.valid = true;
115133
}
116134

135+
public abstract formType(): string;
136+
117137
public sourceFormat(): string {
118138
return this._sourceFormat;
119139
}
@@ -132,7 +152,12 @@ export abstract class SourceFormComponent<T extends OasNode> {
132152

133153
public formatSource(): void {
134154
let nsrc: any = SourceFormComponent.library.writeNode(this._source.value);
135-
let nsrcStr: string = YAML.stringify(nsrc);
155+
let nsrcStr: string;
156+
if (this._sourceFormat === "yaml") {
157+
nsrcStr = YAML.stringify(this.sourceJs(), 100, 4);
158+
} else {
159+
nsrcStr = JSON.stringify(this.sourceJs(), null, 4);
160+
}
136161
this.sourceEditor.setText(nsrcStr);
137162
}
138163

front-end/app/studio/pages/apis/{apiId}/editor/editor.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@ <h2>{{ document().info.title }}</h2>
214214
<main-form [document]="document()" (onCommand)="onCommand($event)" class="editor-detail-form"
215215
*ngIf="selectedType === 'main'"></main-form>
216216
<path-form [path]="selectedPath()" (onCommand)="onCommand($event)" class="editor-detail-form"
217-
(onOperationSelected)="selectOperation(selectedPath(), $event)" (onDeselect)="deselectPath()"
217+
(onNodeSelected)="selectNode($event)" (onDeselect)="deselectPath()"
218218
*ngIf="selectedType === 'path'"></path-form>
219219
<operation-form [operation]="selectedOperation()" (onCommand)="onCommand($event)" class="editor-detail-form"
220+
(onNodeSelected)="selectNode($event)"
220221
(onDeselect)="deselectOperation()" *ngIf="selectedType === 'operation'"></operation-form>
221222
<definition-form [definition]="selectedDefinition()" (onCommand)="onCommand($event)" class="editor-detail-form"
223+
(onNodeSelected)="selectNode($event)"
222224
(onDeselect)="deselectDefinition()" *ngIf="selectedType === 'definition'"></definition-form>
223225
<problem-form [problem]="selectedProblem()" (onCommand)="onCommand($event)" class="editor-detail-form"
224226
(onGoToProblem)="goToProblem()"

front-end/app/studio/pages/apis/{apiId}/editor/editor.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {AddPathDialogComponent} from "./_components/dialogs/add-path.component";
3333
import {DeleteDefinitionSchemaCommand, DeleteNodeCommand, DeletePathCommand} from "./_commands/delete.command";
3434
import {AllNodeVisitor, ModelUtils} from "./_util/model.util";
3535
import {ObjectUtils} from "./_util/object.util";
36+
import {NodeSelectionEvent} from "./_components/forms/source-form.base";
3637

3738

3839
@Component({
@@ -217,8 +218,8 @@ export class ApiEditorComponent {
217218
if (this.selectedType === "operation" && this.selectedItem === operation) {
218219
this.selectPath(operation.parent() as Oas20PathItem);
219220
} else {
220-
this.selectedType = "operation";
221221
this.selectedItem = operation;
222+
this.selectedType = "operation";
222223
}
223224
}
224225

@@ -229,8 +230,17 @@ export class ApiEditorComponent {
229230
if (this.selectedType !== "operation") {
230231
return;
231232
}
232-
this.selectedType = "path";
233233
this.selectedItem = this.selectedItem.parent();
234+
this.selectedType = "path";
235+
}
236+
237+
/**
238+
* Called when the user does something to cause the selection to change.
239+
* @param event
240+
*/
241+
public selectNode(event: NodeSelectionEvent): void {
242+
this.selectedItem = event.node;
243+
this.selectedType = event.type;
234244
}
235245

236246
/**

0 commit comments

Comments
 (0)