Exemplo n.º 1
0
def get_view_menu_items(include_reports: bool) -> List[TopicMenuTopic]:
    # The page types that are implementing the PageRenderer API should also be
    # part of the menu. Bring them into a visual like structure to make it easy to
    # integrate them.
    page_type_items: List[Tuple[str, Tuple[str, Visual]]] = []
    for page_type in pagetypes.all_page_types().values():
        if not issubclass(page_type, pagetypes.PageRenderer):
            continue

        for page in page_type.pages():
            if page._show_in_sidebar():
                visual = page.internal_representation().copy()
                visual[
                    "hidden"] = False  # Is currently to configurable for pagetypes
                visual[
                    "icon"] = None  # Is currently to configurable for pagetypes

                page_type_items.append(
                    (page_type.type_name(), (page.name(), visual)))

    # Apply some view specific filters
    views_to_show = [
        (name, view) for name, view in views.get_permitted_views().items()
        if (not active_config.visible_views or name in active_config.
            visible_views) and (not active_config.hidden_views
                                or name not in active_config.hidden_views)
    ]

    network_topology_visual_spec = ParentChildTopologyPage.visual_spec()
    pages_to_show = [(network_topology_visual_spec["name"],
                      network_topology_visual_spec)]

    visuals_to_show = [("views", e) for e in views_to_show]
    visuals_to_show += [("dashboards", e)
                        for e in dashboard.get_permitted_dashboards().items()]
    visuals_to_show += [("pages", e) for e in pages_to_show]
    visuals_to_show += page_type_items

    if reporting and include_reports:
        reporting.load_reports()
        visuals_to_show += [("reports", e)
                            for e in reporting.permitted_reports().items()]

    return make_topic_menu(visuals_to_show)
Exemplo n.º 2
0
    def show(self):
        if not watolib.is_wato_slave_site():
            if not config.wato_enabled:
                html.write_text(_("Setup is disabled."))
                return False

        user_folders = compute_foldertree()

        #
        # Render link target selection
        #
        selected_topic, selected_target = user.load_file(
            "foldertree", (_("Hosts"), "allhosts"))

        # Apply some view specific filters
        views_to_show = [
            (name, view) for name, view in views.get_permitted_views().items()
            if (not config.visible_views or name in config.visible_views) and (
                not config.hidden_views or name not in config.hidden_views)
        ]

        visuals_to_show = [("views", e) for e in views_to_show]
        visuals_to_show += [
            ("dashboards", e)
            for e in dashboard.get_permitted_dashboards().items()
        ]

        topics = make_topic_menu(visuals_to_show)
        topic_choices: Choices = [(topic.title, topic.title)
                                  for topic in topics]

        html.open_table()
        html.open_tr()
        html.open_td()
        html.dropdown(
            "topic",
            topic_choices,
            deflt=selected_topic,
            onchange="cmk.sidebar.wato_tree_topic_changed(this)",
        )
        html.close_td()
        html.close_tr()

        html.open_tr()
        html.open_td()

        for topic in topics:
            targets: Choices = []
            for item in topic.items:
                if item.url and item.url.startswith("dashboard.py"):
                    name = "dashboard|" + item.name
                else:
                    name = item.name
                targets.append((name, item.title))

            if topic.title != selected_topic:
                default = ""
                style: Optional[str] = "display:none"
            else:
                default = selected_target
                style = None
            html.dropdown(
                "target_%s" % topic.title,
                targets,
                deflt=default,
                onchange="cmk.sidebar.wato_tree_target_changed(this)",
                style=style,
            )

        html.close_td()
        html.close_tr()
        html.close_table()

        # Now render the whole tree
        if user_folders:
            render_tree_folder("wato-hosts",
                               list(user_folders.values())[0],
                               "cmk.sidebar.wato_tree_click")
Exemplo n.º 3
0
 def _get_dashboard_menu_items(self) -> List[TopicMenuTopic]:
     return make_topic_menu([
         ("dashboards", e)
         for e in dashboard.get_permitted_dashboards().items()
     ])