Implemented job upload
This commit is contained in:
@@ -5,6 +5,7 @@ const _ = require("lodash");
|
||||
async function DecodeEstimate(filePath) {
|
||||
const parsedFilePath = path.parse(filePath);
|
||||
let extensionlessFilePath = `${parsedFilePath.dir}\\${parsedFilePath.name}`;
|
||||
console.log("DecodeEstimate -> extensionlessFilePath", extensionlessFilePath);
|
||||
|
||||
const ret = {
|
||||
...(await DecodeAd1File(extensionlessFilePath)),
|
||||
@@ -150,7 +151,7 @@ async function DecodeVehFile(extensionlessFilePath) {
|
||||
// "V_PROD_DT",
|
||||
"V_MODEL_YR",
|
||||
// "V_MAKECODE",
|
||||
"V_MAKEDESC",
|
||||
"V_MAKE_DESC",
|
||||
"V_MODEL",
|
||||
"V_TYPE",
|
||||
// "V_BSTYLE",
|
||||
@@ -177,53 +178,62 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
let records = await dbf.readRecords();
|
||||
|
||||
let joblines = records.map((record) =>
|
||||
_.pick(record, [
|
||||
// "LINE_NO",
|
||||
"LINE_IND",
|
||||
// "LINE_REF",
|
||||
// "TRAN_CODE",
|
||||
// "DB_REF",
|
||||
"UNQ_SEQ",
|
||||
// "WHO_PAYS",
|
||||
"LINE_DESC",
|
||||
"PART_TYPE",
|
||||
// "PART_DESCJ",
|
||||
// "GLASS_FLAG",
|
||||
"OEM_PARTNO",
|
||||
// "PRICE_INC",
|
||||
// "ALT_PART_I",
|
||||
// "TAX_PART",
|
||||
"DB_PRICE",
|
||||
"ACT_PRICE",
|
||||
// "PRICE_J",
|
||||
// "CERT_PART",
|
||||
"PART_QTY",
|
||||
// "ALT_CO_ID",
|
||||
// "ALT_PARTNO",
|
||||
// "ALT_OVERRD",
|
||||
// "ALT_PARTM",
|
||||
// "PRT_DSMK_P",
|
||||
// "PRT_DSMK_M",
|
||||
// "MOD_LBR_TY",
|
||||
// "DB_HRS",
|
||||
// "MOD_LB_HRS",
|
||||
// "LBR_INC",
|
||||
// "LBR_OP",
|
||||
// "LBR_HRS_J",
|
||||
// "LBR_TYP_J",
|
||||
// "LBR_OP_J",
|
||||
// "PAINT_STG",
|
||||
// "PAINT_TONE",
|
||||
// "LBR_TAX",
|
||||
// "LBR_AMT",
|
||||
// "MISC_AMT",
|
||||
// "MISC_SUBLT",
|
||||
// "MISC_TAX",
|
||||
// "BETT_TYPE",
|
||||
// "BETT_PCTG",
|
||||
// "BETT_AMT",
|
||||
// "BETT_TAX",
|
||||
])
|
||||
_.transform(
|
||||
_.pick(record, [
|
||||
// "LINE_NO",
|
||||
"LINE_IND",
|
||||
// "LINE_REF",
|
||||
// "TRAN_CODE",
|
||||
// "DB_REF",
|
||||
"UNQ_SEQ",
|
||||
// "WHO_PAYS",
|
||||
"LINE_DESC",
|
||||
"PART_TYPE",
|
||||
// "PART_DESCJ",
|
||||
// "GLASS_FLAG",
|
||||
"OEM_PARTNO",
|
||||
// "PRICE_INC",
|
||||
// "ALT_PART_I",
|
||||
// "TAX_PART",
|
||||
"DB_PRICE",
|
||||
"ACT_PRICE",
|
||||
// "PRICE_J",
|
||||
// "CERT_PART",
|
||||
"PART_QTY",
|
||||
// "ALT_CO_ID",
|
||||
// "ALT_PARTNO",
|
||||
// "ALT_OVERRD",
|
||||
// "ALT_PARTM",
|
||||
// "PRT_DSMK_P",
|
||||
// "PRT_DSMK_M",
|
||||
// "MOD_LBR_TY",
|
||||
// "DB_HRS",
|
||||
// "MOD_LB_HRS",
|
||||
// "LBR_INC",
|
||||
// "LBR_OP",
|
||||
// "LBR_HRS_J",
|
||||
// "LBR_TYP_J",
|
||||
// "LBR_OP_J",
|
||||
// "PAINT_STG",
|
||||
// "PAINT_TONE",
|
||||
// "LBR_TAX",
|
||||
// "LBR_AMT",
|
||||
// "MISC_AMT",
|
||||
// "MISC_SUBLT",
|
||||
// "MISC_TAX",
|
||||
// "BETT_TYPE",
|
||||
// "BETT_PCTG",
|
||||
// "BETT_AMT",
|
||||
// "BETT_TAX",
|
||||
]),
|
||||
function (result, val, key) {
|
||||
if (key === "UNQ_SEQ") {
|
||||
console.log("unq");
|
||||
return (result[key.toLowerCase()] = val.toString());
|
||||
}
|
||||
return (result[key.toLowerCase()] = val);
|
||||
}
|
||||
)
|
||||
);
|
||||
return { joblines: { data: joblines } };
|
||||
}
|
||||
|
||||
@@ -1,14 +1,49 @@
|
||||
const { ipcMain } = require("electron");
|
||||
const { ipcMain, dialog } = require("electron");
|
||||
const { StartWatcher, StopWatcher } = require("./file-watcher");
|
||||
const ipcTypes = require("../../src/ipc.types").default;
|
||||
const ipcTypes = require("../../src/ipc.types");
|
||||
const settings = require("electron-settings");
|
||||
const { mainWindow } = require("../main");
|
||||
const _ = require("lodash");
|
||||
|
||||
ipcMain.on(ipcTypes.fileWatcher.toMain.start, async (event, arg) => {
|
||||
ipcMain.on(
|
||||
ipcTypes.default.fileWatcher.toMain.filepathsGet,
|
||||
async (event, object) => {
|
||||
const filePaths = await settings.get("filePaths");
|
||||
event.reply(
|
||||
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
||||
filePaths
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.on(ipcTypes.default.fileWatcher.toMain.start, async (event, arg) => {
|
||||
const filePaths = StartWatcher();
|
||||
event.sender.send(ipcTypes.fileWatcher.toRenderer.startSuccess, filePaths);
|
||||
event.sender.send(ipcTypes.fileWatcher.toRenderer.filepathsList, filePaths);
|
||||
// event.sender.send(ipcTypes.default.fileWatcher.toRenderer.startSuccess);
|
||||
event.sender.send(
|
||||
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
||||
filePaths
|
||||
);
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.fileWatcher.toMain.stop, async (event, arg) => {
|
||||
ipcMain.on(ipcTypes.default.fileWatcher.toMain.stop, async (event, arg) => {
|
||||
StopWatcher();
|
||||
event.sender.send(ipcTypes.fileWatcher.toRenderer.stopSuccess);
|
||||
event.sender.send(ipcTypes.default.fileWatcher.toRenderer.stopSuccess);
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.default.fileWatcher.toMain.addPath, async (event, arg) => {
|
||||
const result = await dialog.showOpenDialog(mainWindow, {
|
||||
properties: ["openDirectory"],
|
||||
});
|
||||
|
||||
await settings.set(
|
||||
"filePaths",
|
||||
_.union(result.filePaths, await settings.get("filePaths"))
|
||||
);
|
||||
|
||||
const newFilePaths = await settings.get("filePaths");
|
||||
|
||||
event.sender.send(
|
||||
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
||||
newFilePaths
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,15 +1,27 @@
|
||||
const chokidar = require("chokidar");
|
||||
const { ipcMain } = require("electron");
|
||||
const settings = require("electron-settings");
|
||||
const { default: ipcTypes } = require("../../src/ipc.types");
|
||||
const ipcTypes = require("../../src/ipc.types");
|
||||
const path = require("path");
|
||||
const { DecodeEstimate } = require("../decoder/decoder");
|
||||
const { BrowserWindow, Notification } = require("electron");
|
||||
const _ = require("lodash");
|
||||
|
||||
var watcher;
|
||||
|
||||
function StartWatcher() {
|
||||
const filePaths = settings.getSync("filePaths") || [];
|
||||
const filePaths =
|
||||
settings
|
||||
.getSync("filePaths")
|
||||
.map((fp) => path.join(fp, "**.[eE][nN][vV]")) || [];
|
||||
console.log("StartWatcher -> filePaths", filePaths);
|
||||
|
||||
Notification({
|
||||
title: "Watcher started!",
|
||||
body: "Watcher has been started..",
|
||||
}).show();
|
||||
|
||||
watcher = chokidar.watch(filePaths, {
|
||||
ignored: /[\/\\]\./,
|
||||
//ignored: /[\/\\]\./,
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
@@ -18,14 +30,16 @@ function StartWatcher() {
|
||||
},
|
||||
});
|
||||
watcher
|
||||
.on("add", function (path) {
|
||||
.on("add", async function (path) {
|
||||
console.log("File", path, "has been added");
|
||||
HandleNewFile(path);
|
||||
})
|
||||
.on("addDir", function (path) {
|
||||
console.log("Directory", path, "has been added");
|
||||
})
|
||||
.on("change", function (path) {
|
||||
.on("change", async function (path) {
|
||||
console.log("File", path, "has been changed");
|
||||
HandleNewFile(path);
|
||||
})
|
||||
.on("unlink", function (path) {
|
||||
console.log("File", path, "has been removed");
|
||||
@@ -35,27 +49,48 @@ function StartWatcher() {
|
||||
})
|
||||
.on("error", function (error) {
|
||||
console.log("Error happened", error);
|
||||
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.error, error);
|
||||
const b = BrowserWindow.getFocusedWindow();
|
||||
b.webContents.send(ipcTypes.fileWatcher.toRenderer.error, error);
|
||||
})
|
||||
.on("ready", onWatcherReady)
|
||||
.on("raw", function (event, path, details) {
|
||||
// This event should be triggered everytime something happens.
|
||||
console.log("Raw event info:", event, path, details);
|
||||
// console.log("Raw event info:", event, path, details);
|
||||
});
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
function onWatcherReady() {
|
||||
console.log("Ready!");
|
||||
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.startSuccess);
|
||||
const b = BrowserWindow.getFocusedWindow();
|
||||
b.webContents.send(ipcTypes.default.fileWatcher.toRenderer.startSuccess);
|
||||
}
|
||||
|
||||
async function StopWatcher() {
|
||||
await watcher.close();
|
||||
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.stopSuccess);
|
||||
console.log("Watcher Stopped!", watcher);
|
||||
console.log("Watcher Stopped!");
|
||||
}
|
||||
|
||||
exports.StartWatcher = StartWatcher;
|
||||
exports.StopWatcher = StopWatcher;
|
||||
exports.watcher = watcher;
|
||||
|
||||
async function HandleNewFile(path) {
|
||||
const b = BrowserWindow.getAllWindows()[0];
|
||||
b.webContents.send(ipcTypes.default.estimate.toRenderer.estimateDecodeStart);
|
||||
const newJob = await DecodeEstimate(path);
|
||||
const newJobLow = _.transform(newJob, function (result, val, key) {
|
||||
result[key.toLowerCase()] = val;
|
||||
});
|
||||
console.log("HandleNewFile -> newJobLow", newJobLow);
|
||||
|
||||
b.webContents.send(
|
||||
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
|
||||
newJobLow
|
||||
);
|
||||
|
||||
Notification({
|
||||
title: "Job Uploaded",
|
||||
body: "A new job has been uploaded.",
|
||||
}).show();
|
||||
}
|
||||
|
||||
@@ -8,19 +8,9 @@ require("./file-watcher/file-watcher-ipc");
|
||||
|
||||
console.log("*** Added IPC Handlers ***");
|
||||
|
||||
ipcMain.on(
|
||||
ipcTypes.default.fileWatcher.toMain.filepathsGet,
|
||||
async (event, object) => {
|
||||
const filePaths = await settings.get("filePaths");
|
||||
event.reply(
|
||||
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
||||
filePaths
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.on("test", async (event, object) => {
|
||||
console.log("Received test IPC Command");
|
||||
const job = await DecodeEstimate("C:\\VPS\\EMS\\687_3_A.AD1");
|
||||
event.reply("test-success", { status: 0, message: null, data: job });
|
||||
//const job = await DecodeEstimate("C:\\VPS\\EMS\\687_3_A.AD1");
|
||||
console.log(mainWindow);
|
||||
event.reply("test-toRenderer", { status: 0, message: null });
|
||||
});
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
const path = require("path");
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
const { app, BrowserWindow, ipcMain } = require("electron");
|
||||
const isDev = require("electron-is-dev");
|
||||
const settings = require("electron-settings");
|
||||
const ipcTypes = require("../src/ipc.types");
|
||||
const { StartWatcher } = require("./file-watcher/file-watcher");
|
||||
|
||||
require("./ipc-main-handler");
|
||||
|
||||
@@ -20,8 +22,9 @@ if (require("electron-squirrel-startup")) {
|
||||
|
||||
console.log(`${__dirname}/preload.js`);
|
||||
|
||||
var mainWindow = null;
|
||||
let mainWindow;
|
||||
function createWindow() {
|
||||
makeSingleInstance();
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
@@ -35,7 +38,6 @@ function createWindow() {
|
||||
preload: path.join(__dirname, "preload.js"), // use a preload script
|
||||
},
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
// win.loadFile("index.html");
|
||||
mainWindow.loadURL(
|
||||
@@ -46,15 +48,17 @@ function createWindow() {
|
||||
|
||||
// Open the DevTools.
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools({ mode: "detach" });
|
||||
mainWindow.webContents.openDevTools({
|
||||
// mode: "detach"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.mainWindow = mainWindow;
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
console.log("*** Ready to launch the app! ***");
|
||||
createWindow();
|
||||
|
||||
if (isDev) {
|
||||
@@ -63,10 +67,14 @@ app.whenReady().then(() => {
|
||||
.then((name) => console.log(`Added Extension: ${name}`))
|
||||
.catch((error) => console.log(`An error occurred: , ${error}`));
|
||||
}
|
||||
|
||||
//Start all of the watchers.
|
||||
StartWatcher();
|
||||
// ipcMain.on(ipcTypes.default.webcontent, (event, ...obj) => {
|
||||
// console.log("event", event);
|
||||
// mainWindow.webContents.send(event, obj);
|
||||
// });
|
||||
});
|
||||
|
||||
if (isDev) app.setAppUserModelId(process.execPath);
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
@@ -86,3 +94,15 @@ app.on("activate", () => {
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
||||
function makeSingleInstance() {
|
||||
if (process.mas) return;
|
||||
|
||||
app.requestSingleInstanceLock();
|
||||
|
||||
app.on("second-instance", () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user