Commit d76239170c1610173d3a3e0272679aeb0343a0fe
1 parent
66a04c55f2
Exists in
master
Ready
Showing 4 changed files with 232 additions and 0 deletions Side-by-side Diff
index.js
1 | 1 | var config = require('./config.json'); |
2 | +var oracledb = require('oracledb'); | |
3 | +var express = require('express'); | |
4 | +var util = require('util'); | |
5 | +var nunjucks = require('nunjucks'); | |
6 | + | |
7 | +var app = express(); | |
8 | +app.set('views', './views'); | |
9 | +nunjucks.configure('views', { | |
10 | + autoescape: true, | |
11 | + express: app | |
12 | +}); | |
13 | + | |
14 | +var logger = console; | |
15 | +var oraCon; | |
16 | + | |
17 | +function connectToOracle(callback) { | |
18 | + oracledb.getConnection(config.oracle, function(err, connection) { | |
19 | + if (err) { | |
20 | + logger.warn('Can not connect to oracle db: ' + err); | |
21 | + process.exit(1); | |
22 | + } | |
23 | + | |
24 | + oraCon = connection; | |
25 | + logger.info("Oracle db connected") | |
26 | + | |
27 | + if (callback) { | |
28 | + callback(null, oraCon); | |
29 | + } | |
30 | + }) | |
31 | +} | |
32 | + | |
33 | +function getTrx(callback) { | |
34 | + oraCon.execute( | |
35 | + "SELECT T_TRANS.*,T_STORE_USER.FULL_NAME FROM T_TRANS LEFT JOIN T_STORE_USER ON T_TRANS.USER_NAME = T_STORE_USER.USER_NAME WHERE TRUNC(TIME_START) = TRUNC(sysdate) AND TRANS_STAT='1200' ORDER BY T_TRANS.TIME_START DESC", | |
36 | + function(err, result) { | |
37 | + if (err) { | |
38 | + callback(err); | |
39 | + return; | |
40 | + } | |
41 | + | |
42 | + | |
43 | + var metadata = result.metaData; | |
44 | + var metadataCount = metadata.length; | |
45 | + | |
46 | + var retval = []; | |
47 | + | |
48 | + var count = result.rows.length; | |
49 | + for (var i=1; i <= count; i++) { | |
50 | + row = result.rows[i-1]; | |
51 | + | |
52 | + var data = {}; | |
53 | + | |
54 | + for (var metadataIdx = 0; metadataIdx < metadataCount; metadataIdx++) { | |
55 | + data[metadata[metadataIdx].name] = row[metadataIdx]; | |
56 | + } | |
57 | + retval.push(data); | |
58 | + } | |
59 | + | |
60 | + callback(err, retval); | |
61 | + } | |
62 | + ); | |
63 | + | |
64 | +} | |
65 | + | |
66 | +function init() { | |
67 | + connectToOracle(); | |
68 | + | |
69 | + app.listen(config.listen_port, function () { | |
70 | + console.log('Example app listening on port ' + config.listen_port); | |
71 | + }); | |
72 | +} | |
73 | + | |
74 | +function renderTrx(req, res, next) { | |
75 | + //res.send('Hello World!'); | |
76 | + getTrx(function(err, transactions) { | |
77 | + if (err) { | |
78 | + res.end('Something wrong'); | |
79 | + return; | |
80 | + } | |
81 | + | |
82 | + //res.end(JSON.stringify(result)); | |
83 | + res.render('index.html', {title: "Pending Trx", transactions: transactions}); | |
84 | + | |
85 | + }); | |
86 | +} | |
87 | + | |
88 | +app.get('/', renderTrx); | |
89 | + | |
90 | +init(); |
package.json
... | ... | @@ -0,0 +1,27 @@ |
1 | +{ | |
2 | + "name": "sate24-pending-monitor", | |
3 | + "version": "1.0.0", | |
4 | + "description": "ST24 Pending Trx Monitor", | |
5 | + "main": "index.js", | |
6 | + "dependencies": { | |
7 | + "express": "^4.14.0", | |
8 | + "nunjucks": "^2.4.2", | |
9 | + "oracledb": "^1.9.3" | |
10 | + }, | |
11 | + "devDependencies": {}, | |
12 | + "scripts": { | |
13 | + "test": "mocha" | |
14 | + }, | |
15 | + "repository": { | |
16 | + "type": "git", | |
17 | + "url": "git@gitlab.kodesumber.com:reload97/sate24-pending-monitor.git" | |
18 | + }, | |
19 | + "keywords": [ | |
20 | + "st24", | |
21 | + "ppob", | |
22 | + "reload97", | |
23 | + "r97" | |
24 | + ], | |
25 | + "author": "Adhidarma Hadiwinoto <me@adhisimon.org>", | |
26 | + "license": "ISC" | |
27 | +} |
views/index.html
... | ... | @@ -0,0 +1,81 @@ |
1 | +{% extends "template.html" %} | |
2 | + | |
3 | +{% block content %} | |
4 | + | |
5 | +<table class="table table-striped"> | |
6 | + <tr> | |
7 | + <th class="hidden-xs"> NO. </th> | |
8 | + <th class="hidden-xs"> TRX ID </th> | |
9 | + <th class="hidden-xs"> TIME START </th> | |
10 | + <th class="hidden-xs"> NOM </th> | |
11 | + <th class="hidden-xs"> DESTINATION </th> | |
12 | + <th class="hidden-xs"> SUPPLIER </th> | |
13 | + <th class="hidden-xs"> INFO </th> | |
14 | + <th class="visible-xs"> PENDING TRX </th> | |
15 | + </tr> | |
16 | + | |
17 | + {% set i = 0 %} | |
18 | + {% for transaction in transactions %} | |
19 | + <tr> | |
20 | + {% set i = i + 1 %} | |
21 | + | |
22 | + <td class="text-right hidden-xs"> {{ i }}. </td> | |
23 | + | |
24 | + <td class="hidden-xs"> {{ transaction.MESSAGEID }} </td> | |
25 | + | |
26 | + <td class="hidden-xs"> | |
27 | + {{ transaction.TIME_START | string | replace("GMT+0700 (WIB)", "") }} | |
28 | + </td> | |
29 | + | |
30 | + <td class="hidden-xs"> {{ transaction.NOM }} </td> | |
31 | + | |
32 | + <td class="hidden-xs"> {{ transaction.NO_HP }} </td> | |
33 | + | |
34 | + <td class="hidden-xs"> {{ transaction.CHIP_INFO }} </td> | |
35 | + | |
36 | + <td class="hidden-xs"> | |
37 | + {% if transaction.MASALAH %} | |
38 | + {{ transaction.MASALAH }} | |
39 | + {% else %} | |
40 | + - | |
41 | + {% endif %} | |
42 | + </td> | |
43 | + | |
44 | + <td class="visible-xs"> | |
45 | + | |
46 | + <dl> | |
47 | + <dt> Time </dt> | |
48 | + <dd> | |
49 | + {{ transaction.TIME_START | string | replace("GMT+0700 (WIB)", "") }} | |
50 | + </dd> | |
51 | + | |
52 | + <dt> Nom </dt> | |
53 | + <dd> | |
54 | + {{ transaction.NOM }} | |
55 | + </dd> | |
56 | + | |
57 | + <dt> Destination </dt> | |
58 | + <dd> | |
59 | + {{ transaction.NO_HP }} | |
60 | + </dd> | |
61 | + | |
62 | + <dt> Supplier </dt> | |
63 | + <dd> | |
64 | + {{ transaction.CHIP_INFO }} | |
65 | + </dd> | |
66 | + | |
67 | + <dt> Info </dt> | |
68 | + <dd> | |
69 | + {% if transaction.MASALAH %} | |
70 | + {{ transaction.MASALAH }} | |
71 | + {% else %} | |
72 | + - | |
73 | + {% endif %} | |
74 | + </dd> | |
75 | + | |
76 | + <dl> | |
77 | + </td> | |
78 | + </tr> | |
79 | + {% endfor %} | |
80 | +</table> | |
81 | +{% endblock %} |
views/template.html
... | ... | @@ -0,0 +1,35 @@ |
1 | +<!DOCTYPE html> | |
2 | +<html lang="en"> | |
3 | +<head> | |
4 | + <meta charset="utf-8"> | |
5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
6 | + <meta name="viewport" content="width=device-width, initial-scale=1"> | |
7 | + <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> | |
8 | + | |
9 | + <title> | |
10 | + {% if title %} | |
11 | + {{ title }} | |
12 | + {% else %} | |
13 | + Trx Monitor | |
14 | + {% endif %} | |
15 | + </title> | |
16 | + | |
17 | + <!-- Bootstrap --> | |
18 | + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
19 | +</head> | |
20 | + | |
21 | +<body> | |
22 | + | |
23 | + {% if title %} | |
24 | + <h1>{{ title }}</h1> | |
25 | + {% endif %} | |
26 | + | |
27 | + {% block content %} | |
28 | + {% endblock %} | |
29 | + | |
30 | + <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | |
31 | + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
32 | + <!-- Include all compiled plugins (below), or include individual files as needed --> | |
33 | + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> | |
34 | +</body> | |
35 | +</html> |