-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10441 from netbox-community/9071-plugin-menu
9071 add header to plugin menu
- Loading branch information
Showing
8 changed files
with
211 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from dataclasses import dataclass | ||
from typing import Sequence, Optional | ||
|
||
from utilities.choices import ButtonColorChoices | ||
|
||
|
||
__all__ = ( | ||
'get_model_item', | ||
'get_model_buttons', | ||
'Menu', | ||
'MenuGroup', | ||
'MenuItem', | ||
'MenuItemButton', | ||
) | ||
|
||
|
||
# | ||
# Navigation menu data classes | ||
# | ||
|
||
@dataclass | ||
class MenuItemButton: | ||
|
||
link: str | ||
title: str | ||
icon_class: str | ||
permissions: Optional[Sequence[str]] = () | ||
color: Optional[str] = None | ||
|
||
|
||
@dataclass | ||
class MenuItem: | ||
|
||
link: str | ||
link_text: str | ||
permissions: Optional[Sequence[str]] = () | ||
buttons: Optional[Sequence[MenuItemButton]] = () | ||
|
||
|
||
@dataclass | ||
class MenuGroup: | ||
|
||
label: str | ||
items: Sequence[MenuItem] | ||
|
||
|
||
@dataclass | ||
class Menu: | ||
|
||
label: str | ||
icon_class: str | ||
groups: Sequence[MenuGroup] | ||
|
||
|
||
# | ||
# Utility functions | ||
# | ||
|
||
def get_model_item(app_label, model_name, label, actions=('add', 'import')): | ||
return MenuItem( | ||
link=f'{app_label}:{model_name}_list', | ||
link_text=label, | ||
permissions=[f'{app_label}.view_{model_name}'], | ||
buttons=get_model_buttons(app_label, model_name, actions) | ||
) | ||
|
||
|
||
def get_model_buttons(app_label, model_name, actions=('add', 'import')): | ||
buttons = [] | ||
|
||
if 'add' in actions: | ||
buttons.append( | ||
MenuItemButton( | ||
link=f'{app_label}:{model_name}_add', | ||
title='Add', | ||
icon_class='mdi mdi-plus-thick', | ||
permissions=[f'{app_label}.add_{model_name}'], | ||
color=ButtonColorChoices.GREEN | ||
) | ||
) | ||
if 'import' in actions: | ||
buttons.append( | ||
MenuItemButton( | ||
link=f'{app_label}:{model_name}_import', | ||
title='Import', | ||
icon_class='mdi mdi-upload', | ||
permissions=[f'{app_label}.add_{model_name}'], | ||
color=ButtonColorChoices.CYAN | ||
) | ||
) | ||
|
||
return buttons |
Oops, something went wrong.