这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
b9e79c0
[imad-console] Updates ui/index.html
akash-joshi Sep 17, 2016
337fca3
Made some changes
akash-joshi Sep 18, 2016
b5352af
[imad-console] Updates server.js
akash-joshi Sep 20, 2016
de9d9d5
[imad-console] Updates ui/index.html
akash-joshi Sep 20, 2016
479420a
[imad-console] Updates ui/style.css
akash-joshi Sep 20, 2016
5f13efa
[imad-console] Updates ui/index.html
akash-joshi Sep 20, 2016
2b3f0b5
[imad-console] Updates ui/style.css
akash-joshi Sep 20, 2016
da50b91
Create article-one.html
akash-joshi Sep 20, 2016
b35b611
[imad-console] Updates ui/article-one.html
akash-joshi Sep 20, 2016
d2ee941
[imad-console] Updates server.js
akash-joshi Sep 20, 2016
99eb0d6
[imad-console] Updates ui/article-one.html
akash-joshi Sep 20, 2016
4eb9773
[imad-console] Updates ui/article-one.html
akash-joshi Sep 21, 2016
4b20167
[imad-console] Updates ui/style.css
akash-joshi Sep 21, 2016
8b39d1f
[imad-console] Updates ui/article-one.html
akash-joshi Sep 21, 2016
b77108c
[imad-console] Updates ui/article-one.html
akash-joshi Sep 21, 2016
c7c6ead
[imad-console] Updates ui/article-one.html
akash-joshi Sep 21, 2016
fc0129d
[imad-console] Updates server.js
akash-joshi Sep 21, 2016
e648998
[imad-console] Updates server.js
akash-joshi Sep 21, 2016
aea0d94
[imad-console] Updates server.js
akash-joshi Sep 21, 2016
3f20b47
[imad-console] Updates server.js
akash-joshi Sep 23, 2016
be166e0
[imad-console] Updates server.js
akash-joshi Sep 23, 2016
5da4cd2
[imad-console] Updates ui/main.js
akash-joshi Sep 23, 2016
f61b475
[imad-console] Updates ui/index.html
akash-joshi Sep 23, 2016
3ec1f3e
[imad-console] Updates ui/main.js
akash-joshi Sep 23, 2016
5610770
[imad-console] Updates ui/main.js
akash-joshi Sep 23, 2016
b8581b5
[imad-console] Updates ui/index.html
akash-joshi Sep 25, 2016
9262301
[imad-console] Updates ui/index.html
akash-joshi Sep 25, 2016
0109356
[imad-console] Updates server.js
akash-joshi Sep 25, 2016
e27bb74
[imad-console] Updates ui/index.html
akash-joshi Sep 25, 2016
3306e28
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
53e4eed
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
33f15c9
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
591ded0
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
d520b5f
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
c954c71
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
83bd2db
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
8833aca
[imad-console] Updates ui/index.html
akash-joshi Sep 25, 2016
5ffdacc
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
761fbda
[imad-console] Updates ui/index.html
akash-joshi Sep 25, 2016
c1f3de0
[imad-console] Updates ui/main.js
akash-joshi Sep 25, 2016
5822556
[imad-console] Updates ui/main.js
akash-joshi Oct 2, 2016
abbc03e
[imad-console] Updates ui/main.js
akash-joshi Oct 2, 2016
348945d
[imad-console] Updates ui/main.js
akash-joshi Oct 2, 2016
c767a5e
[imad-console] Updates ui/index.html
akash-joshi Oct 2, 2016
79be304
[imad-console] Updates ui/index.html
akash-joshi Oct 2, 2016
f4996c7
[imad-console] Updates ui/index.html
akash-joshi Oct 2, 2016
15960f0
[imad-console] Updates ui/index.html
akash-joshi Oct 5, 2016
896f178
[imad-console] Updates ui/index.html
akash-joshi Oct 5, 2016
42cc321
[imad-console] Updates ui/style.css
akash-joshi Oct 5, 2016
f71d7b7
[imad-console] Updates ui/index.html
akash-joshi Oct 5, 2016
1033f42
[imad-console] Updates ui/index.html
akash-joshi Oct 5, 2016
5cec62d
[imad-console] Updates ui/index.html
akash-joshi Oct 5, 2016
46791f0
[imad-console] Updates ui/index.html
akash-joshi Oct 5, 2016
54a560d
[imad-console] Updates ui/main.js
akash-joshi Oct 5, 2016
f609c43
[imad-console] Updates ui/main.js
akash-joshi Oct 5, 2016
d6d0587
[imad-console] Updates ui/main.js
akash-joshi Oct 5, 2016
61cd9bf
[imad-console] Updates server.js
akash-joshi Oct 5, 2016
1d13f40
[imad-console] Updates server.js
akash-joshi Oct 5, 2016
0ddc14e
[imad-console] Updates server.js
akash-joshi Oct 5, 2016
9b37ec9
[imad-console] Updates server.js
akash-joshi Oct 5, 2016
290511e
[imad-console] Updates server.js
akash-joshi Oct 5, 2016
0011d80
[imad-console] Updates server.js
akash-joshi Oct 5, 2016
dbe48ab
[imad-console] Updates ui/main.js
akash-joshi Oct 5, 2016
8ad7606
[imad-console] Updates ui/main.js
akash-joshi Oct 5, 2016
5f8b803
Update package.json
akash-joshi Oct 19, 2016
5cd3912
Update package.json
akash-joshi Oct 19, 2016
a0d930d
Update package.json
akash-joshi Oct 19, 2016
4592498
Update server.js
akash-joshi Oct 19, 2016
d663d98
Update server.js
akash-joshi Oct 24, 2016
2720565
Update index.html
akash-joshi Oct 24, 2016
727ada7
Update style.css
akash-joshi Oct 24, 2016
88803e1
[imad-console] Updates server.js
akash-joshi Oct 27, 2016
bda70ab
[imad-console] Updates server.js
akash-joshi Oct 27, 2016
5498e45
[imad-console] Updates server.js
akash-joshi Oct 27, 2016
3a196e7
Update package.json
akash-joshi Oct 27, 2016
ae73f62
Update package.json
akash-joshi Oct 27, 2016
74cb551
Update package.json
akash-joshi Oct 27, 2016
5a3c1a9
Update server.js
akash-joshi Oct 27, 2016
4cecaa1
Update server.js
akash-joshi Oct 27, 2016
c38254d
Update package.json
akash-joshi Oct 27, 2016
608b95e
Update package.json
akash-joshi Oct 27, 2016
e08d5cb
Update server.js
akash-joshi Oct 27, 2016
bfde36c
Update server.js
akash-joshi Oct 27, 2016
45ca506
[imad-console] Updates server.js
akash-joshi Nov 3, 2016
a7e0fa3
[imad-console] Updates server.js
akash-joshi Nov 3, 2016
34af3a8
[imad-console] Updates server.js
akash-joshi Nov 3, 2016
98418e1
[imad-console] Updates server.js
akash-joshi Nov 3, 2016
6df2f23
[imad-console] Updates server.js
akash-joshi Nov 3, 2016
862b9dc
[imad-console] Updates server.js
akash-joshi Nov 3, 2016
0f5e941
Delete article-one.html
akash-joshi Nov 3, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"description": "IMAD 2016 course app",
"main": "server.js",
"scripts": {
"start": "npm install",
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.14.0",
"morgan": "^1.7.0"
}
"morgan": "^1.7.0",
"pg": "^6.1.0"
}
}
90 changes: 86 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,106 @@
var express = require('express');
var morgan = require('morgan');
var path = require('path');

