Example #1
0
def get_view_menu_items() -> 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 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()]
    visuals_to_show += page_type_items

    return make_topic_menu(visuals_to_show)
Example #2
0
    def show(self):
        def render_topic(topic, s, foldable=True):
            first = True
            for t, title, name, _is_view in s:
                if t == topic:
                    if first:
                        if foldable:
                            html.begin_foldable_container("dashboards",
                                                          topic,
                                                          False,
                                                          topic,
                                                          indent=True)
                        else:
                            html.open_ul()
                        first = False
                    bulletlink(
                        title,
                        'dashboard.py?name=%s' % name,
                        onclick="return cmk.sidebar.wato_views_clicked(this)")

            if not first:  # at least one item rendered
                if foldable:
                    html.end_foldable_container()
                else:
                    html.open_ul()

        by_topic = visuals_by_topic(
            dashboard.get_permitted_dashboards().items(),
            default_order=[_('Overview')])
        topics = [topic for topic, _entry in by_topic]

        if len(topics) < 2:
            render_topic(by_topic[0][0], by_topic[0][1], foldable=False)
        else:
            for topic, s in by_topic:
                render_topic(topic, s)

        links = []
        if config.user.may("general.edit_dashboards"):
            if config.debug:
                links.append((_("Export"), "export_dashboards.py"))
            links.append((_("Edit"), "edit_dashboards.py"))
            footnotelinks(links)
Example #3
0
def get_view_menu_items():
    # type: () -> Dict[Text, List[ViewMenuItem]]
    # TODO: One bright day drop this whole visuals stuff and only use page_types
    page_type_topics = {
    }  # type: Dict[Text, List[Tuple[Text, Text, str, bool]]]
    for page_type in pagetypes.all_page_types().values():
        if issubclass(page_type, pagetypes.PageRenderer):
            for t, title, url in page_type.sidebar_links():
                page_type_topics.setdefault(t, []).append(
                    (t, title, url, False))

    visuals_topics_with_entries = visuals_by_topic(
        list(views.get_permitted_views().items()) +
        list(dashboard.get_permitted_dashboards().items()))
    all_topics_with_entries = []
    for topic, entries in visuals_topics_with_entries:
        if topic in page_type_topics:
            entries = entries + page_type_topics[topic]
            del page_type_topics[topic]
        all_topics_with_entries.append((topic, entries))

    all_topics_with_entries += page_type_topics.items()

    # Filter hidden / not permitted entries
    by_topic = OrderedDict()  # type: Dict[Text, List[ViewMenuItem]]
    for topic, entries in all_topics_with_entries:
        for t, title, name, is_view in entries:
            if is_view and config.visible_views and name not in config.visible_views:
                continue
            if is_view and config.hidden_views and name in config.hidden_views:
                continue
            if t != topic:
                continue

            url = view_menu_url(name, is_view)
            by_topic.setdefault(topic, []).append(
                ViewMenuItem(title=title, name=name, is_view=is_view, url=url))

    return by_topic
Example #4
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")
Example #5
0
    def show(self):
        if not watolib.is_wato_slave_site():
            if not config.wato_enabled:
                html.write_text(_("WATO is disabled."))
                return False

        user_folders = compute_foldertree()

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

        topic_views = visuals_by_topic(
            views.get_permitted_views().items() +
            dashboard.get_permitted_dashboards().items())
        topics = [(t, t) for t, _s in topic_views]

        html.open_table()
        html.open_tr()
        html.td(_('Topic:'), class_="label")
        html.open_td()
        html.dropdown("topic",
                      topics,
                      deflt=selected_topic,
                      onchange='cmk.sidebar.wato_tree_topic_changed(this)')
        html.close_td()
        html.close_tr()

        html.open_tr()
        html.td(_("View:"), class_="label")
        html.open_td()

        for topic, view_list in topic_views:
            targets = []
            for t, title, name, is_view in view_list:
                if config.visible_views and name not in config.visible_views:
                    continue
                if config.hidden_views and name in config.hidden_views:
                    continue
                if t == topic:
                    if not is_view:
                        name = 'dashboard|' + name
                    targets.append((name, title))

            if topic != selected_topic:
                default, style = '', 'display:none'
            else:
                default, style = selected_target, None
            html.dropdown(
                "target_%s" % topic,
                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')
Example #6
0
 def _get_dashboard_menu_items(self) -> List[TopicMenuTopic]:
     return make_topic_menu([
         ("dashboards", e)
         for e in dashboard.get_permitted_dashboards().items()
     ])
Example #7
0
    def show(self):
        def render_topic(topic, entries):
            first = True
            for t, title, name, is_view in entries:
                if is_view and config.visible_views and name not in config.visible_views:
                    continue
                if is_view and config.hidden_views and name in config.hidden_views:
                    continue
                if t == topic:
                    if first:
                        html.begin_foldable_container("views",
                                                      topic,
                                                      False,
                                                      topic,
                                                      indent=True)
                        first = False
                    if is_view:
                        bulletlink(
                            title,
                            "view.py?view_name=%s" % name,
                            onclick=
                            "return cmk.sidebar.wato_views_clicked(this)")
                    elif "?name=" in name:
                        bulletlink(title, name)
                    else:
                        bulletlink(
                            title,
                            'dashboard.py?name=%s' % name,
                            onclick=
                            "return cmk.sidebar.wato_views_clicked(this)")

            # TODO: One day pagestypes should handle the complete snapin.
            # for page_type in pagetypes.all_page_types().values():
            #     if issubclass(page_type, pagetypes.PageRenderer):
            #         for t, title, url in page_type.sidebar_links():
            #             if t == topic:
            #                 bulletlink(title, url)

            if not first:  # at least one item rendered
                html.end_foldable_container()

        # TODO: One bright day drop this whole visuals stuff and only use page_types
        page_type_topics = {}
        for page_type in pagetypes.all_page_types().values():
            if issubclass(page_type, pagetypes.PageRenderer):
                for t, title, url in page_type.sidebar_links():
                    page_type_topics.setdefault(t, []).append(
                        (t, title, url, False))

        visuals_topics_with_entries = visuals_by_topic(
            views.get_permitted_views().items() +
            dashboard.get_permitted_dashboards().items())
        all_topics_with_entries = []
        for topic, entries in visuals_topics_with_entries:
            if topic in page_type_topics:
                entries = entries + page_type_topics[topic]
                del page_type_topics[topic]
            all_topics_with_entries.append((topic, entries))

        all_topics_with_entries += sorted(page_type_topics.items())

        for topic, entries in all_topics_with_entries:
            render_topic(topic, entries)

        links = []
        if config.user.may("general.edit_views"):
            if config.debug:
                links.append((_("Export"), "export_views.py"))
            links.append((_("Edit"), "edit_views.py"))
            footnotelinks(links)