mirror of
https://gitlab.silvrtree.co.uk/martind2000/old-silvrgit.git
synced 2025-01-10 17:25:09 +00:00
temp and weight
This commit is contained in:
parent
bf32417c19
commit
839a9cd843
146
app/js/temp.js
146
app/js/temp.js
@ -1,108 +1,54 @@
|
||||
var app = angular.module( "Temp", []);
|
||||
app.controller(
|
||||
"TempController",
|
||||
function( $scope, tempService) {
|
||||
var app = angular.module( "Temp", [])
|
||||
.controller("TempController", function( $scope, tempService) {
|
||||
|
||||
$scope.tempData = [];
|
||||
$scope.tempData = [];
|
||||
|
||||
loadRemoteData();
|
||||
loadRemoteData();
|
||||
|
||||
function applyRemoteData(newData)
|
||||
{
|
||||
$scope.tempData = newData;
|
||||
}
|
||||
|
||||
function loadRemoteData() {
|
||||
tempService.getTemp()
|
||||
.then(
|
||||
function(tempData) {
|
||||
applyRemoteData(tempData);
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
app.service(
|
||||
"tempService",
|
||||
function($http, $q) {
|
||||
return({getTemp:getTemp});
|
||||
|
||||
function getTemp() {
|
||||
var request = $http({
|
||||
method: "get",
|
||||
url:"http://api.silvrtree.co.uk/temp/all",
|
||||
params: {
|
||||
/* action:"get"*/
|
||||
}
|
||||
});
|
||||
return (request.then(handleSuccess, handleError));
|
||||
}
|
||||
|
||||
|
||||
function handleError(response) {
|
||||
if ( !angular.isObject(response.data) || !response.data.message) {
|
||||
return( $q.reject("An unknown error occured"));
|
||||
function applyRemoteData(newData)
|
||||
{
|
||||
$scope.tempData = newData;
|
||||
}
|
||||
|
||||
return($q.reject(response.data.message));
|
||||
function loadRemoteData() {
|
||||
console.log('Loading data...');
|
||||
tempService.getTemp()
|
||||
.then(
|
||||
function(tempData) {
|
||||
applyRemoteData(tempData);
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
).service(
|
||||
"tempService",
|
||||
function($http, $q) {
|
||||
return({getTemp:getTemp});
|
||||
|
||||
function getTemp() {
|
||||
var request = $http({
|
||||
method: "get",
|
||||
url:"http://api.silvrtree.co.uk/temp/all",
|
||||
params: {
|
||||
/* action:"get"*/
|
||||
}
|
||||
});
|
||||
return (request.then(handleSuccess, handleError));
|
||||
}
|
||||
|
||||
|
||||
function handleError(response) {
|
||||
if ( !angular.isObject(response.data) || !response.data.message) {
|
||||
return( $q.reject("An unknown error occured"));
|
||||
}
|
||||
|
||||
return($q.reject(response.data.message));
|
||||
}
|
||||
|
||||
function handleSuccess(response)
|
||||
{
|
||||
return(response.data);
|
||||
}
|
||||
|
||||
function handleSuccess(response)
|
||||
{
|
||||
return(response.data);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(function () {
|
||||
console.log('Starting socket?');
|
||||
var url = "ws://api.silvrtree.co.uk:8039";
|
||||
|
||||
var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket;
|
||||
this.socket = new wsCtor(url, 'stream');
|
||||
|
||||
|
||||
|
||||
|
||||
this.handleData = function(d) {
|
||||
switch(d.id) {
|
||||
case 'LightingDataReceived':
|
||||
// this.updateLighting(d.sensorData.d);
|
||||
break;
|
||||
case 'ProjectorDataReceived':
|
||||
// this.updateProj(d.sensorData.d);
|
||||
break;
|
||||
case 'HeatingDataReceived':
|
||||
break;
|
||||
default:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.handleWebsocketMessage = function (message) {
|
||||
try {
|
||||
var command = JSON.parse(message.data);
|
||||
}
|
||||
catch (e) { /* do nothing */
|
||||
}
|
||||
|
||||
if (command) {
|
||||
//this.dispatchCommand(command);
|
||||
this.handleData(command);
|
||||
}
|
||||
};
|
||||
|
||||
this.handleWebsocketClose = function () {
|
||||
alert("WebSocket Connection Closed.");
|
||||
};
|
||||
|
||||
this.socket.onmessage = this.handleWebsocketMessage.bind(this);
|
||||
this.socket.onclose = this.handleWebsocketClose.bind(this);
|
||||
})();
|
||||
);
|
47
app/js/tempSocket.js
Normal file
47
app/js/tempSocket.js
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
(function () {
|
||||
console.log('Starting socket?');
|
||||
var url = "ws://api.silvrtree.co.uk:8039";
|
||||
|
||||
var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket;
|
||||
this.socket = new wsCtor(url, 'stream');
|
||||
|
||||
|
||||
|
||||
|
||||
this.handleData = function(d) {
|
||||
switch(d.id) {
|
||||
case 'LightingDataReceived':
|
||||
// this.updateLighting(d.sensorData.d);
|
||||
break;
|
||||
case 'ProjectorDataReceived':
|
||||
// this.updateProj(d.sensorData.d);
|
||||
break;
|
||||
case 'HeatingDataReceived':
|
||||
break;
|
||||
default:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.handleWebsocketMessage = function (message) {
|
||||
try {
|
||||
var command = JSON.parse(message.data);
|
||||
}
|
||||
catch (e) { /* do nothing */
|
||||
}
|
||||
|
||||
if (command) {
|
||||
//this.dispatchCommand(command);
|
||||
this.handleData(command);
|
||||
}
|
||||
};
|
||||
|
||||
this.handleWebsocketClose = function () {
|
||||
alert("WebSocket Connection Closed.");
|
||||
};
|
||||
|
||||
this.socket.onmessage = this.handleWebsocketMessage.bind(this);
|
||||
this.socket.onclose = this.handleWebsocketClose.bind(this);
|
||||
})();
|
@ -1,17 +1,22 @@
|
||||
var app = angular.module("Weight", []);
|
||||
app.controller("WeightController", function ($scope, weightService) {
|
||||
$scope.newWeight = 0;
|
||||
app.controller("WeightController", function ($scope, weightService) {
|
||||
$scope.newWeight = 0.0;
|
||||
|
||||
$scope.weightData = [];
|
||||
|
||||
loadRemoteData();
|
||||
$scope.submitForm = function () {
|
||||
"use strict";
|
||||
console.log('Submitting..');
|
||||
console.log($scope.newWeight);
|
||||
$http({method: 'post', url: '/weight', params: {weight: $scope.newWeight}});
|
||||
};
|
||||
|
||||
loadRemoteData();
|
||||
|
||||
function applyRemoteData(newData) {
|
||||
$scope.weightData = newData;
|
||||
}
|
||||
|
||||
|
||||
function loadRemoteData() {
|
||||
weightService.getWeight()
|
||||
.then(
|
||||
@ -21,14 +26,9 @@ app.controller("WeightController", function ($scope, weightService) {
|
||||
)
|
||||
}
|
||||
|
||||
$scope.submitForm = function() {
|
||||
"use strict";
|
||||
console.log('Submitting..');
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
app.service(
|
||||
"weightService",
|
||||
function ($http, $q) {
|
||||
@ -52,7 +52,6 @@ app.service(
|
||||
|
||||
}
|
||||
|
||||
|
||||
function handleError(response) {
|
||||
if (!angular.isObject(response.data) || !response.data.message) {
|
||||
return ( $q.reject("An unknown error occured"));
|
||||
|
41
single.js
Normal file
41
single.js
Normal file
@ -0,0 +1,41 @@
|
||||
var express = require('express'), path = require('path'), http = require('http')
|
||||
;
|
||||
var app = express();
|
||||
GLOBAL.lastcheck = 0;
|
||||
var btcCache = {}, fxCache = {} , trainCache = {};
|
||||
|
||||
app.configure(function () {
|
||||
app.set('port', process.env.PORT || 4545);
|
||||
app.set('view engine', 'ejs');
|
||||
app.use(express.logger('dev'));
|
||||
app.use(express.cookieParser());
|
||||
app.use(express.session({secret: '1234567890QWERTY'}));
|
||||
/* 'default', 'short', 'tiny', 'dev' */
|
||||
app.use(express.methodOverride());
|
||||
|
||||
app.use(express.bodyParser());
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
||||
next();
|
||||
});
|
||||
app.use(app.router);
|
||||
app.use(express.static(path.join(__dirname, 'app')));
|
||||
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
|
||||
|
||||
app.get('/temp', function (req, res) {
|
||||
res.render('pages/temp');
|
||||
});
|
||||
|
||||
app.get('/weight', function (req, res) {
|
||||
res.render('pages/weight');
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* create the server
|
||||
*/
|
||||
http.createServer(app).listen(app.get('port'), function () {
|
||||
console.log("Express server listening on port " + app.get('port'));
|
||||
});
|
@ -1,12 +1,34 @@
|
||||
<% include ../partials/angular_head %>
|
||||
<!DOCTYPE html>
|
||||
<html ng-app="Temp">
|
||||
<head>
|
||||
<title>Temp</title>
|
||||
<style>
|
||||
a[ ng-click ] {
|
||||
color: #ff00cc;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
<link href="//fonts.googleapis.com/css?family=Roboto+Slab:400,300,700" rel="stylesheet" type="text/css">
|
||||
<link rel="stylesheet" type="text/css" href="css/mui.css">
|
||||
<link rel="stylesheet" type="text/css" href="../css/mui.css">
|
||||
<style>
|
||||
body{font-family:'Roboto Slab', "Helvetica Neue", Helvetica, Arial}ul{margin:0;padding:0}li{display:inline;margin:0;padding:0 4px 0 0}.dates{padding:2px;border:solid 1px #80007e;background-color:#ffffff}#btc,#fx{font-size:75%}.up,.ontime{color:darkgreen}.down,.delayed{color:darkred}.nochange{color:#000000}.password{border:1px solid #cccccc;background-color:#efefef;font-family:monospace;white-space:pre}.mui--text-danger{color:#F44336}
|
||||
</style>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/sugar/1.4.1/sugar.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body ng-controller="TempController">
|
||||
<div class="CSSTableGenerator">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Date</td>
|
||||
<td>Reading</td>
|
||||
</tr>
|
||||
<div class="mui-container">
|
||||
<table class="mui-table">
|
||||
<tr>
|
||||
<td>Date</td>
|
||||
<td>Reading</td>
|
||||
</tr>
|
||||
<tr ng-repeat="entry in tempData" >
|
||||
<td>{{ entry.date }}</td><td>{{ entry.reading }}</td>
|
||||
</tr>
|
||||
@ -14,7 +36,11 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="js/weight.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
<script src="js/temp.js"></script>
|
||||
|
||||
|
||||
|
||||
</html>
|
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<html ng-app="Temp">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
|
||||
@ -12,51 +12,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="css/mui.css">
|
||||
<link rel="stylesheet" type="text/css" href="../css/mui.css">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Roboto Slab', "Helvetica Neue", Helvetica, Arial;
|
||||
}
|
||||
ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
li {
|
||||
display: inline;
|
||||
margin: 0;
|
||||
padding: 0 4px 0 0;
|
||||
}
|
||||
|
||||
.dates {
|
||||
padding: 2px;
|
||||
border: solid 1px #80007e;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
#btc, #fx {
|
||||
font-size: 75%;
|
||||
}
|
||||
|
||||
.up, .ontime {
|
||||
color: darkgreen;
|
||||
}
|
||||
|
||||
.down, .delayed {
|
||||
color: darkred;
|
||||
}
|
||||
|
||||
.nochange {
|
||||
color: #000000;
|
||||
}
|
||||
.password {
|
||||
border: 1px solid #cccccc;
|
||||
background-color: #efefef;
|
||||
font-family: monospace;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.mui--text-danger {
|
||||
color: #F44336;
|
||||
}
|
||||
body{font-family:'Roboto Slab', "Helvetica Neue", Helvetica, Arial}ul{margin:0;padding:0}li{display:inline;margin:0;padding:0 4px 0 0}.dates{padding:2px;border:solid 1px #80007e;background-color:#ffffff}#btc,#fx{font-size:75%}.up,.ontime{color:darkgreen}.down,.delayed{color:darkred}.nochange{color:#000000}.password{border:1px solid #cccccc;background-color:#efefef;font-family:monospace;white-space:pre}.mui--text-danger{color:#F44336}
|
||||
</style>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user