Esempio n. 1
0
def test_html_set_theme(my_theme, register_builtin_html):
    html.set_theme(None)
    assert html.get_theme() == "facelift"

    html.set_theme("not_existing")
    assert html.get_theme() == "facelift"

    html.set_theme("my_theme")
    assert html.get_theme() == "my_theme"
Esempio n. 2
0
def _table_head(
    treename: str,
    id_: str,
    isopen: bool,
    title: str,
    show_more_toggle: bool,
) -> None:
    onclick = html.foldable_container_onclick(treename, id_, fetch_url=None)
    img_id = html.foldable_container_img_id(treename, id_)

    html.open_thead()
    html.open_tr(class_="heading")
    html.open_td(id_="nform.%s.%s" % (treename, id_),
                 onclick=onclick,
                 colspan=2)
    html.img(id_=img_id,
             class_=["treeangle", "nform", "open" if isopen else "closed"],
             src="themes/%s/images/tree_closed.png" % (html.get_theme()),
             align="absbottom")
    html.write_text(title)
    if show_more_toggle:
        html.more_button("foldable_" + id_, dom_levels_up=4)
    html.close_td()
    html.close_tr()
    html.close_thead()
Esempio n. 3
0
    def show_topology_content(self,
                              hostnames: List[HostName],
                              mode: str,
                              growth_auto_max_nodes: Optional[int] = None,
                              max_nodes: int = 400,
                              mesh_depth: int = 0) -> None:
        div_id = "node_visualization"
        html.div("", id_=div_id)
        html.javascript(
            "topology_instance = new cmk.node_visualization.TopologyVisualization(%s, %s);"
            % (json.dumps(div_id), json.dumps(mode)))

        if growth_auto_max_nodes:
            html.javascript("topology_instance.set_growth_auto_max_nodes(%d)" %
                            growth_auto_max_nodes)
        html.javascript("topology_instance.set_max_nodes(%d)" % max_nodes)
        html.javascript("topology_instance.set_mesh_depth(%d)" % mesh_depth)
        html.javascript("topology_instance.set_theme(%s)" %
                        json.dumps(html.get_theme()))
        overlay_config = self._get_overlay_config()
        if overlay_config:
            html.javascript(
                "topology_instance.set_initial_overlays_config(%s)" %
                json.dumps(overlay_config))

        html.javascript("topology_instance.show_topology(%s)" %
                        json.dumps(hostnames))
Esempio n. 4
0
def get_themed_perfometer_bg_color():
    # type: () -> str
    """Return the theme specific background color for perfometer rendering"""
    if html.get_theme() == "modern-dark":
        return "#bdbdbd"
    # else (classic and modern theme)
    return "#ffffff"
Esempio n. 5
0
    def show_topology_content(self,
                              hostnames,
                              mode,
                              growth_auto_max_nodes=None,
                              max_nodes=400,
                              mesh_depth=0):
        div_id = "node_visualization"
        html.div("", id=div_id)

        # Filters
        html.open_div(id="topology_filters")
        _view, filters = self._get_topology_view_and_filters()
        html.request.set_var("topology_mesh_depth", str(mesh_depth))
        html.request.set_var("topology_max_nodes", str(max_nodes))
        cmk.gui.views.show_filter_form(is_open=True, filters=filters)
        html.close_div()

        html.javascript(
            "topology_instance = new cmk.node_visualization.TopologyVisualization(%s, %s);"
            % (json.dumps(div_id), json.dumps(mode)))

        if growth_auto_max_nodes:
            html.javascript("topology_instance.set_growth_auto_max_nodes(%d)" %
                            growth_auto_max_nodes)
        html.javascript("topology_instance.set_max_nodes(%d)" % max_nodes)
        html.javascript("topology_instance.set_mesh_depth(%d)" % mesh_depth)
        html.javascript("topology_instance.set_theme(%s)" %
                        json.dumps(html.get_theme()))
        html.javascript("topology_instance.show_topology(%s)" %
                        json.dumps(hostnames))
Esempio n. 6
0
    def _show_body_start(self) -> None:
        body_classes = [
            'side', "screenshotmode" if config.screenshotmode else None
        ]

        if not config.user.may("general.see_sidebar"):
            html.open_body(class_=body_classes, data_theme=html.get_theme())
            return

        interval = config.sidebar_notify_interval if config.sidebar_notify_interval is not None else "null"
        html.open_body(
            class_=body_classes,
            onload=
            'cmk.sidebar.initialize_scroll_position(); cmk.sidebar.init_messages(%s);'
            % interval,
            data_theme=html.get_theme())
Esempio n. 7
0
    def update(self):
        import cmk.gui.sidebar as sidebar  # pylint: disable=import-outside-toplevel
        dashlet = self._dashlet_spec
        snapin = sidebar.snapin_registry.get(self._dashlet_spec['snapin'])
        if not snapin:
            raise MKUserError(None, _('The configured snapin does not exist.'))
        snapin_instance = snapin()

        html.set_browser_reload(self.refresh_interval())
        html.html_head(_('Snapin Dashlet'))
        html.open_body(class_="side", data_theme=html.get_theme())
        html.open_div(id_="check_mk_sidebar")
        html.open_div(id_="side_content")
        html.open_div(id_="snapin_container_%s" % dashlet['snapin'],
                      class_="snapin")
        html.open_div(id_="snapin_%s" % dashlet['snapin'], class_="content")
        styles = snapin_instance.styles()
        if styles:
            html.style(styles)
        snapin_instance.show()
        html.close_div()
        html.close_div()
        html.close_div()
        html.close_div()
        html.body_end()
