Esempio n. 1
0
def bulletlink(text: str,
               url: str,
               target: str = "main",
               onclick: Optional[str] = None) -> None:
    html.open_li(class_="sidebar")
    link(text, url, target, onclick)
    html.close_li()
Esempio n. 2
0
def jqm_page_navfooter(items: NavigationBar, current: str, page_id: str) -> None:
    html.close_div()  # close content
    html.open_div(
        **{
            "data-role": "footer",
            "data-position": "fixed",
            "data-tap-toggle": "false",
            "data-hide-during-focus": "",
        }
    )
    html.open_div(**{"data-role": "navbar"})
    html.open_ul()

    for href, title, icon, custom_css in items:
        href = makeuri(request, [("page", href), ("search", "Search")])
        if current == href:
            custom_css += " ui-state-persist ui-btn-active"
        else:
            html.open_li()
            html.a(
                title,
                href=href,
                class_=custom_css,
                **{
                    "data-transition": "slide",
                    "data-icon": icon,
                    "data-iconpos": "bottom",
                },
            )
            html.close_li()
    html.close_ul()
    html.close_div()
    html.close_div()
    html.close_div()  # close page-div
Esempio n. 3
0
    def _show_entry_cells(self, table, ident, entry):
        table.cell(_("Title"), entry["title"])

        table.cell(_("Conditions"))
        html.open_ul(class_="conditions")
        html.open_li()
        html.write_text(
            "%s: %s" %
            (_("Folder"), Folder.folder(
                entry["conditions"]["host_folder"]).alias_path()))
        html.close_li()
        html.close_ul()
        html.write_text(vs_conditions().value_to_html(entry["conditions"]))

        table.cell(_("Editable by"))
        if entry["owned_by"] is None:
            html.write_text(
                _("Administrators (having the permission "
                  '"Write access to all predefined conditions")'))
        else:
            html.write_text(self._contact_group_alias(entry["owned_by"]))

        table.cell(_("Shared with"))
        if not entry["shared_with"]:
            html.write_text(_("Not shared"))
        else:
            html.write_text(", ".join(
                [self._contact_group_alias(g) for g in entry["shared_with"]]))
Esempio n. 4
0
def _show_affected_folders(affected_folders: List[CREFolder]) -> None:
    html.open_ul()
    for folder in affected_folders:
        html.open_li()
        html.a(folder.alias_path(), href=folder.edit_url())
        html.close_li()
    html.close_ul()
Esempio n. 5
0
def _show_topic(treename: str, topic: TopicMenuTopic,
                show_item_icons: bool) -> None:
    if not topic.items:
        return

    with foldable_container(
            treename=treename,
            id_=topic.name,
            isopen=False,
            title=topic.title,
            indent=True,
            icon="foldable_sidebar",
    ):

        for item in topic.items:
            if show_item_icons:
                html.open_li(class_=["sidebar"] +
                             (["show_more_mode"] if item.is_show_more else []))
                iconlink(item.title, item.url, item.icon or "icon_missing")
                html.close_li()
            else:
                bulletlink(
                    item.title,
                    item.url,
                    onclick="return cmk.sidebar.wato_views_clicked(this)")
Esempio n. 6
0
    def _show_main_menu_content(self) -> None:
        for menu_item in self._get_main_menu_items():
            if isinstance(menu_item.icon, dict):
                active_icon: Icon = {
                    "icon": menu_item.icon["icon"] + "_active",
                    "emblem": menu_item.icon["emblem"],
                }
            else:
                active_icon = menu_item.icon + "_active"

            html.open_li()
            html.popup_trigger(
                (self._get_popup_trigger_content(active_icon, menu_item)),
                ident="mega_menu_" + menu_item.name,
                method=MethodInline(self._get_mega_menu_content(menu_item)),
                cssclass=[menu_item.name],
                popup_group="main_menu_popup",
                hover_switch_delay=150,  # ms
                onopen=menu_item.onopen,
            )
            html.div(
                "",
                id_="popup_shadow",
                onclick="cmk.popup_menu.close_popup()",
                class_="min"
                if user.get_attribute("nav_hide_icons_title") else None,
            )
            html.close_li()
