* added guide for GUI development functioning * Changed table refresh to 1 minut * updated en.lua path * Added lua navbar documentation * Fixed SNMP menu entry highlight * Implemented ticket #7576 * Implemented #7576 * Added lua and vue documentation --------- Co-authored-by: DGabri <gabriele.deri@gmail.com>
5.5 KiB
GUI quickstart guide
This guide is a quickstart to get up and running for GUI development
- Make sure to have node.js installed
- Run
npm installto install all the dependencies - Before making changes to any page make sure to run
npm run watchso that changes are displayed after every file save - After having made changes please build with the appropriate command.
npm run build:ntopng.jsto compile js only. If CSS changes have not been donenpm run build:ntopng.jsto compile css only. If JS changes have not been donenpm run buildto compile all the changes
Project structure
The folder http_src/ contains all the webpages scripts.
-
http_src/vuecontains single vue components that are imported in desired pages -
http_src/utilitiescontains all utility functions -
http_src/ntopng.jscontains all global imports that will be visible inside single components -
pages/is found inhttpdocs/templates/pages/ -
httpdocs/is the folder for GUI data, dist folder is present inside it -
template.render("pages/vue_page.template", { vue_page_name = "PageSNMPDevices", page_context = json_context })some .lua pages render vue components. The name of the component is the value ofvue_page_name, in this case the component isPageSNMPDevices. This is the name of the component importend in the scripthttp_src/vue/ntop_vue.js. This is the import:import { default as PageSNMPDevices } from "./page-snmp-devices.vue"where PageSNMPDevices is the name of the vue component imported and displayed on the webpage and the component is found in the file page-snmp-devices.vue -
The navbar that is present at the left of each page is rendered with lua function:
page_utils.print_header_and_set_active_menu_entry(page_utils.VALUE)where VALUE is the name of the entry that is found insidepage_utils.lua(scripts/lua/modules/page_utils.lua). Please refer to Lua Navbar section later in this document for more info.
General info
- System interface has id = -1
Webpage structure
Pages are rendered lua side, rendering .vue components inside of the pages that need them.
- How to find .vue components that are used on a page?
- take the path of the current webpage and the .lua file that renders it is found
- prepend
scipts/to the page path and the file is opened template.render("VUE-COMPONENT-PATH", { vue_page_name = "PAGE-NAME", page_context = json_context })this function renders VUE-COMPONENT-PATH vue component
- Each page has a
page=*parameter where * is the name of the page. * is used to route each page and have conditional rendering lua side
Lua Navbar
page_utils.menu_sectionsis a Lua table used within our application to store the bindings between different entries in the navbar. Sections are the names under the icons that are found when first opening a page in ntopng
The structure of page_utils.menu_sections follows a key-value pair format, where each entry represents a specific item in the navbar entry. Here's the breakdown:
-
Key: Represents the unique identifier for the navbar entry.
-
Values: An object containing various attributes of the navbar entry, such as:
i18n_title: The title of the entry. Mappings are found in the filescripts/locales/en.luasection: The section to which the entry belongs. Section refers to the father component of the navbar, values are found inpage_utils.menu_sectionsiconis the icon to display in the navbarhelp_link(optional): Provides a URL link for additional help or information related to the entry. This icon is displayed in the top right side of each page header.
-
page_utils.menu_entriesis a Lua table used within our application to store the bindings between different entries in navbar sections. This table organizes these entries into sections, making it easier to manage and navigate through the various sections of the application.Entriesare the available options that pop up when hovering on a section. The same description as page_utils.menu_section is available with only difference that the Values table contains a new option:sectionwhich is used to link a menu entry to the parent section of the navbar.
Lua files
consts.luacontains a list of available filters that are returned to the GUI (VueJS). Only these filters can be used as they are cross checked before doing table column filteringmenu.luacontains a list of entries that are used inside the menu navbartag_utils.luacontains a list of available filters that can be used in frontendflow_alert_store:_get_additional_available_filters()contains available filters to filter columns inside a table. Entry name is used inside the JSON to configure the desired table in the keydata_field.self:add_filter_condition_list('srv_ip', srv_ip)-> is used to add a filter on a specific field, so that this filter is available to use frontend and backend side
Vue
map_table_def_columns = async (columns)is a function used to manipulate table columns and apply some kind of filters. For example filterize can be appliedfilterizefunction adds filtering function to table columns if a value is clicked. Double check in front end and back end is executed to check if selected filter is available.formatterUtils.getFormatter(DATA-TYPE)(VALUE)is a utility function that formats values to a specific unit of measure. Formatter utils can be found inutilities/formatter-utils.js. To format a value chose DATA-TYPE:String (possible values can be found inside types variable inside formatter utils) and pass a VALUE to format