Skip to content

Commit 2c91451

Browse files
committed
actiontype=1 for studio actions
1 parent dce3769 commit 2c91451

File tree

2 files changed

+129
-61
lines changed

2 files changed

+129
-61
lines changed

src/commands/serverActions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ export async function serverActions(): Promise<void> {
66
const { active, host, ns, https, port: defaultPort, username, password } = config("conn");
77
const workspaceFolder = currentWorkspaceFolder();
88
const port = workspaceState.get(workspaceFolder + ":port", defaultPort);
9-
const connInfo = `${host}:${port}[${ns}]`;
9+
const nsEncoded = encodeURIComponent(ns);
10+
const connInfo = `${host}:${port}[${nsEncoded}]`;
1011
const serverUrl = `${https ? "https" : "http"}://${host}:${port}`;
11-
const portalUrl = `${serverUrl}/csp/sys/UtilHome.csp?$NAMESPACE=${ns}`;
12-
const classRef = `${serverUrl}/csp/documatic/%25CSP.Documatic.cls?LIBRARY=${ns}`;
12+
const portalUrl = `${serverUrl}/csp/sys/UtilHome.csp?$NAMESPACE=${nsEncoded}`;
13+
const classRef = `${serverUrl}/csp/documatic/%25CSP.Documatic.cls?LIBRARY=${nsEncoded}`;
1314
const iris = workspaceState.get(workspaceFolder + ":iris", false);
15+
const usernameEncoded = encodeURIComponent(username);
16+
const passwordEncoded = encodeURIComponent(password);
1417
const auth = iris
15-
? `&IRISUsername=${username}&IRISPassword=${password}`
16-
: `&CacheUserName=${username}&CachePassword=${password}`;
18+
? `&IRISUsername=${usernameEncoded}&IRISPassword=${passwordEncoded}`
19+
: `&CacheUserName=${usernameEncoded}&CachePassword=${passwordEncoded}`;
1720

1821
const terminal = [];
1922
if (workspaceState.get(workspaceFolder + ":docker", true)) {

src/commands/studio.ts

Lines changed: 121 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,78 +8,143 @@ interface StudioAction extends vscode.QuickPickItem {
88
id: string;
99
}
1010

11-
function doMenuAction(uri: vscode.Uri, menuType: string): Promise<any> {
12-
uri = uri || vscode.window.activeTextEditor.document.uri;
13-
if (uri.scheme !== FILESYSTEM_SCHEMA) {
14-
return;
11+
class StudioActions {
12+
private uri: vscode.Uri;
13+
private api: AtelierAPI;
14+
private name: string;
15+
16+
public constructor(uri: vscode.Uri) {
17+
this.uri = uri;
18+
this.name = this.uri.path.slice(1).replace(/\//g, ".");
19+
this.api = new AtelierAPI(uri.authority);
20+
}
21+
22+
public processUserAction(userAction): Thenable<any> {
23+
const serverAction = parseInt(userAction.action || 0, 10);
24+
const { target, errorText } = userAction;
25+
if (errorText !== "") {
26+
outputChannel.appendLine(errorText);
27+
outputChannel.show();
28+
}
29+
outputChannel.appendLine(JSON.stringify(userAction));
30+
switch (serverAction) {
31+
case 0:
32+
/// do nothing
33+
break;
34+
case 1: // Display the default Studio dialog with a yes/no/cancel button.
35+
return vscode.window
36+
.showWarningMessage(target, { modal: true }, "Yes", "No")
37+
.then(answer => (answer === "Yes" ? "1" : answer === "No" ? "0" : "2"));
38+
case 2: // Run a CSP page/Template. The Target is the full url to the CSP page/Template
39+
throw new Error("Not suppoorted");
40+
case 3: // Run an EXE on the client.
41+
throw new Error("Not suppoorted");
42+
case 4: // Insert the text in Target in the current document at the current selection point
43+
throw new Error("Not suppoorted");
44+
case 5: // Studio will open the documents listed in Target
45+
throw new Error("Not suppoorted");
46+
case 6: // Display an alert dialog in Studio with the text from the Target variable.
47+
return vscode.window.showWarningMessage(target, { modal: true });
48+
case 7: // Display a dialog with a textbox and Yes/No/Cancel buttons.
49+
return vscode.window.showInputBox({
50+
prompt: target,
51+
});
52+
default:
53+
throw new Error("Not suppoorted");
54+
}
1555
}
16-
const query = "select * from %Atelier_v1_Utils.Extension_GetMenus(?,?,?)";
17-
const name = uri.path.slice(1).replace(/\//g, ".");
18-
const api = new AtelierAPI(uri.authority);
19-
const parameters = [menuType, name, ""];
20-
return api
21-
.actionQuery(query, parameters)
22-
.then(data => data.result.content)
23-
.then(menu =>
24-
menu.reduce(
56+
57+
private userAction(action, afterUserAction = false, answer: string = "", msg: string = ""): Thenable<void> {
58+
if (!action) {
59+
return;
60+
}
61+
const func = afterUserAction ? "AfterUserAction" : "UserAction";
62+
const query = `select * from %Atelier_v1_Utils.Extension_${func}(?, ?, ?, ?)`;
63+
let selectedText = "";
64+
const editor = vscode.window.activeTextEditor;
65+
if (!editor) {
66+
selectedText = "";
67+
}
68+
const selection = editor.selection;
69+
selectedText = editor.document.getText(selection);
70+
71+
const parameters = afterUserAction
72+
? ["0", action.id, this.name, answer]
73+
: ["0", action.id, this.name, selectedText];
74+
return vscode.window.withProgress(
75+
{
76+
cancellable: false,
77+
location: vscode.ProgressLocation.Notification,
78+
title: `Executing user action: ${action.label}`,
79+
},
80+
() =>
81+
this.api
82+
.actionQuery(query, parameters)
83+
.then(data => data.result.content.pop())
84+
.then(this.processUserAction)
85+
.then(answer => {
86+
if (answer) {
87+
return this.userAction(action, true, answer);
88+
}
89+
})
90+
.catch(err => {
91+
outputChannel.appendLine(`Studio Action "${action.label}" not supported`);
92+
outputChannel.show();
93+
})
94+
);
95+
}
96+
97+
private constructMenu(menu): any[] {
98+
return menu
99+
.reduce(
25100
(list, sub) =>
26101
list.concat(
27102
sub.items
28-
.filter(el => el.id !== "" && el.separator == 0 && el.enabled == 1)
29-
.map(el => ({ ...el, id: `${sub.id},${el.id}`, label: el.name, itemId: el.id, type: sub.type }))
103+
.filter(el => el.id !== "" && el.separator == 0)
104+
// .filter(el => el.enabled == 1)
105+
.map(el => ({
106+
...el,
107+
id: `${sub.id},${el.id}`,
108+
label: el.name.replace("&", ""),
109+
itemId: el.id,
110+
type: sub.type,
111+
}))
30112
),
31113
[]
32114
)
33-
)
34-
.then(menuItems =>
35-
menuItems.filter((item: any, index: number, self: any) => {
115+
.sort((el1, el2) => (el1.type === "main" && el2.type !== el1.type ? -1 : 1))
116+
.filter((item: any, index: number, self: any) => {
36117
if (item && item.type === "main") {
37118
return true;
38119
}
39120
return self.findIndex((el): boolean => el.itemId === item.itemId) === index;
40-
})
41-
)
42-
.then(menuItems => {
43-
return vscode.window.showQuickPick<StudioAction>(menuItems, { canPickMany: false });
44-
})
45-
.then(action => {
46-
if (!action) {
47-
return;
48-
}
49-
const query = "select * from %Atelier_v1_Utils.Extension_UserAction(?, ?, ?, ?)";
50-
let selectedText = "";
51-
const editor = vscode.window.activeTextEditor;
52-
if (!editor) {
53-
selectedText = "";
54-
}
55-
const selection = editor.selection;
56-
selectedText = editor.document.getText(selection);
121+
});
122+
}
57123

58-
const parameters = ["0", action.id, name, selectedText];
59-
return vscode.window.withProgress(
60-
{
61-
cancellable: false,
62-
location: vscode.ProgressLocation.Notification,
63-
title: `Executing user action: ${action.label}`,
64-
},
65-
() =>
66-
api
67-
.actionQuery(query, parameters)
68-
.then(data => data.result.content.pop())
69-
.then(userAction => {
70-
if (userAction && userAction.action != "0") {
71-
outputChannel.appendLine(`Studio Action "${action.label}" not supported`);
72-
outputChannel.show();
73-
}
74-
})
75-
);
76-
});
124+
public getMenu(menuType: string): Thenable<any> {
125+
const query = "select * from %Atelier_v1_Utils.Extension_GetMenus(?,?,?)";
126+
const parameters = [menuType, this.name, ""];
127+
128+
return this.api
129+
.actionQuery(query, parameters)
130+
.then(data => data.result.content)
131+
.then(this.constructMenu)
132+
.then(menuItems => {
133+
return vscode.window.showQuickPick<StudioAction>(menuItems, { canPickMany: false });
134+
})
135+
.then(action => this.userAction(action));
136+
}
77137
}
78138

79139
// export function contextMenu(uri: vscode.Uri): Promise<void> {
80140
// return doMenuAction(uri, "context");
81141
// }
82142

83-
export function mainMenu(uri: vscode.Uri) {
84-
return doMenuAction(uri, "");
143+
export async function mainMenu(uri: vscode.Uri) {
144+
uri = uri || vscode.window.activeTextEditor.document.uri;
145+
if (!uri || uri.scheme !== FILESYSTEM_SCHEMA) {
146+
return;
147+
}
148+
const studioActions = new StudioActions(uri);
149+
return studioActions && studioActions.getMenu("");
85150
}

0 commit comments

Comments
 (0)