Exemple #1
0
    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()
Exemple #2
0
    def _show_body_start(self) -> None:
        body_classes = ['side', "screenshotmode" if config.screenshotmode else None]

        if not config.user.may("general.see_sidebar"):
            html.open_body(class_=body_classes)
            return

        interval = config.sidebar_notify_interval if config.sidebar_notify_interval is not None else "null"
        html.open_body(
            class_=body_classes,
            onload='cmk.sidebar.initialize_scroll_position(); cmk.sidebar.init_messages(%s);' %
            interval)
Exemple #3
0
    def _show_body_start(self) -> None:
        body_classes = ['side', "screenshotmode" if config.screenshotmode else None]

        if not user.may("general.see_sidebar"):
            html.open_body(class_=body_classes, data_theme=theme.get())
            return

        interval = config.sidebar_notify_interval if config.sidebar_notify_interval is not None else "null"
        html.open_body(
            class_=body_classes,
            onload=
            'cmk.sidebar.initialize_scroll_position(); cmk.sidebar.init_messages_and_werks(%s, %s); '
            % (json.dumps(interval), json.dumps(bool(may_acknowledge()))),
            data_theme=theme.get(),
        )
Exemple #4
0
    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()
Exemple #5
0
def mobile_html_head(title, ready_code=""):
    html.mobile = True
    html.write(
        """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">"""
    )
    html.open_html()
    html.open_head()
    html.meta(content="text/html;",
              charset="utf-8",
              **{"http-equiv": "Content-Type"})
    html.meta(name="viewport", content="initial-scale=1.0")
    html.meta(name="apple-mobile-web-app-capable", content="yes")
    html.meta(name="apple-mobile-web-app-title", content="Check_MK")
    html.title(title)
    html.stylesheet(href="jquery/jquery.mobile-1.0.css")
    html.stylesheet(href="themes/classic/theme.css")

    html.write(
        html._render_opening_tag("link",
                                 rel="apple-touch-icon",
                                 href="themes/classic/images/ios_logo.png",
                                 close_tag=True))
    html.javascript_file(src='js/mobile_min.js')

    if metrics.cmk_graphs_possible():
        html.javascript_file(src='js/graphs.js')

    # Never allow the mobile page to be opened in a frameset. Redirect top page to the current content page.
    # This will result in a full screen mobile interface page.
    html.javascript(
        '''if(top != self) { window.top.location.href = location; }''')

    html.javascript("""
      $(document).ready(function() { %s });
      $(document).ready(function() {
          $("a").click(function (event) {
            event.preventDefault();
            window.location = $(this).attr("href");
          });
      });""" % ready_code)

    html.close_head()
    html.open_body(class_="mobile")
Exemple #6
0
def mobile_html_head(title: str) -> None:
    html.write_html(
        HTML(
            """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">"""
        ))
    html.open_html()
    html.open_head()
    html.default_html_headers()
    html.meta(name="viewport", content="initial-scale=1.0")
    html.meta(name="apple-mobile-web-app-capable", content="yes")
    html.meta(name="apple-mobile-web-app-title", content="Check_MK")
    html.title(title)
    html.stylesheet(href="jquery/jquery.mobile-1.4.5.min.css")
    html.stylesheet(href="themes/facelift/theme.css")

    html.link(rel="apple-touch-icon", href="themes/facelift/images/ios_logo.png")
    html.javascript_file(src='js/mobile_min.js')

    html.close_head()
    html.open_body(class_="mobile")
Exemple #7
0
def mobile_html_head(title):
    # type: (Text) -> None
    html.mobile = True
    html.write(
        """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">"""
    )
    html.open_html()
    html.open_head()
    html.default_html_headers()
    html.meta(name="viewport", content="initial-scale=1.0")
    html.meta(name="apple-mobile-web-app-capable", content="yes")
    html.meta(name="apple-mobile-web-app-title", content="Check_MK")
    html.title(title)
    html.stylesheet(href="jquery/jquery.mobile-1.2.1.css")
    html.stylesheet(href="themes/classic/theme.css")

    html.write(
        html._render_start_tag("link",
                               rel="apple-touch-icon",
                               href="themes/classic/images/ios_logo.png",
                               close_tag=True))
    html.javascript_file(src='js/mobile_min.js')

    # Never allow the mobile page to be opened in an iframe. Redirect top page to the current content page.
    # This will result in a full screen mobile interface page.
    html.javascript(
        '''if(top != self) { window.top.location.href = location; }''')

    html.javascript("""
      $(document).ready(function() {
          $("a").click(function (event) {
            event.preventDefault();
            window.location = $(this).attr("href");
          });
      });""")

    html.close_head()
    html.open_body(class_="mobile")
Exemple #8
0
    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()