@@ -427,10 +427,98 @@ export class NamespaceTreeItem extends SMTreeItem {
427427 parent : element . parent ,
428428 label : name ,
429429 id,
430- tooltip : `${ name } on ${ serverName } `
430+ tooltip : `${ name } on ${ serverName } ` ,
431+ getChildren : namespaceFeatures ,
432+ params : { serverName }
431433 } ) ;
432434 this . name = name ;
433435 this . contextValue = name === '%SYS' ? 'sysnamespace' : 'namespace' ;
434436 this . iconPath = new vscode . ThemeIcon ( 'archive' ) ;
435437 }
436438}
439+
440+ /**
441+ * getChildren function returning namespace features (the child nodes of a server),
442+ *
443+ * @param element parent
444+ * @param params (unused)
445+ * @returns feature folders of a namespace.
446+ */
447+ async function namespaceFeatures ( element : NamespaceTreeItem , params ?: any ) : Promise < FeatureTreeItem [ ] | undefined > {
448+ return [ new ProjectsTreeItem ( { parent : element , id : element . name , label : element . name } , params . serverName ) ] ;
449+ }
450+
451+ export class ProjectsTreeItem extends FeatureTreeItem {
452+ public readonly name : string ;
453+ constructor (
454+ element : SMItem ,
455+ serverName : string
456+ ) {
457+ const parentFolderId = element . parent ?. id || '' ;
458+ super ( {
459+ parent : element . parent ,
460+ label : 'Projects' ,
461+ id : parentFolderId + ':projects' ,
462+ tooltip : `Projects in this namespace` ,
463+ getChildren : namespaceProjects ,
464+ params : { serverName, ns : element . label }
465+ } ) ;
466+ this . name = 'Projects' ;
467+ this . contextValue = 'projects' ;
468+ this . iconPath = new vscode . ThemeIcon ( 'library' ) ;
469+ }
470+ }
471+
472+ /**
473+ * getChildren function returning projects in a server namespace.
474+ *
475+ * @param element parent
476+ * @param params { serverName }
477+ * @returns projects in a server namespace.
478+ */
479+ async function namespaceProjects ( element : ProjectsTreeItem , params ?: any ) : Promise < ProjectTreeItem [ ] | undefined > {
480+ const children : ProjectTreeItem [ ] = [ ] ;
481+
482+ if ( params ?. serverName && params . ns ) {
483+ const name : string = params . serverName ;
484+ const serverSpec = await getServerSpec ( name )
485+ if ( ! serverSpec ) {
486+ return undefined
487+ }
488+
489+ const response = await makeRESTRequest (
490+ "POST" ,
491+ serverSpec ,
492+ { apiVersion : 1 , namespace : params . ns , path : "/action/query" } ,
493+ { query : "SELECT Name, Description FROM %Studio.Project" , parameters : [ ] }
494+ ) ;
495+ if ( response !== undefined ) {
496+ response . data . result . content . map ( ( project ) => {
497+ children . push ( new ProjectTreeItem ( { parent : element , label : name , id : name } , project . Name , project . Description ) ) ;
498+ } ) ;
499+ }
500+ }
501+
502+ return children ;
503+ }
504+
505+ export class ProjectTreeItem extends SMTreeItem {
506+ public readonly name : string ;
507+ constructor (
508+ element : SMItem ,
509+ name : string ,
510+ description : string
511+ ) {
512+ const parentFolderId = element . parent ?. id || '' ;
513+ const id = parentFolderId + ':' + name ;
514+ super ( {
515+ parent : element . parent ,
516+ label : name ,
517+ id,
518+ tooltip : description
519+ } ) ;
520+ this . name = name ;
521+ this . contextValue = 'project' ;
522+ this . iconPath = new vscode . ThemeIcon ( 'files' ) ;
523+ }
524+ }
0 commit comments