Пример #1
0
 def render(self, query: str) -> str:
     results = self._generate_results(query)
     with html.plugged():
         for topic, search_results in results.items():
             html.open_div(id_=topic, class_="topic")
             self._render_topic(topic)
             html.open_ul()
             for count, result in enumerate(list(search_results)):
                 self._render_result(
                     result,
                     hidden=count >= self._max_num_displayed_results)
             # TODO: Remove this as soon as the index search does limit its search results
             if len(list(
                     search_results)) >= self._max_num_displayed_results:
                 html.input(
                     name="show_all_results",
                     value=_("Show all results"),
                     type_="button",
                     onclick=
                     f"cmk.search.on_click_show_all_results('{topic}');")
             html.close_ul()
             html.close_div()
         html.div(None, class_=["topic", "sentinel"])
         html_text = html.drain()
     return html_text
Пример #2
0
def render_checkbox(view, row, num_tds):
    # value contains the number of columns of this datarow. This is
    # needed for hiliting the correct number of TDs
    html.input(type_="checkbox",
               name=ensure_str(row_id(view, row)),
               value=(num_tds + 1))
    html.label("", ensure_str(row_id(view, row)))
Пример #3
0
def render_group_checkbox_th():
    html.open_th()
    html.input(type_="button",
               class_="checkgroup",
               name="_toggle_group",
               onclick="cmk.selection.toggle_group_rows(this);",
               value='X')
    html.close_th()
Пример #4
0
 def show(self):
     html.open_div(id_="mk_side_search",
                   class_="content_center",
                   onclick="cmk.quicksearch.close_popup();")
     html.input(id_="mk_side_search_field", type_="text", name="search", autocomplete="off")
     html.icon_button("#",
                      _("Search"),
                      "quicksearch",
                      onclick="cmk.quicksearch.on_search_click();")
     html.close_div()
     html.div('', id_="mk_side_clear")
     html.javascript("cmk.quicksearch.register_search_field('mk_side_search_field');")
Пример #5
0
 def show_search_field(self) -> None:
     id_ = f"mk_side_search_field_{self.name}"
     html.open_div(id_="mk_side_search",
                   class_="content_center",
                   onclick="cmk.quicksearch.close_popup();")
     html.input(id_=id_,
                type_="text",
                name="search",
                autocomplete="off",
                placeholder="Search in Monitoring")
     html.icon_button("#",
                      _("Search"),
                      "quicksearch",
                      onclick="cmk.quicksearch.on_search_click();")
     html.close_div()
     html.div('', id_="mk_side_clear")
     html.javascript(f"cmk.quicksearch.register_search_field('{id_}');")
Пример #6
0
 def show_search_field(self) -> None:
     html.open_div(
         id_="mk_side_search_setup",
         class_="content_center",
     )
     html.input(id_=f"mk_side_search_field_{self.name}",
                type_="text",
                name="search",
                autocomplete="off",
                placeholder=_("Search in Setup"),
                onkeydown="cmk.search.on_key_down('setup')",
                oninput="cmk.search.on_input_search('setup');")
     # TODO: Check if this icon button can be removed
     html.icon_button("#",
                      _("Search"),
                      "quicksearch",
                      onclick="cmk.quicksearch.on_search_click();")
     html.close_div()
     html.div('', id_="mk_side_clear")
Пример #7
0
 def show_search_field(self) -> None:
     html.open_div(
         id_="mk_side_search_setup",
         class_="content_center",
     )
     # TODO: Implement submit action (e.g. show all results of current query)
     html.begin_form(f"mk_side_{self.name}", add_transid=False, onsubmit="return false;")
     html.input(id_=f"mk_side_search_field_{self.name}",
                type_="text",
                name="search",
                autocomplete="off",
                placeholder=_("Search in Setup"),
                onkeydown="cmk.search.on_key_down('setup')",
                oninput="cmk.search.on_input_search('setup');")
     html.input(id_=f"mk_side_search_field_clear_{self.name}",
                name="reset",
                type_="button",
                onclick="cmk.search.on_click_reset('setup');")
     html.end_form()
     html.close_div()
     html.div('', id_="mk_side_clear")
