Commit d05bdbd3f4739cb9fedd5b508400f306822e7afa
1 parent
8d57793ce9
Exists in
master
Perbaikan data stock kosong
Showing 2 changed files with 16 additions and 2 deletions Inline Diff
lib/modem-dashboard/router-stocks.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const express = require('express'); | 3 | const express = require('express'); |
4 | const router = express.Router(); | 4 | const router = express.Router(); |
5 | module.exports = router; | 5 | module.exports = router; |
6 | 6 | ||
7 | const matrix = require('komodo-sdk/matrix'); | 7 | const matrix = require('komodo-sdk/matrix'); |
8 | 8 | ||
9 | function pageIndex(req, res, next) { | 9 | function pageIndex(req, res, next) { |
10 | let stocks_array; | ||
11 | 10 | ||
12 | if (!matrix || !matrix.stock || (typeof matrix.stock !== 'object')) { | 11 | if (!matrix || !matrix.stock || (typeof matrix.stock !== 'object')) { |
13 | stocks_array = null; | 12 | res.render( |
13 | 'stocks.html', | ||
14 | { | ||
15 | page_title: 'Stock', | ||
16 | stocks_array: null | ||
17 | } | ||
18 | ) | ||
19 | return; | ||
14 | } | 20 | } |
15 | 21 | ||
22 | let stocks_array = []; | ||
23 | |||
24 | |||
16 | for (let key in matrix.stock) { | 25 | for (let key in matrix.stock) { |
17 | if (matrix.stock.hasOwnProperty(key)) { | 26 | if (matrix.stock.hasOwnProperty(key)) { |
18 | stocks_array.push({ | 27 | stocks_array.push({ |
19 | name: key, | 28 | name: key, |
20 | balance: matrix.stock[key] | 29 | balance: matrix.stock[key] |
21 | }); | 30 | }); |
22 | } | 31 | } |
23 | } | 32 | } |
24 | 33 | ||
25 | res.render( | 34 | res.render( |
26 | 'stocks.html', | 35 | 'stocks.html', |
27 | { | 36 | { |
28 | page_title: 'Stock', | 37 | page_title: 'Stock', |
29 | stocks_array: stocks_array | 38 | stocks_array: stocks_array |
30 | } | 39 | } |
31 | ); | 40 | ); |
32 | 41 | ||
33 | } | 42 | } |
34 | 43 | ||
35 | router.get('/', pageIndex); | 44 | router.get('/', pageIndex); |
lib/modem-dashboard/views/stocks.html
1 | {% extends "template.html" %} | 1 | {% extends "template.html" %} |
2 | 2 | ||
3 | {% block content %} | 3 | {% block content %} |
4 | 4 | ||
5 | {% if stocks_array %} | ||
5 | <table id="stocks" class="table table-hover table-striped"> | 6 | <table id="stocks" class="table table-hover table-striped"> |
6 | {% for stock in stocks_array %} | 7 | {% for stock in stocks_array %} |
7 | <tr> | 8 | <tr> |
8 | <td>{{ stock.name }}</td> | 9 | <td>{{ stock.name }}</td> |
9 | <td>{{ stock.balance }}</td> | 10 | <td>{{ stock.balance }}</td> |
10 | </tr> | 11 | </tr> |
11 | {% endfor %} | 12 | {% endfor %} |
12 | </table> | 13 | </table> |
13 | 14 | ||
15 | {% else %} | ||
16 | Data tidak tersedia | ||
17 | {% endif %} | ||
18 | |||
14 | {% endblock %} | 19 | {% endblock %} |
15 | 20 |