Merge pull request #89 from rickcarlino/master

July 1
pull/91/head
Rick Carlino 2014-07-01 07:42:28 -07:00
commit 70e7142a5c
8 changed files with 119 additions and 105 deletions

View File

@ -0,0 +1,89 @@
# The movement controller provides an indepth view of a device as well as fine-
# grained control options. The name is an artifact and needs to be changed.
# TODO: Network status indicator
# TODO: Device selection
# Run this in the command line for diagnostics.
# ======
# curl -X GET http://skynet.im/subscribe/713c69b1-e36a-11e3-93f8-f3e7e8d1cce9?token=0waw1l97lbwc23xrh0oem7d8rbai3sor --header "skynet_auth_uuid: 4bb4a961-e8e6-11e3-93f8-f3e7e8d1cce9" --header "skynet_auth_token: jce90gf7szxxyldihii1m3xv5d9jatt9"
angular.module('FarmBot').controller "MovementController", [
'$scope'
'Restangular'
($scope, Restangular) ->
$scope.x = 0
$scope.y = 0
$scope.z = 0
$scope.upx = ->
$scope.x = $scope.x + 5
$scope.upy = ->
$scope.y = $scope.y + 5
$scope.upz = ->
$scope.z = $scope.z + 5
$scope.downx = ->
$scope.x = $scope.x - 5
$scope.downy = ->
$scope.y = $scope.y - 5
$scope.downz = ->
$scope.z = $scope.z - 5
Restangular.all('devices').getList().then (data) ->
$scope.devices = data
$scope.device = data[0]
$scope.connectToSkyNet()
$scope.goHome = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: 0
y: 0
z: 0
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.goAbs = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: $scope.x
y: $scope.y
z: $scope.z
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.connectToSkyNet = ->
config =
type: "farmbotdss"
uuid: "901ba251-ed7a-11e3-995a-b7667747c514"
token: "32pwbkzd7qp06bt9zznee5xjhc7kfbt9"
protocol: "websocket"
skynet config, (e, socket) ->
throw e if e
$scope.socket = socket
$scope.socket.on "message", (message) ->
#TODO: Append all incoming messages to an array for display / unit tests.
console.log "message received", message
$scope.debug = ->
$scope.socket.emit "message", JSON.parse($scope.message), (data) ->
console.log data
]

View File

@ -1,14 +0,0 @@
# The Overview controller is in need of a better name. It should be called
# 'controlController' or something. The name 'overview' is somewhat of an
# artifact.
angular.module('FarmBot').controller "OverviewController", [
'$scope'
'Restangular'
'DeviceFactory'
($scope, Restangular, DeviceFactory) ->
Restangular.all('devices').getList().then (data) ->
$scope.devices = data
$scope.device = data[0]
$scope.device.connectToSkyNet()
]

View File

