@@ -3,24 +3,24 @@ import * as vscode from "vscode";
33import { NodeBase } from "./nodeBase" ;
44import { PackageNode } from "./packageNode" ;
55import { RoutineNode } from "./routineNode" ;
6+ import { AtelierAPI } from "../../api" ;
7+ import { ClassNode } from "./classesNode" ;
68
79export class RootNode extends NodeBase {
810 public readonly contextValue : string ;
9- public eventEmitter : vscode . EventEmitter < NodeBase > ;
10- private _items : any [ ] ;
11+ private readonly _category : string ;
1112
1213 public constructor (
1314 label : string ,
15+ fullName : string ,
1416 contextValue : string ,
15- eventEmitter : vscode . EventEmitter < NodeBase > ,
16- items : any [ ] ,
17+ category : string ,
1718 workspaceFolder : string ,
1819 namespace : string
1920 ) {
20- super ( label , label , workspaceFolder , namespace ) ;
21+ super ( label , fullName , workspaceFolder , namespace ) ;
2122 this . contextValue = contextValue ;
22- this . eventEmitter = eventEmitter ;
23- this . _items = items ;
23+ this . _category = category ;
2424 }
2525
2626 public getTreeItem ( ) : vscode . TreeItem {
@@ -32,56 +32,62 @@ export class RootNode extends NodeBase {
3232 }
3333
3434 public async getChildren ( element ) : Promise < NodeBase [ ] > {
35- if ( element . contextValue === "dataRootNode:classesRootNode" ) {
36- return this . getClasses ( ) ;
37- }
38-
39- if ( element . contextValue === "dataRootNode:routinesRootNode" ) {
40- return this . getRoutines ( ) ;
41- }
42- }
43-
44- private async getClasses ( ) : Promise < PackageNode [ ] > {
45- const items = this . makeTree ( this . _items ) ;
46-
47- return items . map (
48- ( { name, nodes } ) : PackageNode => new PackageNode ( name , nodes , this . workspaceFolder , this . namespace )
49- ) ;
35+ const path = this instanceof PackageNode ? this . fullName + "/" : "" ;
36+ return this . getItems ( path , this . _category ) ;
5037 }
38+ public getItems ( path : string , category : string ) : Promise < NodeBase [ ] > {
39+ const sql = "CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)" ;
40+ // const sql = "CALL %Library.RoutineMgr_StudioOpenDialog(?,,,,,,?)";
41+ let spec = "" ;
42+ switch ( category ) {
43+ case "CLS" :
44+ spec = "*.cls" ;
45+ break ;
46+ case "RTN" :
47+ spec = "*.mac,*.int" ;
48+ break ;
49+ case "INC" :
50+ spec = "*.inc" ;
51+ break ;
52+ default :
53+ return ;
54+ }
55+ const direction = "1" ;
56+ const orderBy = "1" ; // by Name
57+ const flat = "0" ;
58+ const notStudio = "0" ;
59+ const generated = "0" ;
5160
52- private async getRoutines ( ) : Promise < RoutineNode [ ] > {
53- return this . _items . map (
54- ( { name } ) : RoutineNode => new RoutineNode ( name , name , this . workspaceFolder , this . namespace )
55- ) ;
56- }
61+ spec = path + spec ;
5762
58- private makeTree ( items : any [ ] ) : any [ ] {
59- let tree ;
60- tree = items . map ( ( { name } ) => ( { name } ) ) ;
61- tree . forEach ( el => {
62- const parent = el . name . split ( "." ) . slice ( 0 , - 2 ) ;
63- el . parent = parent . join ( "." ) ;
64- el . fullName = el . name ;
65- el . name = el . name
66- . split ( "." )
67- . slice ( - 2 )
68- . join ( "." ) ;
69- const parents = parent . map ( ( name , i ) => {
70- return {
71- name,
72- fullName : parent . slice ( 0 , i + 1 ) . join ( "." ) ,
73- parent : parent . slice ( 0 , i ) . join ( "." ) ,
74- } ;
75- } ) ;
76- tree = tree . concat ( parents ) ;
77- } ) ;
78- tree = tree . filter ( ( value , index , self ) => self . findIndex ( ( { fullName } ) => fullName === value . fullName ) === index ) ;
79- tree = tree . sort ( ( el1 , el2 ) => el1 . fullName . localeCompare ( el2 . fullName ) ) ;
80- tree . forEach ( el => {
81- el . nodes = tree . filter ( ch => el . fullName === ch . parent ) ;
82- } ) ;
83- tree = tree . filter ( el => el . parent === "" ) ;
63+ const systemFiles = this . namespace === "%SYS" ? "1" : "0" ;
8464
85- return tree ;
65+ const api = new AtelierAPI ( this . workspaceFolder ) ;
66+ api . setNamespace ( this . namespace ) ;
67+ return api
68+ . actionQuery ( sql , [ spec , direction , orderBy , systemFiles , flat , notStudio , generated ] )
69+ . then ( data => {
70+ const content = data . result . content ;
71+ return content ;
72+ } )
73+ . then ( data =>
74+ data
75+ . map ( el => {
76+ const fullName = ( this instanceof PackageNode ? this . fullName + "." : "" ) + el . Name ;
77+ switch ( el . Type ) {
78+ case "9" :
79+ return new PackageNode ( el . Name , fullName , category , this . workspaceFolder , this . namespace ) ;
80+ case "4" :
81+ return new ClassNode ( el . Name , fullName , this . workspaceFolder , this . namespace ) ;
82+ case "0" :
83+ case "1" :
84+ case "2" :
85+ return new RoutineNode ( el . Name , fullName , this . workspaceFolder , this . namespace ) ;
86+ default :
87+ return null ;
88+ }
89+ } )
90+ . filter ( el => el !== null )
91+ ) ;
8692 }
8793}
0 commit comments