Skip to content

Commit

Permalink
Merge pull request #6 from halcyon-tech/feature/scrolling_results
Browse files Browse the repository at this point in the history
Feature/scrolling results
  • Loading branch information
worksofliam authored Jun 29, 2022
2 parents 10175db + cbb2666 commit cb17fb7
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 112 deletions.
6 changes: 6 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ interface SQLParm {
IS_NULLABLE: "Y" | "N",
DEFAULT?: string,
LONG_COMMENT?: string
}

interface StatementInfo {
content: string,
type: "statement"|"json"|"csv"|"cl"|"sql",
open?: boolean
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@
{
"command": "vscode-db2i.generateSQL",
"title": "Generate SQL",
"category": "Db2 for i",
"icon": "$(add)"
"category": "Db2 for i"
},
{
"command": "vscode-db2i.generateSelect",
"title": "Generate SELECT",
"category": "Db2 for i"
"command": "vscode-db2i.getResultSet",
"title": "View contents",
"category": "Db2 for i",
"icon": "$(output)"
},
{
"command": "vscode-db2i.setCurrentSchema",
Expand Down Expand Up @@ -195,9 +195,9 @@
"group": "db2@1"
},
{
"command": "vscode-db2i.generateSelect",
"command": "vscode-db2i.getResultSet",
"when": "viewItem == table || viewItem == view || viewItem == alias",
"group": "db2@1"
"group": "inline"
},
{
"command": "vscode-db2i.generateSQL",
Expand Down
97 changes: 97 additions & 0 deletions src/language/results/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,103 @@ exports.getLoadingHTML = () => {
`;
}

/**
*
* @param {string} basicSelect
* @returns {string}
*/
exports.generateScroller = (basicSelect) => {
return /*html*/ `
<!DOCTYPE html>
<html lang="en">
<head>
${head}
<script>
const vscode = acquireVsCodeApi();
const basicSelect = ${JSON.stringify(basicSelect)};
const limit = 50;
let nextOffset = 0;
let noMoreRows = false;
let isFetching = false;
window.addEventListener("load", main);
function main() {
let Observer = new IntersectionObserver(function(entries) {
// isIntersecting is true when element and viewport are overlapping
// isIntersecting is false when element and viewport don't overlap
if(entries[0].isIntersecting === true) {
if (isFetching === false && noMoreRows === false) {
fetchNextPage();
}
}
}, { threshold: [0] });
Observer.observe(document.getElementById("nextButton"));
window.addEventListener('message', event => {
const scroller = document.getElementById("scroller");
const data = event.data;
switch (data.command) {
case 'rows':
isFetching = false;
if (scroller.columnDefinitions.length === 0) {
scroller.columnDefinitions = Object.keys(data.rows[0]).map(col => ({
title: col,
columnDataKey: col,
}));
}
if (scroller.rowsData.length > 0) {
scroller.rowsData = [...scroller.rowsData, ...data.rows];
} else {
scroller.rowsData = data.rows;
}
console.log('row check');
if (data.rows.length < limit) {
console.log("No more rows");
noMoreRows = true;
}
const nextButton = document.getElementById("nextButton");
nextButton.innerText = noMoreRows ? 'End of data' : 'Fetching more...';
break;
case 'fetch':
scroller.columnDefinitions = [];
scroller.rowsData = [];
nextOffset = 0;
fetchNextPage();
break;
}
});
}
function fetchNextPage() {
isFetching = true;
vscode.postMessage({
query: basicSelect,
limit,
offset: nextOffset,
});
nextOffset += limit;
}
</script>
</head>
<body>
<vscode-data-grid id="scroller"></vscode-data-grid>
<vscode-divider></vscode-divider>
<p id="nextButton">Execute statement.</p>
</body>
</html>
`;
}

/**
*
* @param {object[]} rows
Expand Down
Loading

0 comments on commit cb17fb7

Please sign in to comment.