Skip to content

Commit 5bddf90

Browse files
authored
Merge pull request #23 from oslabs-beta/master
LA Team's (3.0) final version of the Electron app. Future features/changes: render container stats onto charts/graphs, front-end file restructuring, render route data along with the node tree, etc.
2 parents 9908349 + b16ea81 commit 5bddf90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+9728
-5276
lines changed

.DS_Store

4 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
.eslintrc.js
33
package-lock.json
4-
settings.json
5-
.DS_Store
4+
.DS_Store
5+
user/settings.json
6+
dist

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
node_js:
3+
- "stable"
4+
os:
5+
osx
6+
# jobs:
7+
# allow_failures:
8+
# - os: osx
9+
install:
10+
- npm install

Main.js

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// node requirements
2-
const {
3-
dialog, app, BrowserWindow, ipcMain,
4-
} = require('electron');
2+
const { dialog, app, BrowserWindow, ipcMain } = require('electron');
53
const fs = require('fs');
64
const path = require('path');
75
const connectSQL = require('./model/sql-connect');
@@ -20,9 +18,9 @@ function createWindow() {
2018
// assign win to an instance of a new browser window.
2119
win = new BrowserWindow({
2220
// giving our window its width
23-
width: 900,
21+
width: 1920,
2422
// giving our window its hieght
25-
height: 800,
23+
height: 1080,
2624
// specify the path of the icon -- Which icon is this?.. note too tsure --> Ousman
2725
icon: path.join(__dirname, 'app/assets/icons/icon.png'),
2826
// enable node inegreation --> node intgeration, default is usally false --> Ousman
@@ -44,11 +42,16 @@ function createWindow() {
4442
// read json from settings.json
4543
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
4644
encoding: 'UTF-8',
47-
}),
45+
})
4846
);
4947
// reassign state.splash
5048
state.splash = true;
51-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' }); win = null;
49+
fs.writeFileSync(
50+
path.resolve(__dirname, './user/settings.json'),
51+
JSON.stringify(state),
52+
{ encoding: 'UTF-8' }
53+
);
54+
win = null;
5255
});
5356
}
5457

@@ -62,11 +65,15 @@ app.on('window-all-closed', () => {
6265
// read json from settings.json
6366
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
6467
encoding: 'UTF-8',
65-
}),
68+
})
6669
);
6770
// reassign state.splash
6871
state.splash = true;
69-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
72+
fs.writeFileSync(
73+
path.resolve(__dirname, './user/settings.json'),
74+
JSON.stringify(state),
75+
{ encoding: 'UTF-8' }
76+
);
7077
// process platform is a property that return a string identifying the OS platform on which NodeJs process is running --> Ousman
7178
if (process.platform !== 'darwin') {
7279
// quits application
@@ -85,29 +92,33 @@ app.on('activate', () => {
8592
// Fired by the useEffect hook inside of the Splash.jsx component, this message route will toggle
8693
// splash property inside of settings.json to false once the Splash page renders itself just once
8794
ipcMain.on('toggleSplash', (message) => {
88-
//console.log('toggleSplash message received');
95+
// console.log('toggleSplash message received');
8996
const state = JSON.parse(
9097
// read json from settings.json
9198
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
9299
encoding: 'UTF-8',
93-
}),
100+
})
94101
);
95102
// reassign state.splash to false
96103
state.splash = false;
97104

98105
// overwrite settings.json with false splash property
99-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
106+
fs.writeFileSync(
107+
path.resolve(__dirname, './user/settings.json'),
108+
JSON.stringify(state),
109+
{ encoding: 'UTF-8' }
110+
);
100111

101112
message.returnValue = state.splash;
102113
});
103114

104115
ipcMain.on('checkSplash', (message) => {
105-
//sconsole.log('checkSplash message received');
116+
// sconsole.log('checkSplash message received');
106117
const state = JSON.parse(
107118
// read json from settings.json
108119
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
109120
encoding: 'UTF-8',
110-
}),
121+
})
111122
);
112123

113124
message.returnValue = state.splash;
@@ -116,13 +127,13 @@ ipcMain.on('checkSplash', (message) => {
116127
// Load settings JSON and returns current setup status back to the render process.
117128
// ipc 'setup' route --> Ousman
118129
ipcMain.on('setup', (message) => {
119-
//console.log('setup message received');
130+
// console.log('setup message received');
120131
// assigns state to the returned the object returned from settings.json --> Ousman
121132
const state = JSON.parse(
122133
// read json from settings.json
123134
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
124135
encoding: 'UTF-8',
125-
}),
136+
})
126137
);
127138
// destructure setupRequired from state constant ---> Ousman
128139
const { setupRequired } = state;
@@ -137,21 +148,24 @@ ipcMain.on('submit', (message, newService) => {
137148
const state = JSON.parse(
138149
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
139150
encoding: 'UTF-8',
140-
}),
151+
})
141152
);
142153

