Skip to content

Commit 8919d28

Browse files
committed
merge dev into branch and fix margin on delete button
2 parents 110b7c6 + dac3530 commit 8919d28

21 files changed

+694
-240
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Main.js

Lines changed: 111 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,137 @@
1-
//node requirements
2-
const { dialog, app, BrowserWindow, ipcMain } = require('electron');
1+
// node requirements
2+
const {
3+
dialog, app, BrowserWindow, ipcMain,
4+
} = require('electron');
35
const fs = require('fs');
46
const path = require('path');
57
const connectSQL = require('./model/sql-connect');
68
const connectMongoose = require('./model/mongoose-connect');
79
const CommunicationSchema = require('./model/mongoose-communicatonSchema');
810
const HealthInfoSchema = require('./model/mongoose-healthInfoSchema');
911

10-
//declare a variable pool for SQL connection
12+
// declare a variable pool for SQL connection
1113
let pool;
1214

13-
//declare win variable ---> Ousman
15+
// declare win variable ---> Ousman
1416
let win;
1517

16-
//declaring a createWindow function ---> Ousman
18+
// declaring a createWindow function ---> Ousman
1719
function createWindow() {
18-
//assign win to an instance of a new browser window.
20+
// assign win to an instance of a new browser window.
1921
win = new BrowserWindow({
20-
//giving our window its width
22+
// giving our window its width
2123
width: 900,
22-
//giving our window its hieght
24+
// giving our window its hieght
2325
height: 800,
24-
//specify the path of the icon -- Which icon is this?.. note too tsure --> Ousman
26+
// specify the path of the icon -- Which icon is this?.. note too tsure --> Ousman
2527
icon: path.join(__dirname, 'app/assets/icons/icon.png'),
26-
//enable node inegreation --> node intgeration, default is usally false --> Ousman
28+
// enable node inegreation --> node intgeration, default is usally false --> Ousman
2729
webPreferences: {
2830
nodeIntegration: true,
2931
},
3032
});
3133

3234
// Development
33-
//loads our application window to localHost 8080, application will not render without this loadUrl --> Ousman
35+
// loads our application window to localHost 8080, application will not render without this loadUrl --> Ousman
3436
win.loadURL('http://localhost:8080/');
3537

3638
// Production
3739
// win.loadURL(`file://${path.join(__dirname, './dist/index.html')}`);
38-
39-
//assign window to null on close
40+
41+
// assign window to null on close and set splash property in settings.json back to true so splash page renders on restart
4042
win.on('closed', () => {
41-
win = null;
43+
const state = JSON.parse(
44+
// read json from settings.json
45+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
46+
encoding: 'UTF-8',
47+
}),
48+
);
49+
// reassign state.splash
50+
state.splash = true;
51+
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' }); win = null;
4252
});
4353
}
4454

45-
//invoke createWindow function on Electron application load --> Ousman
55+
// invoke createWindow function on Electron application load --> Ousman
4656
app.on('ready', createWindow);
4757

4858
// quits the application when all windows are closed --> Ousman
4959
app.on('window-all-closed', () => {
50-
//process platform is a property that return a string identifying the OS platform on which NodeJs process is running --> Ousman
60+
console.log('window-all-closed message received');
61+
const state = JSON.parse(
62+
// read json from settings.json
63+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
64+
encoding: 'UTF-8',
65+
}),
66+
);
67+
// reassign state.splash
68+
state.splash = true;
69+
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
70+
// process platform is a property that return a string identifying the OS platform on which NodeJs process is running --> Ousman
5171
if (process.platform !== 'darwin') {
52-
//quits application
72+
// quits application
5373
app.quit();
5474
}
5575
});
5676

57-
//event 'activate' emmitted upon application starting
77+
// event 'activate' emmitted upon application starting
5878
app.on('activate', () => {
59-
//if there is no window present invoke the create window function --> Ousman
79+
// if there is no window present invoke the create window function --> Ousman
6080
if (win === null) {
6181
createWindow();
6282
}
6383
});
6484

85+
// Fired by the useEffect hook inside of the Splash.jsx component, this message route will toggle
86+
// splash property inside of settings.json to false once the Splash page renders itself just once
87+
ipcMain.on('toggleSplash', (message) => {
88+
//console.log('toggleSplash message received');
89+
const state = JSON.parse(
90+
// read json from settings.json
91+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
92+
encoding: 'UTF-8',
93+
}),
94+
);
95+
// reassign state.splash to false
96+
state.splash = false;
97+
98+
// overwrite settings.json with false splash property
99+
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
100+
101+
message.returnValue = state.splash;
102+
});
103+
104+
ipcMain.on('checkSplash', (message) => {
105+
//sconsole.log('checkSplash message received');
106+
const state = JSON.parse(
107+
// read json from settings.json
108+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
109+
encoding: 'UTF-8',
110+
}),
111+
);
112+
113+
message.returnValue = state.splash;
114+
});
115+
65116
// Load settings JSON and returns current setup status back to the render process.
66-
//ipc 'setup' route --> Ousman
117+
// ipc 'setup' route --> Ousman
67118
ipcMain.on('setup', (message) => {
68-
//assigns state to the returned the object returned from settings.json --> Ousman
119+
//console.log('setup message received');
120+
// assigns state to the returned the object returned from settings.json --> Ousman
69121
const state = JSON.parse(
70-
//read json from settings.json
122+
// read json from settings.json
71123
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
72124
encoding: 'UTF-8',
73125
}),
74126
);
75-
//destructure setupRequired from state constant ---> Ousman
76-
const { setupRequired } = state;
77-
//assigning message object a property of return value and assigning it the setupRequired from state destructuring --> Ousman
127+
// destructure setupRequired from state constant ---> Ousman
128+
const { setupRequired } = state;
129+
// assigning message object a property of return value and assigning it the setupRequired from state destructuring --> Ousman
78130
message.returnValue = setupRequired;
79131
});
80132

