Skip to content

Commit ba75e5e

Browse files
authored
Add "Web Applications" tree under namespace in serverManagerView (#184)
1 parent 139b30e commit ba75e5e

File tree

3 files changed

+120
-4
lines changed

3 files changed

+120
-4
lines changed

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@
381381
"command": "intersystems-community.servermanager.viewProject",
382382
"title": "View Code in Project",
383383
"icon": "$(eye)"
384+
},
385+
{
386+
"command": "intersystems-community.servermanager.editWebApp",
387+
"title": "Edit Files in Web Application",
388+
"icon": "$(edit)"
389+
},
390+
{
391+
"command": "intersystems-community.servermanager.viewWebApp",
392+
"title": "View Files in Web Application",
393+
"icon": "$(eye)"
384394
}
385395
],
386396
"submenus": [
@@ -508,6 +518,14 @@
508518
{
509519
"command": "intersystems-community.servermanager.viewProject",
510520
"when": "false"
521+
},
522+
{
523+
"command": "intersystems-community.servermanager.editWebApp",
524+
"when": "false"
525+
},
526+
{
527+
"command": "intersystems-community.servermanager.viewWebApp",
528+
"when": "false"
511529
}
512530
],
513531
"view/title": [
@@ -575,6 +593,16 @@
575593
"when": "view == intersystems-community_servermanager && viewItem == project",
576594
"group": "inline@20"
577595
},
596+
{
597+
"command": "intersystems-community.servermanager.editWebApp",
598+
"when": "view == intersystems-community_servermanager && viewItem == webapp",
599+
"group": "inline@10"
600+
},
601+
{
602+
"command": "intersystems-community.servermanager.viewWebApp",
603+
"when": "view == intersystems-community_servermanager && viewItem == webapp",
604+
"group": "inline@20"
605+
},
578606
{
579607
"command": "intersystems-community.servermanager.openPortalTab",
580608
"when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./",

src/extension.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { AUTHENTICATION_PROVIDER, ServerManagerAuthenticationProvider } from "./
1212
import { importFromRegistry } from "./commands/importFromRegistry";
1313
import { clearPassword, migratePasswords, storePassword } from "./commands/managePasswords";
1414
import { logout, serverSessions } from "./makeRESTRequest";
15-
import { NamespaceTreeItem, ProjectTreeItem, ServerManagerView, ServerTreeItem, SMTreeItem } from "./ui/serverManagerView";
15+
import { NamespaceTreeItem, ProjectTreeItem, ServerManagerView, ServerTreeItem, SMTreeItem, WebAppTreeItem } from "./ui/serverManagerView";
1616

1717
export const extensionId = "intersystems-community.servermanager";
1818
export let globalState: vscode.Memento;
@@ -221,7 +221,7 @@ export function activate(context: vscode.ExtensionContext) {
221221
}),
222222
);
223223

