Module: check_mk
Branch: master
Commit: 7edb80277e1350750e6cf96d0b17761cb7aae373
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7edb80277e1350…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Thu Nov 22 16:27:25 2018 +0100
Refactored wiki snapin to new snapin API
Change-Id: I8ea63338f620fe678c7cb5ee355703ce4d643b78
---
cmk/gui/plugins/sidebar/wiki.py | 264 +++++++++++++++++++++-------------------
1 file changed, 137 insertions(+), 127 deletions(-)
diff --git a/cmk/gui/plugins/sidebar/wiki.py b/cmk/gui/plugins/sidebar/wiki.py
index 2f71204..1863dd2 100644
--- a/cmk/gui/plugins/sidebar/wiki.py
+++ b/cmk/gui/plugins/sidebar/wiki.py
@@ -41,139 +41,149 @@ import cmk.gui.config as config
from cmk.gui.i18n import _
from cmk.gui.globals import html
from cmk.gui.plugins.sidebar import (
- sidebar_snapins,
+ SidebarSnapin,
+ snapin_registry,
bulletlink,
simplelink,
)
-def render_wiki():
- filename = cmk.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 == True:
- 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 == True:
- if title:
- html.begin_foldable_container("wikisnapin", title,
True, title, indent=True)
+(a)snapin_registry.register
+class Wiki(SidebarSnapin):
+ @staticmethod
+ def type_name():
+ return "wiki"
+
+ @classmethod
+ def title(cls):
+ return _("Wiki")
+
+ @classmethod
+ def description(cls):
+ return _("Shows the Wiki Navigation of the OMD Site")
+
+ def show(self):
+ filename = cmk.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 == True:
+ 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 == True:
+ 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:
- 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]
+ 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]
+ if link.startswith("http://") or
link.startswith("https://"):
+ simplelink(name, link, "_blank")
else:
- name = erg[0]
- bulletlink(name, "/%s/wiki/doku.php?id=%s" %
(config.omd_site(), link))
-
- else:
- html.write_text(line)
-
- if ul_started == True:
- 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)
-
-
-sidebar_snapins["wiki"] = {
- "title": _("Wiki"),
- "description": _("Shows the Wiki Navigation of the OMD Site"),
- "render": render_wiki,
- "allowed": ["admin", "user", "guest"],
- "styles": """
- #snapin_container_wiki div.content {
- font-weight: bold;
- color: white;
- }
-
- #snapin_container_wiki div.content p {
- font-weight: normal;
- }
-
- #wiki_navigation {
- text-align: left;
- }
-
- #wiki_search {
- width: 232px;
- padding: 0;
- }
-
- #wiki_side_clear {
- clear: both;
- }
-
- #wiki_search img.iconbutton {
- width: 33px;
- height: 26px;
- margin-top: -25px;
- left: 196px;
- float: left;
- position: relative;
- z-index:100;
- }
-
- #wiki_search input {
- margin: 0;
- padding: 0px 5px;
- font-size: 8pt;
- width: 194px;
- height: 25px;
- background-image: url("images/quicksearch_field_bg.png");
- background-repeat: no-repeat;
- -moz-border-radius: 0px;
- border-style: none;
- float: left;
- }
- """
+ 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 == True:
+ 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)
+
+ def styles(self):
+ return """
+#snapin_container_wiki div.content {
+ font-weight: bold;
+ color: white;
+}
+
+#snapin_container_wiki div.content p {
+ font-weight: normal;
+}
+
+#wiki_navigation {
+ text-align: left;
+}
+
+#wiki_search {
+ width: 232px;
+ padding: 0;
+}
+
+#wiki_side_clear {
+ clear: both;
+}
+
+#wiki_search img.iconbutton {
+ width: 33px;
+ height: 26px;
+ margin-top: -25px;
+ left: 196px;
+ float: left;
+ position: relative;
+ z-index:100;
+}
+
+#wiki_search input {
+ margin: 0;
+ padding: 0px 5px;
+ font-size: 8pt;
+ width: 194px;
+ height: 25px;
+ background-image: url("images/quicksearch_field_bg.png");
+ background-repeat: no-repeat;
+ -moz-border-radius: 0px;
+ border-style: none;
+ float: left;
}
+"""