Esempio n. 7
0
def _show_filter_form(show_filters: List[Filter], context: VisualContext) -> None:
    # Sort filters
    s = sorted([(f.sort_index, f.title, f) for f in show_filters if f.available()])

    html.begin_form("filter")
    html.open_ul(**{"data-role": "listview", "data-inset": "false"})
    for _sort_index, title, f in s:
        html.open_li(**{"data-role": "fieldcontain"})
        html.legend(title)
        f.display(context.get(f.ident, {}))
        html.close_li()
    html.close_ul()
    html.hidden_fields()
    html.hidden_field("search", "Search")
    html.hidden_field("page", "data")
    html.form_has_submit_button = True  # a.results_button functions as a submit button
    html.end_form()
    html.final_javascript(
        """
        const filter_form = document.getElementById("form_filter");
        const results_button = document.getElementsByClassName("results_button")[0];

        cmk.forms.enable_select2_dropdowns(filter_form);
        results_button.onclick = function(event) {
            event.preventDefault();
            filter_form.submit();
        };
        """
    )
Esempio n. 8
0
def _show_affected_rulesets(affected_rulesets: List[Ruleset]) -> None:
    html.open_ul()
    for ruleset in affected_rulesets:
        html.open_li()
        html.a(
            ruleset.title(),
            href=folder_preserving_link([("mode", "edit_ruleset"),
                                         ("varname", ruleset.name)]),
        )
        html.close_li()
    html.close_ul()
Esempio n. 9
0
 def _show_item(self, item: TopicMenuItem) -> None:
     html.open_li(class_="show_more_mode" if item.is_show_more else None)
     html.open_a(
         href=item.url,
         target=item.target,
         onclick="cmk.popup_menu.close_popup()",
     )
     if user.get_attribute("icons_per_item"):
         html.icon(item.icon or "dash")
     self._show_item_title(item)
     html.close_a()
     html.close_li()
Esempio n. 10
0
    def _show_subtree(self, tree, path, show_host):
        if self._is_leaf(tree):
            self._show_leaf(tree, show_host)
            return

        html.open_span(class_="title")

        is_empty = len(tree[3]) == 0
        if is_empty:
            mc = None
        else:
            mc = self._get_mousecode(path)

        css_class = "open" if self._is_open(path) else "closed"

        with self._show_node(tree,
                             show_host,
                             mousecode=mc,
                             img_class=css_class):
            if tree[2].get("icon"):
                html.write_html(html.render_icon(tree[2]["icon"]))
                html.write_text(" ")

            if tree[2].get("docu_url"):
                html.icon_button(
                    tree[2]["docu_url"],
                    _("Context information about this rule"),
                    "url",
                    target="_blank",
                )
                html.write_text(" ")

            html.write_text(tree[2]["title"])

        if not is_empty:
            html.open_ul(
                id_="%d:%s" %
                (self._expansion_level or 0, self._path_id(path)),
                class_=["subtree", css_class],
            )

            if not self._omit_content(path):
                for node in tree[3]:
                    if not node[2].get("hidden"):
                        new_path = path + [node[2]["title"]]
                        html.open_li()
                        self._show_subtree(node, new_path, show_host)
                        html.close_li()

            html.close_ul()

        html.close_span()
Esempio n. 11
0
def page_index() -> None:
    title = _("Checkmk Mobile")
    mobile_html_head(title)
    jqm_page_header(
        title,
        right_button=("javascript:document.location.reload();", _("Reload"), "refresh"),
        id_="data",
    )
    items = []
    for view_name, view_spec in views.get_permitted_views().items():
        if view_spec.get("mobile") and not view_spec.get("hidden"):

            datasource = data_source_registry[view_spec["datasource"]]()
            context = visuals.active_context_from_request(datasource.infos, view_spec["context"])

            view = views.View(view_name, view_spec, context)
            view.row_limit = views.get_limit()
            view.only_sites = visuals.get_only_sites_from_context(context)
            view.user_sorters = views.get_user_sorters()
            view.want_checkboxes = views.get_want_checkboxes()

            url = "mobile_view.py?view_name=%s" % view_name
            count = ""
            if not view_spec.get("mustsearch"):
                painter_options = PainterOptions.get_instance()
                painter_options.load(view_name)
                count = '<span class="ui-li-count">%d</span>' % views.get_row_count(view)

            topic = PagetypeTopics.get_topic(view_spec.get("topic", ""))
            items.append((topic.title(), url, "%s %s" % (view_spec["title"], count)))

    jqm_page_index(_("Checkmk Mobile"), items)
    # Link to non-mobile GUI

    html.hr()
    html.open_ul(**{"data-role": "listview", "data-theme": "b", "data-inset": "true"})
    html.open_li()
    html.a(
        _("Classical web GUI"),
        href="index.py?mobile=",
        **{"data-ajax": "false", "data-transition": "fade"},
    )
    html.close_li()
    html.close_ul()

    html.open_ul(**{"data-role": "listview", "data-theme": "f", "data-inset": "true"})
    html.open_li()
    html.a(_("Logout"), href="logout.py", **{"data-ajax": "false", "data-transition": "fade"})
    html.close_li()
    html.close_ul()
    mobile_html_foot()
