Partially implemented date handling.

This commit is contained in:
Clinton Alexander 2016-06-15 17:37:31 +01:00
parent 129f8ee518
commit 179691f7e4
2 changed files with 61 additions and 10 deletions

View File

@ -20,19 +20,20 @@
<span class="header item"><a href="./">Home</a></span>
</div>
<div class="ui container">
<div class="ui negative message" id="http-error" ng-show="httpError">{{httpError}}</div>
<div class="ui secondary menu">
<div class="left item">
<div class="ui left labeled button">
<span class="ui basic label">2016</span>
<button class="ui icon button"><i class="plus icon"></i></button>
<span class="ui basic label">{{date.year}}</span>
<button class="ui icon button" ng-click="updateDate('year')"><i class="plus icon"></i></button>
</div>
<div class="ui left labeled button">
<span class="ui basic label">01</span>
<button class="ui icon button"><i class="plus icon"></i></button>
<span class="ui basic label">{{date.month}}</span>
<button class="ui icon button" ng-click="updateDate('month')"><i class="plus icon"></i></button>
</div>
<div class="ui left labeled button">
<span class="ui basic label">01</span>
<button class="ui icon button"><i class="plus icon"></i></button>
<span class="ui basic label">{{date.day}}</span>
<button class="ui icon button" ng-click="updateDate('day')"><i class="plus icon"></i></button>
</div>
</div>
<div class="right item">

View File

@ -1,9 +1,59 @@
"use strict"
var irsViewer = angular.module('irsViewer', [])
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 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) => {
date = newDate;
});
}
this.getDate = () => {
return {
year: date.getFullYear(),
month: date.getMonth() + 1, // Month is zero indexed
day: date.getDate()
};
}
this.updateDate = (type) => {
let newDate = date;
switch(type) {
case "year":
newDate.setFullYear(date.getFullYear() + 1);
break;
case "month":
newDate.setMonth(date.getMonth() + 1);
break;
case "day":
newDate.setDate(date.getDate() + 1);
break;
}
return changeDateOnNode(newDate);
};
});
});
irsViewer.controller('HomeController', ($http, $scope, nodeService) => {
let handleHttpFail = (resp) => {
console.log(resp.data)
$scope.httpError = resp.data
}
$scope.errorText = "";
$scope.date = nodeService.getDate();
$scope.updateDate = (type) => { nodeService.updateDate(type).then((newDate) => {$scope.date = newDate}, handleHttpFail) };
irsViewer.controller('HomeController', ($http, $scope) => {
$http.get('http://localhost:31338/api/irs/deals').then((resp) => {
$scope.deals = resp.data
})
$scope.deals = resp.data;
});
})