aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2021-04-15 11:36:55 -0500
committerRossTheRoss <mstrapp@protonmail.com>2021-04-15 11:36:55 -0500
commite1994b6e0342913696f94eec1a4a6b0685e3a015 (patch)
treefe065d851ca3e276c8bbc9cc78f1c6b77777c129 /csci4131
parentRearrange (diff)
downloadhomework-e1994b6e0342913696f94eec1a4a6b0685e3a015.tar
homework-e1994b6e0342913696f94eec1a4a6b0685e3a015.tar.gz
homework-e1994b6e0342913696f94eec1a4a6b0685e3a015.tar.bz2
homework-e1994b6e0342913696f94eec1a4a6b0685e3a015.tar.lz
homework-e1994b6e0342913696f94eec1a4a6b0685e3a015.tar.xz
homework-e1994b6e0342913696f94eec1a4a6b0685e3a015.tar.zst
homework-e1994b6e0342913696f94eec1a4a6b0685e3a015.zip
hw6
Diffstat (limited to 'csci4131')
-rw-r--r--csci4131/hw6/strap012_hw6/index.js39
-rw-r--r--csci4131/hw6/strap012_hw6/package.json2
-rw-r--r--csci4131/hw6/strap012_hw6/public/addContact.html113
-rw-r--r--csci4131/hw6/strap012_hw6/public/contacts.html73
-rw-r--r--csci4131/hw6/strap012_hw6/public/login.html38
-rw-r--r--csci4131/hw6/strap012_hw6/public/stock.html123
-rw-r--r--csci4131/lec/Lec23Ex1.xml5
7 files changed, 390 insertions, 3 deletions
diff --git a/csci4131/hw6/strap012_hw6/index.js b/csci4131/hw6/strap012_hw6/index.js
index a81fbd1..6ce24c2 100644
--- a/csci4131/hw6/strap012_hw6/index.js
+++ b/csci4131/hw6/strap012_hw6/index.js
@@ -39,7 +39,7 @@ app.use(session({
// middle ware to serve static files
app.use(express.static(path.join(__dirname, 'public')));
-// server listens on port 9002 for incoming connections
+// server listens on port for incoming connections
app.listen(port, () => console.log('Listening on port', port));
app.get('/', function (req, res) {
@@ -49,11 +49,46 @@ app.get('/', function (req, res) {
// GET method route for the contacts page.
// It serves contact.html present in public folder
app.get('/contacts', function(req, res) {
- // TODO: Add Implementation
+ if(!req.session.value) {
+ res.redirect('/login');
+ } else {
+ res.sendFile(path.join(__dirname, 'public/contacts.html'));
+ }
+});
+
+app.get('/stock', function (req, res) {
+ if (!req.session.value) {
+ res.redirect('/login');
+ } else {
+ res.sendFile(path.join(__dirname, 'public/stock.html'));
+ }
+});
+
+app.get('/addContact', function (req, res) {
+ if (!req.session.value) {
+ res.redirect('/login');
+ } else {
+ res.sendFile(path.join(__dirname, 'public/addContact.html'));
+ }
+});
+
+app.get('/login', function (req, res) {
+ if (req.session.value) {
+ res.redirect('/contacts');
+ } else {
+ res.sendFile(path.join(__dirname, 'public/login.html'));
+ }
+});
+
+app.post('/logintry', function(req, res) {
+
});
+
// TODO: Add implementation for other necessary end-points
+
+
// Makes Express use a router called utilities
app.use('/api', utilities);
diff --git a/csci4131/hw6/strap012_hw6/package.json b/csci4131/hw6/strap012_hw6/package.json
index a6f8b37..db9cf8f 100644
--- a/csci4131/hw6/strap012_hw6/package.json
+++ b/csci4131/hw6/strap012_hw6/package.json
@@ -4,7 +4,7 @@
"description": "Assignment 6",
"main": "index.js",
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "test": "node index.js"
},
"author": "strap012",
"license": "ISC",
diff --git a/csci4131/hw6/strap012_hw6/public/addContact.html b/csci4131/hw6/strap012_hw6/public/addContact.html
new file mode 100644
index 0000000..12bfaa2
--- /dev/null
+++ b/csci4131/hw6/strap012_hw6/public/addContact.html
@@ -0,0 +1,113 @@
+<!doctype html>
+<html lang="en">
+
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+ </head>
+
+ <body>
+ <nav class="navbar navbar-default">
+ <div class="container-fluid">
+ <ul class="nav navbar-nav">
+ <li><a href="index.html"><b>Home</b></a></li>
+ <li><a href="contacts.html"><b>Contacts</b></a></li>
+ <li><a href="addContact.html"><b>Add Contact</b></a></li>
+ <li><a href="stock.html"><b>Stock Page</b></a></li>
+ </ul>
+ </div>
+ </nav>
+ <br><br>
+
+ <div class="container">
+ <div class="row">
+ <p><br /></p>
+ </div>
+
+ <div class="row">
+ <div class="col-md-4"></div>
+ <div class="col-md-4">
+ <div class="panel panel-default">
+ <form name="addContact" method="post" action="/postContactEntry">
+ <p></p>
+ <table class="table table-bordered table-hover">
+ <tbody>
+ <tr>
+ <td class="col-md-6">Name</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <input type="text" class="form-control" name="name" required>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6">Category</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <select class="form-control" name="category">
+ <option>Personal</option>
+ <option>Academic</option>
+ <option>Industry</option>
+ </select>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6">Location</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <input type="text" class="form-control" name="location" required>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6">Contact Information</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <input type="text" class="form-control" name="contact" required>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6">Email</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <input type="email" class="form-control" name="email" required>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6">Website Name</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <input type="text" class="form-control" name="website_name" required maxlength="100">
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6">Website URL</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <input type="url" class="form-control" name="website_url" required maxlength="200">
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td class="col-md-6"></td>
+ <td class="col-md-6">
+ <input type="submit" value="Submit">
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </form>
+ </div>
+ </div>
+ <div class="col-md-4"></div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/csci4131/hw6/strap012_hw6/public/contacts.html b/csci4131/hw6/strap012_hw6/public/contacts.html
new file mode 100644
index 0000000..15e4032
--- /dev/null
+++ b/csci4131/hw6/strap012_hw6/public/contacts.html
@@ -0,0 +1,73 @@
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+ <script type="text/javascript" defer>
+ //Get JSON
+ var xmlhttp = new XMLHttpRequest();
+ var url = "contacts.json";
+ xmlhttp.onreadystatechange = function () {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ var parse = JSON.parse(xmlhttp.responseText);
+ process(parse);
+ }
+ }
+ xmlhttp.open("GET", url, true);
+ xmlhttp.send();
+
+ function process(a) {
+ var table = document.getElementsByTagName("tbody")[0];
+ var contacts = a.contacts;
+ for (let i = 0; i < contacts.length; i++) {
+ var contact = contacts[i];
+ var row = table.insertRow();
+ for (var j in contact) {
+ if (j != "website_url") {
+ var value = row.insertCell();
+ value.innerHTML = contact[j];
+ } else {
+ var url = row.insertCell();
+ url.innerHTML = "<a href =" + contact[j] + ">" + contact[j] + "</a>";
+ }
+ }
+ }
+ }
+
+ </script>
+ </head>
+ <body>
+ <nav class="navbar navbar-default">
+ <div class="container-fluid">
+ <ul class="nav navbar-nav">
+ <li><a href="index.html"><b>Home</b></a></li>
+ <li><a href="contacts.html"><b>Contacts</b></a></li>
+ <li><a href="addContact.html"><b>Add Contact</b></a></li>
+ <li><a href="stock.html"><b>Stock Page</b></a></li>
+ </ul>
+ </div>
+ </nav>
+ <br><br>
+
+ <div class="container">
+ <table class="table" id="contactsTable">
+ <thead>
+ <tr>
+ <th scope="col">Name</th>
+ <th scope="col">Category</th>
+ <th scope="col">Location</th>
+ <th scope="col">Contact Information</th>
+ <th scope="col">Email</th>
+ <th scope="col">Website <br> (URL) </th>
+ </tr>
+ </thead>
+ <tbody></tbody>
+ </table>
+ </div>
+ <script type="text/javascript">
+
+ </script>
+ </body>
+</html>
diff --git a/csci4131/hw6/strap012_hw6/public/login.html b/csci4131/hw6/strap012_hw6/public/login.html
new file mode 100644
index 0000000..34bbc8c
--- /dev/null
+++ b/csci4131/hw6/strap012_hw6/public/login.html
@@ -0,0 +1,38 @@
+<html>
+
+<head>
+ <script src="https://code.jquery.com/jquery-2.2.4.min.js"integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
+</head>
+
+<body>
+ <form id="myForm" name="myForm">
+ <div>
+ <label for="login">login:</label>
+ <input type="text" id="login" name="login">
+ </div>
+ <div>
+ <label for="password">password:</label>
+ <input type="text"id="password"name="password">
+ </div>
+ <input type="submit"value="Submit!">
+ </form>
+ <script>
+ $(document).ready(function () {
+ $('#myForm').submit(function (event) {
+ event.preventDefault();//collect the form data using Id Selector for whatever data you need to send to server
+ let login=$('#login').val();
+ let password=$('#password').val();
+ $.post('logintry',
+ {"login": login,"password": password},
+ (data) => {
+ console.log(data);
+ if(data.status === 'success'){
+ //pseudo code
+ //Make sure error message is not displayed
+ //Re-direct to contacts page,
+ window.location.href='contacts';}
+ else{
+ //Display error message
+ }});});});</script>
+
+</html> \ No newline at end of file
diff --git a/csci4131/hw6/strap012_hw6/public/stock.html b/csci4131/hw6/strap012_hw6/public/stock.html
new file mode 100644
index 0000000..b55ffcb
--- /dev/null
+++ b/csci4131/hw6/strap012_hw6/public/stock.html
@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+ <style>
+ pre {
+ max-height: 12em;
+ }
+ textarea {
+ width: 100%;
+ min-height: 30rem;
+ background-color: black;
+ font-family: "Lucida Console", Monaco, monospace;
+ font-size: 0.75 rem;
+ line-height: 1.2;
+ color: #fff;
+ }
+ </style>
+</head>
+
+<body>
+ <nav class="navbar navbar-default">
+ <div class="container-fluid">
+ <ul class="nav navbar-nav">
+ <li><a href="index.html"><b>Home</b></a></li>
+ <li><a href="contacts.html"><b>Contacts</b></a></li>
+ <li><a href="addContact.html"><b>Add Contact</b></a></li>
+ <li><a href="stock.html"><b>Stock Page</b></a></li>
+ </ul>
+ </div>
+ </nav>
+ <br><br>
+
+ <div class="container">
+ <div class="panel panel-default">
+ <div class="panel-body"><center>Welcome to Stock Page</center></div>
+ </div>
+ </div>
+
+ <div class="container">
+ <div class="row">
+ <div class="col">
+ <table class="table table-bordered table-hover">
+ <tbody>
+ <tr>
+ <td class="col-md-6">Company</td>
+ <td class="col-md-6">
+ <div class="form-group">
+ <select id="Company" name="Company">
+ <option value="GME">Gamestop</option>
+ <option value="MSFT">Microsoft</option>
+ <option value="BA">Boeing Company</option>
+ <option value="AAPL">Apple Inc</option>
+ <option value="AMZN">Amazon</option>
+ <option value="NVDA">NVIDIA Corporation</option>
+ </select>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <button type="button" onclick="Click()">Get Data</button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+
+ <div class="container">
+ <div id="chartContainer"></div>
+ </div>
+
+ <div class="container">
+ <table class="table" id="StockData">
+ <thead>
+ <tr>
+ <th scope="col" id="meta">Company-MetaData</th>
+ <th scope="col" id="Time">Stock-Info</th>
+ </tr>
+ </thead>
+ <pre>
+ <tbody></tbody>
+ </pre>
+ </table>
+ </div>
+
+ <script>
+ function Click() {
+ var comp = document.getElementById("Company").value;
+ var xmlhttp = new XMLHttpRequest();
+ var url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + comp + "&apikey=8MWSNPDWKH0BTBH2";
+ xmlhttp.onreadystatechange = function () {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ var parse = JSON.parse(xmlhttp.responseText);
+ var table = document.getElementById("StockData").getElementsByTagName("tbody")[0];
+ var row = table.insertRow();
+ for (var i in parse) {
+ var cell = row.insertCell();
+ cell.innerHTML = "<pre>" + JSON.stringify(parse[i], undefined, 2) + "</pre>";
+ }
+ }
+ }
+ xmlhttp.open("GET", url, true);
+ xmlhttp.send();
+
+ }
+ /* TODO:
+ / Bonus 1. Request the TIME_SERIES_DAILY endpoint of alphavantage API
+ / for the company selected in the dropdown. Display the JSON
+ / in the result according to the write up.
+ / Bonus 2. Take the JSON from the alphavantage API and chart it to a
+ / line chart using Chart.js to the chartContainer div. Ensure
+ / the chart meets all requirements from the HW writeup.
+ /*/
+ </script>
+</body>
+</html>
diff --git a/csci4131/lec/Lec23Ex1.xml b/csci4131/lec/Lec23Ex1.xml
new file mode 100644
index 0000000..5568c44
--- /dev/null
+++ b/csci4131/lec/Lec23Ex1.xml
@@ -0,0 +1,5 @@
+<?xmlversion="1.0" encoding="UTF-8"?>
+<car>
+ <model>Honda Civic</model>
+ <year>2001</year>
+</car> \ No newline at end of file