224-
const addWorkspaceFolderAsync = async (readonly: boolean, csp: boolean, namespaceTreeItem?: ServerTreeItem, project?: string) => {
224+
const addWorkspaceFolderAsync = async (readonly: boolean, csp: boolean, namespaceTreeItem?: ServerTreeItem, project?: string, webApp?: string) => {
225225
if (namespaceTreeItem) {
226226
const pathParts = namespaceTreeItem.id?.split(":");
227227
if (pathParts && pathParts.length === 4) {
@@ -245,7 +245,7 @@ export function activate(context: vscode.ExtensionContext) {
245245
}
246246

247247
const params = [csp ? "csp" : "", project ? `project=${project}` : ""].filter(e => e != "").join("&");
248-
const uri = vscode.Uri.parse(`isfs${readonly ? "-readonly" : ""}://${serverName}:${namespace}/${params ? `?${params}` : ""}`);
248+
const uri = vscode.Uri.parse(`isfs${readonly ? "-readonly" : ""}://${serverName}:${namespace}${csp && webApp ? webApp : "/"}${params ? `?${params}` : ""}`);
249249
if ((vscode.workspace.workspaceFolders || []).filter((workspaceFolder) => workspaceFolder.uri.toString() === uri.toString()).length === 0) {
250250
const label = `${project ? `${project} - ` : ""}${serverName}:${namespace}${csp ? ' web files' : ''}${readonly && project == undefined ? " (read-only)" : ""}`;
251251
const added = vscode.workspace.updateWorkspaceFolders(
@@ -307,6 +307,18 @@ export function activate(context: vscode.ExtensionContext) {
307307
})
308308
);
309309

310+
context.subscriptions.push(
311+
vscode.commands.registerCommand(`${extensionId}.editWebApp`, async (webAppTreeItem?: WebAppTreeItem) => {
312+
await addWorkspaceFolderAsync(false, true, <NamespaceTreeItem>webAppTreeItem?.parent?.parent, undefined, webAppTreeItem?.name);
313+
})
314+
);
315+
316+
context.subscriptions.push(
317+
vscode.commands.registerCommand(`${extensionId}.viewWebApp`, async (webAppTreeItem?: WebAppTreeItem) => {
318+
await addWorkspaceFolderAsync(true, true, <NamespaceTreeItem>webAppTreeItem?.parent?.parent, undefined, webAppTreeItem?.name);
319+
})
320+
);
321+
310322
// Listen for relevant configuration changes
311323
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e) => {
312324
if (e.affectsConfiguration("intersystems.servers") || e.affectsConfiguration("objectscript.conn")) {

src/ui/serverManagerView.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,10 @@ export class NamespaceTreeItem extends SMTreeItem {
498498
* @returns feature folders of a namespace.
499499
*/
500500
async function namespaceFeatures(element: NamespaceTreeItem, params?: any): Promise<FeatureTreeItem[] | undefined> {
501-
return [new ProjectsTreeItem({ parent: element, id: element.name, label: element.name }, params.serverName)];
501+
return [
502+
new ProjectsTreeItem({ parent: element, id: element.name, label: element.name }, params.serverName),
503+
new WebAppsTreeItem({ parent: element, id: element.name, label: element.name }, params.serverName)
504+
];
502505
}
503506

504507
export class ProjectsTreeItem extends FeatureTreeItem {
@@ -585,3 +588,76 @@ export class ProjectTreeItem extends SMTreeItem {
585588
this.iconPath = new vscode.ThemeIcon('files');
586589
}
587590
}
591+
592+
export class WebAppsTreeItem extends FeatureTreeItem {
593+
public readonly name: string;
594+
constructor(
595+
element: ISMItem,
596+
serverName: string
597+
) {
598+
const parentFolderId = element.parent?.id || '';
599+
super({
600+
parent: element.parent,
601+
label: 'Web Applications',
602+
id: parentFolderId + ':webapps',
603+
tooltip: `Web Applications in this namespace`,
604+
getChildren: namespaceWebApps,
605+
params: { serverName, ns: element.label }
606+
});
607+
this.name = 'Web Applications';
608+
this.contextValue = 'webapps';
609+
this.iconPath = new vscode.ThemeIcon('library');
610+
}
611+
}
612+
613+
/**
614+
* getChildren function returning web applications in a server namespace.
615+
*
616+
* @param element parent
617+
* @param params { serverName }
618+
* @returns web applications in a server namespace.
619+
*/
620+
async function namespaceWebApps(element: ProjectsTreeItem, params?: any): Promise<WebAppTreeItem[] | undefined> {
621+
const children: ProjectTreeItem[] = [];
622+
623+
if (params?.serverName && params.ns) {
624+
const name: string = params.serverName;
625+
const serverSpec = await getServerSpec(name)
626+
if (!serverSpec) {
627+
return undefined
628+
}
629+
630+
const response = await makeRESTRequest(
631+
"GET",
632+
serverSpec,
633+
{ apiVersion: 1, namespace: "%SYS", path: `/cspapps/${params.ns}` }
634+
);
635+
if (response !== undefined) {
636+
if (response.data.result.content === undefined) {
637+
vscode.window.showErrorMessage(response.data.status.summary);
638+
return undefined;
639+
}
640+
response.data.result.content.map((webapp: string) => {
641+
children.push(new WebAppTreeItem({ parent: element, label: name, id: name }, webapp));
642+
});
643+
}
644+
}
645+
646+
return children;
647+
}
648+
649+
export class WebAppTreeItem extends SMTreeItem {
650+
public readonly name: string;
651+
constructor(element: ISMItem, name: string) {
652+
const parentFolderId = element.parent?.id || '';
653+
const id = parentFolderId + ':' + name;
654+
super({
655+
parent: element.parent,
656+
label: name,
657+
id
658+
});
659+
this.name = name;
660+
this.contextValue = 'webapp';
661+
this.iconPath = new vscode.ThemeIcon('file-code');
662+
}
663+
}

0 commit comments

Comments
 (0)