Delete PointGroupItems before deleting points CC: @connorRigby
parent
1507eb51f8
commit
42d931ad3e
|
@ -60,6 +60,7 @@ module CeleryScriptSettingsBag
|
||||||
BAD_PIN_TYPE = '"%s" is not a type of pin. Allowed values: %s'
|
BAD_PIN_TYPE = '"%s" is not a type of pin. Allowed values: %s'
|
||||||
BAD_POINTER_ID = "Bad point ID: %s"
|
BAD_POINTER_ID = "Bad point ID: %s"
|
||||||
BAD_POINTER_TYPE = '"%s" is not a type of point. Allowed values: %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_REGIMEN = "Regimen #%s does not exist."
|
||||||
BAD_RESOURCE_ID = "Can't find %s with id of %s"
|
BAD_RESOURCE_ID = "Can't find %s with id of %s"
|
||||||
BAD_RESOURCE_TYPE = '"%s" is not a valid resource_type. Allowed values: %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
|
node.invalidate!(BAD_POINTER_ID % node.value) if bad_node
|
||||||
end,
|
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: {
|
pointer_type: {
|
||||||
defn: [e(:PointType)],
|
defn: [e(:PointType)],
|
||||||
},
|
},
|
||||||
|
@ -515,10 +523,10 @@ module CeleryScriptSettingsBag
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
point_group: {
|
point_group: {
|
||||||
args: [:resource_id],
|
args: [:point_group_id],
|
||||||
tags: [:data, :list_like],
|
tags: [:data, :list_like],
|
||||||
blk: ->(n) do
|
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)
|
check_resource_type(n, "PointGroup", resource_id, Device.current)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class PointGroup < ApplicationRecord
|
class PointGroup < ApplicationRecord
|
||||||
SORT_TYPES =
|
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: " +
|
BAD_SORT = "%{value} is not valid. Valid options are: " +
|
||||||
SORT_TYPES.map(&:inspect).join(", ")
|
SORT_TYPES.map(&:inspect).join(", ")
|
||||||
|
|
||||||
|
|
|
@ -6,23 +6,23 @@
|
||||||
# CeleryScript is a tree of PrimaryNode objects in the center and primitive
|
# CeleryScript is a tree of PrimaryNode objects in the center and primitive
|
||||||
# "EdgeNode" types on the edge of the tree.
|
# "EdgeNode" types on the edge of the tree.
|
||||||
class PrimaryNode < ApplicationRecord
|
class PrimaryNode < ApplicationRecord
|
||||||
belongs_to :sequence
|
belongs_to :sequence
|
||||||
validates_presence_of :sequence
|
validates_presence_of :sequence
|
||||||
has_many :edge_nodes
|
has_many :edge_nodes
|
||||||
BAD_KIND = "`kind` must be one of: " +
|
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,
|
validates :kind, inclusion: { in: CeleryScriptSettingsBag::ANY_NODE_NAME,
|
||||||
message: BAD_KIND,
|
message: BAD_KIND,
|
||||||
allow_nil: false }
|
allow_nil: false }
|
||||||
validates :parent_arg_name,
|
validates :parent_arg_name,
|
||||||
inclusion: {in: CeleryScriptSettingsBag::ANY_ARG_NAME,
|
inclusion: { in: CeleryScriptSettingsBag::ANY_ARG_NAME,
|
||||||
message: BAD_KIND,
|
message: BAD_KIND,
|
||||||
allow_nil: true}
|
allow_nil: true }
|
||||||
|
|
||||||
before_save :next_must_be_body_node
|
before_save :next_must_be_body_node
|
||||||
|
|
||||||
def 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
|
end
|
||||||
|
|
||||||
def parent
|
def parent
|
||||||
|
|
|
@ -1,3 +1,21 @@
|
||||||
module PointGroups
|
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
|
end
|
||||||
|
|
|
@ -46,8 +46,11 @@ module Points
|
||||||
points.destroy_all
|
points.destroy_all
|
||||||
else
|
else
|
||||||
Point.transaction do
|
Point.transaction do
|
||||||
archive_points
|
PointGroupItem.transaction do
|
||||||
destroy_all_others
|
PointGroupItem.where(point_id: point_ids || point.id).destroy_all
|
||||||
|
archive_points
|
||||||
|
destroy_all_others
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,6 @@ export const createGroup = ({ points, name }: CreateGroupProps) => {
|
||||||
const action = init("PointGroup", group);
|
const action = init("PointGroup", group);
|
||||||
dispatch(action);
|
dispatch(action);
|
||||||
return dispatch(save(action.payload.uuid)).then(() => {
|
return dispatch(save(action.payload.uuid)).then(() => {
|
||||||
console.log("==");
|
|
||||||
const pg = findPointGroup(getState().resources.index, action.payload.uuid);
|
const pg = findPointGroup(getState().resources.index, action.payload.uuid);
|
||||||
const { id } = pg.body;
|
const { id } = pg.body;
|
||||||
history.push("/app/designer/groups/" + (id ? id : ""));
|
history.push("/app/designer/groups/" + (id ? id : ""));
|
||||||
|
|
|
@ -238,7 +238,7 @@ describe CeleryScript::Corpus do
|
||||||
point_ids: [])
|
point_ids: [])
|
||||||
bad = CeleryScript::AstNode.new({
|
bad = CeleryScript::AstNode.new({
|
||||||
kind: "point_group",
|
kind: "point_group",
|
||||||
args: { resource_id: pg.id },
|
args: { point_group_id: pg.id },
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be true
|
expect(check.valid?).to be true
|
||||||
|
@ -249,7 +249,7 @@ describe CeleryScript::Corpus do
|
||||||
device.auto_sync_transaction do
|
device.auto_sync_transaction do
|
||||||
bad = CeleryScript::AstNode.new({
|
bad = CeleryScript::AstNode.new({
|
||||||
kind: "point_group",
|
kind: "point_group",
|
||||||
args: { resource_id: -1 },
|
args: { point_group_id: -1 },
|
||||||
})
|
})
|
||||||
check = CeleryScript::Checker.new(bad, corpus, device)
|
check = CeleryScript::Checker.new(bad, corpus, device)
|
||||||
expect(check.valid?).to be false
|
expect(check.valid?).to be false
|
||||||
|
|
Loading…
Reference in New Issue