redo file import and save

master
Dave Conway-Jones 2020-10-05 00:00:45 +01:00
rodzic 54040e45ce
commit fbdb4afe01
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 88BA2B8A411BE9FF
4 zmienionych plików z 2236 dodań i 41 usunięć

Wyświetl plik

@ -33,7 +33,7 @@
</head> </head>
<body style="margin:0;" onload="scrollDown()" > <body style="margin:0;" onload="scrollDown()" >
<font style="font-family:'Helvetica Neue', Arial, Helvetica, sans-serif; font-size:9pt;"> <font style="font-family:'Helvetica Neue', Arial, Helvetica, sans-serif; font-size:9pt;">
<div id="header" style="background-color:#910000; position:fixed; height:16px; width:100%; padding:8px;"><input type="button" value="Clear Log" onclick="clearList()";/></div> <div id="header" style="background-color:#910000; position:fixed; height:16px; width:100%; padding:8px;"><input type="button" style="float:right; margin-right:15px" value="Clear Log" onclick="clearList()";/></div>
<div id="debug" style="padding:4px; padding-left:8px; padding-top:34px;"></div> <div id="debug" style="padding:4px; padding-left:8px; padding-top:34px;"></div>
</font> </font>
</body> </body>

File diff suppressed because one or more lines are too long

89
main.js
Wyświetl plik

@ -116,7 +116,12 @@ var settings = {
httpNodeRoot: "/", httpNodeRoot: "/",
userDir: userdir, userDir: userdir,
flowFile: flowfile, flowFile: flowfile,
editorTheme: { projects:{ enabled:false }, palette: { editable:addNodes } }, // enable projects feature flowFilePretty: true,
editorTheme: {
projects:{ enabled:false },
header: { title: options.productName },
palette: { editable:addNodes }
}, // enable projects feature
functionGlobalContext: { }, // enables global context - add extras ehre if you need them functionGlobalContext: { }, // enables global context - add extras ehre if you need them
logging: { logging: {
websock: { websock: {
@ -242,50 +247,56 @@ if (isDev) {
}) })
} }
let fileName = ""; let fileName = path.join(userdir,flowfile);
function saveFlow() { function saveFlow() {
dialog.showSaveDialog({ const file_path = dialog.showSaveDialogSync({
title:"Save Flow As",
filters:[{ name:'JSON', extensions:['json'] }], filters:[{ name:'JSON', extensions:['json'] }],
defaultPath: fileName properties: ["showHiddenFiles"],
}, function(file_path) { defaultPath: fileName,
if (file_path) { buttonLabel: "Save Flow"
var flo = JSON.stringify(RED.nodes.getFlows().flows);
fs.writeFile(file_path, flo, function(err) {
if (err) { dialog.showErrorBox('Error', err); }
else {
dialog.showMessageBox({
icon: nrIcon,
message:"Flow file saved as\n\n"+file_path,
buttons: ["OK"]
});
}
});
}
}); });
if (file_path) {
var flo = JSON.stringify(RED.nodes.getFlows().flows, null , 2);
fs.writeFile(file_path, flo, function(err) {
if (err) { dialog.showErrorBox('Error', err); }
else {
dialog.showMessageBoxSync({
icon: nrIcon,
message:"Flow file saved as\n\n"+file_path,
buttons: ["OK"]
});
}
});
}
} }
function openFlow() { function openFlow() {
dialog.showOpenDialog({ filters:[{ name:'JSON', extensions:['json']} ]}, const fileNames = dialog.showOpenDialogSync({
function (fileNames) { title:"Load Flow File",
if (fileNames && fileNames.length > 0) { filters:[{ name:'JSON', extensions:['json'] }],
fs.readFile(fileNames[0], 'utf-8', function (err, data) { properties: ["openFile","showHiddenFiles"],
try { defaultPath: fileName,
var flo = JSON.parse(data); buttonLabel: "Load Flow"
if (Array.isArray(flo) && (flo.length > 0)) { });
RED.nodes.setFlows(flo,"full"); if (fileNames && fileNames.length > 0) {
fileName = fileNames[0]; fs.readFile(fileNames[0], 'utf-8', function (err, data) {
} try {
else { var flo = JSON.parse(data);
dialog.showErrorBox("Error", "Failed to parse flow file.\n\n "+fileNames[0]+".\n\nAre you sure it's a flow file ?"); if (Array.isArray(flo) && (flo.length > 0)) {
} fileName = fileNames[0];
} RED.nodes.setFlows(flo,"full");
catch(e) { }
dialog.showErrorBox("Error", "Failed to load flow file.\n\n "+fileNames[0]); else {
} dialog.showErrorBox("Error", "Failed to parse flow file.\n\n "+fileNames[0]+".\n\nAre you sure it's a flow file ?");
}); }
} }
} catch(e) {
) dialog.showErrorBox("Error", "Failed to load flow file.\n\n "+fileNames[0]);
}
});
}
} }
// Create the console log window // Create the console log window
@ -298,6 +309,7 @@ function createConsole() {
height: 600, height: 600,
icon: path.join(__dirname, nrIcon), icon: path.join(__dirname, nrIcon),
autoHideMenuBar: true, autoHideMenuBar: true,
titleBarStyle: "hidden",
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true
} }
@ -334,6 +346,7 @@ function createWindow() {
icon: path.join(__dirname, nrIcon), icon: path.join(__dirname, nrIcon),
fullscreenable: true, fullscreenable: true,
autoHideMenuBar: false, autoHideMenuBar: false,
titleBarStyle: "hidden",
kiosk: kioskMode, kiosk: kioskMode,
webPreferences: { webPreferences: {
nodeIntegration: false nodeIntegration: false

Wyświetl plik

@ -4,7 +4,7 @@
"description": "Electron Node-RED application starter kit for development", "description": "Electron Node-RED application starter kit for development",
"main": "main.js", "main": "main.js",
"NRelectron": { "NRelectron": {
"productName": "Node-RED Electron", "productName": "Node-RED Electron App",
"editable": true, "editable": true,
"allowLoadSave": false, "allowLoadSave": false,
"showMap": false, "showMap": false,