59 lines
No EOL
1.3 KiB
JavaScript
59 lines
No EOL
1.3 KiB
JavaScript
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();
|
|
}]
|
|
}
|
|
|
|
});
|
|
|
|
$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);
|
|
});
|
|
}
|
|
|
|
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;
|
|
});
|
|
}
|
|
|
|
o.irTest = function ( ) {
|
|
return $http.get('/irTest');
|
|
}
|
|
|
|
return o;
|
|
}]);
|
|
|
|
app.controller('MainCtrl', ['$scope', 'arduino', function ($scope, arduino){
|
|
|
|
$scope.RCs = arduino.RCs;
|
|
|
|
$scope.sendRC = function(RC){
|
|
arduino.sendRC(RC);
|
|
};
|
|
|
|
$scope.irTest = function(){
|
|
arduino.irTest();
|
|
};
|
|
|
|
}]); |