-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
167 lines (153 loc) · 5.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stock Data Viewer</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style>
.button-wrapper{
text-align: right;
margin-top: 15px;
}
</style>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Stock Data Viewer</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/mohitkh7/stock-data-viewer" target="blank"> View Source Code</a></li>
</ul>
</div>
</div>
</nav>
<div class="container" data-ng-app="app" data-ng-controller="stock">
<h3>Stock Data</h3>
<hr>
<!-- alert message section -->
<div ng-if="is_success || is_error">
<div ng-class="is_success ? 'alert alert-success alert-dismissible': 'alert alert-danger alert-dismissible'">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
{{ alert_message }}
</div>
</div>
<!-- table options -->
<div class="form-group row">
<div class="col-xs-6 col-md-4 col-lg-3">
<label for="filter_text" class="control-label">Filter Records by Share Name : </label>
<input class="form-control" id="filter_text" type="text" placeholder="stock name"ng-model="filter_text" ng-change="filter()">
</div>
<div class="col-xs-6 col-md-offset-4 col-md-4 col-lg-offset-6 col-lg-3 button-wrapper">
<button class="btn btn-primary" ng-disabled="is_btn_disable" ng-click="updateStockData()">Fetch Latest Data</button>
</div>
</div>
<!-- data table -->
<div class="table-responsive">
<table class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th>Stock Code</th>
<th>Stock Name</th>
<th>Open</th>
<th>High</th>
<th>Low</th>
<th>Close</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="s in stock | limitTo : limit">
<td>{{ s.CODE }}</td>
<td>{{ s.NAME }}</td>
<td>{{ s.OPEN }}</td>
<td>{{ s.HIGH }}</td>
<td>{{ s.LOW }}</td>
<td>{{ s.CLOSE }}</td>
</tr>
<tr ng-if="stock.length == 0">
<td colspan="6" class="text-center text-danger">No Stock Record Found</td>
</tr>
</tbody>
</table>
</div>
<p class="text-muted text-right" ng-if="stock.length">Showing {{ limit < stock.length ? limit: stock.length }} out {{ allstock.length }} Results</p>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script>
var app = angular.module('app', []);
app.controller('stock', function($scope, $http) {
const URL = "/data";
$scope.filter_text = "";
$scope.limit = 10;
$scope.is_btn_disable = false;
$scope.is_success = false;
$scope.is_error = false;
$scope.alert_message = "";
$scope.getStockData = function(){
// make API call to get stock data
$scope.is_error = false;
$http({
url: URL,
method: "GET",
})
.then(function(resp){
$scope.allstock = JSON.parse(resp.data);
console.log(JSON.parse(resp.data).length + " stock records fetched");
$scope.filter();
}, function(err){
$scope.stock = [];
$scope.is_error = true;
$scope.alert_message = "Error occured while fetching stock data";
console.log($scope.alert_message);
});
}
$scope.updateStockData = function() {
// make API call to update to latest stock data
$scope.is_error = false;
$scope.is_success = false;
$scope.is_btn_disable = true;
$http({
url: "/update",
method: "GET",
})
.then(function(resp){
data = JSON.parse(resp.data);
console.log(data["message"]);
if (data["status"] == 1) {
$scope.is_success = true;
$scope.getStockData();
}
else
$scope.is_error = true;
$scope.is_btn_disable = false;
$scope.alert_message = data["message"];
}, function(err){
console.log("Error occured while updating stock data");
$scope.is_btn_disable = false;
$scope.is_error = true;
$scope.alert_message = "Error occured while updating stock data";
});
}
// filter stock by name
$scope.filter = function(arr) {
$scope.stock = $scope.allstock.filter(el => { return el["NAME"].includes($scope.filter_text.toUpperCase())});
}
// execute on initalization(load) of page
angular.element(function () {
$scope.getStockData();
});
});
</script>
</html>