Skip to content

Commit 267a56b

Browse files
committed
added some actions for server
1 parent c30cf27 commit 267a56b

File tree

6 files changed

+297
-1215
lines changed

6 files changed

+297
-1215
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [0.7.11]
44

55
- added export setting "objectscript.export.addCategory" if enabled uses previous behavior, adds category folder to export folder, disabled by default
6+
- added Server actions menu, by clicking on server info from status bar. Open Management portal, Class Reference and toggle connection.
67

78
## [0.7.10]
89

api/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as httpModule from 'http';
22
import * as httpsModule from 'https';
33
import { outputConsole, currentWorkspaceFolder } from '../utils';
44
const Cache = require('vscode-cache');
5-
import { config, extensionContext } from '../extension';
5+
import { config, extensionContext, workspaceState } from '../extension';
66

77
const DEFAULT_API_VERSION: number = 3;
88

@@ -16,7 +16,7 @@ export class AtelierAPI {
1616
}
1717

1818
private get apiVersion(): number {
19-
return this._config.version || DEFAULT_API_VERSION;
19+
return workspaceState.get(currentWorkspaceFolder() + ':apiVersion', DEFAULT_API_VERSION);
2020
}
2121

2222
constructor() {
@@ -159,7 +159,12 @@ export class AtelierAPI {
159159
}
160160

161161
serverInfo(): Promise<any> {
162-
return this.request(0, 'GET');
162+
return this.request(0, 'GET').then(info => {
163+
if (info && info.result && info.result.content && info.result.content.api > 0) {
164+
let apiVersion = info.result.content.api;
165+
return workspaceState.update(currentWorkspaceFolder() + ':apiVersion', apiVersion);
166+
}
167+
});
163168
}
164169
// api v1+
165170
getDocNames({

commands/serverActions.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as vscode from 'vscode';
2+
import { config } from '../extension';
3+
4+
export async function serverActions(): Promise<void> {
5+
const conn = config('conn');
6+
const connInfo = `${conn.host}:${conn.port}/${conn.ns}/`;
7+
const serverUrl = `${conn.https ? 'https' : 'http'}://${conn.host}:${conn.port}`;
8+
const portalUrl = `${serverUrl}/csp/sys/UtilHome.csp?$NAMESPACE=${conn.ns}`;
9+
const classRef = `${serverUrl}/csp/documatic/%25CSP.Documatic.cls?LIBRARY=${conn.ns}`;
10+
return vscode.window
11+
.showQuickPick(
12+
[
13+
{
14+
id: 'toggleConnection',
15+
label: 'Toggle connection',
16+
detail: 'Enable/Disable current connection'
17+
},
18+
{
19+
id: 'openPortal',
20+
label: 'Open Management Portal',
21+
detail: portalUrl
22+
},
23+
{
24+
id: 'openClassReference',
25+
label: 'Open class reference',
26+
detail: portalUrl
27+
}
28+
],
29+
{
30+
placeHolder: `Select action for server: ${connInfo}`
31+
}
32+
)
33+
.then(action => {
34+
switch (action.id) {
35+
case 'toggleConnection': {
36+
return vscode.workspace.getConfiguration().update('objectscript.conn.active', !conn.active);
37+
}
38+
case 'openPortal': {
39+
vscode.env.openExternal(vscode.Uri.parse(portalUrl));
40+
}
41+
case 'openClassReference': {
42+
vscode.env.openExternal(vscode.Uri.parse(classRef));
43+
}
44+
}
45+
});
46+
}

extension.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { exportAll, exportExplorerItem } from './commands/export';
99
import { xml2doc } from './commands/xml2doc';
1010
import { subclass } from './commands/subclass';
1111
import { superclass } from './commands/superclass';
12+
import { serverActions } from './commands/serverActions';
1213

1314
import { ObjectScriptClassSymbolProvider } from './providers/ObjectScriptClassSymbolProvider';
1415
import { ObjectScriptRoutineSymbolProvider } from './providers/ObjectScriptRoutineSymbolProvider';
@@ -35,7 +36,7 @@ export const config = (config?: string, workspaceFolderName?: string): any => {
3536
workspaceFolderName = workspaceFolderName || currentWorkspaceFolder();
3637

3738
if (['conn', 'export'].includes(config)) {
38-
if (workspaceFolderName !== '') {
39+
if (workspaceFolderName && workspaceFolderName !== '') {
3940
const workspaceFolder = vscode.workspace.workspaceFolders.find(
4041
el => el.name.toLowerCase() === workspaceFolderName.toLowerCase()
4142
);
@@ -74,31 +75,30 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
7475
vscode.window.registerTreeDataProvider('ObjectScriptExplorer', explorerProvider);
7576

7677
const panel = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
77-
panel.command = 'vscode-objectscript.output';
78-
panel.tooltip = 'Open output';
78+
panel.command = 'vscode-objectscript.serverActions';
7979
panel.show();
8080
const checkConnection = () => {
8181
const conn = config('conn');
82+
const connInfo = `${conn.host}:${conn.port}/${conn.ns}/`;
83+
panel.text = connInfo;
84+
panel.tooltip = '';
8285
vscode.commands.executeCommand('setContext', 'vscode-objectscript.connectActive', conn.active);
8386
if (!conn.active) {
84-
panel.text = '';
87+
panel.text = `${connInfo} - Disabled`;
8588
return;
8689
}
87-
panel.text = `${conn.label}:${conn.ns}`;
90+
panel.text = `${connInfo}`;
8891
const api = new AtelierAPI();
8992
api
9093
.serverInfo()
9194
.then(async info => {
92-
panel.text = `${conn.label}:${conn.ns} - Connected`;
93-
if (info && info.result && info.result.content && info.result.content.api > 0) {
94-
let apiVersion = info.result.content.api;
95-
await vscode.workspace.getConfiguration().update('objectscript.conn.version', apiVersion);
96-
}
95+
panel.text = `${connInfo} - Connected`;
9796
explorerProvider.refresh();
9897
})
9998
.catch((error: Error) => {
10099
outputChannel.appendLine(error.message);
101-
panel.text = `${conn.label}:${conn.ns} - ERROR`;
100+
panel.text = `${connInfo} - ERROR`;
101+
panel.tooltip = error.message;
102102
});
103103
};
104104
checkConnection();
@@ -144,6 +144,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
144144
vscode.commands.registerCommand('vscode-objectscript.viewOthers', viewOthers),
145145
vscode.commands.registerCommand('vscode-objectscript.subclass', subclass),
146146
vscode.commands.registerCommand('vscode-objectscript.superclass', superclass),
147+
vscode.commands.registerCommand('vscode-objectscript.serverActions', serverActions),
147148
vscode.commands.registerCommand('vscode-objectscript.touchBar.viewOthers', viewOthers),
148149
vscode.commands.registerCommand('vscode-objectscript.explorer.refresh', () => explorerProvider.refresh()),
149150
vscode.commands.registerCommand('vscode-objectscript.explorer.openClass', vscode.window.showTextDocument),

0 commit comments

Comments
 (0)