Delete PointGroupItems before deleting points CC: @connorRigby

pull/1492/head
Rick Carlino 2019-10-03 13:52:00 -05:00
parent 1507eb51f8
commit 42d931ad3e
7 changed files with 44 additions and 16 deletions

View File

@ -60,6 +60,7 @@ module CeleryScriptSettingsBag
BAD_PIN_TYPE = '"%s" is not a type of pin. Allowed values: %s'
BAD_POINTER_ID = "Bad point ID: %s"
BAD_POINTER_TYPE = '"%s" is not a type of point. Allowed values: %s'
BAD_POINT_GROUP_ID = "Can't find PointGroup with id of %s"
BAD_REGIMEN = "Regimen #%s does not exist."
BAD_RESOURCE_ID = "Can't find %s with id of %s"
BAD_RESOURCE_TYPE = '"%s" is not a valid resource_type. Allowed values: %s'
@ -194,6 +195,13 @@ module CeleryScriptSettingsBag
node.invalidate!(BAD_POINTER_ID % node.value) if bad_node
end,
},
point_group_id: {
defn: [v(:integer)],
blk: ->(node, device) do
bad_node = !PointGroup.where(id: node.value, device_id: device.id).exists?
node.invalidate!(BAD_POINT_GROUP_ID % node.value) if bad_node
end,
},
pointer_type: {
defn: [e(:PointType)],
},
@ -515,10 +523,10 @@ module CeleryScriptSettingsBag
end,
},
point_group: {
args: [:resource_id],
args: [:point_group_id],
tags: [:data, :list_like],
blk: ->(n) do
resource_id = n.args.fetch(:resource_id).value
resource_id = n.args.fetch(:point_group_id).value
check_resource_type(n, "PointGroup", resource_id, Device.current)
end,
},

View File

@ -1,6 +1,6 @@
class PointGroup < ApplicationRecord
SORT_TYPES =
%w(xy_ascending xy_decending yx_ascending yx_decending random).sort
%w(xy_ascending xy_descending yx_ascending yx_descending random).sort
BAD_SORT = "%{value} is not valid. Valid options are: " +
SORT_TYPES.map(&:inspect).join(", ")

View File

@ -6,23 +6,23 @@
# CeleryScript is a tree of PrimaryNode objects in the center and primitive
# "EdgeNode" types on the edge of the tree.
class PrimaryNode < ApplicationRecord
belongs_to :sequence
belongs_to :sequence
validates_presence_of :sequence
has_many :edge_nodes
has_many :edge_nodes
BAD_KIND = "`kind` must be one of: " +
CeleryScriptSettingsBag::ANY_NODE_NAME.join(", ")
CeleryScriptSettingsBag::ANY_NODE_NAME.join(", ")
validates :kind, inclusion: { in: CeleryScriptSettingsBag::ANY_NODE_NAME,
message: BAD_KIND,
allow_nil: false }
validates :parent_arg_name,
inclusion: {in: CeleryScriptSettingsBag::ANY_ARG_NAME,
message: BAD_KIND,
allow_nil: true}
inclusion: { in: CeleryScriptSettingsBag::ANY_ARG_NAME,
message: BAD_KIND,
allow_nil: true }
before_save :next_must_be_body_node
def next_must_be_body_node
raise "NO!" if(next_id && self.class.find(next_id).parent_arg_name)
raise "NO!" if (next_id && self.class.find(next_id).parent_arg_name)
end
def parent

View File

@ -1,3 +1,21 @@
module PointGroups
Destroy = CreateDestroyer.run!(resource: PointGroup)
class Destroy < Mutations::Command
required do
model :device, class: Device
model :point_group, class: PointGroup
end
def validate
# binding.pry
end
def execute
point_group.destroy! && ""
end
private
def in_use?
end
end
end

View File

@ -46,8 +46,11 @@ module Points
points.destroy_all
else
Point.transaction do
archive_points
destroy_all_others
PointGroupItem.transaction do
PointGroupItem.where(point_id: point_ids || point.id).destroy_all
archive_points
destroy_all_others
end
end
end
end

View File

@ -31,7 +31,6 @@ export const createGroup = ({ points, name }: CreateGroupProps) => {
const action = init("PointGroup", group);
dispatch(action);
return dispatch(save(action.payload.uuid)).then(() => {
console.log("==");
const pg = findPointGroup(getState().resources.index, action.payload.uuid);
const { id } = pg.body;
history.push("/app/designer/groups/" + (id ? id : ""));

View File

@ -238,7 +238,7 @@ describe CeleryScript::Corpus do
point_ids: [])
bad = CeleryScript::AstNode.new({
kind: "point_group",
args: { resource_id: pg.id },
args: { point_group_id: pg.id },
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be true
@ -249,7 +249,7 @@ describe CeleryScript::Corpus do
device.auto_sync_transaction do
bad = CeleryScript::AstNode.new({
kind: "point_group",
args: { resource_id: -1 },
args: { point_group_id: -1 },
})
check = CeleryScript::Checker.new(bad, corpus, device)
expect(check.valid?).to be false