Skip to content

Commit

Permalink
Import dialog fix, sql commands fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StanZGenchev committed Dec 27, 2024
1 parent f57689b commit 62043b9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* SPDX-License-Identifier: EPL-2.0
*/
const viewData = {
id: 'importWindow',
id: 'import',
label: 'Import',
autoFocusTab: false,
path: '/services/web/view-import/import.html'
};
if (typeof exports !== 'undefined') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ projectsView.controller('ProjectsViewController', function (
} else if (id === 'import' || id === 'importZip') {
Dialogs.showWindow({
hasHeader: true,
id: 'importWindow',
id: 'import',
params: {
importType: id !== 'importZip' ? 'file' : 'zip',
uploadPath: contextMenuNodes[0].data.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ body {
height: 100%;
}

#infobar {
padding-inline: 1rem;
padding-block: 0.375rem;
background-color: var(--sapInfobar_NonInteractive_Background, transparent);
}

#embeddedEditor {
margin: 0;
padding: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}

#loadingOverview {
width: 100vw;
height: 100vh;
z-index: 1000;
}

#loadingOverview.bk-hidden {
display: none !important;
}

#loadingOverview:not(.bk-hidden)~#infobar,
#loadingOverview:not(.bk-hidden)~#embeddedEditor {
display: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
const themingHub = new ThemingHub();
const statusBarHub = new StatusBarHub();
const dialogHub = new DialogHub();
let sqlPlaceholder = "-- Press F8 to execute the selected command\n";
let csrfToken;
let loadingOverview = document.getElementById('loadingOverview');
let loadingMessage = document.getElementById('loadingMessage');
const loadingOverview = document.getElementById('loadingOverview');
let monacoTheme = 'vs-light';
let themeId = 'vs-light';
let headElement = document.getElementsByTagName('head')[0];
Expand Down Expand Up @@ -68,7 +66,7 @@ function createEditorInstance() {
containerEl.removeChild(containerEl.children.item(i));
}
let editor = monaco.editor.create(containerEl, {
value: sqlPlaceholder,
value: '',
automaticLayout: true,
language: "sql",
});
Expand All @@ -83,6 +81,19 @@ function createEditorInstance() {
});
}

function createSaveAction() {
return {
id: 'dirigible-sql-save',
label: 'Save',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
precondition: null,
keybindingContext: null,
contextMenuGroupId: 'fileIO',
contextMenuOrder: 1.5,
run: () => statusBarHub.showMessage('SQL commands saved'),
};
}

function createExecuteAction() {
return {
// An unique identifier of the contributed action.
Expand Down Expand Up @@ -131,26 +142,30 @@ function createExecuteAction() {
});
themingHub.addMessageListener({
topic: "database.sql.script",
handler: function (command) {
handler: (command) => {
//_editor.trigger('keyboard', 'type', {text: command.data});
var line = editor.getPosition();
var range = new monaco.Range(line.lineNumber, 1, line.lineNumber, 1);
var id = { major: 1, minor: 1 };
var text = command.data;
var op = { identifier: id, range: range, text: text, forceMoveMarkers: true };
let line = editor.getPosition();
let range = new monaco.Range(line.lineNumber + 1, 1, line.lineNumber + 1, 1);
let id = { major: 1, minor: 1 };
let text;
if (command.startsWith('\n')) text = command;
else text = `\n${command}`;
let op = { identifier: id, range: range, text: text, forceMoveMarkers: true };
editor.executeEdits("source", [op]);
}
});
let sqlCommand = loadSQLCommand();
return sqlPlaceholder + sqlCommand;
if (loadingOverview) loadingOverview.classList.add("bk-hidden");
else console.log(loadingOverview)
return loadSQLCommand();
}).then((fileText) => {
let model = monaco.editor.createModel(fileText, "sql");
_editor.setModel(model);
_editor.addAction(createExecuteAction());
_editor.addAction(createSaveAction());
_editor.onDidChangeCursorPosition(function (e) {
statusBarHub.showLabel("Line " + e.position.lineNumber + " : Column " + e.position.column);
});
_editor.onDidChangeModelContent(function (e) {
_editor.onDidChangeModelContent(function (_e) {
saveSQLCommand(_editor.getValue());
});
});
Expand Down Expand Up @@ -211,21 +226,11 @@ function createExecuteAction() {

const savedSqlCommandKey = `${brandingInfo.keyPrefix}.view-sql.command`;

function getSQLCommand(text) {
let sqlCommand = text;
let sqlPlaceHolderIndex = text.indexOf(sqlPlaceholder);
if (sqlPlaceHolderIndex >= 0) {
sqlCommand = text.substring(sqlPlaceholder.length);
}
return sqlCommand;
}

function saveSQLCommand(text) {
const sqlCommand = getSQLCommand(text);
localStorage.setItem(savedSqlCommandKey, sqlCommand);
function saveSQLCommand(sqlCommands) {
localStorage.setItem(savedSqlCommandKey, sqlCommands);
}

function loadSQLCommand() {
const sqlCommand = localStorage.getItem(savedSqlCommandKey);
return sqlCommand ? sqlCommand : "";
return sqlCommand ? sqlCommand : '';
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<script type="text/javascript" src="/webjars/monaco-editor/min/vs/loader.js"></script>
</head>

<body spellcheck="false">
<body class="bk-vbox" spellcheck="false">
<div id="loadingOverview" class="fd-busy-indicator-extended">
<div class="fd-busy-indicator fd-busy-indicator--l" aria-hidden="false" aria-label="Loading">
<div class="fd-busy-indicator__circle"></div>
Expand All @@ -44,7 +44,7 @@
</div>
<div id="loadingMessage" class="fd-busy-indicator-extended__label">Loading data...</div>
</div>

<div id="infobar">Press F8 to execute the selected command</div>
<div id="embeddedEditor" ng-non-bindable></div>
<script type="module" src="js/sql.js"></script>
</body>
Expand Down

0 comments on commit 62043b9

Please sign in to comment.