Skip to content

Commit eb13e7e

Browse files
authored
Merge pull request #107 from shamby87/copyUI
Add form validation, move copyUI to own file
2 parents e1139cc + 4ff7ce9 commit eb13e7e

File tree

4 files changed

+58
-53
lines changed

4 files changed

+58
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@
552552
"webpack-dev": "webpack --mode development --watch"
553553
},
554554
"devDependencies": {
555-
"@halcyontech/vscode-ibmi-types": "^1.8.0",
555+
"@halcyontech/vscode-ibmi-types": "^2.0.0",
556556
"@types/glob": "^7.1.3",
557557
"@types/node": "14.x",
558558
"@types/vscode": "^1.70.0",

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The module 'vscode' contains the VS Code extensibility API
22
// Import the module and reference it with the alias vscode in your code below
33
import vscode from "vscode"
4-
import schemaBrowser from "./views/schemaBrowser";
4+
import schemaBrowser from "./views/schemaBrowser/schemaBrowser";
55

66
import * as JSONServices from "./language/json";
77
import * as resultsProvider from "./views/results";

src/views/schemaBrowser/copyUI.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { loadBase } from "../../base";
2+
3+
export const copyUI = loadBase().customUI()
4+
.addInput('toFile', 'To File', 'Name', {
5+
minlength: 1,
6+
maxlength: 10
7+
})
8+
.addInput('toLib', 'Library', 'Name', {
9+
default: '*LIBL',
10+
minlength: 1,
11+
maxlength: 10
12+
})
13+
.addInput('fromMbr', 'From member', 'Name, generic*, *FIRST, *ALL', {
14+
default: '*FIRST'
15+
})
16+
.addInput('toMbr', 'To member or label', 'Name, *FIRST, *FROMMBR, *ALL', {
17+
default: '*FIRST'
18+
})
19+
.addSelect('mbrOpt', 'Replace or add records', [
20+
{ text: '*NONE', description: '*NONE', value: '*NONE' },
21+
{ text: '*ADD', description: '*ADD', value: '*ADD' },
22+
{ text: '*REPLACE', description: '*REPLACE', value: '*REPLACE' },
23+
{ text: '*UPDADD', description: '*UPDADD', value: '*UPDADD' },
24+
])
25+
.addSelect('crtFile', 'Create file', [
26+
{ text: '*NO', description: '*NO', value: '*NO' },
27+
{ text: '*YES', description: '*YES', value: '*YES' },
28+
])
29+
.addSelect('outFmt', 'Print format', [
30+
{ text: '*CHAR', description: '*CHAR', value: '*CHAR' },
31+
{ text: '*HEX', description: '*HEX', value: '*HEX' },
32+
])
33+
.addButtons(
34+
{ id: 'copy', label: 'Copy', requiresValidation: true },
35+
{ id: 'cancel', label: 'Cancel' }
36+
);

src/views/schemaBrowser.ts renamed to src/views/schemaBrowser/schemaBrowser.ts

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11

22
import vscode, { ThemeIcon } from "vscode"
3-
import Schemas from "../database/schemas";
4-
import Table from "../database/table";
5-
import { getInstance, loadBase } from "../base";
3+
import Schemas from "../../database/schemas";
4+
import Table from "../../database/table";
5+
import { getInstance, loadBase } from "../../base";
66

7-
import Configuration from "../configuration";
7+
import Configuration from "../../configuration";
88

9-
import Types from "./types";
10-
import Statement from "../database/statement";
9+
import Types from "../types";
10+
import Statement from "../../database/statement";
11+
import { copyUI } from "./copyUI";
1112

1213
const viewItem = {
1314
"tables": `table`,
@@ -272,57 +273,25 @@ export default class schemaBrowser {
272273

273274
vscode.commands.registerCommand(`vscode-db2i.copyData`, async (object: SQLObject) => {
274275
if (object) {
275-
const base = loadBase();
276-
const page = await base.customUI()
277-
.addInput('toFile', 'To File')
278-
.addInput('toLib', 'Library')
279-
.addInput('fromMbr', 'From member', 'Name, generic*, *FIRST, *ALL', {
280-
default: '*FIRST'
281-
})
282-
.addInput('toMbr', 'To member or label', 'Name, *FIRST, *FROMMBR, *ALL', {
283-
default: '*FIRST'
284-
})
285-
.addSelect('mbrOpt', 'Replace or add records', [
286-
{text: '*NONE', description: '*NONE', value: '*NONE'},
287-
{text: '*ADD', description: '*ADD', value: '*ADD'},
288-
{text: '*REPLACE', description: '*REPLACE', value: '*REPLACE'},
289-
{text: '*UPDADD', description: '*UPDADD', value: '*UPDADD'},
290-
])
291-
.addSelect('crtFile', 'Create file', [
292-
{text: '*NO', description: '*NO', value: '*NO'},
293-
{text: '*YES', description: '*YES', value: '*YES'},
294-
])
295-
.addSelect('outFmt', 'Print format', [
296-
{text: '*CHAR', description: '*CHAR', value: '*CHAR'},
297-
{text: '*HEX', description: '*HEX', value: '*HEX'},
298-
])
299-
.addButtons(
300-
{id: 'copy', label:'Copy'},
301-
{id: 'cancel', label:'Cancel'}
302-
)
303-
.loadPage<any>((`Copy File - ${object.schema}.${object.name}`));
276+
const page = await copyUI.loadPage<any>((`Copy File - ${object.schema}.${object.name}`));
304277

305278
if(page && page.data) {
306279
const data = page.data;
307280
page.panel.dispose();
308281

309282
if (data.buttons == 'copy') {
310-
if (data.library != "" && data.file != "") {
311-
try {
312-
await vscode.window.withProgress({
313-
location: vscode.ProgressLocation.Notification,
314-
title: `Copying ${object.name}...`
315-
}, async () => {
316-
await Table.copyFile(object.system.schema, object.system.name, data);
317-
});
318-
319-
vscode.window.showInformationMessage(`Table copied`);
320-
this.clearCacheAndRefresh();
321-
} catch (e) {
322-
vscode.window.showErrorMessage(e.message);
323-
}
324-
} else {
325-
vscode.window.showErrorMessage("Schema and Name cannot be blank.");
283+
try {
284+
await vscode.window.withProgress({
285+
location: vscode.ProgressLocation.Notification,
286+
title: `Copying ${object.name}...`
287+
}, async () => {
288+
await Table.copyFile(object.system.schema, object.system.name, data);
289+
});
290+
291+
vscode.window.showInformationMessage(`Table copied`);
292+
this.clearCacheAndRefresh();
293+
} catch (e) {
294+
vscode.window.showErrorMessage(e.message);
326295
}
327296
}
328297
}

0 commit comments

Comments
 (0)