Пример #8
0
    def _show_host_row(self, rendered_hosts, table, hostname, search_text,
                       show_checkboxes, colspan, host_errors,
                       contact_group_names):
        if search_text and (search_text.lower() not in hostname.lower()):
            return

        host = self._folder.host(hostname)
        rendered_hosts.append(hostname)
        effective = host.effective_attributes()

        table.row()

        # Column with actions (buttons)

        if show_checkboxes:
            table.cell(html.render_input(
                "_toggle_group",
                type_="button",
                class_="checkgroup",
                onclick="cmk.selection.toggle_all_rows();",
                value='X'),
                       sortable=False,
                       css="checkbox")
            # Use CSS class "failed" in order to provide information about
            # selective toggling inventory-failed hosts for Javascript
            html.input(name="_c_%s" % hostname,
                       type_="checkbox",
                       value=colspan,
                       class_="failed" if host.discovery_failed() else None)
            html.label("", "_c_%s" % hostname)

        table.cell(_("Actions"), css="buttons", sortable=False)
        self._show_host_actions(host)

        # Hostname with link to details page (edit host)
        table.cell(_("Hostname"))
        errors = host_errors.get(hostname, []) + host.validation_errors()
        if errors:
            msg = _("Warning: This host has an invalid configuration: ")
            msg += ", ".join(errors)
            html.icon(msg, "validation_error")
            html.nbsp()

        if host.is_offline():
            html.icon(_("This host is disabled"), "disabled")
            html.nbsp()

        if host.is_cluster():
            html.icon(
                _("This host is a cluster of %s") %
                ", ".join(host.cluster_nodes()), "cluster")
            html.nbsp()

        html.a(hostname, href=host.edit_url())

        # Show attributes
        for attr in host_attribute_registry.attributes():
            if attr.show_in_table():
                attrname = attr.name()
                if attrname in host.attributes():
                    tdclass, tdcontent = attr.paint(
                        host.attributes()[attrname], hostname)
                else:
                    tdclass, tdcontent = attr.paint(effective.get(attrname),
                                                    hostname)
                    tdclass += " inherited"
                table.cell(attr.title(),
                           escaping.escape_attribute(tdcontent),
                           css=tdclass)

        # Am I authorized?
        reason = host.reason_why_may_not("read")
        if not reason:
            icon = "authok"
            title = _("You have permission to this host.")
        else:
            icon = "autherr"
            title = escaping.strip_tags(reason)

        table.cell(_('Auth'),
                   html.render_icon(icon, title),
                   css="buttons",
                   sortable=False)

        # Permissions and Contact groups - through complete recursion and inhertance
        permitted_groups, host_contact_groups, _use_for_services = host.groups(
        )
        table.cell(
            _("Permissions"),
            HTML(", ").join([
                self._render_contact_group(contact_group_names, g)
                for g in permitted_groups
            ]))
        table.cell(
            _("Contact Groups"),
            HTML(", ").join([
                self._render_contact_group(contact_group_names, g)
                for g in host_contact_groups
            ]))

        if not config.wato_hide_hosttags:
            table.cell(_("Tags"), css="tag-ellipsis")
            tag_groups, show_all_code = self._limit_labels(host.tag_groups())
            html.write(
                cmk.gui.view_utils.render_tag_groups(tag_groups,
                                                     "host",
                                                     with_links=False))
            html.write(show_all_code)

        table.cell(_("Explicit labels"), css="tag-ellipsis")
        labels, show_all_code = self._limit_labels(host.labels())
        html.write(
            cmk.gui.view_utils.render_labels(
                labels,
                "host",
                with_links=False,
                label_sources={k: "explicit"
                               for k in labels.keys()}))
        html.write(show_all_code)

        # Located in folder
        if self._folder.is_search_folder():
            table.cell(_("Folder"))
            html.a(host.folder().alias_path(), href=host.folder().url())
