mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
Initial work to implement user script templates
This commit is contained in:
parent
ee8ffaca7d
commit
80ae202ad1
8 changed files with 420 additions and 8 deletions
79
scripts/lua/modules/user_script_templates/multi_select.lua
Normal file
79
scripts/lua/modules/user_script_templates/multi_select.lua
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/user_script_templates/?.lua;" .. package.path
|
||||
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Make sure to import the Superclass!
|
||||
local user_script_template = require "user_script_template"
|
||||
local http_lint = require "http_lint"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local multi_select = classes.class(user_script_template)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
multi_select.meta = {
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Prepare an instance of the template
|
||||
-- @return A table with the template built
|
||||
function multi_select:init()
|
||||
-- Call the parent constructor
|
||||
self.super:init()
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
function multi_select:parseConfig(script, conf)
|
||||
return http_lint.validateListItems(script, conf)
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
function multi_select:describeConfig(script, hooks_conf)
|
||||
|
||||
if (not hooks_conf.all) then
|
||||
return '' -- disabled, nothing to show
|
||||
end
|
||||
|
||||
local conf = hooks_conf.all.script_conf
|
||||
|
||||
local msg = ''
|
||||
if not table.empty(conf.items) then
|
||||
|
||||
local temp_msg = {}
|
||||
local groups = script.gui.groups
|
||||
|
||||
-- build a string containing selected elements separated by comma
|
||||
for _, group in ipairs(groups) do
|
||||
local elements = group.elements
|
||||
for _, element in ipairs(elements) do
|
||||
|
||||
local id = element[1]
|
||||
local label = element[2]
|
||||
|
||||
if table.has_key(conf.items, id) then
|
||||
-- if the label is nil then use the id
|
||||
table.insert(temp_msg, label or id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
msg = table.concat(temp_msg, ', ')
|
||||
end
|
||||
|
||||
return (msg)
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return multi_select
|
||||
Loading…
Add table
Add a link
Reference in a new issue