reassign machines
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local Adapter = require('miniAdapter')
|
||||
local class = require('class')
|
||||
local Config = require('config')
|
||||
local Event = require('event')
|
||||
local itemDB = require('itemDB')
|
||||
local sync = require('sync').sync
|
||||
@@ -84,6 +85,22 @@ function Storage:initStorage()
|
||||
end
|
||||
end
|
||||
|
||||
function Storage:saveConfiguration()
|
||||
local t = { }
|
||||
for k,v in pairs(self.nodes) do
|
||||
t[k] = v.adapter
|
||||
v.adapter = nil
|
||||
end
|
||||
|
||||
-- TODO: Should be named 'storage'
|
||||
Config.update('milo', self.nodes)
|
||||
|
||||
for k,v in pairs(t) do
|
||||
self.nodes[k].adapter = v
|
||||
end
|
||||
self:initStorage()
|
||||
end
|
||||
|
||||
function Storage:getSingleNode(mtype)
|
||||
local node = Util.find(self.nodes, 'mtype', mtype)
|
||||
if node and node.adapter and node.adapter.online then
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
local Config = require('config')
|
||||
local Event = require('event')
|
||||
local itemDB = require('itemDB')
|
||||
local Milo = require('milo')
|
||||
@@ -13,21 +12,6 @@ local context = Milo:getContext()
|
||||
|
||||
local nodeWizard
|
||||
|
||||
local function saveConfig()
|
||||
local t = { }
|
||||
for k,v in pairs(context.storage.nodes) do
|
||||
t[k] = v.adapter
|
||||
v.adapter = nil
|
||||
end
|
||||
|
||||
Config.update('milo', context.storage.nodes)
|
||||
|
||||
for k,v in pairs(t) do
|
||||
context.storage.nodes[k].adapter = v
|
||||
end
|
||||
context.storage:initStorage()
|
||||
end
|
||||
|
||||
local networkPage = UI.Page {
|
||||
titleBar = UI.TitleBar {
|
||||
previousPage = true,
|
||||
@@ -173,7 +157,7 @@ end
|
||||
function networkPage:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
if not device[event.selected.name] then
|
||||
self.notification:error('Unable to edit while disconnected')
|
||||
UI:setPage('machineMover', event.selected)
|
||||
else
|
||||
UI:setPage('nodeWizard', event.selected)
|
||||
end
|
||||
@@ -182,7 +166,7 @@ function networkPage:eventHandler(event)
|
||||
local node = self.grid:getSelected()
|
||||
if node then
|
||||
context.storage.nodes[node.name] = nil
|
||||
saveConfig()
|
||||
context.storage:saveConfiguration()
|
||||
end
|
||||
self:applyFilter()
|
||||
self.grid:draw()
|
||||
@@ -511,7 +495,7 @@ function nodeWizard:eventHandler(event)
|
||||
Util.merge(context.storage.nodes[self.node.name], self.node)
|
||||
context.storage.nodes[self.node.name].adapter = adapter
|
||||
|
||||
saveConfig()
|
||||
context.storage:saveConfiguration()
|
||||
|
||||
UI:setPreviousPage()
|
||||
|
||||
|
||||
107
milo/plugins/machineMover.lua
Normal file
107
milo/plugins/machineMover.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
local Craft = require('craft2')
|
||||
local Milo = require('milo')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local context = Milo:getContext()
|
||||
local device = _G.device
|
||||
|
||||
local page = UI.Page {
|
||||
titleBar = UI.TitleBar { title = 'Reassign Machine' },
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -4,
|
||||
values = context.storage.nodes,
|
||||
columns = {
|
||||
{ key = 'suffix', width = 4, justify = 'right' },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Type', key = 'mtype', width = 4 },
|
||||
{ heading = 'Pri', key = 'priority', width = 3 },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
help = 'Select Node',
|
||||
},
|
||||
accept = UI.Button {
|
||||
x = -9, y = -2,
|
||||
event = 'grid_select',
|
||||
text = 'Accept',
|
||||
},
|
||||
cancel = UI.Button {
|
||||
x = -18, y = -2,
|
||||
event = 'cancel',
|
||||
text = 'Cancel',
|
||||
},
|
||||
accelerators = {
|
||||
grid_select = 'nextView',
|
||||
},
|
||||
notification = UI.Notification { },
|
||||
}
|
||||
|
||||
function page.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
local t = { row.name:match(':(.+)_(%d+)$') }
|
||||
if #t ~= 2 then
|
||||
t = { row.name:match('(.+)_(%d+)$') }
|
||||
end
|
||||
if t and #t == 2 then
|
||||
row.name, row.suffix = table.unpack(t)
|
||||
row.name = row.name .. '_' .. row.suffix
|
||||
end
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end
|
||||
|
||||
function page.grid:getRowTextColor(row, selected)
|
||||
if row.mtype == 'ignore' then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
function page:applyFilter()
|
||||
local t = Util.filter(context.storage.nodes, function(v)
|
||||
return v.mtype ~= 'hidden' and device[v.name]
|
||||
end)
|
||||
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
|
||||
function page:enable(machine)
|
||||
self.machine = machine
|
||||
self:applyFilter()
|
||||
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
local target = self.grid:getSelected()
|
||||
if target then
|
||||
local adapter = target.adapter
|
||||
local name = target.name
|
||||
Util.merge(target, self.machine)
|
||||
target.adapter = adapter
|
||||
target.name = name
|
||||
|
||||
context.storage.nodes[self.machine.name] = nil
|
||||
context.storage:saveConfiguration()
|
||||
|
||||
for k,v in pairs(Craft.machineLookup) do
|
||||
if v == self.machine.name then
|
||||
Craft.machineLookup[k] = name
|
||||
end
|
||||
Util.writeTable(Craft.MACHINE_LOOKUP, Craft.machineLookup)
|
||||
end
|
||||
|
||||
UI:setPreviousPage()
|
||||
end
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
UI:setPreviousPage()
|
||||
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
end
|
||||
|
||||
UI:addPage('machineMover', page)
|
||||
Reference in New Issue
Block a user