def render_list(ids, links): n = 0 for entry in links: n += 1 try: if isinstance(entry[1], type(True)): idss = ids + [str(n)] id_ = '/'.join(idss) html.begin_foldable_container("customlinks", id_, isopen=entry[1], title=entry[0], icon="foldable_sidebar") render_list(idss, entry[2]) html.end_foldable_container() elif isinstance(entry[1], str): frame = entry[3] if len(entry) > 3 else "main" if len(entry) > 2 and entry[2]: icon_file = entry[2] # Old configs used files named "link_<name>.gif". Those .gif files have # been removed from Checkmk. Replacing such images with the default icon if icon_file.endswith(".gif"): icon_name = "link" else: icon_name = icon_file.rsplit(".", 1)[0].replace( "icon_", "") else: icon_name = "link" linktext = HTML( html.render_icon(icon_name) + " " + entry[0]) simplelink(linktext, entry[1], frame) else: html.write_text( _("Second part of tuple must be list or string, not %s\n" ) % str(entry[1])) except Exception as e: html.write_text( _("invalid entry %s: %s<br>\n") % (entry, e))
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.")))
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)