Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
Working on parsing the datablock
Browse files Browse the repository at this point in the history
  • Loading branch information
Aggelos Vogiatzis authored and Aggelos Vogiatzis committed Jul 24, 2021
1 parent de10e94 commit bf1f547
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Webpages/datablock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ <h1 class="title">Datablock:</h1>
<div style="text-align: center;">
<button onclick="openDbSel();" class="button">Select Datablock</button>
</div>
<script src="index.js"></script>
<script defer src="index.js"></script>
</body>
</html>
16 changes: 14 additions & 2 deletions Webpages/datablock/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
const { ipcRenderer,dialog } = require('electron');



function openDbSel() {
console.log('Opening Selection window');
async function openDbSel() {
let dialogOptions = {
title: 'Navigate to Datablock text file and select it',
properties: ['openFile'],
filters: [
{ name: 'txt', extensions: [txt] }
],
};


let lookWindow = await dialog.showOpenDialog(dialogOptions);
console.log(lookWindow);

}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"decimal.js": "^10.3.1",
"electron-reloader": "^1.2.1",
"electron-squirrel-startup": "^1.0.0",
"fs": "^0.0.1-security",
"knex": "^0.95.7",
"nodes7": "^0.3.12",
"pg": "^8.6.0"
Expand Down
66 changes: 59 additions & 7 deletions src/backend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, Tray, Menu, Notification } = require('electron');
const { app, BrowserWindow, ipcMain, Tray, Menu, Notification, dialog } = require('electron');
const knex = require('knex');
const path = require('path');
let tray = null;
Expand All @@ -10,14 +10,15 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';


// Database connection renderer process handler

ipcMain.on("dbConnection", (event, data) => {
// Call function to connect to db
dbData = data;
connectToDB(data, event);
});


ipcMain.on("disconnect", (event, data) => {
// Call function to connect to db
// Destroy DB connection
db.destroy();
event.reply("conn-valid", [false, "Manually Disconnected"]);
dbOK = false;
Expand All @@ -28,6 +29,29 @@ ipcMain.on("dbOK", (event, data) => {
// Checks DB connection status
event.reply("dbOK",[dbOK, dbData]);
});
ipcMain.on("openFile", (event, data) => {
let dialogOptions = {
title: 'Navigate to Datablock text file and select it',
properties: ['openFile'],
filters: [
{ name: 'txt', extensions: ['txt'] }
],
};


dialog.showOpenDialog(
dialogOptions
).then((file) => {
if (file.canceled === true) {
console.log("No file selected");
} else {
console.log(file.filePaths);
event.reply('sendFile', file);

}

});
});



Expand All @@ -48,6 +72,13 @@ const menuTemplate = [
createDatabaseWindow();
}
},
{
label: 'Datablock',
click: () => {
new Notification({ title: "Datablock", body: "Opening Datablock selection window" }).show()
createDatablockSelWindow();
}
},
{
label: 'Charts',
click: () => {
Expand Down Expand Up @@ -76,6 +107,9 @@ const createMainWindow = () => {
mainWindow.webContents.openDevTools();
mainWindow.setResizable(false);
};



const createDatabaseWindow = () => {
const databaseWindow = new BrowserWindow({
width: 800,
Expand All @@ -85,6 +119,24 @@ const createDatabaseWindow = () => {
contextIsolation: false,
}
});

databaseWindow.loadFile(path.join(__dirname, '/database/index.html'));
databaseWindow.removeMenu();
databaseWindow.webContents.openDevTools();
databaseWindow.setResizable(false);
};


const createDatablockSelWindow = () => {
const dBlockWindow = new BrowserWindow({
width: 800,
height: 400,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
// enableRemoteModule: true,
}
});

// const dbMenu = [
// {
Expand All @@ -96,10 +148,10 @@ const createDatabaseWindow = () => {
// ];


databaseWindow.loadFile(path.join(__dirname, '/database/index.html'));
databaseWindow.removeMenu();
databaseWindow.webContents.openDevTools();
databaseWindow.setResizable(false);
dBlockWindow.loadFile(path.join(__dirname, '/datablock/index.html'));
dBlockWindow.removeMenu();
dBlockWindow.webContents.openDevTools();
dBlockWindow.setResizable(false);

// const customMenu1 = Menu.buildFromTemplate(dbMenu);
// Menu.setApplicationMenu(customMenu1);
Expand Down
46 changes: 46 additions & 0 deletions src/datablock/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
body {
font-family: 'Open Sans', sans-serif;
/* font-family: 'Roboto', sans-serif; */
/* font-weight: 300; */
margin: auto;
color: white;
background-color: #363636;
}

.title {
margin: 10px;
text-align: center;
font-size: 30px;
}

.bigTitle {
margin: 10px;
text-align: center;
font-size: 40px;
}

.args {
text-align: center;
}

.button {
background-color: rgb(0, 0, 0);
/* Green */
min-width: 250px;
border: none;
color: white;
padding: 12px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 5px;
}

.button:hover {
background-color: white;
color: black;
}
20 changes: 20 additions & 0 deletions src/datablock/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<title>Datablock</title>
</head>
<body>

<div>
<h1 class="title">Datablock:</h1>
</div>
<div style="text-align: center;">
<button onclick="openDbSel();" class="button">Select Datablock</button>
</div>
<script src="index.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions src/datablock/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { ipcRenderer } = require('electron');
const { giveFileGetBlock } = require('../parseDatablock/parser');

ipcRenderer.on('sendFile', (event, data) => {
console.log(data);
giveFileGetBlock(data.filePaths[0]);
});

async function openDbSel() {
ipcRenderer.send('openFile');
}
54 changes: 54 additions & 0 deletions src/parseDatablock/dbRules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module.exports = {
"names": [
": Bool",
": Byte",
": Word",
": DWord",
": Char",
": SInt",
": Int",
": DInt",
": USInt",
": UInt",
": UDInt",
": Real",
": LReal",
": Time",
": String"
],
"memory": [
0.1,
1,
2,
4,
1,
1,
2,
4,
2,
2,
4,
4,
8,
4,
256
],
"types":
[
"X",
"BYTE",
"WORD",
"DWORD",
"CHAR",
"SINT",
"INT",
"DINT",
"USINT",
"UINT",
"UDINT",
"REAL",
"LREAL",
"TIME",
"STRING"
]
}
22 changes: 22 additions & 0 deletions src/parseDatablock/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const rules = require('./dbRules');
const Decimal = require('decimal.js');
const fs = require('fs');


let dbVars = {};

async function giveFileGetBlock(filePath) {
fs.readFile(filePath, 'utf8', (err, data) => {
if(err) {
console.error(err);
return;
} else {
console.log(data);
}
});
};


module.exports = {
giveFileGetBlock: giveFileGetBlock,
};

0 comments on commit bf1f547

Please sign in to comment.