Skip to content

Commit

Permalink
Update to add sorting to the objects in the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
caleteeter committed Sep 8, 2023
1 parent d586b95 commit 8639a06
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/models/serverObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export async function loadNamespaces(root?: string): Promise<ServerObject[]> {
const ns = serverObjects.filter((value) => {
return value.isNs ? value : undefined;
});
return getNamespaces(ns, root);

const sorted = sortObjects(ns);

return getNamespaces(sorted, root);
}
return new Array<ServerObject>();
}
Expand All @@ -44,33 +47,33 @@ export async function loadDictionaries(ns: string): Promise<ServerObject[]> {
? value
: undefined;
});
return dicts;
return sortObjects(dicts);
}
return new Array<ServerObject>();
}

export async function loadFunctions(ns: string): Promise<ServerObject[]> {
const serverObjects = await loadServerObjects();
if (serverObjects !== undefined) {
const dicts = serverObjects.filter((value) => {
const funcs = serverObjects.filter((value) => {
return value.typeNum === 100 && !value.isNs && value.namespace === ns
? value
: undefined;
});
return dicts;
return sortObjects(funcs);
}
return new Array<ServerObject>();
}

export async function loadTables(ns: string): Promise<ServerObject[]> {
const serverObjects = await loadServerObjects();
if (serverObjects !== undefined) {
const dicts = serverObjects.filter((value) => {
const tables = serverObjects.filter((value) => {
return value.typeNum === 98 && !value.isNs && value.namespace === ns
? value
: undefined;
});
return dicts;
return sortObjects(tables);
}
return new Array<ServerObject>();
}
Expand All @@ -80,15 +83,15 @@ export async function loadVariables(ns: string): Promise<ServerObject[]> {
const views = await loadViews();

if (serverObjects !== undefined) {
const dicts = serverObjects.filter((value) => {
const vars = serverObjects.filter((value) => {
return views.indexOf(value.name) === -1 &&
value.typeNum === -7 &&
!value.isNs &&
value.namespace === ns
? value
: undefined;
});
return dicts;
return sortObjects(vars);
}
return new Array<ServerObject>();
}
Expand All @@ -99,7 +102,15 @@ export async function loadViews(): Promise<string[]> {
const views = rawViewArray?.filter((item) => {
return item !== "s#" && item !== "" && item !== ",";
});
return views ?? new Array<string>();
const sorted = views?.sort((object1, object2) => {
if (object1 < object2) {
return -1;
} else if (object1 > object2) {
return 1;
}
return 0;
});
return sorted ?? new Array<string>();
}

function getNamespaces(input: ServerObject[], root = "."): ServerObject[] {
Expand All @@ -118,3 +129,15 @@ function getNamespaces(input: ServerObject[], root = "."): ServerObject[] {

return output;
}

function sortObjects(input: ServerObject[]): ServerObject[] {
const sorted = input.sort((object1, object2) => {
if (object1.fname < object2.fname) {
return -1;
} else if (object1.fname > object2.fname) {
return 1;
}
return 0;
});
return sorted;
}

0 comments on commit 8639a06

Please sign in to comment.