var Pool = require('pg').Pool;
var app = express();
app.use(morgan('combined'));

var counter =0;
var config = {
user : 'krusty-crab',
database : 'krusty-crab',
host : 'db.imad.hasura-app.io',
port : '5432',
password : process.env.DB_PASSWORD
}
function createTemplate(data){
var title = data.title;
var heading = data.heading;
var date = data.date;
var content = data.content;
var htmlTemplate = `<html>
<head>
<link href="/ui/style.css" rel="stylesheet" />
${title}
</head>
<body>
<div>
<a href="/"> Home </a>
</div>
<hr/>
<div class="center">
<h1>
${heading}
</h1>
</div>
<div class="center">
${date.toDateString()}
</div>
<div>
${content}
</div>
</body>
</html>`;
return htmlTemplate;
}

app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'index.html'));
});

var names=[];
app.get('/submit-name', function(req, res) {
var name = req.query.name;
names.push(name);
res.send(JSON.stringify(names));
});

app.get('/counter', function (req,res){
counter++;
res.send(counter.toString());
});

var pool = new Pool(config);
app.get('/test-db',function (req,res){
pool.query('SELECT * FROM test', function (err,result){
if(err){
res.status(500).send(err.toString());
} else{
res.send(JSON.stringify(result.rows));
}
})
//make select req and return response
});

