@@ -3,24 +3,24 @@ import * as vscode from "vscode";
3
3
import { NodeBase } from "./nodeBase" ;
4
4
import { PackageNode } from "./packageNode" ;
5
5
import { RoutineNode } from "./routineNode" ;
6
+ import { AtelierAPI } from "../../api" ;
7
+ import { ClassNode } from "./classesNode" ;
6
8
7
9
export class RootNode extends NodeBase {
8
10
public readonly contextValue : string ;
9
- public eventEmitter : vscode . EventEmitter < NodeBase > ;
10
- private _items : any [ ] ;
11
+ private readonly _category : string ;
11
12
12
13
public constructor (
13
14
label : string ,
15
+ fullName : string ,
14
16
contextValue : string ,
15
- eventEmitter : vscode . EventEmitter < NodeBase > ,
16
- items : any [ ] ,
17
+ category : string ,
17
18
workspaceFolder : string ,
18
19
namespace : string
19
20
) {
20
- super ( label , label , workspaceFolder , namespace ) ;
21
+ super ( label , fullName , workspaceFolder , namespace ) ;
21
22
this . contextValue = contextValue ;
22
- this . eventEmitter = eventEmitter ;
23
- this . _items = items ;
23
+ this . _category = category ;
24
24
}
25
25
26
26
public getTreeItem ( ) : vscode . TreeItem {
@@ -32,56 +32,62 @@ export class RootNode extends NodeBase {
32
32
}
33
33
34
34
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 ) ;
50
37
}
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" ;
51
60
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 ;
57
62
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" ;
84
64
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
+ ) ;
86
92
}
87
93
}
0 commit comments