Skip to content

Commit 4f7f386

Browse files
committed
new module added and mode created
1 parent 9753277 commit 4f7f386

File tree

16 files changed

+523
-33
lines changed

16 files changed

+523
-33
lines changed

apps/crud/app.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var logger = require('morgan');
55
var cookieParser = require('cookie-parser');
66
var bodyParser = require('body-parser');
77
var engine = require('ejs-mate');
8-
var connection = require('express-myconnection');
9-
var mysql = require('mysql');
8+
//var connection = require('express-myconnection');
9+
1010

1111
var routes = require('./routes/index');
1212
var users = require('./routes/users');
@@ -33,15 +33,16 @@ app.use(express.static(path.join(__dirname, 'public')));
3333
connection peer, register as middleware
3434
type koneksi : single,pool and request
3535
-------------------------------------------*/
36-
app.use(
36+
/*app.use(
3737
connection(mysql,{
3838
host: 'localhost',
3939
user: 'root',
4040
password : '',
4141
port : 3306, //port mysql
42-
database:'expressdemo'
42+
database:'expressdemo',
43+
multipleStatements:true
4344
},'request')
44-
);
45+
);*/
4546

4647
app.use('/', routes);
4748
app.use('/users', users);

apps/crud/lib/database.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var mysql = require('mysql');
2+
var pool = mysql.createPool({
3+
connectionLimit : 10,
4+
host : 'localhost',
5+
user : 'root',
6+
password : '',
7+
port : 3306, //port mysql
8+
database:'expressdemo',
9+
multipleStatements:true
10+
});
11+
12+
exports.getConnection = function(callback) {
13+
pool.getConnection(function(err, conn) {
14+
if(err) {
15+
return callback(err);
16+
}
17+
callback(err, conn);
18+
});
19+
};

apps/crud/lib/pagination.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var pagination = {};
2+
3+
pagination.get = function (args) {
4+
if (!args || !args.rows || !args.total)
5+
return new Error('parameters: {page: 1, links: 5, rows: 5, total: 50}');
6+
7+
var page = args.page || 1,
8+
total = Math.ceil(parseInt(args.total) / parseInt(args.rows)),
9+
links = args.links || 5;
10+
links = links%2 ? links : links+1;
11+
links = Math.min(links, total);
12+
13+
// no pagination
14+
if (page == 1 && page == total) {
15+
return null;
16+
}
17+
18+
var pager = [];
19+
20+
// left buttons
21+
if (page > 1) {
22+
pager.push({first: true, index: 1});
23+
pager.push({prev: true, index: page-1});
24+
}
25+
26+
// page links
27+
var half = Math.floor(links/2);
28+
if (page-half <= 0) {
29+
var start = 1,
30+
end = links;
31+
} else if (page+half >= total) {
32+
var start = total-links+1,
33+
end = total;
34+
} else {
35+
var start = page-half,
36+
end = start+links-1;
37+
}
38+
for (var i=start; i <= end; i++) {
39+
pager.push(i == page ? {active: true, index: i} : {page: true, index: i});
40+
}
41+
42+
// right buttons
43+
if (page < total) {
44+
pager.push({next: true, index: page+1});
45+
pager.push({last: true, index: total});
46+
}
47+
48+
return pager;
49+
};
50+
51+
module.exports = pagination;

apps/crud/models/studentModel.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var db = require('.././lib/database');
2+
var studentModel = {};
3+
4+
studentModel.listAll = function (page,limit) {
5+
var output = null;
6+
db.getConnection(function(err,connection){
7+
var sql = 'SELECT COUNT(*) AS cnt FROM students;';
8+
sql += 'SELECT * FROM students LIMIT '+page+','+limit+'';
9+
10+
connection.query(sql,function(err,result){
11+
if(err)
12+
console.log("Error Selecting : %s ",err );
13+
14+
return result;
15+
});
16+
});
17+
};
18+
19+
module.exports = studentModel;

apps/crud/node_modules/sr-pagination/.npmignore

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/crud/node_modules/sr-pagination/LICENSE

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/crud/node_modules/sr-pagination/README.md

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/crud/node_modules/sr-pagination/component.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/crud/node_modules/sr-pagination/lib/pagination.js

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/crud/node_modules/sr-pagination/package.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)