From ce7ce2b65e1a1d831478efb8584c29f24a49d0f6 Mon Sep 17 00:00:00 2001 From: Michelle <mi00354@surrey.ac.uk> Date: Sun, 23 May 2021 20:28:43 +0100 Subject: [PATCH] Connected db to submissions front end --- NodeAPI/index.js | 11 +++++------ NodeAPI/public/css/style.css | 12 +++++++++++- NodeAPI/views/submissions.ejs | 5 ++++- NodeAPI/views/table.ejs | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 NodeAPI/views/table.ejs diff --git a/NodeAPI/index.js b/NodeAPI/index.js index 1e2f3da..76eac26 100644 --- a/NodeAPI/index.js +++ b/NodeAPI/index.js @@ -41,11 +41,11 @@ app.post('/predict', (req,res) => { if(err) { return console.dir(err); } // Create collection if does not exist - var collection = db.createCollection('Pred_Records'); + var collection = db.db('ClusterNLP').collection('Pred_Records'); // Get the data to be stored var plot = req.body.plot; - var prediction = JSON.parse(body).predictionText; + var prediction = JSON.parse(JSON.parse(body).predictionText); // Get rcord to be inserted var rec = {'Plot':plot, 'Prediction': prediction}; @@ -67,17 +67,16 @@ app.post('/predict', (req,res) => { app.get('/submissions', function (req, res) { var resultArray = []; - /**MongoClient.connect(url, function(err, database) { + MongoClient.connect(url, function(err, db) { if(err) { return console.dir(err); } - var cursor = database.db().collection('Pred_Records').find() + var cursor = db.db('ClusterNLP').collection('Pred_Records').find(); cursor.forEach(function(doc, err){ resultArray.push(doc) }, function(){ db.close(); res.render('submissions', {items: resultArray}); }); - });**/ - res.render('submissions', {}); + }); }); \ No newline at end of file diff --git a/NodeAPI/public/css/style.css b/NodeAPI/public/css/style.css index e71915c..c2b5458 100644 --- a/NodeAPI/public/css/style.css +++ b/NodeAPI/public/css/style.css @@ -146,8 +146,8 @@ p { color: #f2f2f2; text-align: center; padding: 14px 16px; - text-decoration: none; font-size: 1.3em; + text-decoration: none; font-family: Calibri, 'Trebuchet MS', sans-serif; font-weight: bold; } @@ -156,6 +156,7 @@ p { .topnav a:hover { background-color: #ddd; color: #e95e01; + text-decoration: none; } /* Add a color to the active/current link */ @@ -173,4 +174,13 @@ p { .subtitle{ color: #e95e01; font-size: 1.2em; +} + +table, th, td { + border: 1px solid black; + color: black; +} + +td{ + min-width: 10em; } \ No newline at end of file diff --git a/NodeAPI/views/submissions.ejs b/NodeAPI/views/submissions.ejs index d85468f..d085446 100644 --- a/NodeAPI/views/submissions.ejs +++ b/NodeAPI/views/submissions.ejs @@ -17,7 +17,10 @@ <a href="/">NLP11</a> <a class="active" href="/submissions">Submissions</a> </div> - <body class="text-center" > + <body> + + <h1>Posts</h1> + <%- include("table", {items}); %> </body> </div> diff --git a/NodeAPI/views/table.ejs b/NodeAPI/views/table.ejs new file mode 100644 index 0000000..5f802e5 --- /dev/null +++ b/NodeAPI/views/table.ejs @@ -0,0 +1,17 @@ +<table class="table"> + <tr> + <th>Prediction</th> + <th>Plot</th> + </tr> + <%if (items.length >0){ %> + <% items.forEach(function(row) { %> + <tr> + <td><%= row.Prediction %></td> + <td><%= row.Plot %></td> + </tr> + <% })}else{ %> + <tr> + <td colspan="6">No Record Found</td> + </tr> + <% } %> + </table> \ No newline at end of file -- GitLab