{# MENU It builds menu from the decorator @menu The menu can be accessed in the __.MENU. __.MENU is an sorted list of all the menu items Structures: [ (index, name, enpoint or sub_items, kwargs), ... ] index: int - The position of the item name: str - The name to place in the menu |- endpoint: str endpoint #or |- sub_items: list of [ (index, name, endpoint, kwargs), ... ] kwargs: - active - endpoint_kwargs - has_submenu - index - visible: #} {# -------------------------------------------------------------------------- #} {# To a create navbar :brand: The brand of the site, can include anything :url: The url when the brand is clicked on :fluid: If true it will expand menu all across :fixed: If true it will place the menu on top in a fixed position :fixed_padding_top: When fixed, specify the top padding in px :menu_id: if there are more that one menu, to make them unique :groups: (list) - list of menu groups to accept :exclude_groups: (list) - list of menu groups to exclude :show_menus: (bool) - to hide/show menu. Usually for admin when user is not authenticated. per menu show/hide, use [visible] #} {% macro navbar(brand="", url="/", fluid=True, fixed=True, fixed_padding_top="70px", menu_id=1, groups=[], exclude_groups=[], show_menus=True) %} {% if fixed %} {% endif %} {% endmacro %} {% macro _navbar_sub_list(nav) %} {% if nav[3]["visible"] %} {% if nav[3]["has_submenu"] and nav[2] %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% set show_user_avatar = nav_kwargs["show_profile_avatar"] and current_user and current_user.is_authenticated %} {% if nav_name %} {% endif %} {% else %} {{ _navbar_nav_item(nav) }} {% endif %} {% endif %} {% endmacro %} {% macro _navbar_nav_item(item) %} {% if item[3]["visible"] %} {% set item_name = item[1] %} {% set item_endpoint = item[2] %} {% set item_kwargs = item[3] %} {% set item_fa_icon = item_kwargs["fa_icon"] %} {% set item_endpoint_kwargs = item_kwargs["endpoint_kwargs"] %} {% if "url" in item_kwargs %} {% set item_url = item_kwargs["url"] %} {% else %} {% set item_url = url_for(item_endpoint, **item_endpoint_kwargs) %} {% endif %} {% set item_target = "" %} {% if "target" in item_kwargs %} {% set item_target = item_kwargs["target"] %} {% endif %}
  • {% if item_fa_icon %}{% endif %} {{ item_name | safe }}
  • {% endif %} {% endmacro %} {% macro _navbar_list_content(nav, allow_pull=False, align_right=False) %} {% if allow_pull %} {% if align_right %} {% if nav[3]["align_right"] %} {{ _navbar_sub_list(nav) }} {% endif %} {% elif not nav[3]["align_right"] %} {{ _navbar_sub_list(nav) }} {% endif %} {% else %} {{ _navbar_sub_list(nav) }} {% endif %} {% endmacro %} {% macro _navbar_list(allow_pull=true, align_right=false, groups=None, exclude_groups=None) %} {% endmacro %} {# -------------------------------------------------------------------------- #} {# :: Help extract the main title and the sub title for the active menu navigation Useful to quickly bootstrap an admin :: #} {# :: Extract the main menu of the navigation :: #} {% macro current_title() %} {% for nav in __.MENU %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["active"] %} {{ nav_name }} {% endif %} {% endfor %} {% endmacro %} {# :: Extract the sub menu of the current endpoint navigation :: #} {% macro current_sub_title() %} {% for nav in __.MENU %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["active"] %} {% for item in nav_items %} {% set item_name = item[1] %} {% set item_endpoint = item[2] %} {% if item_endpoint == request.endpoint %} {{ item_name }} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endmacro %} {# -------------------------------------------------------------------------- #} {# BREADCRUM #} {% macro breadcrum(key) %} {% endmacro %} {# -------------------------------------------------------------------------- #} {# :: Panel @params key: str - The key name of the menu, to display only this set @param use_active: bool - When True, it will select the active menu and buil the menu on it @param panel: str - with bootstrap 3, it can be use to change the panel @param class_: str - A class name to add to the menu :: #} {% macro panel(key=None, use_active=False, panel="default", class_="") %}
    {% if use_active %} {% for nav in __.MENU %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["active"] %} {% if nav_items %} {{ _panel_sub_menu(nav) }} {% endif %} {% endif %} {% endfor %} {% elif key %} {% for nav in __.MENU %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_kwargs["key"] == key %} {% if nav_items %} {{ _panel_sub_menu(nav) }} {% endif %} {% endif %} {% endfor %} {% else %} {% for nav in __.MENU %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% if nav_items %} {{ _panel_sub_menu(nav) }} {% endif %} {% endfor %} {% endif %}
    {% endmacro %} {% macro _panel_sub_menu(nav) %} {% set nav_name = nav[1] %} {% set nav_items = nav[2] %} {% set nav_kwargs = nav[3] %} {% endmacro %} {% macro _panel_listgroup(nav_items) %} {% endmacro %}