toggle show trusted in network app

This commit is contained in:
kepler155c@gmail.com 2018-12-04 21:16:48 -05:00
parent 7d17a21aa4
commit 72142e12cc
1 changed files with 33 additions and 1 deletions

View File

@ -1,5 +1,6 @@
_G.requireInjector(_ENV) _G.requireInjector(_ENV)
local Config = require('config')
local Event = require('event') local Event = require('event')
local Socket = require('socket') local Socket = require('socket')
local UI = require('ui') local UI = require('ui')
@ -20,6 +21,9 @@ local gridColumns = {
{ heading = 'Status', key = 'status' }, { heading = 'Status', key = 'status' },
} }
local trusted = Util.readTable('usr/.known_hosts')
local config = Config.load('network', { })
if UI.term.width >= 30 then if UI.term.width >= 30 then
table.insert(gridColumns, { heading = 'Fuel', key = 'fuel', width = 5 }) table.insert(gridColumns, { heading = 'Fuel', key = 'fuel', width = 5 })
table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' }) table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' })
@ -40,6 +44,15 @@ local page = UI.Page {
{ text = 'Remove', event = 'untrust' }, { text = 'Remove', event = 'untrust' },
} }, } },
{ text = 'Help', event = 'help' }, { text = 'Help', event = 'help' },
{
text = '\206',
x = -3,
dropdown = {
{ text = 'Show all', event = 'show_all' },
UI.MenuBar.spacer,
{ text = 'Show trusted', event = 'show_trusted' },
},
},
}, },
}, },
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
@ -143,6 +156,15 @@ This only needs to be done once.
q = 'cancel', q = 'cancel',
} }
}) })
elseif event.type == 'show_all' then
config.showTrusted = false
Config.update('network', config)
elseif event.type == 'show_trusted' then
config.showTrusted = true
Config.update('network', config)
elseif event.type == 'quit' then elseif event.type == 'quit' then
Event.exitPullEvents() Event.exitPullEvents()
end end
@ -184,7 +206,17 @@ function page.grid:getDisplayValues(row)
end end
Event.onInterval(1, function() Event.onInterval(1, function()
page.grid:update() local t = { }
if config.showTrusted then
for k,v in pairs(network) do
if trusted[k] then
t[k] = v
end
end
page.grid:setValues(t)
else
page.grid:update()
end
page.grid:draw() page.grid:draw()
page:sync() page:sync()
end) end)