Esempio n. 12
0
def _show_affected_hosts(affected_hosts: List[CREHost]) -> None:
    html.open_ul()
    html.open_li()
    for nr, host in enumerate(affected_hosts):
        if nr > 20:
            html.write_text(_("... (%d more)") % (len(affected_hosts) - 20))
            break

        if nr > 0:
            html.write_text(", ")

        html.a(host.name(), href=host.edit_url())
    html.close_li()
    html.close_ul()
Esempio n. 13
0
 def _show_items(self, topic_id: str, topic: TopicMenuTopic) -> None:
     html.open_ul()
     for item in sorted(topic.items, key=lambda g: g.sort_index):
         self._show_item(item)
     html.open_li(class_="show_all_items")
     html.open_a(href="",
                 onclick="cmk.popup_menu.mega_menu_show_all_items('%s')" %
                 topic_id)
     if user.get_attribute("icons_per_item"):
         html.icon("trans")
     html.write_text(_("Show all"))
     html.close_a()
     html.close_li()
     html.close_ul()
Esempio n. 14
0
def jqm_page_index_topic_renderer(topic: str, items: Items) -> None:
    has_items_for_topic = any(i for i in items if i[0] == topic)
    if not has_items_for_topic:
        return

    html.p(topic)
    html.open_ul(**{"data-role": "listview", "data-inset": "true"})
    for top, href, title in items:
        if top == topic:
            html.open_li()
            html.open_a(href=href, **{"data-ajax": "false", "data-transition": "flip"})
            html.write_html(HTML(title))
            html.close_a()
            html.close_li()
    html.close_ul()
Esempio n. 15
0
 def _show_tree_nodes(self, maps, children):
     for map_name, map_cfg in maps.items():
         html.open_li()
         if map_name in children:
             with foldable_container(
                 treename="nagvis",
                 id_=map_name,
                 isopen=False,
                 title=map_cfg["alias"],
                 title_url=map_cfg["url"],
                 title_target="main",
                 indent=False,
                 icon="foldable_sidebar",
             ):
                 self._show_tree_nodes(children[map_name], children)
         else:
             html.a(map_cfg["alias"], href=map_cfg["url"], target="main", class_="link")
         html.close_li()
Esempio n. 16
0
def _show_aux_tag_used_by_tags(tags: Set[cmk.utils.tags.GroupedTag]) -> None:
    if not tags:
        return

    html.open_ul()
    html.open_li()
    builtin_config = cmk.utils.tags.BuiltinTagConfig()
    for index, tag in enumerate(sorted(tags, key=lambda t: t.choice_title)):
        if index > 0:
            html.write_text(", ")

        # Builtin tag groups can not be edited
        if builtin_config.tag_group_exists(tag.group.id):
            html.write_text(_u(tag.choice_title))
        else:
            edit_url = folder_preserving_link([("mode", "edit_tag"),
                                               ("edit", tag.group.id)])
            html.a(_u(tag.choice_title), href=edit_url)
    html.close_li()
    html.close_ul()
Esempio n. 17
0
def render_mobile_list(rows, view, group_cells, cells, num_columns,
                       show_checkboxes):
    if not is_mobile(request, response):
        html.show_error(_("This view can only be used in mobile mode."))
        return

    # Force relative timestamp always. This saves space.
    painter_options = PainterOptions.get_instance()
    painter_options.set("ts_format", "rel")

    html.open_ul(class_="mobilelist", **{"data-role": "listview"})

    # Paint data rows
    for row in rows:
        html.open_li()
        rendered_cells = [cell.render(row) for cell in cells]
        if rendered_cells:  # First cell (assumedly state) is left
            rendered_class, rendered_content = rendered_cells[0]
            html.p(rendered_content,
                   class_=["ui-li-aside", "ui-li-desc", rendered_class])

            if len(rendered_cells) > 1:
                content = HTML(" &middot; ").join([
                    rendered_cell[1]
                    for rendered_cell in rendered_cells[1:num_columns + 1]
                ])
                html.h3(content)

                for rendered_cell, cell in zip(
                        rendered_cells[num_columns + 1:],
                        cells[num_columns + 1:]):
                    rendered_class, rendered_content = rendered_cell
                    html.open_p(class_="ui-li-desc")
                    cell.paint_as_header()
                    html.write_text(": ")
                    html.span(rendered_content, class_=rendered_class)
                    html.close_p()

        html.close_li()
    html.close_ul()
    html.javascript('$("ul.mobilelist a").attr("data-ajax", "false");')