app.get('/articles/:articleName', function (req, res) {
// SELECT * FROM article WHERE title = '\'; DELETE WHERE a = \'asdf'
pool.query("SELECT * FROM article WHERE title = $1", [req.params.articleName], function (err, result) {
if (err) {
res.status(500).send(err.toString());
} else {
if (result.rows.length === 0) {
res.status(404).send('Article not found');
} else {
var articleData = result.rows[0];
res.send(createTemplate(articleData));
}
}
});
});

app.get('/ui/style.css', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'style.css'));
});

app.get('/ui/main.js', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'main.js'));
});

app.get('/ui/madi.png', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'madi.png'));
});


var port = 8080; // Use 8080 for local development because you might already have apache running on 80
app.listen(8080, function () {
var port = process.env.PORT || 8080 // Use 8080 for local development because you might already have apache running on 80
app.listen(port, function () {
console.log(`IMAD course app listening on port ${port}!`);
});
26 changes: 22 additions & 4 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
<head>
<link href="/ui/style.css" rel="stylesheet" />
</head>
<body>
<body class="mobile">
<div class="center">
<img src="/ui/madi.png" class="img-medium"/>
<img id ="madi" src="https://upload.wikimedia.org/wikipedia/commons/7/7b/Donkey_1_arp_750px.jpg" class="img-medium"/>
</div>
<br>
<div class="center text-big bold">
Hi! I am your webapp.
<div class="center bold">
Hi! I am Akash, and this is my first webapp.
<h4> A new heading </h4>
I've made some changes
</div>
<script type="text/javascript" src="/ui/main.js">

</script>
<div >
<p> Reasons to hire me : </p>
<ol>
<li> Am person </li>
<li> Have heartbeat </li>
</ol></div>
<div class="footer center">
This button <button id="counter"> Click me!</button> has been clicked <span id="count">0</span> times
<hr/>
<input type="text" id="name" placeholder="name"></input>
<input type="Submit" value="Submit" class="center" id="submit_btn"></input>
<ul id="namelist">
</ul>
</div>
<script type="text/javascript" src="/ui/main.js"></script>
</body>
</html>
51 changes: 50 additions & 1 deletion ui/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
console.log('Loaded!');
// counter code
var button = document.getElementById('counter');
var counter=0;
button.onclick = function () {

var request = new XMLHttpRequest();

request.onreadystatechange = function () {
if(request.readyState === XMLHttpRequest.DONE){
if(request.status === 200){ //DO NOT COMPARE WITH "200" INSTEAD WITH 200
var counter=request.responseText; //Should be request.responseText
var span = document.getElementById('count');
span.innerHTML= counter.toString();
}
}
};

request.open("GET", document.URL+"counter", true);
request.send(null);
};

// Get Name
var submit = document.getElementById('submit_btn');
submit.onclick = function () {
//make request to get names
var request = new XMLHttpRequest();
var nameInput = document.getElementById('name');
var name=nameInput.value;
request.onreadystatechange = function () {
if(request.readyState === XMLHttpRequest.DONE){
if(request.status === 200){
var names = request.responseText;
names = JSON.parse(names);
var list='';
for(var i=0; i<names.length;i++){
list += '<li>' + names[i] + '</li>';
var ul=document.getElementById('namelist');
ul.innerHTML = list;
}
}
}
};

request.open("GET", document.URL+"submit-name?name="+name, true);
request.send(null);
// capture names



};
11 changes: 9 additions & 2 deletions ui/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
body {
height: 100%;
width: 100%;
font-family: sans-serif;
font-size: 3vw;
background-color: lightgrey;
margin-top: 75px;
}
Expand All @@ -9,14 +12,18 @@ body {
}

.text-big {
font-size: 300%;
/*font-size: 200%;*/
}

.bold {
font-weight: bold;
}

.img-medium {
height: 200px;
height: 300px;
}

.mobile{
margin-left: 40px;
margin-right: 40px;
}