commit
0c8a7a98b2
|
@ -8,11 +8,14 @@ ctrl = [
|
|||
'Info'
|
||||
($scope, Data, Devices, Info) ->
|
||||
nope = (e) -> alert 'Doh!'; console.error e
|
||||
$scope.logs = Info.logs
|
||||
$scope.form = Devices
|
||||
$scope.logs = Info.logs
|
||||
$scope.device = Devices
|
||||
Devices.socket.on 'ready',->
|
||||
Devices.fetchLogs (d) -> Info.logs.push(data) for data in (d.data || [])
|
||||
$scope.createDevice = -> Devices.save().error(nope)
|
||||
$scope.updateCalibration = ->
|
||||
console.log 'wut'
|
||||
Devices.send("update_calibration", Devices)
|
||||
]
|
||||
controller =
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
angular.module('FarmBot').directive 'calibrationbutton', [ ->
|
||||
{
|
||||
restrict: 'AEC'
|
||||
template: '<button
|
||||
class="button-like"
|
||||
ng-class="{red: !isTrue(), green: isTrue()}"
|
||||
type="button">
|
||||
{{ label() }}
|
||||
</button>'
|
||||
scope: toggleval: '@'
|
||||
link: ($scope, el, attr) ->
|
||||
el.on 'click', -> $scope.toggle()
|
||||
controller: [
|
||||
'$scope'
|
||||
'Devices'
|
||||
($scope, Devices) ->
|
||||
$scope.isTrue = -> if Devices[@toggleval] then yes else no
|
||||
$scope.label = ->
|
||||
if Devices[@toggleval] then 'YES' else 'NO'
|
||||
$scope.toggle = ->
|
||||
Devices[this.toggleval] = if Devices[this.toggleval] then 0 else 1
|
||||
Devices.send("update_calibration", _.pick(Devices, this.toggleval))
|
||||
]
|
||||
}
|
||||
]
|
|
@ -13,6 +13,13 @@ class Command
|
|||
return Command.all[type](args)
|
||||
|
||||
@all:
|
||||
update_calibration: (the_whole_friggin_bot) ->
|
||||
{
|
||||
message_type: 'update_calibration'
|
||||
command: the_whole_friggin_bot
|
||||
}
|
||||
|
||||
|
||||
read_status: (values) ->
|
||||
message_type: 'read_status'
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ private
|
|||
if auth.success?
|
||||
@current_device = auth.result
|
||||
else
|
||||
binding.pry
|
||||
sorry("""You failed to authenticate with the API. Ensure that you have
|
||||
provided a `bot_token` and `bot_uuid` header in the HTTP request.
|
||||
""".squish, 401)
|
||||
|
|
|
@ -17,11 +17,9 @@ module Api
|
|||
|
||||
# PATCH/PUT /api/device
|
||||
def update
|
||||
current_device
|
||||
.if_null { create }
|
||||
.if_not_null do
|
||||
render json: current_device.update_attributes(device_params)
|
||||
end
|
||||
# Because of the way bots are shared, there is no true 'update' action.
|
||||
# Just a creation/reasignment of bots based on UUID / Token.
|
||||
create
|
||||
end
|
||||
|
||||
# DELETE /api/devices/1
|
||||
|
|
|
@ -4,18 +4,20 @@ module Devices
|
|||
|
||||
required do
|
||||
model :user, class: User
|
||||
string :uuid
|
||||
string :token
|
||||
end
|
||||
|
||||
optional do
|
||||
string :name, default: 'Not set.'
|
||||
string :uuid, default: 'Not set.'
|
||||
string :token, default: 'Not set.'
|
||||
end
|
||||
|
||||
def execute
|
||||
create Device, inputs.except(:user) do |dev|
|
||||
dev = Device.find_or_initialize_by(uuid: uuid, token: token)
|
||||
if update_attributes(dev, inputs.except(:user))
|
||||
user.update_attributes(device: dev)
|
||||
end
|
||||
dev
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,19 +40,19 @@
|
|||
.row
|
||||
.large-12.columns
|
||||
%label FarmBot Name *
|
||||
%input{id: 'botname', placeholder: "Brocolli Overlord", type: "text", ng_model: 'form.name', required: true}/
|
||||
%input{id: 'botname', placeholder: "Brocolli Overlord", type: "text", ng_model: 'device.name', required: true}/
|
||||
.row
|
||||
.large-6.columns
|
||||
%label UUID *
|
||||
%input{placeholder: "ad698900-2546-11e3-87fb-c560cb0ca47b", type: "text", ng_model: 'form.uuid', required: true}/
|
||||
%input{placeholder: "ad698900-2546-11e3-87fb-c560cb0ca47b", type: "text", ng_model: 'device.uuid', required: true}/
|
||||
.large-6.columns
|
||||
%label Security Token *
|
||||
%input{placeholder: "4bbd2jm242dl5wmimbwz4rvlu77m0a4i", type: "text", ng_model: 'form.token', required: true}/
|
||||
%input{placeholder: "4bbd2jm242dl5wmimbwz4rvlu77m0a4i", type: "text", ng_model: 'device.token', required: true}/
|
||||
.row
|
||||
.large-12.columns
|
||||
%button.green.button-like
|
||||
{{ !!form._id ? "Update" : "Add" }} FarmBot
|
||||
%button.gray.button-like{ng_if: '!!form._id', ng_click: 'refreshLogs()', type: 'button'}
|
||||
{{ !!device._id ? "Update" : "Add" }} FarmBot
|
||||
%button.gray.button-like{ng_if: '!!device._id', ng_click: 'refreshLogs()', type: 'button'}
|
||||
Fetch Logs
|
||||
/ sorry
|
||||
%br
|
||||
|
@ -69,11 +69,9 @@
|
|||
%thead
|
||||
%tr
|
||||
%th.row-axis Axis
|
||||
%th.row-length Length
|
||||
%th.row-input Max Speed
|
||||
%th.row-input Accelerate For
|
||||
%th.row-input Timeout After
|
||||
%th.row-input Steps Per mm
|
||||
%th.row-invert
|
||||
Invert
|
||||
%br
|
||||
|
@ -82,36 +80,65 @@
|
|||
Invert
|
||||
%br
|
||||
Motor
|
||||
%th.row-invert Negatives
|
||||
%tbody
|
||||
%tr
|
||||
%td X
|
||||
%td 1.23 m
|
||||
%td
|
||||
%input
|
||||
%input{ng_model: "device.MOVEMENT_MAX_SPD_X"}
|
||||
%br
|
||||
mm/s
|
||||
%td
|
||||
%input
|
||||
%input{ng_model: "device.MOVEMENT_STEPS_ACC_DEC_X"}
|
||||
%br
|
||||
steps
|
||||
%td
|
||||
%input
|
||||
%input{ng_model: "device.MOVEMENT_TIMEOUT_X"}
|
||||
%br
|
||||
seconds
|
||||
%td
|
||||
%input
|
||||
%calibrationbutton{toggleval: "MOVEMENT_INVERT_ENDPOINTS_X"}
|
||||
%td
|
||||
%calibrationbutton{toggleval: "MOVEMENT_INVERT_MOTOR_Y"}
|
||||
%tr
|
||||
%td Y
|
||||
%td
|
||||
%input{ng_model: "device.MOVEMENT_MAX_SPD_Y"}
|
||||
%br
|
||||
mm/s
|
||||
%td
|
||||
%input{ng_model: "device.MOVEMENT_STEPS_ACC_DEC_Y"}
|
||||
%br
|
||||
steps
|
||||
%td
|
||||
%button.xx-small.green YES
|
||||
%input{ng_model: "device.MOVEMENT_TIMEOUT_Y"}
|
||||
%br
|
||||
seconds
|
||||
%td
|
||||
%button.xx-small.green YES
|
||||
%calibrationbutton{toggleval: "MOVEMENT_INVERT_ENDPOINTS_Y"}
|
||||
%td
|
||||
%button.xx-small.red NO
|
||||
%calibrationbutton{toggleval: "MOVEMENT_INVERT_MOTOR_Y"}
|
||||
%tr
|
||||
%td Z
|
||||
%td
|
||||
%input{ng_model: "device.MOVEMENT_MAX_SPD_Z"}
|
||||
%br
|
||||
mm/s
|
||||
%td
|
||||
%input{ng_model: "device.MOVEMENT_STEPS_ACC_DEC_Z"}
|
||||
%br
|
||||
steps
|
||||
%td
|
||||
%input{ng_model: "device.MOVEMENT_TIMEOUT_Z"}
|
||||
%br
|
||||
seconds
|
||||
%td
|
||||
%calibrationbutton{toggleval: "MOVEMENT_INVERT_ENDPOINTS_Z"}
|
||||
%td
|
||||
%calibrationbutton{toggleval: "MOVEMENT_INVERT_MOTOR_Z"}
|
||||
%p
|
||||
%button.xx-small.yellow.pull-right
|
||||
%button.xx-small.yellow.pull-right{ng_click: "updateCalibration()"}
|
||||
calibrate
|
||||
|
||||
.row
|
||||
.small-12.columns
|
||||
.row
|
||||
|
|
|
@ -7,6 +7,7 @@ describe Api::DevicesController do
|
|||
describe '#create' do
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:user2) { FactoryGirl.create(:user) }
|
||||
|
||||
it 'creates a new device for a user' do
|
||||
sign_in user
|
||||
|
@ -18,5 +19,15 @@ describe Api::DevicesController do
|
|||
expect(user.device).to eq(new_device)
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it 'shares devices between two users' do
|
||||
bot = user.device
|
||||
sign_in user2
|
||||
params = {name: 'Frank', uuid: bot.uuid, token: bot.token}
|
||||
post :create, params
|
||||
user.reload
|
||||
user2.reload
|
||||
expect(user.device._id).to eq(user2.device._id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,14 +9,15 @@ describe Api::DevicesController do
|
|||
describe '#update' do
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:user2) { FactoryGirl.create(:user) }
|
||||
|
||||
it 'updates a Device' do
|
||||
sign_in user
|
||||
fake_name = Faker::Name.name
|
||||
put :update, {id: user.device.id, name: fake_name}, format: :json
|
||||
put :update, {id: user.device.id, name: fake_name, uuid: 1, token: 2}, format: :json
|
||||
# put path, params, options
|
||||
user.reload
|
||||
device = user.device
|
||||
device = user.reload.device.reload
|
||||
expect(device.name).to eq(fake_name)
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
@ -25,12 +26,21 @@ describe Api::DevicesController do
|
|||
user.update_attributes(device: nil)
|
||||
sign_in user
|
||||
fake_name = Faker::Name.name
|
||||
put :update, {}, format: :json
|
||||
put :update, {uuid: 1, token: 2}, format: :json
|
||||
user.reload
|
||||
expect(user.device).to be_kind_of(Device)
|
||||
[:uuid, :token, :name].each do |key|
|
||||
expect(user.device[key]).to eq('Not set.')
|
||||
end
|
||||
expect(user.device['name']).to eq('Not set.')
|
||||
expect(user.device['uuid']).to eq('1')
|
||||
expect(user.device['token']).to eq('2')
|
||||
end
|
||||
|
||||
it 'shares devices between two users' do
|
||||
bot = user.device
|
||||
sign_in user2
|
||||
post :update, { name: 'Frank', uuid: bot.uuid, token: bot.token }
|
||||
user.reload
|
||||
user2.reload
|
||||
expect(user.device._id).to eq(user2.device._id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,10 +4,4 @@ describe 'Device Management' do
|
|||
include Capybara::Angular::DSL
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
# it 'adds a device', js: true do
|
||||
# pending
|
||||
# visit 'dashboard#/devices'
|
||||
# fill_in 'botname', with: 'LOL!@'
|
||||
# end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue