Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/simple_edit_view #159

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SQLJobManager {

const newJob = predefinedJob || (new SQLJob({
libraries: [config.currentLibrary, ...config.libraryList],
naming: `system`,
naming: `sql`,
"full open": false,
"transaction isolation": "none",
"query optimize goal": "1",
Expand All @@ -38,7 +38,7 @@ export class SQLJobManager {
this.totalJobs += 1;

this.jobs.push({
name: `${name || 'New job'} ${this.totalJobs}`,
name: `${name || 'New job'} (${this.totalJobs})`,
job: newJob
});

Expand Down
124 changes: 73 additions & 51 deletions src/views/jobManager/editJob/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { loadBase } from "../../../base";
import { JDBCOptions } from "../../../connection/types";
import { ComplexTab } from "@halcyontech/vscode-ibmi-types/api/CustomUI";

import getSimpleView from "./simpleView";
import getPerfTab from "./perfTab";
import getFormatTab from "./formatTab";
import getSystemTab from "./systemTab";
Expand All @@ -15,63 +16,84 @@ export function formatDescription(text: string): string {
.replace(/\s/g, " "); // Replace spaces with non-breaking spaces
}

let useSimpleView = true;

export async function editJobUi(
options: JDBCOptions,
jobName?: string
): Promise<JDBCOptions | undefined> {
const base = loadBase();
const ui = base.customUI();

const syspropsTab = getSystemTab(options);
const otherpropsTab = getOtherTab(options);
const formatpropsTab = getFormatTab(options);
const performancepropsTab = getPerfTab(options);
const sortPropsTab = getSortTab(options);

let tabs: ComplexTab[] = [
{ label: `System`, fields: syspropsTab.fields },
{ label: `Format`, fields: formatpropsTab.fields },
{ label: `Performance`, fields: performancepropsTab.fields },
{ label: `Sort`, fields: sortPropsTab.fields },
{ label: `Other`, fields: otherpropsTab.fields },
];

ui.addComplexTabs(tabs).addButtons(
{ id: `apply`, label: `Apply changes` },
{ id: `cancel`, label: `Cancel` }
);

const page = await ui.loadPage<{ [key: string]: string }>(
`Edit ${jobName} options`
);

if (page && page.data) {
page.panel.dispose();

if (page.data.buttons === `apply`) {
const keys = Object.keys(page.data);

// We need to play with some of the form data to put it back into JDBCOptions
for (const key of keys) {
switch (key) {
case `libraries`:
options.libraries = page.data[key].split(`,`).map((v) => v.trim());
break;
case `buttons`:
// Do nothing with buttons
break;

default:
// Handle of true/false values back into boolean types
switch (page.data[key]) {
case `true`: options[key] = true; break;
case `false`: options[key] = false; break;
default: options[key] = page.data[key]; break;

while (true) {
const base = loadBase();
const ui = base.customUI();

if (useSimpleView) {
getSimpleView(ui, options);

} else {
const syspropsTab = getSystemTab(options);
const otherpropsTab = getOtherTab(options);
const formatpropsTab = getFormatTab(options);
const performancepropsTab = getPerfTab(options);
const sortPropsTab = getSortTab(options);

let tabs: ComplexTab[] = [
{ label: `System`, fields: syspropsTab.fields },
{ label: `Format`, fields: formatpropsTab.fields },
{ label: `Performance`, fields: performancepropsTab.fields },
{ label: `Sort`, fields: sortPropsTab.fields },
{ label: `Other`, fields: otherpropsTab.fields },
];

ui.addComplexTabs(tabs);
}

ui.addButtons(
{ id: `apply`, label: `Apply changes` },
{ id: `cancel`, label: `Cancel` },
{ id: `swap`, label: `Use ${useSimpleView ? `Detailed` : `Simple`} view` },
);

const page = await ui.loadPage<{ [key: string]: string }>(
`Edit ${jobName} options`
);

if (page && page.data) {
page.panel.dispose();

switch (page.data.buttons) {
case `apply`:
const keys = Object.keys(page.data);

// We need to play with some of the form data to put it back into JDBCOptions
for (const key of keys) {
switch (key) {
case `libraries`:
options.libraries = page.data[key].split(`,`).map((v) => v.trim());
break;
case `buttons`:
// Do nothing with buttons
break;

default:
// Handle of true/false values back into boolean types
switch (page.data[key]) {
case `true`: options[key] = true; break;
case `false`: options[key] = false; break;
default: options[key] = page.data[key]; break;
}
}
}
}
}

return options;

return options;
case `swap`:
useSimpleView = !useSimpleView;
break;

default:
return;
}
}
}

Expand Down
118 changes: 118 additions & 0 deletions src/views/jobManager/editJob/simpleView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { JDBCOptions } from "../../../connection/types";
import { getInstance } from "../../../base";
import { formatDescription } from ".";
import { CustomUI } from "@halcyontech/vscode-ibmi-types/api/CustomUI";

const dbNameText = `Specifies the database to use for a connection to an independent auxiliary storage pool (ASP). When you specify
a database name, the name must exist in the relational database directory on the system and correspond to either
an independent ASP or the system default database.`;

export default function getSimpleView(ui: CustomUI, options: JDBCOptions) {
const connection = getInstance().getConnection()

ui
.addSelect(
`naming`,
`Naming`,
[
{
value: `system`,
text: `as in schema/table`,
description: `System naming`,
selected: options.naming === `system`,
},
{
value: `sql`,
text: `as in schema.table`,
description: `SQL naming`,
selected: options.naming === `sql`,
},
],
`Specifies the naming convention used when referring to tables.`
)
.addInput(
`libraries`,
`Library list`,
`List of system libraries, separated by commas or spaces`,
{ rows: 2, default: options.libraries.join(`, `) }
)
.addSelect(`database name`, `Database name`, [
{text: `System Base`, description: `*SYSBAS`, value: ``, selected: options["database name"] === ``},
...Object.values(connection.aspInfo).map(asp => ({text: asp, description: asp, value: asp, selected: options["database name"] === asp}))
], formatDescription(dbNameText))
.addSelect(
`auto commit`,
`Auto commit`,
[
{
value: `true`,
description: `True`,
text: `Commit (true)`,
selected: options["auto commit"] === true,
},
{
value: `false`,
description: `False`,
text: `No commit (false)`,
selected: options["auto commit"] === false,
},
],
`Specifies whether auto-commit mode is the default connection mode for new connections. Note that, in order to use transaction isolation levels other than *NONE when using auto-commit mode, the property "true autocommit" needs to be set to true.`
)
.addSelect(
`transaction isolation`,
`Transaction isolation`,
[
{
value: `none`,
description: `None`,
text: `No commit (none)`,
selected: options["transaction isolation"] === `none`,
},
{
value: `read committed`,
description: `Read committed`,
text: `read committed`,
selected: options["transaction isolation"] === `read committed`,
},
{
value: `read uncommitted`,
description: `Read uncommitted`,
text: `read uncommitted`,
selected: options["transaction isolation"] === `read uncommitted`,
},
{
value: `repeatable read`,
description: `Repeatable read`,
text: `repeatable read`,
selected: options["transaction isolation"] === `repeatable read`,
},
{
value: `serializable`,
description: `Serializable`,
text: `serializable`,
selected: options["transaction isolation"] === `serializable`,
},
],
`Specifies the default transaction isolation.`
)
.addSelect(
`true autocommit`,
`True autocommit`,
[
{
value: `false`,
text: `Do not use true autocommit`,
description: `false`,
selected: options["true autocommit"] === false,
},
{
value: `true`,
text: `Use true autocommit`,
description: `true`,
selected: options["true autocommit"] === true,
},
],
`Specifies whether the connection should use true auto commit support. True autocommit means that autocommit is on and is running under a isolation level other than *NONE. By default, the driver handles autocommit by running under the system isolation level of *NONE.`
)
}
Loading