mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 13:20:19 +03:00
Add sorting
This commit is contained in:
parent
d1562d5ff1
commit
c2d081dbd7
|
@ -3,7 +3,7 @@
|
|||
import { getChildDebugElement } from '../../../tests/helpers';
|
||||
import { Component } from '@angular/core';
|
||||
import { OptionsService, MenuItem } from '../../services/index';
|
||||
|
||||
import { compareEndpoints, menuItemsList } from './sort';
|
||||
import {
|
||||
inject,
|
||||
async
|
||||
|
@ -64,6 +64,16 @@ describe('Redoc components', () => {
|
|||
component.activeItemCaption.should.be.equal('');
|
||||
});
|
||||
|
||||
it('should confirm that component is sorted', () => {
|
||||
for(var i=0;i<menuItemsList.length;i++) {
|
||||
if(menuItemsList[i].items !== null){
|
||||
for(var j=0;j<menuItemsList[i].items.length;j++){
|
||||
component.menuItems[i].items[j].name.should.be.equal(menuItemsList[i].items[j].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should set active item and cat captions on change event', () => {
|
||||
let parentItem: MenuItem = {
|
||||
id: 'id',
|
||||
|
|
|
@ -15,7 +15,7 @@ import { trigger, state, animate, transition, style } from '@angular/core';
|
|||
import { ScrollService, MenuService, OptionsService, MenuItem } from '../../services/';
|
||||
import { PerfectScrollbar } from '../../shared/components';
|
||||
import { BrowserDomAdapter as DOM } from '../../utils/browser-adapter';
|
||||
|
||||
import { compareEndpoints, menuItemsList } from './sort';
|
||||
const global = window;
|
||||
|
||||
@Component({
|
||||
|
@ -114,6 +114,16 @@ export class SideMenu implements OnInit, OnDestroy {
|
|||
init() {
|
||||
this.menuItems = this.menuService.items;
|
||||
|
||||
for(var i=0;i<this.menuItems.length;i++){
|
||||
if(this.menuItems[i].items !== null){
|
||||
for(var j=0;j<this.menuItems[i].items.length;j++){
|
||||
if(this.menuItems[i].items[j].items == null)
|
||||
this.menuItems[i].items.sort(compareEndpoints);
|
||||
else
|
||||
this.menuItems[i].items[j].items.sort(compareEndpoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.$mobileNav = DOM.querySelector(this.$element, '.mobile-nav');
|
||||
this.$resourcesNav = DOM.querySelector(this.$element, '#resources-nav');
|
||||
|
||||
|
|
204
lib/components/SideMenu/sort.ts
Normal file
204
lib/components/SideMenu/sort.ts
Normal file
|
@ -0,0 +1,204 @@
|
|||
export const compareEndpoints = (a,b) => {
|
||||
let sortOrderComparisonResult: number;
|
||||
if(a.metadata.sortOrder != null && b.metadata.sortOrder != null)
|
||||
sortOrderComparisonResult = a.metadata.sortOrder.localeCompare(b.metadata.sortOrder);
|
||||
let operationComparisonResult: number;
|
||||
if(a.metadata.operation != null && b.metadata.operation != null)
|
||||
operationComparisonResult = a.metadata.operation.localeCompare(b.metadata.operation);
|
||||
let nameComparisonResult: number = a.name.localeCompare(b.name);
|
||||
|
||||
if(sortOrderComparisonResult != null && sortOrderComparisonResult !== 0)
|
||||
return sortOrderComparisonResult;
|
||||
else if(operationComparisonResult != null && operationComparisonResult !== 0)
|
||||
return operationComparisonResult;
|
||||
else
|
||||
return nameComparisonResult;
|
||||
}
|
||||
export let menuItemsList =
|
||||
[
|
||||
{
|
||||
name: "Pagination",
|
||||
id: "section/Pagination",
|
||||
items: []
|
||||
},
|
||||
{
|
||||
name: "JSONP",
|
||||
id: "section/JSONP",
|
||||
items: []
|
||||
},
|
||||
{
|
||||
name: "Authentication",
|
||||
id: "section/Authentication",
|
||||
items: []
|
||||
},
|
||||
{
|
||||
name: "pet",
|
||||
id: "tag/pet",
|
||||
items: [
|
||||
{
|
||||
name: "Deletes a pet",
|
||||
id: "/paths/~1pet~1{petId}/delete",
|
||||
metadata: {operation: "delete"}
|
||||
},
|
||||
{
|
||||
name: "Find pet by ID",
|
||||
id: "/paths/~1pet~1{petId}/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Finds Pets by status",
|
||||
id: "/paths/~1pet~1findByStatus/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Finds Pets by tags",
|
||||
id: "/paths/~1pet~1findByTags/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Add a new pet to the store",
|
||||
id: "/paths/~1pet/post",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "Updates a pet in the store with form data",
|
||||
id: "/paths/~1pet~1{petId}/post",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "uploads an image",
|
||||
id: "/paths/~1pet~1{petId}~1uploadImage/post",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "Update an existing pet",
|
||||
id: "/paths/~1pet/put",
|
||||
metadata: {operation: "put"}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "store",
|
||||
id: "tag/store",
|
||||
items: [
|
||||
{
|
||||
name: "Delete purchase order by ID",
|
||||
id: "/paths/~1store~1order~1{orderId}/delete",
|
||||
metadata: {operation: "delete"}
|
||||
},
|
||||
{
|
||||
name: "Find purchase order by ID",
|
||||
id: "/paths/~1store~1order~1{orderId}/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Returns pet inventories by status",
|
||||
id: "/paths/~1store~1inventory/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Place an order for a pet",
|
||||
id: "/paths/~1store~1order/post",
|
||||
metadata: {operation: "post"}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "user",
|
||||
id: "tag/user",
|
||||
items: [
|
||||
{
|
||||
name: "Delete user",
|
||||
id: "/paths/~1user~1{username}/delete",
|
||||
metadata: {operation: "delete"}
|
||||
},
|
||||
{
|
||||
name: "Get user by user name",
|
||||
id: "/paths/~1user~1{username}/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Logs out current logged in user session",
|
||||
id: "/paths/~1user~1logout/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Logs user into the system",
|
||||
id: "/paths/~1user~1login/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Create user",
|
||||
id: "/paths/~1user/post",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "Creates list of users with given input array",
|
||||
id: "/paths/~1user~1createWithArray/post",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "Creates list of users with given input array",
|
||||
id: "/paths/~1user~1createWithList/post",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "Updated user",
|
||||
id: "/paths/~1user~1{username}/put",
|
||||
metadata: {operation: "put"}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Pagination",
|
||||
id: "tag/Pagination",
|
||||
items: [
|
||||
{
|
||||
name: "Finds Pets by status",
|
||||
id: "/paths/~1pet~1findByStatus/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Finds Pets by tags",
|
||||
id: "/paths/~1pet~1findByTags/get",
|
||||
metadata: {operation: "get"}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "JSONP",
|
||||
id: "tag/JSONP",
|
||||
items: [
|
||||
{
|
||||
name: "Find pet by ID",
|
||||
id: "/paths/~1pet~1{petId}/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Find purchase order by ID",
|
||||
id: "/paths/~1store~1order~1{orderId}/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Finds Pets by status",
|
||||
id: "/paths/~1pet~1findByStatus/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Finds Pets by tags",
|
||||
id: "/paths/~1pet~1findByTags/get",
|
||||
metadata: {operation: "get"}
|
||||
},
|
||||
{
|
||||
name: "Get user by user name",
|
||||
id: "/paths/~1user~1{username}/get",
|
||||
metadata: {operation: "post"}
|
||||
},
|
||||
{
|
||||
name: "Returns pet inventories by status",
|
||||
id: "/paths/~1store~1inventory/get",
|
||||
metadata: {operation: "post"}
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
|
@ -332,6 +332,9 @@ export class MenuService {
|
|||
|
||||
let res = [];
|
||||
for (let operationInfo of tag.operations) {
|
||||
let xSortOrder;
|
||||
let orderInfo = operationInfo['x-sort-order'];
|
||||
if(orderInfo>=0 && orderInfo<tag.operations.length && Number.isInteger(orderInfo)) xSortOrder = operationInfo['x-sort-order'];
|
||||
let subItem = {
|
||||
name: SchemaHelper.operationSummary(operationInfo),
|
||||
id: operationInfo._pointer,
|
||||
|
@ -341,7 +344,8 @@ export class MenuService {
|
|||
pointer: operationInfo._pointer,
|
||||
operationId: operationInfo.operationId,
|
||||
operation: operationInfo.operation,
|
||||
deprecated: !!operationInfo.deprecated
|
||||
deprecated: !!operationInfo.deprecated,
|
||||
sortOrder: xSortOrder+""
|
||||
},
|
||||
parent: parent
|
||||
};
|
||||
|
@ -409,7 +413,6 @@ export class MenuService {
|
|||
items: null
|
||||
};
|
||||
item.items = this.getOperationsItems(item, tag);
|
||||
|
||||
res.push(item);
|
||||
}
|
||||
return res;
|
||||
|
|
Loading…
Reference in New Issue
Block a user