Пример #9
0
    def show(self):
        # type: () -> None
        filename = Path(cmk.utils.paths.omd_root).joinpath(
            'var/dokuwiki/data/pages/sidebar.txt')

        html.open_form(id_="wiki_search",
                       onsubmit="cmk.sidebar.wiki_search('%s');" %
                       config.omd_site())
        html.input(id_="wiki_search_field", type_="text", name="wikisearch")
        html.icon_button("#",
                         _("Search"),
                         "wikisearch",
                         onclick="cmk.sidebar.wiki_search('%s');" %
                         config.omd_site())
        html.close_form()
        html.div('', id_="wiki_side_clear")

        start_ul = True
        ul_started = False
        try:
            title = None
            for line in filename.open(encoding="utf-8").readlines():
                line = line.strip()
                if line == "":
                    if ul_started:
                        html.end_foldable_container()
                        start_ul = True
                        ul_started = False
                elif line.endswith(":"):
                    title = line[:-1]
                elif line == "----":
                    pass
                    # html.br()

                elif line.startswith("*"):
                    if start_ul:
                        if title:
                            html.begin_foldable_container("wikisnapin",
                                                          title,
                                                          True,
                                                          title,
                                                          indent=True)
                        else:
                            html.open_ul()
                        start_ul = False
                        ul_started = True

                    erg = re.findall(r'\[\[(.*)\]\]', line)
                    if len(erg) == 0:
                        continue
                    erg = erg[0].split('|')
                    if len(erg) > 1:
                        link = erg[0]
                        name = erg[1]
                    else:
                        link = erg[0]
                        name = erg[0]

                    if link.startswith("http://") or link.startswith(
                            "https://"):
                        simplelink(name, link, "_blank")
                    else:
                        erg = name.split(':')
                        if len(erg) > 0:
                            name = erg[-1]
                        else:
                            name = erg[0]
                        bulletlink(
                            name, "/%s/wiki/doku.php?id=%s" %
                            (config.omd_site(), link))

                else:
                    html.write_text(line)

            if ul_started:
                html.close_ul()
        except IOError:
            html.write_html(
                html.render_p(
                    html.render_text(
                        "To get a navigation menu, you have to create a ") +
                    html.render_a("sidebar",
                                  href="/%s/wiki/doku.php?id=%s" %
                                  (config.omd_site(), _("sidebar")),
                                  target="main") +  #
                    html.render_text(" in your wiki first.")))
Пример #10
0
    def show(self):
        filename = cmk.utils.paths.omd_root + '/var/dokuwiki/data/pages/sidebar.txt'
        html.javascript("""
        function wiki_search()
        {
            var oInput = document.getElementById('wiki_search_field');
            top.frames["main"].location.href =
               "/%s/wiki/doku.php?do=search&id=" + escape(oInput.value);
        }
        """ % config.omd_site())

        html.open_form(id_="wiki_search", onsubmit="wiki_search();")
        html.input(id_="wiki_search_field", type_="text", name="wikisearch")
        html.icon_button("#",
                         _("Search"),
                         "wikisearch",
                         onclick="wiki_search();")
        html.close_form()
        html.div('', id_="wiki_side_clear")

        start_ul = True
        ul_started = False
        try:
            title = None
            for line in file(filename).readlines():
                line = line.strip()
                if line == "":
                    if ul_started:
                        html.end_foldable_container()
                        start_ul = True
                        ul_started = False
                elif line.endswith(":"):
                    title = line[:-1]
                elif line == "----":
                    pass
                    # html.br()

                elif line.startswith("*"):
                    if start_ul:
                        if title:
                            html.begin_foldable_container("wikisnapin",
                                                          title,
                                                          True,
                                                          title,
                                                          indent=True)
                        else:
                            html.open_ul()
                        start_ul = False
                        ul_started = True

                    erg = re.findall(r'\[\[(.*)\]\]', line)
                    if len(erg) == 0:
                        continue
                    erg = erg[0].split('|')
                    if len(erg) > 1:
                        link = erg[0]
                        name = erg[1]
                    else:
                        link = erg[0]
                        name = erg[0]

                    if link.startswith("http://") or link.startswith(
                            "https://"):
                        simplelink(name, link, "_blank")
                    else:
                        erg = name.split(':')
                        if len(erg) > 0:
                            name = erg[-1]
                        else:
                            name = erg[0]
                        bulletlink(
                            name, "/%s/wiki/doku.php?id=%s" %
                            (config.omd_site(), link))

                else:
                    html.write_text(line)

            if ul_started:
                html.close_ul()
        except IOError:
            sidebar = html.render_a("sidebar",
                                    href="/%s/wiki/doku.php?id=%s" %
                                    (config.omd_site(), _("sidebar")),
                                    target="main")
            html.write_html("<p>To get a navigation menu, you have to create a %s in your wiki first.</p>"\
                                                                               % sidebar)