81-
// Adds a new service to the services array within the user/setting.json file
133+
// Loads existing settings JSON and update settings to include new services entered by the user.
134+
// on ipc 'submit' request --> Ousman
82135
ipcMain.on('submit', (message, newService) => {
83136
// Declares a variable state and initialize it to the returned parsed json object from the user/settings.json file
84137
const state = JSON.parse(
@@ -102,15 +155,15 @@ ipcMain.on('submit', (message, newService) => {
102155
});
103156

104157
// Load settings JSON and returns updated state back to the render process.
105-
//on ipc 'dashboard' request --> Ousman
158+
// on ipc 'dashboard' request --> Ousman
106159
ipcMain.on('dashboard', (message) => {
107160
// Declares a variable state and initialize it to the returned parse json object from the user/settings.json file
108161
const state = JSON.parse(
109162
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
110163
encoding: 'UTF-8',
111164
}),
112165
);
113-
//destructure services from state... what is services? --> Ousman
166+
// destructure services from state... what is services? --> Ousman
114167
const { services } = state;
115168
const dashboardList = services.reduce((acc, curVal) => {
116169
acc.push(curVal[0]);
@@ -130,30 +183,29 @@ ipcMain.on('deleteService', (message, index) => {
130183
}),
131184
);
132185

133-
// Checks if there is more than one services in the services array
134-
if(state.services.length > 1){
135-
// If true, removes the service at position 'index'
136-
state.services.splice(index,1);
137-
}else{
138-
// Else reassign state to what the user/setting.json file was originally before any database was save
139-
state= {"setupRequired":true, "services":["hard","coded","in"] }
186+
// Send a response back with the updated services
187+
const { splash } = state;
188+
// Checks if there is more than one services in the services array
189+
if (state.services.length > 1) {
190+
// If true, removes the service at position 'index'
191+
state.services.splice(index, 1);
192+
} else {
193+
// Else reassign state to what the user/setting.json file was originally before any database was save
194+
state = { setupRequired: true, services: ['hard', 'coded', 'in'], splash };
140195
}
141-
142-
// Rewrites user/settings.json to show state
143-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), {
144-
encoding: 'UTF-8'})
145196

146-
// Send a response back with the updated services
197+
// Rewrites json from settings.json
198+
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
147199
message.sender.send('deleteResponse', state.services);
148200
});
149201

150202

151203
// Queries the database for communications information and returns it back to the render process.
152204
ipcMain.on('overviewRequest', (message, index) => {
153-
const services = JSON.parse(
205+
const { services } = JSON.parse(
154206
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), { encoding: 'UTF-8' }),
155-
).services;
156-
207+
);
208+
157209
const databaseType = services[index][1];
158210
const URI = services[index][2];
159211

@@ -163,36 +215,33 @@ ipcMain.on('overviewRequest', (message, index) => {
163215
if (err) {
164216
console.log(`An error occured while querying the database: ${err}`);
165217
message.sender.send('overviewResponse', JSON.stringify(err));
166-
}
167-
168-
const queryResults = JSON.stringify(data);
169-
// Asynchronous event emitter used to transmit query results back to the render process.
170-
message.sender.send('overviewResponse', queryResults);
171-
218+
}
219+
220+
const queryResults = JSON.stringify(data);
221+
// Asynchronous event emitter used to transmit query results back to the render process.
222+
message.sender.send('overviewResponse', queryResults);
172223
});
173224
}
174-
225+
175226
if (databaseType === 'SQL') {
176227
pool = connectSQL(index, URI);
177228
const getCommunications = 'SELECT * FROM communications';
178229
pool.query(getCommunications, (err, result) => {
179230
if (err) {
231+
// error object to log to Electron GUI ---> Ousman
232+
const errorAlert = {
233+
type: 'error',
234+
title: 'Error in Main process',
235+
message: 'Database information could not be retreived. Check that table exists.',
236+
};
180237

181-
//error object to log to Electron GUI ---> Ousman
182-
const errorAlert = {
183-
type: "error",
184-
title: "Error in Main process",
185-
message: "Database information could not be retreived. Check that table exists."
186-
};
187-
188-
//after requiring dialog in the topmost section of main. We invoke the method showMessagebox passing the error object we created --> Ousman
189-
dialog.showMessageBox(errorAlert);
190-
238+
// after requiring dialog in the topmost section of main. We invoke the method showMessagebox passing the error object we created --> Ousman
239+
dialog.showMessageBox(errorAlert);
191240

192-
message.sender.send(JSON.stringify('Database info could not be retreived.'));
193241

242+
message.sender.send(JSON.stringify('Database info could not be retreived.'));
194243
} else {
195-
console.log('Connected to SQL Database')
244+
console.log('Connected to SQL Database');
196245
const queryResults = JSON.stringify(result.rows);
197246
// Asynchronous event emitter used to transmit query results back to the render process.
198247
message.sender.send('overviewResponse', queryResults);

0 commit comments

Comments
 (0)