Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort button #2259

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export class IconButtonComponent extends AbstractBaseComponent {
if (this.type === 'import') {
return "pficon pficon-import";
}
if (this.type === 'sort') {
return "fa fa-sort-amount-down";
}
return "fa fa-info";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
[title]="'Add a property to the schema.'"></icon-button>
<icon-button (onClick)="deleteAllSchemaProperties()" [disabled]="!hasProperties()" [pullRight]="true" type="delete"
[title]="'Delete all properties from the schema.'"></icon-button>
<icon-button (onClick)="toggleSorted()" [pullRight]="true" type="sort"
[title]="'Sort properties'"></icon-button>
</span>
<div body>
<!-- Warning when no properties exist -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class PropertiesSectionComponent extends AbstractBaseComponent {

_pconfigOpen: boolean = false;

_sorted: boolean = true;

/**
* C'tor.
* @param changeDetectorRef
Expand Down Expand Up @@ -88,6 +90,10 @@ export class PropertiesSectionComponent extends AbstractBaseComponent {
this._pconfigOpen = !this._pconfigOpen;
}

public toggleSorted(): void {
this._sorted = !this._sorted;
}

public hasProperties(): boolean {
return this.properties().length > 0;
}
Expand All @@ -96,9 +102,15 @@ export class PropertiesSectionComponent extends AbstractBaseComponent {
let rval: Schema[] = [];

let sourceSchema: OasSchema = this.getPropertySourceSchema();
sourceSchema.getPropertyNames().sort((left, right) => {
return left.localeCompare(right);
}).forEach(name => rval.push(sourceSchema.getProperty(name)));
// let propertyNames: String[] = sourceSchema.getPropertyNames();

if (this._sorted) {
sourceSchema.getPropertyNames().sort((left, right) => {
return left.localeCompare(right)
}).forEach(name => rval.push(sourceSchema.getProperty(name)));
} else {
sourceSchema.getPropertyNames().forEach(name => rval.push(sourceSchema.getProperty(name)));
}

return rval;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
contextHelp="The core of any REST API is the set of resources/paths it exposes. Each path is of the form '/path/to/resource' and can support a number of operations.">
<span actions>
<icon-button (onClick)="addPathDialog.open(document, getCurrentPathSelection())" [pullRight]="true" type="add"></icon-button>
<icon-button (onClick)="toggleSortPath()" [pullRight]="true" type="sort" title="Sort path"></icon-button>
</span>
<div body tabindex="0" class="path-list master-entity-list" (keydown)="onPathsKeypress($event)" #pathList>
<signpost *ngIf="paths().length === 0">
Expand All @@ -117,6 +118,7 @@
<span actions>
<icon-button (onClick)="openAddDefinitionEditor()" [pullRight]="true" type="add" title="Create Data Type"></icon-button>
<icon-button *ngIf="importsEnabled()" (onClick)="importDataTypes()" [pullRight]="true" type="import" title="Import Data Type"></icon-button>
<icon-button (onClick)="toggleSortDefinition()" [pullRight]="true" type="sort" title="Sort Data Type"></icon-button>
</span>
<div body tabindex="0" class="definition-list master-entity-list" (keydown)="onDefinitionsKeypress($event)" #defList>
<signpost *ngIf="definitions().length === 0">
Expand All @@ -136,6 +138,7 @@
<span actions>
<icon-button (onClick)="openAddResponseEditor()" [pullRight]="true" type="add" title="Create Response"></icon-button>
<icon-button *ngIf="importsEnabled()" (onClick)="importResponses()" [pullRight]="true" type="import" title="Import Response"></icon-button>
<icon-button (onClick)="toggleSortResponse()" [pullRight]="true" type="sort" title="Sort Response"></icon-button>
</span>
<div body tabindex="0" class="response-list master-entity-list" (keydown)="onResponsesKeypress($event)" #respList>
<signpost *ngIf="responses().length === 0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export class EditorMasterComponent extends AbstractBaseComponent {
_paths: OasPathItem[];
_defs: (Oas20SchemaDefinition | Oas30SchemaDefinition)[];
_responses: (Oas20ResponseDefinition | Oas30ResponseDefinition)[];
_sortedDefinition: Boolean = true;
_sortedPath: Boolean = true;
_sortedResponse: Boolean = true;

/**
* C'tor.
Expand Down Expand Up @@ -194,38 +197,47 @@ export class EditorMasterComponent extends AbstractBaseComponent {
}

/**
* Returns an array of paths that match the filter criteria and are sorted alphabetically.
* Returns an array of paths that match the filter criteria and are sorted alphabetically or not.
*/
public paths(): OasPathItem[] {
if (!this._paths) {
let viz: FindPathItemsVisitor = new FindPathItemsVisitor(this.filterCriteria);
if (this.document && this.document.paths) {
this.document.paths.getPathItems().forEach(pathItem => {
VisitorUtil.visitNode(pathItem, viz);
});
}
let viz: FindPathItemsVisitor = new FindPathItemsVisitor(this.filterCriteria);
if (this.document && this.document.paths) {
this.document.paths.getPathItems().forEach(pathItem => {
VisitorUtil.visitNode(pathItem, viz);
});
}

if (this._sortedPath) {
this._paths = viz.getSortedPathItems();
} else {
this._paths = viz.pathItems;
}

return this._paths;
}

/**
* Returns the array of definitions, filtered by search criteria and sorted.
* Returns the array of definitions, filtered by search criteria and sorted or not.
*/
public definitions(): (Oas20SchemaDefinition | Oas30SchemaDefinition)[] {
let viz: FindSchemaDefinitionsVisitor = new FindSchemaDefinitionsVisitor(this.filterCriteria);
if (!this._defs) {
if (this.document.is2xDocument() && (this.document as Oas20Document).definitions) {
(this.document as Oas20Document).definitions.getDefinitions().forEach( definition => {
VisitorUtil.visitNode(definition, viz);
})
} else if (this.document.is3xDocument() && (this.document as Oas30Document).components) {
(this.document as Oas30Document).components.getSchemaDefinitions().forEach( definition => {
VisitorUtil.visitNode(definition, viz);
})
}

if (this.document.is2xDocument() && (this.document as Oas20Document).definitions) {
(this.document as Oas20Document).definitions.getDefinitions().forEach(definition => {
VisitorUtil.visitNode(definition, viz);
})
} else if (this.document.is3xDocument() && (this.document as Oas30Document).components) {
(this.document as Oas30Document).components.getSchemaDefinitions().forEach(definition => {
VisitorUtil.visitNode(definition, viz);
})
}

if (this._sortedDefinition) {
this._defs = viz.getSortedSchemaDefinitions();
} else {
this._defs = viz.schemaDefinitions;
}

return this._defs;
}

Expand All @@ -238,22 +250,27 @@ export class EditorMasterComponent extends AbstractBaseComponent {
}

/**
* Returns an array of responses filtered by the search criteria and sorted.
* Returns an array of responses filtered by the search criteria and sorted or not.
*/
public responses(): (Oas20ResponseDefinition | Oas30ResponseDefinition)[] {
let viz: FindResponseDefinitionsVisitor = new FindResponseDefinitionsVisitor(this.filterCriteria);
if (!this._responses) {
if (this.document.is2xDocument() && (this.document as Oas20Document).responses) {
(this.document as Oas20Document).responses.getResponses().forEach( response => {
VisitorUtil.visitNode(response, viz);
})
} else if (this.document.is3xDocument() && (this.document as Oas30Document).components) {
(this.document as Oas30Document).components.getResponseDefinitions().forEach( response => {
VisitorUtil.visitNode(response, viz);
})
}

if (this.document.is2xDocument() && (this.document as Oas20Document).responses) {
(this.document as Oas20Document).responses.getResponses().forEach(response => {
VisitorUtil.visitNode(response, viz);
})
} else if (this.document.is3xDocument() && (this.document as Oas30Document).components) {
(this.document as Oas30Document).components.getResponseDefinitions().forEach(response => {
VisitorUtil.visitNode(response, viz);
})
}

if (this._sortedResponse) {
this._responses = viz.getSortedResponseDefinitions();
} else {
this._responses = viz.responseDefinitions;
}

return this._responses;
}

Expand Down Expand Up @@ -862,6 +879,18 @@ export class EditorMasterComponent extends AbstractBaseComponent {
this.onImportComponent.emit(ComponentType.response);
}

public toggleSortDefinition() {
this._sortedDefinition = !this._sortedDefinition;
}

public toggleSortPath() {
this._sortedPath = !this._sortedPath;
}

public toggleSortResponse() {
this._sortedResponse = !this._sortedResponse;
}

}


Expand Down
Loading