Add new `Weed` PointerType

pull/1738/head
Rick Carlino 2020-03-22 18:32:00 -05:00
parent 1ba0ff7871
commit 3700406687
8 changed files with 52 additions and 4 deletions

View File

@ -46,5 +46,6 @@ module Resources
Plant => Points,
Point => Points,
ToolSlot => Points,
Weed => Points,
}
end # Resources

View File

@ -30,8 +30,8 @@ module CeleryScriptSettingsBag
ALLOWED_PACKAGES = %w(farmbot_os arduino_firmware)
ALLOWED_PIN_MODES = [DIGITAL = 0, ANALOG = 1]
ALLOWED_PIN_TYPES = PIN_TYPE_MAP.keys
ALLOWED_POINTER_TYPE = %w(GenericPointer ToolSlot Plant)
ALLOWED_RESOURCE_TYPE = %w(Device Point Plant ToolSlot GenericPointer)
ALLOWED_POINTER_TYPE = %w(GenericPointer ToolSlot Plant Weed)
ALLOWED_RESOURCE_TYPE = %w(Device Point Plant ToolSlot Weed GenericPointer)
ALLOWED_RPC_NODES = %w(assertion calibrate change_ownership
check_updates dump_info emergency_lock
emergency_unlock execute execute_script

View File

@ -8,6 +8,7 @@ class InUsePoint < ApplicationRecord
GenericPointer.name => DEFAULT_NAME,
ToolSlot.name => "slot",
Plant.name => "plant",
Weed.name => "weed"
}
def readonly?

View File

@ -4,7 +4,7 @@ class Point < ApplicationRecord
# axis value > 21k right now - RC
# Using real constants instead of strings results
# in circular dep. errors.
POINTER_KINDS = ["GenericPointer", "Plant", "ToolSlot"]
POINTER_KINDS = ["GenericPointer", "Plant", "ToolSlot", "Weed"]
self.inheritance_column = "pointer_type"
belongs_to :device

View File

@ -0,0 +1,4 @@
class Weed < Point
DEFAULT_ICON = "/app-resources/img/icons/generic-plant.svg"
ATTRS = %w(meta name plant_stage planted_at pointer_type radius x y z)
end

View File

@ -0,0 +1,19 @@
class WeedSerializer < BasePointSerializer
attributes :plant_stage, :planted_at, :radius, :meta
def x
object.x.round
end
def y
object.y.round
end
def z
object.z.round
end
def meta
object.meta || {}
end
end

View File

@ -45,7 +45,7 @@
"coveralls": "3.0.11",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.2",
"farmbot": "9.1.2",
"farmbot": "9.2.0-rc1",
"i18next": "19.3.3",
"install": "0.13.0",
"lodash": "4.17.15",

View File

@ -46,6 +46,29 @@ describe Api::PointsController do
end
end
it "creates a weed" do
sign_in user
time = (DateTime.now - 1.day).to_json
p = { x: 23,
y: 45,
name: "unwelcomed guest",
pointer_type: "Weed",
planted_at: time,
plant_stage: "sprouted" }
post :create, body: p.to_json, params: { format: :json }
expect(response.status).to eq(200)
weed = Weed.last
expect(weed.x).to eq(p[:x])
expect(weed.y).to eq(p[:y])
expect(weed.name).to eq(p[:name])
expect(weed.plant_stage).to eq("sprouted")
expect(p[:plant_stage]).to eq("sprouted")
expect(weed.created_at).to be_truthy
p.keys.each do |key|
expect(json).to have_key(key)
end
end
it "validates pointer_type" do
sign_in user
body = { pointer_type: "TypoPointer", x: 0, y: 0 }