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/self codes p2 #168

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9f73c36
start self codes from saved config
ajshedivy Oct 23, 2023
eef2a54
self codes panel
ajshedivy Nov 15, 2023
1cbcd7d
add self code error panel to results
ajshedivy Nov 15, 2023
f063c3a
activate self codes when switching selected job
ajshedivy Nov 16, 2023
ebf03ca
add scrollable json cells
ajshedivy Nov 27, 2023
e37f4ef
Merge branch 'main' into feature/self_codes_p2
ajshedivy Dec 6, 2023
399f59e
Merge branch 'main' of https://github.com/halcyon-tech/vscode-db2i in…
ajshedivy Jan 2, 2024
d402a8e
generate table dyanmically for self codes
ajshedivy Jan 3, 2024
8140afb
Merge branch 'feature/self_codes_p2' of https://github.com/halcyon-te…
ajshedivy Jan 3, 2024
0ba27a8
show self code error table when new errors are detected
ajshedivy Jan 3, 2024
0423ec2
add get header css to self code view
ajshedivy Jan 8, 2024
031d49b
refactor formatted cell detection
ajshedivy Jan 9, 2024
a345aae
Remove type in raw JavaScript
worksofliam Jan 12, 2024
5752f58
self code error cleanup
ajshedivy Jan 12, 2024
6682b89
Merge branch 'feature/self_codes_p2' of https://github.com/halcyon-te…
ajshedivy Jan 12, 2024
cf5d7db
increase retry count
ajshedivy Jan 18, 2024
f331d73
Change how cached data is used for render decisions
worksofliam Jan 18, 2024
705f0e4
Self code time out to replace for loop
worksofliam Jan 18, 2024
1be4d06
remove vscode from sqljob
ajshedivy Jan 18, 2024
8c3a14e
Merge branch 'main' into feature/self_codes_p2
worksofliam Feb 13, 2024
dae4583
Add type to rs panel
worksofliam Feb 13, 2024
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
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@
"name": "Results",
"when": "code-for-ibmi:connected == true",
"contextualTitle": "IBM i"
},
{
"type": "webview",
"id": "vscode-db2i.selfCodeErrorPanel",
"name": "Self Code Errors",
"when": "code-for-ibmi:connected == true && vscode-db2i:hasSelfCodes == true && vscode-db2i:selfCodeCountChanged == true",
"contextualTitle": "IBM i"
}
],
"db2-explorer": [
Expand Down
8 changes: 8 additions & 0 deletions src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ export class SQLJobManager {
const jobExists = this.jobs.findIndex(info => info.name === selectedName);

this.selectedJob = jobExists;
if (jobExists >= 0) {
const curJob: JobInfo = this.jobs[jobExists];
if (curJob.job.options.selfcodes) {
curJob.job.setSelfCodes(curJob.job.options.selfcodes);
} else {
curJob.job.setSelfCodes([]);
}
}

return (this.selectedJob >= 0);
}
Expand Down
10 changes: 9 additions & 1 deletion src/connection/sqlJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ServerComponent } from "./serverComponent";
import { JDBCOptions, ConnectionResult, Rows, QueryResult, JobLogEntry, CLCommandResult, VersionCheckResult, GetTraceDataResult, ServerTraceDest, ServerTraceLevel, SetConfigResult, QueryOptions } from "./types";
import { Query } from "./query";
import { EventEmitter } from "stream";
import { commands } from "vscode";
worksofliam marked this conversation as resolved.
Show resolved Hide resolved

export enum JobStatus {
NotStarted = "notStarted",
Expand Down Expand Up @@ -186,6 +187,9 @@ export class SQLJob {
this.id = connectResult.job;
this.status = JobStatus.Ready;

commands.executeCommand(`setContext`, `vscode-db2i:hasSelfCodes`, false);
commands.executeCommand(`setContext`, `vscode-db2i:selfCodeCountChanged`, false);

return connectResult;
}
query<T>(sql: string, opts?: QueryOptions): Query<T> {
Expand Down Expand Up @@ -236,11 +240,15 @@ export class SQLJob {
const query: string = `SET SYSIBMADM.SELFCODES = SYSIBMADM.VALIDATE_SELF('${signedCodes.join(', ')}')`
await this.query<any>(query).run();
this.options.selfcodes = codes;
if (codes.length === 0) {
commands.executeCommand(`setContext`, `vscode-db2i:hasSelfCodes`, false);
} else {
commands.executeCommand(`setContext`, `vscode-db2i:hasSelfCodes`, true);
}
} catch (e) {
throw e;
}
}

async setTraceConfig(dest: ServerTraceDest, level: ServerTraceLevel): Promise<SetConfigResult> {
const reqObj = {
id: SQLJob.getNewUniqueId(),
Expand Down
15 changes: 14 additions & 1 deletion src/views/jobManager/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ export class ConfigManager {
const options = this.getConfig(name);

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

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

Expand Down
158 changes: 145 additions & 13 deletions src/views/results/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,48 @@ export function generateScroller(basicSelect: string, isCL: boolean): string {
});
}

function isJsonString(str) {
worksofliam marked this conversation as resolved.
Show resolved Hide resolved
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}

function getFormattedCell(cellValue) {
// Handle undefined cells
var formattedValue = cellValue === undefined ? 'null' : cellValue;

// Format JSON cells
if (isJsonString(formattedValue)) {
var formattedJson = JSON.stringify(JSON.parse(formattedValue), null, 2);
var pre = document.createElement('pre');
pre.style.maxHeight = '100px';
pre.style.overflowY = 'auto';
pre.style.margin = '0';
pre.textContent = formattedJson;
return pre;
} else {
// Handle non-JSON cells
return document.createTextNode(formattedValue);
}
}

function appendRows(tableId, arrayOfObjects) {
var tBodyRef = document.getElementById(tableId).getElementsByTagName('tbody')[0];

for (const row of arrayOfObjects) {
// Insert a row at the end of table
var newRow = tBodyRef.insertRow()
var newRow = tBodyRef.insertRow();

for (const cell of row) {
// Insert a cell at the end of the row
var newCell = newRow.insertCell();

// Append a text node to the cell

//TODO: handle cell formatting here
var newDiv = document.createElement("div");
newDiv.className = "hoverable";
newDiv.appendChild(document.createTextNode(cell === undefined ? 'null' : cell));

newCell.appendChild(newDiv);
var cellContent = getFormattedCell(cell);
newCell.appendChild(cellContent);
}
}

}

</script>
</head>
<body>
Expand All @@ -179,4 +198,117 @@ export function generateScroller(basicSelect: string, isCL: boolean): string {
</body>
</html>
`;
}

export function generateDynamicTable(): string {
// const parsedData = JSON.parse(data);

return /*html*/`
<!DOCTYPE html>
<html lang="en">
<head>
${getHeader({withCollapsed: false})}
<script>
/*
${new Date().getTime()}
*/
const vscode = acquireVsCodeApi();
let mustLoadHeaders = true;
let totalRows = 0;
window.addEventListener("load", main);
function main() {
window.addEventListener('message', event => {
const data = event.data;
switch (data.command) {
case 'setTableData':
if (mustLoadHeaders && event.data.columnList) {
setHeaders('resultset', event.data.columnList);
mustLoadHeaders = false;
}

if (data.rows && data.rows.length > 0) {
totalRows += data.rows.length;
appendRows('resultset', data.rows);
}
const nextButton = document.getElementById("nextButton");
if (data.rows === undefined && totalRows === 0) {
nextButton.innerText = 'Query executed with no result set returned. Rows affected: ' + data.update_count;
} else {
nextButton.innerText = ('Loaded ' + totalRows + '. End of data');
}
break;
}
});
}


function setHeaders(tableId, columns) {
var tHeadRef = document.getElementById(tableId).getElementsByTagName('thead')[0];
tHeadRef.innerHTML = '';

// Insert a row at the end of table
var newRow = tHeadRef.insertRow();

columns.forEach(colName => {
// Insert a cell at the end of the row
var newCell = newRow.insertCell();

// Append a text node to the cell
var newText = document.createTextNode(colName);
newCell.appendChild(newText);
});
}

function isJsonString(str: string): boolean {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}

function getFormattedCell(cellValue) {
// Handle undefined cells
var formattedValue = cellValue === undefined ? 'null' : cellValue;

// Format JSON cells
if (isJsonString(formattedValue)) {
var formattedJson = JSON.stringify(JSON.parse(formattedValue), null, 2);
var pre = document.createElement('pre');
pre.style.maxHeight = '100px';
pre.style.overflowY = 'auto';
pre.style.margin = '0';
pre.textContent = formattedJson;
return pre;
} else {
// Handle non-JSON cells
return document.createTextNode(formattedValue);
}
}

function appendRows(tableId, arrayOfObjects) {
var tBodyRef = document.getElementById(tableId).getElementsByTagName('tbody')[0];

for (const row of arrayOfObjects) {
var newRow = tBodyRef.insertRow();

for (const cell of row) {
var newCell = newRow.insertCell();
var cellContent = getFormattedCell(cell);
newCell.appendChild(cellContent);
}
}
}
</script>
</head>
<body>
<table id="resultset">
<thead></thead>
<tbody></tbody>
</table>
<p id="nextButton"></p>
</body>
</html>
`;
}
Loading
Loading