mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 12:46:00 +00:00
basic XML import works + small fixes
This commit is contained in:
@@ -18,7 +18,7 @@ export class JslGridDisplay extends GridDisplay {
|
||||
|
||||
this.filterable = true;
|
||||
|
||||
if (structure.columns) {
|
||||
if (structure?.columns) {
|
||||
this.columns = _.uniqBy(
|
||||
structure.columns
|
||||
.map(col => ({
|
||||
@@ -39,7 +39,7 @@ export class JslGridDisplay extends GridDisplay {
|
||||
);
|
||||
}
|
||||
|
||||
if (structure.__isDynamicStructure) {
|
||||
if (structure?.__isDynamicStructure) {
|
||||
this.columns = analyseCollectionDisplayColumns(rows, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
rows: rowFunc ? model.rows.map(rowFunc) : model.rows,
|
||||
structure: {
|
||||
...model.structure,
|
||||
columns: func(model.structure.columns),
|
||||
columns: func(model.structure?.columns),
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -40,7 +40,7 @@
|
||||
</script>
|
||||
|
||||
<ManagerInnerContainer width={managerSize}>
|
||||
{#each structure.columns || [] as column, index}
|
||||
{#each structure?.columns || [] as column, index}
|
||||
{#if index == editingColumn}
|
||||
<ColumnNameEditor
|
||||
defaultValue={column.columnName}
|
||||
@@ -54,7 +54,7 @@
|
||||
onBlur={() => (editingColumn = null)}
|
||||
focusOnCreate
|
||||
blurOnEnter
|
||||
existingNames={structure.columns.map(x => x.columnName)}
|
||||
existingNames={structure?.columns.map(x => x.columnName)}
|
||||
/>
|
||||
{:else}
|
||||
<ColumnManagerRow
|
||||
@@ -77,6 +77,6 @@
|
||||
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
|
||||
}}
|
||||
placeholder="New column"
|
||||
existingNames={(structure.columns || []).map(x => x.columnName)}
|
||||
existingNames={(structure?.columns || []).map(x => x.columnName)}
|
||||
/>
|
||||
</ManagerInnerContainer>
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
'icon file': 'mdi mdi-file',
|
||||
'icon loading': 'mdi mdi-loading mdi-spin',
|
||||
'icon close': 'mdi mdi-close',
|
||||
'icon stop': 'mdi mdi-close-octagon',
|
||||
'icon filter': 'mdi mdi-filter',
|
||||
'icon filter-off': 'mdi mdi-filter-off',
|
||||
'icon reload': 'mdi mdi-reload',
|
||||
|
||||
@@ -174,7 +174,7 @@
|
||||
<svelte:fragment slot="footer">
|
||||
<div class="flex m-2">
|
||||
{#if busy}
|
||||
<LargeButton icon="icon close" on:click={handleCancel}>Cancel</LargeButton>
|
||||
<LargeButton icon="icon stop" on:click={handleCancel}>Stop</LargeButton>
|
||||
{:else}
|
||||
<LargeFormButton on:click={handleExecute} icon="icon run">Run</LargeFormButton>
|
||||
{/if}
|
||||
|
||||
@@ -3,7 +3,7 @@ const stream = require('stream');
|
||||
const NodeXmlStream = require('node-xml-stream');
|
||||
|
||||
class ParseStream extends stream.Transform {
|
||||
constructor({ elementName }) {
|
||||
constructor({ itemElementName }) {
|
||||
super({ objectMode: true });
|
||||
this.rowsWritten = 0;
|
||||
this.parser = new NodeXmlStream();
|
||||
@@ -17,7 +17,7 @@ class ParseStream extends stream.Transform {
|
||||
}
|
||||
});
|
||||
this.parser.on('closetag', (name, attrs) => {
|
||||
if (name == elementName) {
|
||||
if (name == itemElementName) {
|
||||
this.rowsWritten += 1;
|
||||
this.push({ ...this.stack[this.stack.length - 1].attrs, ...this.stack[this.stack.length - 1].nodes });
|
||||
}
|
||||
@@ -30,11 +30,11 @@ class ParseStream extends stream.Transform {
|
||||
}
|
||||
}
|
||||
|
||||
async function reader({ fileName, encoding = 'utf-8', elementName }) {
|
||||
async function reader({ fileName, encoding = 'utf-8', itemElementName }) {
|
||||
console.log(`Reading file ${fileName}`);
|
||||
|
||||
const fileStream = fs.createReadStream(fileName, encoding);
|
||||
const parser = new ParseStream({ elementName });
|
||||
const parser = new ParseStream({ itemElementName });
|
||||
fileStream.pipe(parser);
|
||||
return parser;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,68 @@
|
||||
const fs = require('fs');
|
||||
const stream = require('stream');
|
||||
|
||||
function escapeXml(value) {
|
||||
return value.replace(/[<>&'"]/g, function (c) {
|
||||
switch (c) {
|
||||
case '<':
|
||||
return '<';
|
||||
case '>':
|
||||
return '>';
|
||||
case '&':
|
||||
return '&';
|
||||
case "'":
|
||||
return ''';
|
||||
case '"':
|
||||
return '"';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class StringifyStream extends stream.Transform {
|
||||
constructor() {
|
||||
constructor({ itemElementName, rootElementName }) {
|
||||
super({ objectMode: true });
|
||||
this.itemElementName = itemElementName;
|
||||
this.rootElementName = rootElementName;
|
||||
|
||||
this.startElement(this.rootElementName);
|
||||
}
|
||||
|
||||
startElement(element) {
|
||||
this.push('<');
|
||||
this.push(element);
|
||||
this.push('>\n');
|
||||
}
|
||||
|
||||
endElement(element) {
|
||||
this.push('</');
|
||||
this.push(element);
|
||||
this.push('>\n');
|
||||
}
|
||||
|
||||
elementValue(element, value) {
|
||||
this.startElement(element);
|
||||
this.push(escapeXml(`${value}`));
|
||||
this.endElement(element);
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, done) {
|
||||
this.push(JSON.stringify(chunk) + '\n');
|
||||
this.startElement(this.itemElementName);
|
||||
for (const key of Object.keys(chunk)) {
|
||||
this.elementValue(key, chunk[key]);
|
||||
}
|
||||
this.endElement(this.itemElementName);
|
||||
done();
|
||||
}
|
||||
|
||||
_final(callback) {
|
||||
this.endElement(this.rootElementName);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
async function writer({ fileName, encoding = 'utf-8' }) {
|
||||
async function writer({ fileName, encoding = 'utf-8', itemElementName, rootElementName }) {
|
||||
console.log(`Writing file ${fileName}`);
|
||||
const stringify = new StringifyStream();
|
||||
const stringify = new StringifyStream({ itemElementName, rootElementName });
|
||||
const fileStream = fs.createWriteStream(fileName, encoding);
|
||||
stringify.pipe(fileStream);
|
||||
stringify['finisher'] = fileStream;
|
||||
|
||||
@@ -14,9 +14,16 @@ const fileFormat = {
|
||||
args: [
|
||||
{
|
||||
type: 'text',
|
||||
name: 'elementName',
|
||||
label: 'Element name',
|
||||
apiName: 'elementName',
|
||||
name: 'rootElementName',
|
||||
label: 'Root element name',
|
||||
apiName: 'rootElementName',
|
||||
direction: 'target',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
name: 'itemElementName',
|
||||
label: 'Item element name',
|
||||
apiName: 'itemElementName',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user