Module: check_mk
Branch: master
Commit: 1e5430702dba26b6702fd017713d93a306abee82
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1e5430702dba26…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Thu Nov 22 15:37:56 2018 +0100
Moved custom links snapin to dedicated module
Change-Id: I38c7a1e84786bbc5f65ea125e7ece352a0d9a23e
---
cmk/gui/plugins/sidebar/custom_links.py | 99 +++++++++++++++++++++++++++++++++
cmk/gui/plugins/sidebar/shipped.py | 81 ---------------------------
2 files changed, 99 insertions(+), 81 deletions(-)
diff --git a/cmk/gui/plugins/sidebar/custom_links.py
b/cmk/gui/plugins/sidebar/custom_links.py
new file mode 100644
index 0000000..49dfb7c
--- /dev/null
+++ b/cmk/gui/plugins/sidebar/custom_links.py
@@ -0,0 +1,99 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+import cmk.paths
+import cmk.gui.config as config
+from cmk.gui.htmllib import HTML
+from cmk.gui.i18n import _
+from cmk.gui.globals import html
+from cmk.gui.plugins.sidebar import sidebar_snapins, simplelink
+
+
+def render_custom_links():
+ links = config.custom_links.get(config.user.baserole_id)
+ if not links:
+ html.write_text((_(
+ "Please edit <tt>%s</tt> in order to configure which links
are shown in this snapin.") %
+ (cmk.paths.default_config_dir + "/multisite.mk")) +
"\n")
+ return
+
+ 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])
+ 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 Check_MK. Replacing such images with the
default icon
+ if icon_file.endswith(".gif"):
+ icon_file = "icon_link.png"
+ else:
+ icon_file = "icon_link.png"
+
+ linktext = HTML(html.render_icon("images/%s" % icon_file) +
" " + 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))
+
+ render_list([], links)
+
+
+sidebar_snapins["custom_links"] = {
+ "title": _("Custom Links"),
+ "description": _("This snapin contains custom links which can be
"
+ "configured via the configuration variable "
+ "<tt>custom_links</tt> in
<tt>multisite.mk</tt>"),
+ "render": render_custom_links,
+ "allowed": ["user", "admin", "guest"],
+ "styles": """
+#snapin_custom_links div.sublist {
+ padding-left: 10px;
+}
+#snapin_custom_links img {
+ margin-right: 5px;
+}
+#snapin_custom_links img.icon {
+ width: 16px;
+ height: 16px;
+}
+"""
+}
diff --git a/cmk/gui/plugins/sidebar/shipped.py b/cmk/gui/plugins/sidebar/shipped.py
index a675fe5..7a66ea0 100644
--- a/cmk/gui/plugins/sidebar/shipped.py
+++ b/cmk/gui/plugins/sidebar/shipped.py
@@ -30,14 +30,10 @@
# from sidebar.py to the snapin objects that need these pages.
import re
-
import cmk.paths
-
import cmk.gui.config as config
-from cmk.gui.htmllib import HTML
from cmk.gui.i18n import _
from cmk.gui.globals import html
-
from cmk.gui.plugins.sidebar import (
sidebar_snapins,
bulletlink,
@@ -45,83 +41,6 @@ from cmk.gui.plugins.sidebar import (
)
#.
-# .--Custom Links--------------------------------------------------------.
-# | ____ _ _ _ _ |
-# | / ___| _ ___| |_ ___ _ __ ___ | | (_)_ __ | | _____ |
-# | | | | | | / __| __/ _ \| '_ ` _ \ | | | | '_ \| |/ / __| |
-# | | |__| |_| \__ \ || (_) | | | | | | | |___| | | | | <\__ \ |
-# | \____\__,_|___/\__\___/|_| |_| |_| |_____|_|_| |_|_|\_\___/ |
-# | |
-# '----------------------------------------------------------------------'
-
-
-def render_custom_links():
- links = config.custom_links.get(config.user.baserole_id)
- if not links:
- html.write_text((_(
- "Please edit <tt>%s</tt> in order to configure which links
are shown in this snapin.") %
- (cmk.paths.default_config_dir + "/multisite.mk")) +
"\n")
- return
-
- 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])
- 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 Check_MK. Replacing such images with the
default icon
- if icon_file.endswith(".gif"):
- icon_file = "icon_link.png"
- else:
- icon_file = "icon_link.png"
-
- linktext = HTML(html.render_icon("images/%s" % icon_file) +
" " + 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))
-
- render_list([], links)
-
-
-sidebar_snapins["custom_links"] = {
- "title": _("Custom Links"),
- "description": _("This snapin contains custom links which can be
"
- "configured via the configuration variable "
- "<tt>custom_links</tt> in
<tt>multisite.mk</tt>"),
- "render": render_custom_links,
- "allowed": ["user", "admin", "guest"],
- "styles": """
-#snapin_custom_links div.sublist {
- padding-left: 10px;
-}
-#snapin_custom_links img {
- margin-right: 5px;
-}
-#snapin_custom_links img.icon {
- width: 16px;
- height: 16px;
-}
-"""
-}
-
-#.
# .--Dokuwiki------------------------------------------------------------.
# | ____ _ _ _ _ |
# | | _ \ ___ | | ___ ___ _(_) | _(_) |