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_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,
|
||||
},
|
||||
|
|
|
@ -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(", ")
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -46,11 +46,14 @@ module Points
|
|||
points.destroy_all
|
||||
else
|
||||
Point.transaction do
|
||||
PointGroupItem.transaction do
|
||||
PointGroupItem.where(point_id: point_ids || point.id).destroy_all
|
||||
archive_points
|
||||
destroy_all_others
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -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 : ""));
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue