From 62f3c2bb3daea454a773cc9c5744131ac8decedd Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 13 Feb 2022 10:45:20 +0100 Subject: [PATCH] json lines tab --- packages/api/src/controllers/archive.js | 7 + packages/api/src/controllers/jsldata.js | 11 +- .../src/appobj/ArchiveFileAppObject.svelte | 6 +- packages/web/src/tabs/ArchiveFileTab.svelte | 7 +- packages/web/src/tabs/FreeTableTab.svelte | 37 +++-- .../web/src/tabs/JsonLinesEditorTab.svelte | 150 ++++++++++++++++++ packages/web/src/tabs/index.js | 2 + 7 files changed, 199 insertions(+), 21 deletions(-) create mode 100644 packages/web/src/tabs/JsonLinesEditorTab.svelte diff --git a/packages/api/src/controllers/archive.js b/packages/api/src/controllers/archive.js index 052987e1..bd82a877 100644 --- a/packages/api/src/controllers/archive.js +++ b/packages/api/src/controllers/archive.js @@ -141,6 +141,13 @@ module.exports = { }); }, + saveText_meta: true, + async saveText({ folder, file, text }) { + await fs.writeFile(path.join(resolveArchiveFolder(folder), `${file}.jsonl`), text); + socket.emitChanged(`archive-files-changed-${folder}`); + return true; + }, + async getNewArchiveFolder({ database }) { const isLink = database.endsWith(database); const name = isLink ? database.slice(0, -5) : database; diff --git a/packages/api/src/controllers/jsldata.js b/packages/api/src/controllers/jsldata.js index b20280bf..2ba1eca4 100644 --- a/packages/api/src/controllers/jsldata.js +++ b/packages/api/src/controllers/jsldata.js @@ -10,7 +10,10 @@ const socket = require('../utility/socket'); function readFirstLine(file) { return new Promise((resolve, reject) => { lineReader.open(file, (err, reader) => { - if (err) reject(err); + if (err) { + reject(err); + return; + } if (reader.hasNextLine()) { reader.nextLine((err, line) => { if (err) reject(err); @@ -151,4 +154,10 @@ module.exports = { saveFreeTableData(getJslFileName(jslid), data); return true; }, + + saveText_meta: true, + async saveText({ jslid, text }) { + await fs.promises.writeFile(getJslFileName(jslid), text); + return true; + }, }; diff --git a/packages/web/src/appobj/ArchiveFileAppObject.svelte b/packages/web/src/appobj/ArchiveFileAppObject.svelte index edbbf627..60eee5e9 100644 --- a/packages/web/src/appobj/ArchiveFileAppObject.svelte +++ b/packages/web/src/appobj/ArchiveFileAppObject.svelte @@ -157,15 +157,15 @@ const handleOpenYamlFile = () => { openTextFile(data.fileName, data.fileType, data.folderName, 'YamlEditorTab', 'img yaml'); }; - const handleOpenJsonText = () => { - openTextFile(data.fileName, data.fileType, data.folderName, 'JsonEditorTab', 'img json'); + const handleOpenJsonLinesText = () => { + openTextFile(data.fileName, data.fileType, data.folderName, 'JsonLinesEditorTab', 'img json'); }; function createMenu() { return [ data.fileType == 'jsonl' && { text: 'Open (readonly)', onClick: handleOpenRead }, data.fileType == 'jsonl' && { text: 'Open as data sheet', onClick: handleOpenWrite }, - data.fileType == 'jsonl' && { text: 'Open in text editor', onClick: handleOpenJsonText }, + data.fileType == 'jsonl' && { text: 'Open in text editor', onClick: handleOpenJsonLinesText }, { text: 'Delete', onClick: handleDelete }, { text: 'Rename', onClick: handleRename }, data.fileType == 'jsonl' && diff --git a/packages/web/src/tabs/ArchiveFileTab.svelte b/packages/web/src/tabs/ArchiveFileTab.svelte index 950cf3ec..982b17bf 100644 --- a/packages/web/src/tabs/ArchiveFileTab.svelte +++ b/packages/web/src/tabs/ArchiveFileTab.svelte @@ -5,8 +5,9 @@ - + diff --git a/packages/web/src/tabs/FreeTableTab.svelte b/packages/web/src/tabs/FreeTableTab.svelte index 9c92c467..d01bc300 100644 --- a/packages/web/src/tabs/FreeTableTab.svelte +++ b/packages/web/src/tabs/FreeTableTab.svelte @@ -32,6 +32,9 @@ } from 'dbgate-datalib'; import { setContext } from 'svelte'; import { writable } from 'svelte/store'; + import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte'; + import ToolStripContainer from '../buttons/ToolStripContainer.svelte'; +import ToolStripExportButton from '../buttons/ToolStripExportButton.svelte'; import registerCommand from '../commands/registerCommand'; import DataGrid from '../datagrid/DataGrid.svelte'; import ErrorInfo from '../elements/ErrorInfo.svelte'; @@ -141,18 +144,24 @@ {:else if errorMessage} {:else} - + + + + + + + {/if} diff --git a/packages/web/src/tabs/JsonLinesEditorTab.svelte b/packages/web/src/tabs/JsonLinesEditorTab.svelte new file mode 100644 index 00000000..81512bd1 --- /dev/null +++ b/packages/web/src/tabs/JsonLinesEditorTab.svelte @@ -0,0 +1,150 @@ + + + + + + setEditorData(e.detail)} + on:focus={() => { + activator.activate(); + invalidateCommands(); + }} + bind:this={domEditor} + mode="json" + /> + + + + + diff --git a/packages/web/src/tabs/index.js b/packages/web/src/tabs/index.js index b0d7f714..fa5c843c 100644 --- a/packages/web/src/tabs/index.js +++ b/packages/web/src/tabs/index.js @@ -16,6 +16,7 @@ import * as QueryDesignTab from './QueryDesignTab.svelte'; import * as CommandListTab from './CommandListTab.svelte'; import * as YamlEditorTab from './YamlEditorTab.svelte'; import * as JsonEditorTab from './JsonEditorTab.svelte'; +import * as JsonLinesEditorTab from './JsonLinesEditorTab.svelte'; import * as CompareModelTab from './CompareModelTab.svelte'; import * as JsonTab from './JsonTab.svelte'; import * as ChangelogTab from './ChangelogTab.svelte'; @@ -40,6 +41,7 @@ export default { CommandListTab, YamlEditorTab, JsonEditorTab, + JsonLinesEditorTab, CompareModelTab, JsonTab, ChangelogTab,