This repository has been archived on 2024-01-30. You can view files and clone it, but cannot push or open issues or pull requests.
trev/nodejs/public/javascripts/angularApp.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-01-12 17:49:13 +01:00
var app = angular.module('autome', ['ui.router']);
app.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/home.html',
controller: 'MainCtrl',
resolve: {
postPromise: ['arduino', function(arduino) {
return arduino.getRCs();
}]
}
2016-01-12 17:49:13 +01:00
});
$urlRouterProvider.otherwise('home');
}]);
app.factory('arduino', ['$http', function($http){
var o = {
RCs: []
};
o.getRCs = function ( ) {
return $http.get('/getRCs').success(function(data) {
angular.copy(data, o.RCs);
});
2016-01-12 17:49:13 +01:00
}
o.sendRC = function (RC) {
var code = (RC.state) ? RC.off_value : RC.on_value;
return $http.post('/register', {code}).success(function (data) {
RC.state = (RC.state) ? false : true;
});
}
2016-01-21 22:01:57 +01:00
o.irTest = function ( ) {
return $http.get('/irTest');
}
2016-01-12 17:49:13 +01:00
return o;
}]);
app.controller('MainCtrl', ['$scope', 'arduino', function ($scope, arduino){
$scope.RCs = arduino.RCs;
2016-02-18 15:44:58 +01:00
$scope.sendRC = function(RC){
arduino.sendRC(RC);
};
2016-01-21 22:01:57 +01:00
$scope.irTest = function(){
arduino.irTest();
2016-01-21 22:01:57 +01:00
};
2016-01-12 17:49:13 +01:00
}]);