Skip to content

Commit

Permalink
Merge pull request #178 from codefori/feature/never_a_new_job
Browse files Browse the repository at this point in the history
Show 'Never' on new SQL job information box
  • Loading branch information
worksofliam authored Dec 5, 2023
2 parents 3308f24 + 28201cf commit 36136ee
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 42 deletions.
37 changes: 27 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { JobManagerView } from "./views/jobManager/jobManagerView";
import Configuration from "./configuration";
import { ConfigManager } from "./views/jobManager/ConfigManager";
import { Examples, ServiceInfoLabel } from "./views/examples";
import { updateStatusBar } from "./views/jobManager/statusBar";

interface IBMiLevels {
version: number;
Expand All @@ -30,6 +31,8 @@ export async function onConnectOrServerInstall(): Promise<boolean> {

await ServerComponent.checkForUpdate();

updateStatusBar();

if (ServerComponent.isInstalled()) {
JobManagerView.setVisible(true);

Expand All @@ -38,7 +41,7 @@ export async function onConnectOrServerInstall(): Promise<boolean> {

switch (newJob) {
case `ask`:
return await askAboutNewJob();
return await askAboutNewJob(true);

case `new`:
await commands.executeCommand(`vscode-db2i.jobManager.newJob`);
Expand Down Expand Up @@ -67,7 +70,8 @@ export function setupConfig(context: ExtensionContext) {

getInstance().onEvent(`disconnected`, async () => {
JobManagerView.setVisible(false);
await JobManager.endAll();
JobManager.endAll();
updateStatusBar();

// Remove old service examples
delete Examples[ServiceInfoLabel];
Expand Down Expand Up @@ -101,15 +105,28 @@ export async function fetchSystemInfo() {
}
}

export async function askAboutNewJob(): Promise<boolean> {
const chosen = await window.showInformationMessage(`Would you like to start an SQL Job?`, `Yes`, `Always`, `No`);
if (chosen === `Yes` || chosen === `Always`) {
if (chosen === `Always`) {
await Configuration.set(`alwaysStartSQLJob`, `new`);
}
export async function askAboutNewJob(startup?: boolean): Promise<boolean> {
const instance = getInstance();
const connection = instance.getConnection();

if (connection) {
const options = startup ? [`Yes`, `Always`, `No`, `Never`] : [`Yes`, `No`];

const chosen = await window.showInformationMessage(`Would you like to start an SQL Job?`, ...options);
switch (chosen) {
case `Yes`:
case `Always`:
if (chosen === `Always`) {
await Configuration.set(`alwaysStartSQLJob`, `new`);
}

await commands.executeCommand(`vscode-db2i.jobManager.newJob`);
return true;
await commands.executeCommand(`vscode-db2i.jobManager.newJob`);
return true;

case `Never`:
await Configuration.set(`alwaysStartSQLJob`, `never`);
break;
}
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 4 additions & 12 deletions src/views/jobManager/ConfigManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Disposable, ProgressLocation, ThemeIcon, TreeItem, TreeItemCollapsibleState, commands, window } from "vscode";
import Configuration from "../../configuration";
import { JDBCOptions } from "../../connection/types";
import { SQLJobItem } from "./jobManagerView";
import { JobManagerView, SQLJobItem } from "./jobManagerView";
import { JobManager } from "../../config";
import { SQLJob } from "../../connection/sqlJob";
import { editJobUi } from "./editJob";
Expand Down Expand Up @@ -42,16 +42,7 @@ export class ConfigManager {
const options = this.getConfig(name);

if (options) {
await window.withProgress({ location: ProgressLocation.Window }, async (progress) => {
try {
progress.report({ message: `Spinning up SQL job...` });
await JobManager.newJob(new SQLJob(options), name);
} catch (e) {
window.showErrorMessage(e.message);
}

this.refresh();
});
commands.executeCommand(`vscode-db2i.jobManager.newJob`, options, name);
}
}),

Expand Down Expand Up @@ -108,7 +99,8 @@ export class ConfigManager {
}

static getConfig(name: string): JDBCOptions | undefined {
return this.getSavedConfigs()[name];
const configs = this.getSavedConfigs(); // Returns a proxy
return Object.assign({}, configs[name]);
}

private static storeConfig(name: string, options: JDBCOptions) {
Expand Down
23 changes: 12 additions & 11 deletions src/views/jobManager/jobManagerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { JobManager } from "../../config";
import { JobInfo } from "../../connection/manager";
import { ServerComponent } from "../../connection/serverComponent";
import { SQLJob, TransactionEndType } from "../../connection/sqlJob";
import { ServerTraceDest, ServerTraceLevel } from "../../connection/types";
import { JDBCOptions, ServerTraceDest, ServerTraceLevel } from "../../connection/types";
import { ConfigGroup, ConfigManager } from "./ConfigManager";
import { editJobUi } from "./editJob";
import { displayJobLog } from "./jobLog";
Expand All @@ -26,17 +26,18 @@ export class JobManagerView implements TreeDataProvider<any> {

...ConfigManager.initialiseSaveCommands(),

vscode.commands.registerCommand(`vscode-db2i.jobManager.newJob`, async (predefinedJob?: SQLJob, name?: string) => {
await window.withProgress({ location: ProgressLocation.Window }, async (progress) => {
try {
progress.report({ message: `Spinning up SQL job...` });
await JobManager.newJob(predefinedJob, name);
} catch (e) {
window.showErrorMessage(e.message);
}
vscode.commands.registerCommand(`vscode-db2i.jobManager.newJob`, async (options?: JDBCOptions, name?: string) => {
try {
updateStatusBar({newJob: true});
await JobManager.newJob(
(options ? new SQLJob(options) : undefined),
name
);
} catch (e) {
window.showErrorMessage(e.message);
}

this.refresh();
});
this.refresh();
}),

vscode.commands.registerCommand(`vscode-db2i.jobManager.closeJob`, async (node?: SQLJobItem) => {
Expand Down
22 changes: 14 additions & 8 deletions src/views/jobManager/statusBar.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { MarkdownString, StatusBarAlignment, ThemeColor, languages, window } from "vscode";
import { ServerComponent } from "../../connection/serverComponent";
import { SQLJobManager } from "../../connection/manager";
import { JobManager } from "../../config";

const statusItem = languages.createLanguageStatusItem(`sqlStatus`, {language: `sql`});
import { getInstance } from "../../base";

const item = window.createStatusBarItem(`sqlJob`, StatusBarAlignment.Left);

export async function updateStatusBar() {
if (ServerComponent.isInstalled()) {
export async function updateStatusBar(options: {newJob?: boolean} = {}) {
const instance = getInstance();
const connection = instance.getConnection();

if (connection && ServerComponent.isInstalled()) {
const selected = JobManager.getSelection();

let text;
let backgroundColour: ThemeColor|undefined = undefined;
let toolTipItems = [];

if (options.newJob) {
text = `$(sync~spin) Spinning up job...`;
} else
if (selected) {
text = `$(database) ${selected.name}`;

Expand All @@ -39,11 +43,13 @@ export async function updateStatusBar() {
toolTipItems.push(`[Start Job](command:vscode-db2i.jobManager.newJob)`);
}

const toolTip = new MarkdownString(toolTipItems.join(`\n\n---\n\n`), true);
toolTip.isTrusted = true;
if (toolTipItems.length > 0) {
const toolTip = new MarkdownString(toolTipItems.join(`\n\n---\n\n`), true);
toolTip.isTrusted = true;
item.tooltip = toolTip;
}

item.text = text;
item.tooltip = toolTip;
item.backgroundColor = backgroundColour;

item.show();
Expand Down

0 comments on commit 36136ee

Please sign in to comment.