def update(self): import cmk.gui.sidebar as sidebar # pylint: disable=import-outside-toplevel dashlet = self._dashlet_spec snapin = sidebar.snapin_registry.get(self._dashlet_spec['snapin']) if not snapin: raise MKUserError(None, _('The configured element does not exist.')) snapin_instance = snapin() html.set_browser_reload(self.refresh_interval()) html.html_head(_('Sidebar element')) html.open_body(class_="side", data_theme=theme.get()) html.open_div(id_="check_mk_sidebar") html.open_div(id_="side_content") html.open_div(id_="snapin_container_%s" % dashlet['snapin'], class_="snapin") html.open_div(id_="snapin_%s" % dashlet['snapin'], class_="content") styles = snapin_instance.styles() if styles: html.style(styles) snapin_instance.show() html.close_div() html.close_div() html.close_div() html.close_div() html.body_end()
def update(self): import cmk.gui.sidebar as sidebar dashlet = self._dashlet_spec snapin = sidebar.snapin_registry.get(self._dashlet_spec['snapin']) if not snapin: raise MKUserError(None, _('The configured snapin does not exist.')) snapin_instance = snapin() html.set_browser_reload(self.refresh_interval()) html.html_head(_('Snapin Dashlet')) html.style(''' #side_content { height: auto; top: 0; padding-top: 4px; padding-left: 4px; } div.snapin:last-child { margin-bottom: 0; } div.snapin div.content { background-image: none; background-color: #508AA1; } div.snapin { margin: 0; padding: 0; } body.side { overflow-x: hidden; overflow-y: auto; }''') html.open_body(class_="side") html.open_div(id_="check_mk_sidebar") html.open_div(id_="side_content") html.open_div(id_="snapin_container_%s" % dashlet['snapin'], class_="snapin") html.open_div(id_="snapin_%s" % dashlet['snapin'], class_="content") styles = snapin_instance.styles() if styles: html.style(styles) snapin_instance.show() html.close_div() html.close_div() html.close_div() html.close_div() html.body_end()
def show(self, title: Optional[str] = None, content: Optional['HTML'] = None) -> None: # TODO: Right now the method renders the full HTML page, i.e. # the header, sidebar, and page content. Ideallly we should # split this up. Possible solutions might be: # # 1. If we remove the page side.py the code for the header # and the page content can be moved to the page index.py. # 2. Alternatively, we could extract a helper function that # provides the header and body (without content). Then # helper could then be used by index.py and side.py. # # In both cases this method would only render the sidebar # content afterwards. html.clear_default_javascript() html.html_head(title or _("Checkmk Sidebar"), javascripts=["side"]) self._show_body_start() self._show_sidebar() self._show_page_content(content) html.body_end()
def show(self, title: Optional[str] = None, content: Optional[HTML] = None) -> None: # TODO: Right now the method renders the full HTML page, i.e. # the header, sidebar, and page content. Ideallly we should # split this up. Possible solutions might be: # # 1. If we remove the page side.py the code for the header # and the page content can be moved to the page index.py. # 2. Alternatively, we could extract a helper function that # provides the header and body (without content). Then # helper could then be used by index.py and side.py. # # In both cases this method would only render the sidebar # content afterwards. if config.sidebar_notify_interval is not None: interval = config.sidebar_notify_interval else: interval = 'null' html.clear_default_javascript() if title is None: title = _("Check_MK Sidebar") html.html_head(title, javascripts=["side"]) body_classes = ['side'] if config.screenshotmode: body_classes.append("screenshotmode") if not config.user.may("general.see_sidebar"): html.open_body(class_=body_classes) html.div("", id_="check_mk_sidebar") else: html.open_body( class_=body_classes, onload= 'cmk.sidebar.initialize_scroll_position(); cmk.sidebar.set_sidebar_size(); cmk.sidebar.init_messages(%s);' % interval, onunload="cmk.sidebar.store_scroll_position()") html.open_div(id_="check_mk_sidebar") self._sidebar_head() user_config = UserSidebarConfig(config.user, config.sidebar) refresh_snapins = [] restart_snapins = [] static_snapins = [] html.open_div( class_="scroll" if config.sidebar_show_scrollbar else None, id_="side_content") for snapin in user_config.snapins: name = snapin.snapin_type.type_name() # Performs the initial rendering and might return an optional refresh url, # when the snapin contents are refreshed from an external source refresh_url = self.render_snapin(snapin) if snapin.snapin_type.refresh_regularly(): refresh_snapins.append([name, refresh_url]) elif snapin.snapin_type.refresh_on_restart(): refresh_snapins.append([name, refresh_url]) restart_snapins.append(name) else: static_snapins.append(name) html.close_div() self._sidebar_foot(user_config) html.close_div() html.javascript( "cmk.sidebar.initialize_sidebar(%0.2f, %s, %s, %s);\n" % ( config.sidebar_update_interval, json.dumps(refresh_snapins), json.dumps(restart_snapins), json.dumps(static_snapins), )) html.open_div(id_="content_area") if content is not None: html.write(content) html.close_div() html.body_end()
def show(self): # type: () -> None if not config.user.may("general.see_sidebar"): return None if config.sidebar_notify_interval is not None: interval = config.sidebar_notify_interval else: interval = 'null' html.clear_default_javascript() html.html_head(_("Check_MK Sidebar"), javascripts=["side"]) html.write('<body class="side') if config.screenshotmode: html.write(" screenshotmode") html.write( '" onload="cmk.sidebar.initialize_scroll_position(); cmk.sidebar.set_sidebar_size(); cmk.sidebar.init_messages(%s);" ' 'onunload="cmk.sidebar.store_scroll_position()">\n' % interval) html.open_div(id_="check_mk_sidebar") self._sidebar_head() user_config = UserSidebarConfig(config.user, config.sidebar) refresh_snapins = [] restart_snapins = [] html.open_div(class_="scroll" if config.sidebar_show_scrollbar else None, id_="side_content") for snapin in user_config.snapins: name = snapin.snapin_type.type_name() # Performs the initial rendering and might return an optional refresh url, # when the snapin contents are refreshed from an external source refresh_url = self.render_snapin(snapin) if snapin.snapin_type.refresh_regularly(): refresh_snapins.append([name, refresh_url]) elif snapin.snapin_type.refresh_on_restart(): refresh_snapins.append([name, refresh_url]) restart_snapins.append(name) html.close_div() self._sidebar_foot(user_config) html.close_div() html.write("<script language=\"javascript\">\n") if restart_snapins: html.write("cmk.sidebar.set_sidebar_restart_time(%s);\n" % time.time()) html.write("cmk.sidebar.set_sidebar_update_interval(%0.2f);\n" % config.sidebar_update_interval) html.write("cmk.sidebar.register_edge_listeners();\n") html.write("cmk.sidebar.set_sidebar_size();\n") html.write("cmk.sidebar.set_refresh_snapins(%s);\n" % json.dumps(refresh_snapins)) html.write("cmk.sidebar.set_restart_snapins(%s);\n" % json.dumps(restart_snapins)) html.write("cmk.sidebar.execute_sidebar_scheduler();\n") html.write("cmk.sidebar.register_event_handlers();\n") html.write("window.onresize = function() { cmk.sidebar.set_sidebar_size(); };\n") html.write( "if (cmk.sidebar.is_content_frame_accessible()) { cmk.sidebar.update_content_location(); };\n" ) html.write("</script>\n") html.body_end()