mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 19:56: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;
|
this.filterable = true;
|
||||||
|
|
||||||
if (structure.columns) {
|
if (structure?.columns) {
|
||||||
this.columns = _.uniqBy(
|
this.columns = _.uniqBy(
|
||||||
structure.columns
|
structure.columns
|
||||||
.map(col => ({
|
.map(col => ({
|
||||||
@@ -39,7 +39,7 @@ export class JslGridDisplay extends GridDisplay {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (structure.__isDynamicStructure) {
|
if (structure?.__isDynamicStructure) {
|
||||||
this.columns = analyseCollectionDisplayColumns(rows, this);
|
this.columns = analyseCollectionDisplayColumns(rows, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
rows: rowFunc ? model.rows.map(rowFunc) : model.rows,
|
rows: rowFunc ? model.rows.map(rowFunc) : model.rows,
|
||||||
structure: {
|
structure: {
|
||||||
...model.structure,
|
...model.structure,
|
||||||
columns: func(model.structure.columns),
|
columns: func(model.structure?.columns),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ManagerInnerContainer width={managerSize}>
|
<ManagerInnerContainer width={managerSize}>
|
||||||
{#each structure.columns || [] as column, index}
|
{#each structure?.columns || [] as column, index}
|
||||||
{#if index == editingColumn}
|
{#if index == editingColumn}
|
||||||
<ColumnNameEditor
|
<ColumnNameEditor
|
||||||
defaultValue={column.columnName}
|
defaultValue={column.columnName}
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
onBlur={() => (editingColumn = null)}
|
onBlur={() => (editingColumn = null)}
|
||||||
focusOnCreate
|
focusOnCreate
|
||||||
blurOnEnter
|
blurOnEnter
|
||||||
existingNames={structure.columns.map(x => x.columnName)}
|
existingNames={structure?.columns.map(x => x.columnName)}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<ColumnManagerRow
|
<ColumnManagerRow
|
||||||
@@ -77,6 +77,6 @@
|
|||||||
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
|
dispatchChangeColumns($$props, cols => [...cols, { columnName }]);
|
||||||
}}
|
}}
|
||||||
placeholder="New column"
|
placeholder="New column"
|
||||||
existingNames={(structure.columns || []).map(x => x.columnName)}
|
existingNames={(structure?.columns || []).map(x => x.columnName)}
|
||||||
/>
|
/>
|
||||||
</ManagerInnerContainer>
|
</ManagerInnerContainer>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
'icon file': 'mdi mdi-file',
|
'icon file': 'mdi mdi-file',
|
||||||
'icon loading': 'mdi mdi-loading mdi-spin',
|
'icon loading': 'mdi mdi-loading mdi-spin',
|
||||||
'icon close': 'mdi mdi-close',
|
'icon close': 'mdi mdi-close',
|
||||||
|
'icon stop': 'mdi mdi-close-octagon',
|
||||||
'icon filter': 'mdi mdi-filter',
|
'icon filter': 'mdi mdi-filter',
|
||||||
'icon filter-off': 'mdi mdi-filter-off',
|
'icon filter-off': 'mdi mdi-filter-off',
|
||||||
'icon reload': 'mdi mdi-reload',
|
'icon reload': 'mdi mdi-reload',
|
||||||
|
|||||||
@@ -174,7 +174,7 @@
|
|||||||
<svelte:fragment slot="footer">
|
<svelte:fragment slot="footer">
|
||||||
<div class="flex m-2">
|
<div class="flex m-2">
|
||||||
{#if busy}
|
{#if busy}
|
||||||
<LargeButton icon="icon close" on:click={handleCancel}>Cancel</LargeButton>
|
<LargeButton icon="icon stop" on:click={handleCancel}>Stop</LargeButton>
|
||||||
{:else}
|
{:else}
|
||||||
<LargeFormButton on:click={handleExecute} icon="icon run">Run</LargeFormButton>
|
<LargeFormButton on:click={handleExecute} icon="icon run">Run</LargeFormButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const stream = require('stream');
|
|||||||
const NodeXmlStream = require('node-xml-stream');
|
const NodeXmlStream = require('node-xml-stream');
|
||||||
|
|
||||||
class ParseStream extends stream.Transform {
|
class ParseStream extends stream.Transform {
|
||||||
constructor({ elementName }) {
|
constructor({ itemElementName }) {
|
||||||
super({ objectMode: true });
|
super({ objectMode: true });
|
||||||
this.rowsWritten = 0;
|
this.rowsWritten = 0;
|
||||||
this.parser = new NodeXmlStream();
|
this.parser = new NodeXmlStream();
|
||||||
@@ -17,7 +17,7 @@ class ParseStream extends stream.Transform {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.parser.on('closetag', (name, attrs) => {
|
this.parser.on('closetag', (name, attrs) => {
|
||||||
if (name == elementName) {
|
if (name == itemElementName) {
|
||||||
this.rowsWritten += 1;
|
this.rowsWritten += 1;
|
||||||
this.push({ ...this.stack[this.stack.length - 1].attrs, ...this.stack[this.stack.length - 1].nodes });
|
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}`);
|
console.log(`Reading file ${fileName}`);
|
||||||
|
|
||||||
const fileStream = fs.createReadStream(fileName, encoding);
|
const fileStream = fs.createReadStream(fileName, encoding);
|
||||||
const parser = new ParseStream({ elementName });
|
const parser = new ParseStream({ itemElementName });
|
||||||
fileStream.pipe(parser);
|
fileStream.pipe(parser);
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,68 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const stream = require('stream');
|
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 {
|
class StringifyStream extends stream.Transform {
|
||||||
constructor() {
|
constructor({ itemElementName, rootElementName }) {
|
||||||
super({ objectMode: true });
|
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) {
|
_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();
|
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}`);
|
console.log(`Writing file ${fileName}`);
|
||||||
const stringify = new StringifyStream();
|
const stringify = new StringifyStream({ itemElementName, rootElementName });
|
||||||
const fileStream = fs.createWriteStream(fileName, encoding);
|
const fileStream = fs.createWriteStream(fileName, encoding);
|
||||||
stringify.pipe(fileStream);
|
stringify.pipe(fileStream);
|
||||||
stringify['finisher'] = fileStream;
|
stringify['finisher'] = fileStream;
|
||||||
|
|||||||
@@ -14,9 +14,16 @@ const fileFormat = {
|
|||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
name: 'elementName',
|
name: 'rootElementName',
|
||||||
label: 'Element name',
|
label: 'Root element name',
|
||||||
apiName: 'elementName',
|
apiName: 'rootElementName',
|
||||||
|
direction: 'target',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'itemElementName',
|
||||||
|
label: 'Item element name',
|
||||||
|
apiName: 'itemElementName',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user