Hello!
At the moment when the user access the project is enabled to use some parts of the menu.
so if not enable appear the prohibited icon on rollover
I did it enabling those parts from numbers in the user notes with:
if notes:
try:
parts = notes.split(";")
for part in parts:
if part.startswith("zones:"):
zone_numbers = part.split(":")[1]
enabled_zones = set(zone_numbers.split(","))
elif part.startswith("access:"):
# Get the access value and determine enabled items
access_numbers = part.split(":")[1]
enabled_access = [int(digit) for digit in access_numbers]
I would like to know if is possible to hide those parts of the menu instead, so they don´t appear to the user with no privileges.
Thanks and happy Christmas,
Alejandro
If you build your menu's items
by script
I can see three easy choices:
- Set
items.n.enabled : true / false
depending on role.
- Set
items.n.style.display : none
to hide the option with CSS.
- Omit the option from
items
.
That doesn't sound like a good plan. You should be using roles not users for ease of maintenance and so you don't have to edit the project to add a user.
If your menu is fixed (rather than scripted) then you can use an expression binding on enabled
or style.display
and something like
hasRole | Ignition User Manual to enable or show the option.
I think the opposite of display : none
would be display : inline
.
3 Likes
def runAction(self):
try:
horizontal_menu = self.getChild("root").getChild("HorizontalMenu_0")
if horizontal_menu is None:
raise AttributeError("HorizontalMenu component not found")
# Get the enabledAccess list from the session custom property
enabled_access = self.session.custom.enabledAccess
filtered_items = []
for index, item in enumerate(horizontal_menu.props.items):
# Check if index is within the range of enabledAccess
if index < len(enabled_access):
if enabled_access[index] > 0: # Add to filtered list if enabled
filtered_items.append(item)
# Update the menu's items property with the filtered list
horizontal_menu.props.items = filtered_items
except Exception as e:
# Log an error message if something went wrong
error_message = "Error setting menu item enabled state: {}".format(str(e))
system.util.getLogger("HorizontalMenu").error(error_message)
Finally I used this code enabling the menu items I want to use, with visibility class didn´t work.
In my case anything over 0 is enabled
I not using roles because each usr has very specific privileges altough is probably the best way.