Esempio n. 8
0
    def show_topology_content(self,
                              hostnames: List[HostName],
                              mode: str,
                              growth_auto_max_nodes: Optional[int] = None,
                              max_nodes: int = 400,
                              mesh_depth: int = 0) -> None:
        div_id = "node_visualization"
        html.div("", id=div_id)

        # Filters
        html.open_div(id="topology_filters")
        view, filters = self._get_topology_view_and_filters()
        html.request.set_var("topology_mesh_depth", str(mesh_depth))
        html.request.set_var("topology_max_nodes", str(max_nodes))
        cmk.gui.views.show_filter_form(view, filters)
        html.final_javascript("cmk.page_menu.open_popup('popup_filters');")
        html.close_div()

        html.javascript(
            "topology_instance = new cmk.node_visualization.TopologyVisualization(%s, %s);" %
            (json.dumps(div_id), json.dumps(mode)))

        if growth_auto_max_nodes:
            html.javascript("topology_instance.set_growth_auto_max_nodes(%d)" %
                            growth_auto_max_nodes)
        html.javascript("topology_instance.set_max_nodes(%d)" % max_nodes)
        html.javascript("topology_instance.set_mesh_depth(%d)" % mesh_depth)
        html.javascript("topology_instance.set_theme(%s)" % json.dumps(html.get_theme()))
        overlay_config = self._get_overlay_config()
        if overlay_config:
            html.javascript("topology_instance.set_initial_overlays_config(%s)" %
                            json.dumps(overlay_config))

        html.javascript("topology_instance.show_topology(%s)" % json.dumps(hostnames))
Esempio n. 9
0
def show_topology_content(hostnames, mode):
    div_id = "node_visualization"
    html.div("", id=div_id)

    html.javascript(
        "topology_instance = new cmk.node_visualization.TopologyVisualization(%s, %s);"
        % (json.dumps(div_id), json.dumps(mode)))

    html.javascript("topology_instance.set_theme(%s)" %
                    json.dumps(html.get_theme()))
    html.javascript("topology_instance.show_topology(%s)" %
                    json.dumps(hostnames))
Esempio n. 10
0
def _bi_map():
    aggr_name = html.request.var("aggr_name")
    layout_id = html.request.var("layout_id")
    html.header("BI visualization")
    div_id = "node_visualization"
    html.div("", id=div_id)
    html.javascript(
        "node_instance = new cmk.node_visualization.BIVisualization(%s);" %
        json.dumps(div_id))

    html.javascript("node_instance.set_theme(%s)" %
                    json.dumps(html.get_theme()))
    html.javascript("node_instance.show_aggregations(%s, %s)" %
                    (json.dumps([aggr_name]), json.dumps(layout_id)))
Esempio n. 11
0
    def page(self):
        themes = [theme for theme, _title in cmk.gui.config.theme_choices()]
        current_theme = html.get_theme()
        try:
            theme_index = themes.index(current_theme)
        except ValueError:
            raise MKUserError(None, _("Could not determine current theme."))

        if len(themes) == theme_index + 1:
            new_theme = themes[0]
        else:
            new_theme = themes[theme_index + 1]

        _set_user_attribute("ui_theme", new_theme)
Esempio n. 12
0
def add_default_render_options(graph_render_options, render_unthemed=False):
    options = get_default_graph_render_options()
    options.update(graph_render_options)
    options.setdefault("size", config.user.load_file("graph_size", (70, 16)))

    # Update the graph colors that are set to "default" with the theme specific colors.
    # When rendering to PDF the theme colors must not be applied, but the regular colors
    # have to be used.
    theme_colors = _graph_colors(html.get_theme() if not render_unthemed else "pdf")
    for attr_name in ["background_color", "foreground_color", "canvas_color"]:
        if options[attr_name] == "default":
            options[attr_name] = theme_colors[attr_name]

    return options
Esempio n. 13
0
def _bi_map() -> None:
    aggr_name = html.request.var("aggr_name")
    layout_id = html.request.var("layout_id")
    title = _("BI visualization")
    breadcrumb = make_simple_page_breadcrumb(mega_menu_registry.menu_monitoring(), title)
    html.header(title, breadcrumb)
    div_id = "node_visualization"
    html.div("", id=div_id)
    html.javascript("node_instance = new cmk.node_visualization.BIVisualization(%s);" %
                    json.dumps(div_id))

    html.javascript("node_instance.set_theme(%s)" % json.dumps(html.get_theme()))
    html.javascript("node_instance.show_aggregations(%s, %s)" %
                    (json.dumps([aggr_name]), json.dumps(layout_id)))
Esempio n. 14
0
def host_service_graph_dashlet_pnp(graph_identification):
    site = graph_identification[1]["site"]
    source = int(graph_identification[1]["graph_index"])

    pnp_host = cmk.utils.pnp_cleanup(graph_identification[1]["host_name"])
    pnp_svc = cmk.utils.pnp_cleanup(
        graph_identification[1]["service_description"])
    url_prefix = config.site(site)["url_prefix"]

    pnp_theme = html.get_theme()
    if pnp_theme == "classic":
        pnp_theme = "multisite"

    html.write(url_prefix + "pnp4nagios/index.php/image?host=%s&srv=%s&source=%d&view=%s&theme=%s" % \
        (html.urlencode(pnp_host), html.urlencode(pnp_svc), source, html.request.var("timerange"), pnp_theme))
Esempio n. 15
0
def _get_current_theme_titel() -> str:
    return [
        titel for theme_id, titel in config.theme_choices()
        if theme_id == html.get_theme()
    ][0]
Esempio n. 16
0
def get_themed_perfometer_bg_color():
    if html.get_theme() == "modern-dark":
        return "#bdbdbd"
    # else (classic and modern theme)
    return "#ffffff"