Skip to content

Commit e4ddaa6

Browse files
committed
microservices shows up when the button is pressed instead of an error also I added a doughnut chart
1 parent 08274be commit e4ddaa6

8 files changed

Lines changed: 34 additions & 33 deletions

File tree

Main.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const connectMongoose = require('./model/mongoose-connect');
66
const CommunicationSchema = require('./model/mongoose-communicatonSchema');
77
const HealthInfoSchema = require('./model/mongoose-healthInfoSchema');
88

9+
//declare a variable pool for SQL connection
10+
let pool;
911
let win;
1012
function createWindow() {
1113
win = new BrowserWindow({
@@ -55,19 +57,17 @@ ipcMain.on('setup', (message) => {
5557
// Loads existing settings JSON and update settings to include new services entered by the user.
5658
ipcMain.on('submit', (message, newService) => {
5759
// set the variable 'state' to the contents of /user/settings.json
58-
// contents => "setupRequired" (boolean) ,"michelleWasHere" (boolean),"services" (Array)
60+
// contents => "setupRequired" (boolean),"services" (Array)
5961
// setupRequired- toggle the page for adding database
60-
// michelleWasHere - I believe initiate the service array
6162
// services - name of DB stores dbType, and uri
6263
const state = JSON.parse(
6364
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
6465
encoding: 'UTF-8',
6566
}),
6667
);
67-
// if statement is used to replace hard coded data. Hard coded data and the michelleWasHere key is needed to avoid a load error caused by Electron querying the database before a user has added or selected a database.
68-
if (state.michelleWasHere) {
68+
// if statement is used to replace hard coded data. Hard coded data is needed to avoid a load error caused by Electron querying the database before a user has added or selected a database.
69+
if (state.setupRequired) {
6970
state.setupRequired = false;
70-
state.michelleWasHere = false;
7171
state.services = [JSON.parse(newService)];
7272
//is updating the /user/settings.json file with the first new service
7373
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
@@ -100,13 +100,15 @@ ipcMain.on('dashboard', (message) => {
100100

101101
// Queries the database for communications information and returns it back to the render process.
102102
ipcMain.on('overviewRequest', (message, index) => {
103-
// Gets the database type from /user/settings.json services: [[name, dbType, uri],...]
104-
const databaseType = JSON.parse(
103+
//acquires the services from user settings.json file
104+
const services = JSON.parse(
105105
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), { encoding: 'UTF-8' }),
106-
).services[index][1];
106+
).services
107+
const databaseType = services[index][1];
108+
const URI = services[index][2];
107109

108110
if (databaseType === 'MongoDB') {
109-
connectMongoose(index);
111+
connectMongoose(index,URI);
110112
CommunicationSchema.find({}, (err, data) => {
111113
if (err) {
112114
console.log(`An error occured while querying the database: ${err}`);
@@ -121,13 +123,13 @@ ipcMain.on('overviewRequest', (message, index) => {
121123
}
122124

123125
if (databaseType === 'SQL') {
124-
// What is index? index - is passed on from ServiceDashboard as a prop when the button was created. When the button is pressed, the serviceSelected is set to <ServiceOverview index ={i}>. The ServiceOverview makes the ipcRenderer.send('overviewRequest', props.index). The index indicates which service is being called
125-
const pool = connectSQL(index);
126+
pool = connectSQL(index,URI);
126127
const getCommunications = 'SELECT * FROM communications';
127128
pool.query(getCommunications, (err, result) => {
128129
if (err) {
129130
return message.sender.send(JSON.stringify('Database info could not be retrieved.'));
130131
}
132+
console.log('Connected to SQL Database')
131133
//queryResults is an array of objects with the following keys {"id","currentmicroservice","targetedendpoint","reqtype","resstatus","resmessage","timesent"}
132134
const queryResults = JSON.stringify(result.rows);
133135
// Asynchronous event emitter used to transmit query results back to the render process.
@@ -143,7 +145,6 @@ ipcMain.on('detailsRequest', (message, index) => {
143145
).services[index][1];
144146

145147
if (databaseType === 'MongoDB') {
146-
connectMongoose(index);
147148
HealthInfoSchema.find({}, (err, data) => {
148149
if (err) {
149150
message.sender.send('detailsResponse', JSON.stringify(err));
@@ -155,8 +156,8 @@ ipcMain.on('detailsRequest', (message, index) => {
155156
}
156157

157158
if (databaseType === 'SQL') {
158-
//what is index?
159-
const pool = connectSQL(index);
159+
160+
// const pool = connectSQL(index);
160161
const getHealth = 'SELECT * FROM healthInfo';
161162
pool.query(getHealth, (err, result) => {
162163
if (err) {

app/assets/pieChart.png

47.3 KB
Loading

app/components/ServiceDetails.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
22
import React, { useState } from 'react';
33
import Modal from './Modal.jsx';
4+
import pieChart from '../assets/pieChart.png'
5+
46

57
// Renders health info detail buttons
68
const ServiceDetails = (props) => {
@@ -16,8 +18,10 @@ const ServiceDetails = (props) => {
1618
const { currentMicroservice } = props;
1719

1820
// Dictionary used by the healthInfoButtons loop below
21+
// { id: 'request', alt: 'Request Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
22+
1923
const buttonProperties = [
20-
{ id: 'request', alt: 'Request Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
24+
{ id: 'request', alt: 'Request Data', src: pieChart },
2125
{ id: 'response', alt: 'Response Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
2226
{ id: 'speed', alt: 'Speed Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
2327
{ id: 'processes', alt: 'Processes Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
@@ -32,6 +36,7 @@ const ServiceDetails = (props) => {
3236
const healthInfoButtons = [];
3337
for (let i = 0; i < buttonProperties.length; i += 1) {
3438
healthInfoButtons.push(
39+
<div>
3540
<div className="healthChartContainer">
3641
<input
3742
onClick={() => {
@@ -43,9 +48,14 @@ const ServiceDetails = (props) => {
4348
type="image"
4449
id={buttonProperties[i].id}
4550
src={buttonProperties[i].src}
46-
width="50px"
51+
width="60px"
4752
alt={buttonProperties[i].alt}
4853
/>
54+
<br/>
55+
<div style={{color:'white', paddingLeft:'7px'}}>
56+
{buttonProperties[i].id}
57+
</div>
58+
</div>
4959
</div>,
5060
);
5161
}

app/components/ServiceOverview.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const ServiceOverview = (props) => {
2525
ipcRenderer.on('overviewResponse', (event, data) => {
2626
// Adds to state and context.
2727
setOverviewState(Object.values(JSON.parse(data)));
28-
console.log('OverviewState:', overviewState)
28+
console.log('gathering data')
2929
serviceComponents.overviewData = JSON.parse(data);
3030
});
3131
}, []);

app/components/ServicesDashboard.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const ServicesDashboard = (props) => {
2525
type="button"
2626
key={`${i}${context[i]}`}
2727
onClick={() => {
28+
// jenae added this
29+
console.log('main button clicked')
2830
setSelection(<ServiceOverview index={i} />);
2931
}}>
3032
{context[i]}
@@ -49,7 +51,6 @@ const ServicesDashboard = (props) => {
4951
type="submit"
5052
key="BackToStart"
5153
onClick={() => {
52-
// always return true since false is passed into the toggleSetup
5354
setup.setupRequired = setup.toggleSetup(false);
5455
setSelection(<AddService />);
5556
}}

model/mongoose-connect.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const mongoose = require('mongoose');
2-
const { services } = require('../user/settings.json');
32

43
// Mongoose connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
5-
const connectMongoose = (i) => {
6-
const URI = services[i][2];
4+
const connectMongoose = (i, URI) => {
75
return mongoose.connect(URI, { useNewUrlParser: true, useUnifiedTopology: true }, (err) => {
8-
if (err) console.log(err);
6+
if (err) return console.log(err);
97
console.log('Connected to Mongo database!');
108
});
119
};

model/sql-connect.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
const { Pool } = require('pg');
2-
const { services } = require('../user/settings.json');
32

43
// SQL connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
5-
const connectSQL = (i) => {
6-
//there are no links - the following is being used for SQL "services": [["hard", "coded", "solution"]], useContext should be used here
7-
const URI = services[i][2];
4+
const connectSQL = (i, URI) => {
85
const pool =new Pool({
96
connectionString: URI,
107
})
11-
//verifying that the connection has been made by stating the time it was connected
12-
// This code could be causing too many request to the database
13-
// pool.query('SELECT NOW()', (err, res) => {
14-
// if(err) return message.sender.send('detailsResponse', JSON.stringify('Did not connect to database',err));
15-
// console.log('Database '+services[i][0]+' has been connected at '+res.rows[0].now)
16-
// })
178
return pool ;
189
};
1910

user/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":false,"michelleWasHere":false,"services":[["microservice1","SQL","postgres://gymyqkck:KDN5_PWumJO6UorMKuex8LLGBsTlISs8@salt.db.elephantsql.com:5432/gymyqkck"]]}
1+
{"setupRequired":true, "services":["hard","coded","in"]}

0 commit comments

Comments
 (0)