From 1aa0bffec32a82435c2163e956fa2d38bdacd9f6 Mon Sep 17 00:00:00 2001 From: Sunil Shetye Date: Fri, 4 Oct 2024 20:00:12 +0530 Subject: merge the two processors into one function --- .../components/SchematicEditor/SchematicToolbar.js | 7 +- .../src/redux/actions/saveSchematicActions.js | 7 +- blocks/eda-frontend/src/utils/GalleryUtils.js | 26 ++++- blocks/xcos2xml/links/ExplicitLink.xsl | 118 +++++++-------------- blocks/xcos2xml/replacesplitblocks.sh | 2 +- 5 files changed, 69 insertions(+), 91 deletions(-) diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js index 751e7d71..d7b371cc 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js @@ -32,7 +32,7 @@ import { editorZoomIn, editorZoomOut, editorZoomAct, deleteComp, PrintPreview, R import { useSelector, useDispatch } from 'react-redux' import { toggleSimulate, closeCompProperties, setSchXmlData, saveSchematic, openLocalSch } from '../../redux/actions/index' import api from '../../utils/Api' -import { getXsltProcessor } from '../../utils/GalleryUtils' +import { transformXcos } from '../../utils/GalleryUtils' const { mxUtils @@ -403,11 +403,10 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) { reader.onload = function (event) { const title = filename.replace(re, '') let dataDump = event.target.result - let xmlDoc = mxUtils.parseXml(dataDump) + const xmlDoc = mxUtils.parseXml(dataDump) const rexcos = /\.xcos$/i if (rexcos.test(filename)) { - getXsltProcessor().then(processor => { - xmlDoc = processor.transformToDocument(xmlDoc) + transformXcos(xmlDoc).then(xmlDoc => { dataDump = new XMLSerializer().serializeToString(xmlDoc) readXmlFile(xmlDoc, dataDump, title) }) diff --git a/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js b/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js index 18b6a932..818bef29 100644 --- a/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js +++ b/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js @@ -4,7 +4,7 @@ import api from '../../utils/Api' import GallerySchSample from '../../utils/GallerySchSample' import { renderGalleryXML } from '../../components/SchematicEditor/Helper/ToolbarTools' import { setTitle } from './index' -import { getXsltProcessor } from '../../utils/GalleryUtils' +import { transformXcos } from '../../utils/GalleryUtils' export const setSchTitle = (title) => (dispatch) => { dispatch({ @@ -166,7 +166,7 @@ export const loadGallery = (saveId) => (dispatch, getState) => { // Check if the data is xcos or xml const parser = new DOMParser() - let xmlDoc = parser.parseFromString(data.data_dump, 'application/xml') + const xmlDoc = parser.parseFromString(data.data_dump, 'application/xml') const isXcos = xmlDoc.getElementsByTagName('XcosDiagram').length > 0 const handleGalleryLoad = (dispatch, data, dataDump) => { @@ -182,8 +182,7 @@ export const loadGallery = (saveId) => (dispatch, getState) => { } if (isXcos) { - getXsltProcessor().then(processor => { - xmlDoc = processor.transformToDocument(xmlDoc) + transformXcos(xmlDoc).then(xmlDoc => { const dataDump = new XMLSerializer().serializeToString(xmlDoc) handleGalleryLoad(dispatch, data, dataDump) }).catch(error => { diff --git a/blocks/eda-frontend/src/utils/GalleryUtils.js b/blocks/eda-frontend/src/utils/GalleryUtils.js index b1035a00..54fd408e 100644 --- a/blocks/eda-frontend/src/utils/GalleryUtils.js +++ b/blocks/eda-frontend/src/utils/GalleryUtils.js @@ -1,4 +1,4 @@ -export const getXsltProcessor = async () => { +const getXsltProcessor = async () => { const xcos2xml = '/xcos2xml.xsl' const response = await fetch(xcos2xml) const text = await response.text() @@ -9,7 +9,7 @@ export const getXsltProcessor = async () => { return processor } -export const getSplitXsltProcessor = async () => { +const getSplitXsltProcessor = async () => { const xcos2xml = '/splitblock.xsl' const response = await fetch(xcos2xml) const text = await response.text() @@ -19,3 +19,25 @@ export const getSplitXsltProcessor = async () => { processor.importStylesheet(xsl) return processor } + +export const transformXcos = async (xmlDoc) => { + const splitBlock = / --> - - - - - - - 1 - - - - - - - - - - - - - - - 0 - - - - - - - - - - - 0 - - - Unknown - - - - - - - - + + + + 1 + + + + + + + + + + + + + + + 0 + + + + + + + + + + + 0 + + + Unknown + + + - - \ No newline at end of file + diff --git a/blocks/xcos2xml/replacesplitblocks.sh b/blocks/xcos2xml/replacesplitblocks.sh index 2c98d00e..d223c5cd 100755 --- a/blocks/xcos2xml/replacesplitblocks.sh +++ b/blocks/xcos2xml/replacesplitblocks.sh @@ -58,7 +58,7 @@ trap "cat $TMPFILE2; rm -f $TMPFILE1 $TMPFILE2" 0 1 2 15 if test -n "$INPUTXML"; then xmllint --format "$INPUTXML" > "$TMPFILE2" - if ! diff -q "$TMPFILE2" "$INPUTXML"; then + if ! diff -q "$TMPFILE2" "$INPUTXML" >&2; then cp -f "$TMPFILE2" "$INPUTXML" echo "$INPUTXML updated" >&2 fi -- cgit