Commit a11f2895d65cf536bc3edeadef3d1784833a1239
1 parent
73fe179e0d
Exists in
master
tanggal pada sms
Showing 3 changed files with 9 additions and 4 deletions Inline Diff
lib/modem-dashboard/router-sms.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const moment = require('moment'); | 3 | const moment = require('moment'); |
4 | const express = require('express'); | 4 | const express = require('express'); |
5 | 5 | ||
6 | const localDb = require('../local-db'); | 6 | const localDb = require('../local-db'); |
7 | 7 | ||
8 | const router = express.Router(); | 8 | const router = express.Router(); |
9 | module.exports = router; | 9 | module.exports = router; |
10 | 10 | ||
11 | function pageSmsIndex(req, res, next) { | 11 | function pageSmsIndex(req, res, next) { |
12 | if (!req.query.input_date) { | ||
13 | req.query.input_date = moment().format('YYYY-MM-DD'); | ||
14 | } | ||
15 | |||
12 | res.render( | 16 | res.render( |
13 | 'sms.index.html', | 17 | 'sms.index.html', |
14 | { | 18 | { |
15 | page_title: 'Histori SMS' | 19 | page_title: 'Histori SMS', |
20 | input_date: req.query.input_date | ||
16 | } | 21 | } |
17 | ) | 22 | ) |
18 | } | 23 | } |
19 | 24 | ||
20 | function pageSmsDataTables(req, res, next) { | 25 | function pageSmsDataTables(req, res, next) { |
21 | const db = localDb.getConnection(); | 26 | const db = localDb.getConnection(); |
22 | 27 | ||
23 | const created_date = moment().format('YYYY-MM-DD'); | 28 | const created_date = req.query.input_date || moment().format('YYYY-MM-DD'); |
24 | const query = "SELECT rowid, * FROM sms WHERE created_date = ? ORDER BY created DESC, rowid DESC"; | 29 | const query = "SELECT rowid, * FROM sms WHERE created_date = ? ORDER BY created DESC, rowid DESC"; |
25 | db.all(query, created_date, function (err, rows) { | 30 | db.all(query, created_date, function (err, rows) { |
26 | if (err) { | 31 | if (err) { |
27 | res.end("Ada error: " + err); | 32 | res.end("Ada error: " + err); |
28 | return; | 33 | return; |
29 | } | 34 | } |
30 | res.json({data: rows}); | 35 | res.json({data: rows}); |
31 | }); | 36 | }); |
32 | } | 37 | } |
33 | 38 | ||
34 | router.get('/', pageSmsIndex); | 39 | router.get('/', pageSmsIndex); |
35 | router.get('/datatables', pageSmsDataTables); | 40 | router.get('/datatables', pageSmsDataTables); |
36 | 41 |
lib/modem-dashboard/views/date-selector.html
1 | <div class="panel panel-default"> | 1 | <div class="panel panel-default"> |
2 | <div class="panel-body"> | 2 | <div class="panel-body"> |
3 | <form class="form-horizontal"> | 3 | <form class="form-horizontal"> |
4 | <div class="form-group"> | 4 | <div class="form-group"> |
5 | <label for="inputDate" class="col-sm-2 control-label">Tanggal:</label> | 5 | <label for="inputDate" class="col-sm-2 control-label">Tanggal:</label> |
6 | <div class="col-sm-3"> | 6 | <div class="col-sm-3"> |
7 | <input type="date" class="form-control" id="inputDate" placeholder="Tanggal" name="inputDate" value="{{ inputDate }}"> | 7 | <input type="date" class="form-control" id="inputDate" placeholder="Tanggal" name="inputDate" value="{{ input_date }}"> |
8 | </div> | 8 | </div> |
9 | </div> | 9 | </div> |
10 | 10 | ||
11 | <div class="form-group hidden-print"> | 11 | <div class="form-group hidden-print"> |
12 | <div class="col-sm-offset-2 col-sm-10"> | 12 | <div class="col-sm-offset-2 col-sm-10"> |
13 | <input type="submit" name="submit" value="Submit" class="btn btn-primary"> | 13 | <input type="submit" name="submit" value="Submit" class="btn btn-primary"> |
14 | </div> | 14 | </div> |
15 | </div> | 15 | </div> |
16 | </form> | 16 | </form> |
17 | </div> | 17 | </div> |
18 | </div> | 18 | </div> |
19 | 19 |
lib/modem-dashboard/views/sms.index.html
1 | {% extends "template.html" %} | 1 | {% extends "template.html" %} |
2 | 2 | ||
3 | {% block head %} | 3 | {% block head %} |
4 | <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap.min.css"> | 4 | <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/dataTables.bootstrap.min.css"> |
5 | <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script> | 5 | <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script> |
6 | <script type="text/javascript" src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js"></script> | 6 | <script type="text/javascript" src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js"></script> |
7 | {% endblock %} | 7 | {% endblock %} |
8 | 8 | ||
9 | {% block content %} | 9 | {% block content %} |
10 | 10 | ||
11 | {% include "date-selector.html" %} | 11 | {% include "date-selector.html" %} |
12 | 12 | ||
13 | <table id="smsHistory" class="display table table-hover table-striped"> | 13 | <table id="smsHistory" class="display table table-hover table-striped"> |
14 | <thead> | 14 | <thead> |
15 | <tr> | 15 | <tr> |
16 | <th>#</th> | 16 | <th>#</th> |
17 | <th>Tanggal</th> | 17 | <th>Tanggal</th> |
18 | <th>Arah</th> | 18 | <th>Arah</th> |
19 | <th>IMSI Modem</th> | 19 | <th>IMSI Modem</th> |
20 | <th>Dari/Ke</th> | 20 | <th>Dari/Ke</th> |
21 | <th>Pesan</th> | 21 | <th>Pesan</th> |
22 | </tr> | 22 | </tr> |
23 | </thead> | 23 | </thead> |
24 | <tfoot> | 24 | <tfoot> |
25 | <tr> | 25 | <tr> |
26 | <th>#</th> | 26 | <th>#</th> |
27 | <th>Tanggal</th> | 27 | <th>Tanggal</th> |
28 | <th>Arah</th> | 28 | <th>Arah</th> |
29 | <th>IMSI Modem</th> | 29 | <th>IMSI Modem</th> |
30 | <th>Dari / Ke</th> | 30 | <th>Dari / Ke</th> |
31 | <th>Pesan</th> | 31 | <th>Pesan</th> |
32 | </tr> | 32 | </tr> |
33 | </tfoot> | 33 | </tfoot> |
34 | </table> | 34 | </table> |
35 | 35 | ||
36 | <script> | 36 | <script> |
37 | $(document).ready(function() { | 37 | $(document).ready(function() { |
38 | $('#smsHistory').DataTable( { | 38 | $('#smsHistory').DataTable( { |
39 | "ajax": "/sms/datatables", | 39 | "ajax": "/sms/datatables?input_date={{ input_date}}", |
40 | "language": { "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Indonesian.json" }, | 40 | "language": { "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Indonesian.json" }, |
41 | "columns": [ | 41 | "columns": [ |
42 | { "data": "rowid" }, | 42 | { "data": "rowid" }, |
43 | { "data": "created" }, | 43 | { "data": "created" }, |
44 | { "data": "direction" }, | 44 | { "data": "direction" }, |
45 | { "data": "imsi" }, | 45 | { "data": "imsi" }, |
46 | { "data": "partner" }, | 46 | { "data": "partner" }, |
47 | { "data": "msg" } | 47 | { "data": "msg" } |
48 | ], | 48 | ], |
49 | "order": [ | 49 | "order": [ |
50 | [1, "desc"] | 50 | [1, "desc"] |
51 | ], | 51 | ], |
52 | "lengthMenu": [[50, 100, 200, -1], [50, 100, 200, "All"]] | 52 | "lengthMenu": [[50, 100, 200, -1], [50, 100, 200, "All"]] |
53 | } ); | 53 | } ); |
54 | } ); | 54 | } ); |
55 | </script> | 55 | </script> |
56 | 56 | ||
57 | {% endblock %} | 57 | {% endblock %} |
58 | 58 |