mirror of
https://github.com/corda/corda.git
synced 2024-12-21 22:07:55 +00:00
Added loading and fixed date updating.
This commit is contained in:
parent
179691f7e4
commit
8324cef612
@ -11,6 +11,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="semantic/semantic.css">
|
||||
|
||||
<script src="bower_components/jquery/dist/jquery.js"></script>
|
||||
<script src="bower_components/lodash/lodash.js"></script>
|
||||
<script src="semantic/semantic.js"></script>
|
||||
<script src="bower_components/angular/angular.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
@ -21,7 +22,11 @@
|
||||
</div>
|
||||
<div class="ui container">
|
||||
<div class="ui negative message" id="http-error" ng-show="httpError">{{httpError}}</div>
|
||||
<div class="ui info message" id="info-message" ng-show="infoMsg">{{infoMsg}}</div>
|
||||
<div class="ui secondary menu">
|
||||
<div class="ui active dimmer" ng-show="isLoading()">
|
||||
<div class="ui text loader">Loading</div>
|
||||
</div>
|
||||
<div class="left item">
|
||||
<div class="ui left labeled button">
|
||||
<span class="ui basic label">{{date.year}}</span>
|
||||
|
@ -5,21 +5,31 @@ let irsViewer = angular.module('irsViewer', []);
|
||||
let nodeService = irsViewer.factory('nodeService', ($http) => {
|
||||
return new (function() {
|
||||
var date = new Date(2016, 0, 1, 0, 0, 0);
|
||||
var curLoading = {};
|
||||
|
||||
var load = (type, promise) => {
|
||||
curLoading[type] = true;
|
||||
return promise.then((arg1) => {
|
||||
curLoading[type] = false;
|
||||
return arg1;
|
||||
});
|
||||
}
|
||||
|
||||
var changeDateOnNode = (newDate) => {
|
||||
// Produces yyyy-dd-mm. JS is missing proper date formatting libs
|
||||
const dateStr = newDate.toISOString().substring(0, 10);
|
||||
return $http.put('http://localhost:31338/api/irs/demodate', "\"" + dateStr + "\"").then((resp) => {
|
||||
return load('date', $http.put('http://localhost:31338/api/irs/demodate', "\"" + dateStr + "\"")).then((resp) => {
|
||||
date = newDate;
|
||||
return this.getDateModel(date);
|
||||
});
|
||||
}
|
||||
|
||||
this.getDate = () => {
|
||||
return {
|
||||
year: date.getFullYear(),
|
||||
month: date.getMonth() + 1, // Month is zero indexed
|
||||
day: date.getDate()
|
||||
};
|
||||
return load('date', $http.get('http://localhost:31338/api/irs/demodate')).then((resp) => {
|
||||
const parts = resp.data.split("-");
|
||||
date = new Date(parts[0], parts[1] - 1, parts[2]); // JS uses 0 based months
|
||||
return this.getDateModel(date);
|
||||
});
|
||||
}
|
||||
|
||||
this.updateDate = (type) => {
|
||||
@ -40,6 +50,26 @@ let nodeService = irsViewer.factory('nodeService', ($http) => {
|
||||
|
||||
return changeDateOnNode(newDate);
|
||||
};
|
||||
|
||||
this.getDeals = () => {
|
||||
return load('deals', $http.get('http://localhost:31338/api/irs/deals')).then((resp) => {
|
||||
return resp.data;
|
||||
});
|
||||
}
|
||||
|
||||
this.getDateModel = (date) => {
|
||||
return {
|
||||
"year": date.getFullYear(),
|
||||
"month": date.getMonth() + 1, // JS uses 0 based months
|
||||
"day": date.getDate()
|
||||
};
|
||||
}
|
||||
|
||||
this.isLoading = () => {
|
||||
return _.reduce(Object.keys(curLoading), (last, key) => {
|
||||
return (last || curLoading[key]);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -49,11 +79,12 @@ irsViewer.controller('HomeController', ($http, $scope, nodeService) => {
|
||||
$scope.httpError = resp.data
|
||||
}
|
||||
|
||||
$scope.isLoading = nodeService.isLoading;
|
||||
$scope.infoMsg = "";
|
||||
$scope.errorText = "";
|
||||
$scope.date = nodeService.getDate();
|
||||
$scope.updateDate = (type) => { nodeService.updateDate(type).then((newDate) => {$scope.date = newDate}, handleHttpFail) };
|
||||
$scope.date = { "year": "...", "month": "...", "day": "..." };
|
||||
$scope.updateDate = (type) => { nodeService.updateDate(type).then((newDate) => {$scope.date = newDate}, handleHttpFail); };
|
||||
|
||||
$http.get('http://localhost:31338/api/irs/deals').then((resp) => {
|
||||
$scope.deals = resp.data;
|
||||
});
|
||||
nodeService.getDate().then((date) => $scope.date = date);
|
||||
nodeService.getDeals().then((deals) => $scope.deals = deals);
|
||||
})
|
Loading…
Reference in New Issue
Block a user