Skip to content

Commit 95ef7e2

Browse files
committed
update code
1 parent 17a517e commit 95ef7e2

File tree

4 files changed

+51
-69
lines changed

4 files changed

+51
-69
lines changed

bin/www

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
* Module dependencies.
55
*/
66

7-
var app = require('../app');
8-
var debug = require('debug')('nodetest2:server');
9-
var http = require('http');
7+
let app = require('../app');
8+
let debug = require('debug')('nodetest2:server');
9+
let http = require('http');
1010

1111
/**
1212
* Get port from environment and store in Express.
1313
*/
1414

15-
var port = normalizePort(process.env.PORT || '3000');
15+
let port = normalizePort(process.env.PORT || '3000');
1616
app.set('port', port);
1717

1818
/**
1919
* Create HTTP server.
2020
*/
2121

22-
var server = http.createServer(app);
22+
let server = http.createServer(app);
2323

2424
/**
2525
* Listen on provided port, on all network interfaces.
@@ -36,7 +36,7 @@ server.on('listening', onListening);
3636
*/
3737

3838
function normalizePort(val) {
39-
var port = parseInt(val, 10);
39+
let port = parseInt(val, 10);
4040

4141
if (isNaN(port)) {
4242
// named pipe
@@ -60,7 +60,7 @@ function onError(error) {
6060
throw error;
6161
}
6262

63-
var bind = typeof port === 'string'
63+
let bind = typeof port === 'string'
6464
? 'Pipe ' + port
6565
: 'Port ' + port;
6666

@@ -84,8 +84,8 @@ function onError(error) {
8484
*/
8585

8686
function onListening() {
87-
var addr = server.address();
88-
var bind = typeof addr === 'string'
87+
let addr = server.address();
88+
let bind = typeof addr === 'string'
8989
? 'pipe ' + addr
9090
: 'port ' + addr.port;
9191
debug('Listening on ' + bind);

public/stylesheets/style.css

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ body {
55
background-color: lightblue !important;
66
}
77

8-
div{
9-
margin-left: 200px;
10-
}
11-
128
th{
139
text-align: center !important;
14-
}
15-
16-
10+
}

routes/index.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,6 @@ router.post('/', (req, res, next) => {
3030
res.send();
3131
} else {
3232

33-
/*User.count(function(err,c){
34-
//console.log('Count is ' + c);
35-
let e = c+1;
36-
//console.log("e"+e);
37-
38-
let newPerson = new User({
39-
unique_id:e,
40-
username: personInfo.username,
41-
fullname: personInfo.fullname,
42-
age: personInfo.age
43-
});
44-
45-
newPerson.save(function(err, Person){
46-
if(err)
47-
console.log(err);
48-
else
49-
console.log('Success');
50-
});
51-
52-
});*/
5333
let c = 1;
5434
User.findOne({}, (err, data) => {
5535

@@ -94,7 +74,7 @@ router.put('/user/:id', (req, res) => {
9474
fullname: personInfo.fullname,
9575
age: personInfo.age
9676
}, (err, rawResponse) => {
97-
console.log(rawResponse);
77+
// console.log(rawResponse);
9878
});
9979

10080
});

views/index.ejs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
data: $('#form1').serialize(),
2727
dataType: "json",
2828
success: function (response) {
29-
//console.log('response');
3029
clearInputs();
3130
Show();
3231
//$( "#a" ).click();
@@ -37,7 +36,6 @@
3736
});
3837
3938
$('table').on('click', '.update-button', function () {
40-
//alert('asssaaa');
4139
let rowEl = $(this).closest('tr');
4240
let id = rowEl.find('.id').text();
4341
let fullname = rowEl.find('.fullname').val();
@@ -57,7 +55,6 @@
5755
5856
});
5957
$('table').on('click', '.delete-button', function () {
60-
// alert("DELETE");
6158
let rowEl = $(this).closest('tr');
6259
let id = rowEl.find('.id').text();
6360
@@ -76,27 +73,27 @@
7673
Show();
7774
});
7875
function Show() {
79-
// alert("Show");
8076
$.ajax({
8177
type: 'GET',
8278
url: '/show',
8379
dataType: "json",
8480
success: function (response) {
8581
console.log(response);
86-
let tbodyEl = $('tbody');
82+
// let tbodyEl = $('tbody');
83+
let tbodyEl = $("#myTable > tbody")
8784
8885
tbodyEl.html('');
8986
9087
response.forEach(function (product) {
9188
tbodyEl.append('\
9289
<tr>\
9390
<td class="id">' + product.unique_id + '</td>\
94-
<td><input type="text" class="fullname" value="' + product.fullname + '"></td>\
95-
<td><input type="text" class="username" value="' + product.username + '"></td>\
96-
<td><input type="text" class="age" value="' + product.age + '"></td>\
91+
<td><input type="text" class="fullname form-control" value="' + product.fullname + '"></td>\
92+
<td><input type="text" class="username form-control" value="' + product.username + '"></td>\
93+
<td><input type="number" class="age form-control" value="' + product.age + '"></td>\
9794
<td>\
98-
<button class="update-button">UPDATE</button>\
99-
<button class="delete-button">DELETE</button>\
95+
<button class="update-button btn btn-secondary">UPDATE</button>\
96+
<button class="delete-button btn btn-danger">DELETE</button>\
10097
</td>\
10198
</tr>\
10299
');
@@ -119,31 +116,42 @@
119116
</head>
120117

121118
<body>
122-
<button id="a">Show</button>
119+
<button id="a" class="btn btn-primary">Show</button>
120+
<br />
121+
<br />
123122
<form id="form1" method="POST">
124-
<label>UserName:</label><input type="text" name="username" id="username" required>
125-
<br />
126-
<label>Fullname:</label><input type="text" name="fullname" id="fullname" required>
127-
<br />
128-
<label>Age:</label><input type="Number" name="age" id="age" required>
123+
<table style="margin-left:auto; margin-right:auto;">
124+
<tr>
125+
<td><label>UserName</label></td>
126+
<td><input class="form-control" type="text" name="username" id="username" required></td>
127+
</tr>
128+
<tr>
129+
<td><label>Fullname</label></td>
130+
<td><input class="form-control" type="text" name="fullname" id="fullname" required></td>
131+
</tr>
132+
<tr>
133+
<td><label>Age</label></td>
134+
<td><input class="form-control" type="Number" name="age" id="age" required></td>
135+
</tr>
136+
</table>
129137
<br />
130-
<button type="Submit" id="add">Submit</button>
138+
<button type="Submit" id="add" class="btn btn-success">Submit</button>
131139
</form>
132-
<div>
133-
<table>
134-
<thead>
135-
<tr>
136-
<th>ID</th>
137-
<th>FullName</th>
138-
<th>UserName</th>
139-
<th>Age</th>
140-
</tr>
141-
</thead>
142-
<tbody>
143-
144-
</tbody>
145-
</table>
146-
</div>
140+
<br />
141+
<table id='myTable' style="margin-left:auto; margin-right:auto;">
142+
<thead>
143+
<tr>
144+
<th>ID</th>
145+
<th>FullName</th>
146+
<th>UserName</th>
147+
<th>Age</th>
148+
<th>Action</th>
149+
</tr>
150+
</thead>
151+
<tbody>
152+
153+
</tbody>
154+
</table>
147155
</body>
148156

149157
</html>

0 commit comments

Comments
 (0)