-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathactionEditor.ts
More file actions
221 lines (207 loc) Β· 10.4 KB
/
actionEditor.ts
File metadata and controls
221 lines (207 loc) Β· 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import vscode, { l10n } from "vscode";
import { ActionTools } from "../api/actions";
import { Tools } from "../api/Tools";
import { Action, ActionEnvironment, ActionRefresh, ActionType } from "../typings";
import { CustomVariables } from "../ui/views/environment/customVariables";
import { Tab } from "../webviews/CustomUI";
import { CustomEditor } from "./customEditorProvider";
// Used to list info about available variables
type VariableInfo = {
name: string
text: string
}
type VariableInfoList = {
member: VariableInfo[]
streamFile: VariableInfo[]
object: VariableInfo[]
}
type ActionData = {
name: string
command: string
extensions: string
type: ActionType
environment: ActionEnvironment
refresh: ActionRefresh
runOnProtected: boolean
outputToFile: string
deployFirst: boolean
postDownload: string
}
const editedActions: Set<{ name: string, type?: ActionType }> = new Set;
export function isActionEdited(action: Action) {
return editedActions.has({ name: action.name, type: action.type });
}
export function editAction(targetAction: Action, doAfterSave?: () => Thenable<void>, workspace?: vscode.WorkspaceFolder) {
const customVariables = CustomVariables.getAll().map(variable => `<li><b><code>&${variable.name}</code></b>: <code>${variable.value}</code></li>`).join(``);
const actionEditor = new CustomEditor<ActionData>(`${targetAction.type}/${targetAction.name}.action`, (actionData) => save(targetAction, actionData, workspace).then(doAfterSave), () => editedActions.delete({ name: targetAction.name, type: targetAction.type }))
.addInput(
`command`,
vscode.l10n.t(`Command(s) to run`),
vscode.l10n.t(`Below are available variables based on the Type you have select below. You can specify different commands on each line. Each command run is stateless and run in their own job.`),
{ rows: 5, default: targetAction.command }
)
.addTabs(
Object.entries(getVariablesInfo())
.map(([type, variables]) => ({
label: Tools.capitalize(type),
value: `<ul>${variables.map(variable => `<li><b><code>${variable.name}</code></b>: ${variable.text}</li>`).join(``)}${customVariables}</ul>`
} as Tab)), getDefaultTabIndex(targetAction.type)
)
.addHorizontalRule()
.addInput(`extensions`, vscode.l10n.t(`Extensions`), vscode.l10n.t(`A comma separated list of extensions for this action. This can be a member extension, a streamfile extension, an object type or an object attribute`), { default: targetAction.extensions?.join(`, `) })
.addSelect(`type`, vscode.l10n.t(`Type`), workspace ? [{
selected: targetAction.type === `file`,
value: `file`,
description: vscode.l10n.t(`Local File (Workspace)`),
text: vscode.l10n.t(`Actions for local files in the VS Code Workspace.`)
}] :
[
{
selected: targetAction.type === `member`,
value: `member`,
description: vscode.l10n.t(`Member`),
text: vscode.l10n.t(`Source members in the QSYS file system`),
},
{
selected: targetAction.type === `streamfile`,
value: `streamfile`,
description: vscode.l10n.t(`Streamfile`),
text: vscode.l10n.t(`Streamfiles in the IFS`)
},
{
selected: targetAction.type === `object`,
value: `object`,
description: vscode.l10n.t(`Object`),
text: vscode.l10n.t(`Objects in the QSYS file system`)
}
],
vscode.l10n.t(`The types of files this action can support.`),
workspace ? true : false
)
.addSelect(`environment`, vscode.l10n.t(`Environment`), [
{
selected: targetAction.environment === `ile`,
value: `ile`,
description: vscode.l10n.t(`ILE`),
text: vscode.l10n.t(`Runs as an ILE command`)
},
{
selected: targetAction.environment === `qsh`,
value: `qsh`,
description: vscode.l10n.t(`QShell`),
text: vscode.l10n.t(`Runs the command through QShell`)
},
{
selected: targetAction.environment === `pase`,
value: `pase`,
description: vscode.l10n.t(`PASE`),
text: vscode.l10n.t(`Runs the command in the PASE environment`)
}], vscode.l10n.t(`Environment for command to be executed in.`)
)
.addSelect(`refresh`, vscode.l10n.t(`Refresh`), [
{
selected: targetAction.refresh === `no`,
value: `no`,
description: vscode.l10n.t(`No`),
text: vscode.l10n.t(`No refresh`)
},
{
selected: targetAction.refresh === `parent`,
value: `parent`,
description: vscode.l10n.t(`Parent`),
text: vscode.l10n.t(`The parent container is refreshed`)
},
{
selected: targetAction.refresh === `filter`,
value: `filter`,
description: vscode.l10n.t(`Filter`),
text: vscode.l10n.t(`The parent filter is refreshed`)
},
{
selected: targetAction.refresh === `browser`,
value: `browser`,
description: vscode.l10n.t(`Browser`),
text: vscode.l10n.t(`The entire browser is refreshed`)
}], vscode.l10n.t(`The browser level to refresh after the action is done`)
);
if (workspace) {
actionEditor.addCheckbox(`deployFirst`, vscode.l10n.t(`Deploy before running`), vscode.l10n.t("When enabled, the local workspace will be deployed before the action is run."), targetAction.deployFirst);
actionEditor.addInput(`postDownload`, vscode.l10n.t(`Post execution downloads`), vscode.l10n.t("A comma separated list of remote files/folders to download when the Action is complete. Supports variables. Using <code>.evfevent</code> in combination with a build tool will populate the Problems view."), { default: targetAction.postDownload?.join(', ') });
}
actionEditor
.addCheckbox("runOnProtected", vscode.l10n.t(`Run on protected/read only`), vscode.l10n.t(`Allows the execution of this Action on protected or read only targets`), targetAction.runOnProtected)
.addInput(`outputToFile`, vscode.l10n.t(`Copy output to file`), vscode.l10n.t(`Copy the action output to a file. Variables can be used to define the file's path; use <code>&i</code> to compute file index.<br/>Example: <code>~/outputs/&CURLIB_&OPENMBR&i.txt</code>.`), { default: targetAction.outputToFile })
.open();
editedActions.add({ name: targetAction.name, type: targetAction.type });
}
async function save(targetAction: Action, actionData: ActionData, workspace?: vscode.WorkspaceFolder) {
const oldType = targetAction.type;
const postDownload = actionData.postDownload.split(',').map(path => path.trim()).filter(Boolean);
const extensions = actionData.extensions.split(`,`).map(item => item.trim().toUpperCase()).filter(Boolean);
Object.assign(targetAction, actionData,
//Fields that needs to be tranformed before saving
{
command: actionData.command.replace(new RegExp(`\\\r`, `g`), ``), // We don't want \r (Windows line endings)
extensions: extensions.length ? extensions : undefined,
outputToFile: actionData.outputToFile || undefined,
postDownload: postDownload.length ? postDownload : undefined
});
const typeChanged = (oldType !== targetAction.type);
if (typeChanged && (await ActionTools.getActions(workspace)).some(a => a.name === targetAction.name && a.type === targetAction.type)) {
throw new Error(l10n.t("The action '{0}' already exists for the '{1}' type", targetAction.name, targetAction.type!))
}
await ActionTools.updateAction(targetAction, workspace, { oldType });
if (typeChanged) {
editedActions.delete({ name: targetAction.name, type: oldType });
editedActions.add({ name: targetAction.name, type: targetAction.type });
}
}
const generic: () => VariableInfo[] = () => [
{ name: `&CURLIB`, text: vscode.l10n.t(`Current library, changeable in Library List`) },
{ name: `&USERNAME`, text: vscode.l10n.t(`Username for connection`) },
{ name: `&WORKDIR`, text: vscode.l10n.t(`Current working directory, changeable in IFS Browser`) },
{ name: `&HOST`, text: vscode.l10n.t(`Hostname or IP address from the current connection`) },
{ name: `&BUILDLIB`, text: vscode.l10n.t(`The same as <code>&CURLIB</code>`) },
{ name: `&LIBLC`, text: vscode.l10n.t(`Library list delimited by comma`) },
{ name: `&LIBLS`, text: vscode.l10n.t(`Library list delimited by space`) }
];
export function getVariablesInfo(): VariableInfoList {
return {
member: [
{ name: `&OPENLIB`, text: vscode.l10n.t(`Library name where the source member lives (<code>&OPENLIBL</code> for lowercase)`) },
{ name: `&OPENSPF`, text: vscode.l10n.t(`Source file name where the source member lives (<code>&OPENSPFL</code> for lowercase)`) },
{ name: `&OPENMBR`, text: vscode.l10n.t(`Name of the source member (<code>&OPENMBRL</code> for lowercase)`) },
{ name: `&EXT`, text: vscode.l10n.t(`Extension of the source member (<code>&EXTL</code> for lowercase)`) },
...generic()
],
streamFile: [
{ name: `&FULLPATH`, text: vscode.l10n.t(`Full path of the file on the remote system`) },
{ name: `&FILEDIR`, text: vscode.l10n.t(`Directory of the file on the remote system`) },
{ name: `&RELATIVEPATH`, text: vscode.l10n.t(`Relative path of the streamfile from the working directory or workspace`) },
{ name: `&PARENT`, text: vscode.l10n.t(`Name of the parent directory or source file`) },
{ name: `&BASENAME`, text: vscode.l10n.t(`Name of the file, including the extension`) },
{ name: `&NAME`, text: vscode.l10n.t(`Name of the file (<code>&NAMEL</code> for lowercase)`) },
{ name: `&EXT`, text: vscode.l10n.t(`Extension of the file (<code>&EXTL</code> for lowercase)`) },
...generic()
],
object: [
{ name: `&LIBRARY`, text: vscode.l10n.t(`Library name where the object lives (<code>&LIBRARYL</code> for lowercase)`) },
{ name: `&NAME`, text: vscode.l10n.t(`Name of the object (<code>&NAMEL</code> for lowercase)`) },
{ name: `&TYPE`, text: vscode.l10n.t(`Type of the object (<code>&TYPEL</code> for lowercase)`) },
{ name: `&EXT`, text: vscode.l10n.t(`Extension/attribute of the object (<code>&EXTL</code> for lowercase)`) },
...generic()
]
}
}
function getDefaultTabIndex(type?: ActionType) {
switch (type) {
case `file`:
case `streamfile`:
return 1;
case `object`:
return 2;
case `member`:
default:
return 0;
}
}