143-
// Checks if setup is required by checking if the value for the state key 'setupRequired' is true
154+
// Checks if setup is required by checking if the value for the state key 'setupRequired' is true
144155
if (state.setupRequired) {
145156
// If setup is required, the value for key 'setupRequired' is reassign to false and the value for key 'services' is reassign to an array with newService as its only element
146157
state.setupRequired = false;
147158
state.services = [JSON.parse(newService)];
148159
} else {
149160
// Else the newService is pushed into the services array
150161
state.services.push(JSON.parse(newService));
151-
}
162+
}
152163

153164
// Rewrites user/settings.json to show state
154-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
165+
fs.writeFileSync(
166+
path.resolve(__dirname, './user/settings.json'),
167+
JSON.stringify(state)
168+
);
155169
});
156170

157171
// Load settings JSON and returns updated state back to the render process.
@@ -161,7 +175,7 @@ ipcMain.on('dashboard', (message) => {
161175
const state = JSON.parse(
162176
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
163177
encoding: 'UTF-8',
164-
}),
178+
})
165179
);
166180
// destructure services from state... what is services? --> Ousman
167181
const { services } = state;
@@ -180,31 +194,36 @@ ipcMain.on('deleteService', (message, index) => {
180194
let state = JSON.parse(
181195
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
182196
encoding: 'UTF-8',
183-
}),
197+
})
184198
);
185199

186200
// Send a response back with the updated services
187201
const { splash } = state;
188-
// Checks if there is more than one services in the services array
202+
// Checks if there is more than one services in the services array
189203
if (state.services.length > 1) {
190-
// If true, removes the service at position 'index'
204+
// If true, removes the service at position 'index'
191205
state.services.splice(index, 1);
192206
} else {
193-
// Else reassign state to what the user/setting.json file was originally before any database was save
207+
// Else reassign state to what the user/setting.json file was originally before any database was save
194208
state = { setupRequired: true, services: ['hard', 'coded', 'in'], splash };
195209
}
196210

197211
// Rewrites json from settings.json
198-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
212+
fs.writeFileSync(
213+
path.resolve(__dirname, './user/settings.json'),
214+
JSON.stringify(state),
215+
{ encoding: 'UTF-8' }
216+
);
199217
message.sender.send('deleteResponse', state.services);
200218
});
201219

202-
203220
// Queries the database for communications information and returns it back to the render process.
204221
ipcMain.on('overviewRequest', (message, index) => {
205222
console.log('hello from overview request');
206223
const { services } = JSON.parse(
207-
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), { encoding: 'UTF-8' }),
224+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
225+
encoding: 'UTF-8',
226+
})
208227
);
209228

210229
const databaseType = services[index][1];
@@ -233,14 +252,16 @@ ipcMain.on('overviewRequest', (message, index) => {
233252
const errorAlert = {
234253
type: 'error',
235254
title: 'Error in Main process',
236-
message: 'Database information could not be retreived. Check that table exists.',
255+
message:
256+
'Database information could not be retreived. Check that table exists.',
237257
};
238258

239259
// after requiring dialog in the topmost section of main. We invoke the method showMessagebox passing the error object we created --> Ousman
240260
dialog.showMessageBox(errorAlert);
241261

242-
243-
message.sender.send(JSON.stringify('Database info could not be retreived.'));
262+
message.sender.send(
263+
JSON.stringify('Database info could not be retreived.')
264+
);
244265
} else {
245266
console.log('Connected to SQL Database');
246267
const queryResults = JSON.stringify(result.rows);
@@ -256,7 +277,9 @@ ipcMain.on('overviewRequest', (message, index) => {
256277
ipcMain.on('detailsRequest', (message, index) => {
257278
console.log('detailsRequest message received');
258279
const databaseType = JSON.parse(
259-
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), { encoding: 'UTF-8' }),
280+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
281+
encoding: 'UTF-8',
282+
})
260283
).services[index][1];
261284

262285
if (databaseType === 'MongoDB') {
@@ -267,14 +290,18 @@ ipcMain.on('detailsRequest', (message, index) => {
267290
const queryResults = JSON.stringify(data);
268291
// Asynchronous event emitter used to transmit query results back to the render process.
269292
message.sender.send('detailsResponse', queryResults);
293+
console.log('Message Sent');
270294
});
271295
}
272296

273297
if (databaseType === 'SQL') {
274298
const getHealth = 'SELECT * FROM healthInfo';
275299
pool.query(getHealth, (err, result) => {
276300
if (err) {
277-
message.sender.send('detailsResponse', JSON.stringify('Database info could not be retreived.'));
301+
message.sender.send(
302+
'detailsResponse',
303+
JSON.stringify('Database info could not be retreived.')
304+
);
278305
}
279306
const queryResults = JSON.stringify(result.rows);
280307
// Asynchronous event emitter used to transmit query results back to the render process.
@@ -283,4 +310,3 @@ ipcMain.on('detailsRequest', (message, index) => {
283310
});
284311
}
285312
});
286-

0 commit comments

Comments
 (0)