@ -1,89 +1,28 @@
# The overview controller provides an indepth view of a device as well as fine-
# grained controll options. Needs a better name.
# TODO: Network status indicator
# TODO: Device selection
# Run this in the command line for diagnostics.
# ======
# curl -X GET http://skynet.im/subscribe/713c69b1-e36a-11e3-93f8-f3e7e8d1cce9?token=0waw1l97lbwc23xrh0oem7d8rbai3sor --header "skynet_auth_uuid: 4bb4a961-e8e6-11e3-93f8-f3e7e8d1cce9" --header "skynet_auth_token: jce90gf7szxxyldihii1m3xv5d9jatt9"
# The deivce settings controller mostly handles SkyNet configuration options.
# If you're storing things related to a particular device and it's not an action
# it probably belongs in here.
app = angular.module('FarmBot')
angular.module('FarmBot').controller "OverviewController", [
'$scope'
'Restangular'
($scope, Restangular, Skynet) ->
controller = ($scope, Restangular) ->
$scope.devices = Restangular.all('devices').getList().$object
$scope.x = 0
$scope.y = 0
$scope.z = 0
$scope.device = {}
$scope.upx = ->
$scope.x = $scope.x + 5
$scope.upy = ->
$scope.y = $scope.y + 5
$scope.upz = ->
$scope.z = $scope.z + 5
$scope.downx = ->
$scope.x = $scope.x - 5
$scope.downy = ->
$scope.y = $scope.y - 5
$scope.downz = ->
$scope.z = $scope.z - 5
$scope.removeDevice = (device) ->
device.remove().then ->
$scope.devices = _.without($scope.devices, device);
Restangular.all('devices').getList().then (data) ->
$scope.devices = data
$scope.device = data[0]
$scope.connectToSkyNet()
$scope.selectDevice = (device) ->
$scope.device = device
$scope.goHome = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: 0
y: 0
z: 0
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.createDevice = ->
if typeof($scope.device._id) != 'undefined'
$scope.device.put().then (data) ->
$scope.device = {}
else
$scope.devices.post($scope.device).then (data) ->
$scope.devices.push(data)
$scope.device = {}
$scope.goAbs = ->
$scope.socket.emit "message",
devices: $scope.device.uuid
payload:
message_type: 'single_command'
time_stamp: new Date()
command:
action: 'MOVE ABSOLUTE'
x: $scope.x
y: $scope.y
z: $scope.z
speed: 100 # Not sure about this one.
amount: 0 # Is this for "DOSE WATER"?
delay: 0
, (data) ->
console.log data
return true
$scope.connectToSkyNet = ->
config =
type: "farmbotdss"
uuid: "901ba251-ed7a-11e3-995a-b7667747c514"
token: "32pwbkzd7qp06bt9zznee5xjhc7kfbt9"
protocol: "websocket"
skynet config, (e, socket) ->
throw e if e
$scope.socket = socket
$scope.socket.on "message", (message) ->
console.log "message received", message
$scope.debug = ->
$scope.socket.emit "message", JSON.parse($scope.message), (data) ->
console.log data
]
app.controller "SettingsController", ['$scope', 'Restangular', controller]

View File

@ -22,8 +22,8 @@ app.config [
).when("/settings",
templateUrl: "settings.html"
controller: "SettingsController"
).when("/overview",
templateUrl: "overview.html"
controller: "OverviewController"
).when("/movement",
templateUrl: "movement.html"
controller: "MovementController"
).otherwise redirectTo: "/main"
]

View File

@ -1,8 +1,8 @@
%div{'ng-app' => 'FarmBot'}
// TODO: Write a view helper that traverses /views/dashboard/ng-partials and
// includes them here.
%script{:id => "overview.html", :type => "text/ng-template"}
= render partial: "dashboard/ng-partials/overview"
%script{:id => "movement.html", :type => "text/ng-template"}
= render partial: "dashboard/ng-partials/movement"
%script{:id => "settings.html", :type => "text/ng-template"}
= render partial: "dashboard/ng-partials/settings"
%script{:id => "main.html", :type => "text/ng-template"}

View File

@ -19,8 +19,8 @@
%ul.left
-if current_user
%li{class: ("active" if current_page? page_path('#/settings'))}
= link_to 'Control', '/dashboard#/overview'
// TODO: Add CSS rul based on hash fragment.
= link_to 'Control', '/dashboard#/movement'
// TODO: Add CSS rule based on hash fragment?
%li{class: ("active" if current_page? page_path('#/settings'))}
= link_to 'Settings', '/dashboard#/settings'
%li{class: ("active" if current_page? page_path('help'))}

View File

@ -6,9 +6,9 @@ describe "Restauranteur controllers", ->
module("FarmBot")
inject ($controller) ->
@scope = {}
@ctrl = $controller("OverviewController", $scope: scope)
@ctrl = $controller("MovementController", $scope: scope)
describe "OverviewController", ->
describe "MovementController", ->
it "initializes X, Y and Z", ->
expect(scope.x).toBe(0)
expect(scope.y).toBe(0)