예제 #1
0
def ajax_dashlet_pos():
    dashlet, board = check_ajax_update()

    board["mtime"] = int(time.time())

    dashlet["position"] = saveint(html.var("x")), saveint(html.var("y"))
    dashlet["size"] = saveint(html.var("w")), saveint(html.var("h"))
    visuals.save("dashboards", dashboards)
    html.write("OK %d" % board["mtime"])
예제 #2
0
def ajax_dashlet_pos():
    dashlet, board = check_ajax_update()

    board['mtime'] = int(time.time())

    dashlet['position'] = saveint(html.var('x')), saveint(html.var('y'))
    dashlet['size']     = saveint(html.var('w')), saveint(html.var('h'))
    visuals.save('dashboards', dashboards)
    html.write('OK %d' % board['mtime'])
예제 #3
0
def load_dashboard_with_cloning(name, edit=True):
    board = available_dashboards[name]
    if edit and board["owner"] != config.user_id:
        # This dashboard which does not belong to the current user is about to
        # be edited. In order to make this possible, the dashboard is being
        # cloned now!
        board = copy.deepcopy(board)
        board["owner"] = config.user_id

        dashboards[(config.user_id, name)] = board
        available_dashboards[name] = board
        visuals.save("dashboards", dashboards)

    return board
예제 #4
0
def load_dashboard_with_cloning(name, edit = True):
    board = available_dashboards[name]
    if edit and board['owner'] != config.user_id:
        # This dashboard which does not belong to the current user is about to
        # be edited. In order to make this possible, the dashboard is being
        # cloned now!
        board = copy.deepcopy(board)
        board['owner'] = config.user_id

        dashboards[(config.user_id, name)] = board
        available_dashboards[name] = board
        visuals.save('dashboards', dashboards)

    return board
예제 #5
0
def page_delete_dashlet():
    if not config.may("general.edit_dashboards"):
        raise MKAuthException(_("You are not allowed to edit dashboards."))

    board = html.var('name')
    if not board:
        raise MKGeneralException(_('The name of the dashboard is missing.'))

    try:
        ident = int(html.var('id'))
    except ValueError:
        raise MKGeneralException(_('Invalid dashlet id'))

    load_dashboards()

    if board not in available_dashboards:
        raise MKGeneralException(_('The requested dashboard does not exist.'))
    dashboard = available_dashboards[board]

    try:
        dashlet = dashboard['dashlets'][ident]
    except IndexError:
        raise MKGeneralException(_('The dashlet does not exist.'))

    html.header(_('Confirm Dashlet Deletion'), stylesheets=["pages", "views"])

    html.begin_context_buttons()
    back_url = html.var('back', 'dashboard.py?name=%s&edit=1' % board)
    html.context_button(_('Back'), back_url, 'back')
    html.end_context_buttons()

    result = html.confirm(_('Do you really want to delete this dashlet?'),
                          method='GET',
                          add_transid=True)
    if result == False:
        html.footer()
        return  # confirm dialog shown
    elif result == True:  # do it!
        try:
            dashboard['dashlets'].pop(ident)
            dashboard['mtime'] = int(time.time())
            visuals.save('dashboards', dashboards)

            html.message(_('The dashlet has been deleted.'))
        except MKUserError, e:
            html.write("<div class=error>%s</div>\n" %
                       html.attrencode(e.message))
            return
예제 #6
0
def page_delete_dashlet():
    if not config.may("general.edit_dashboards"):
        raise MKAuthException(_("You are not allowed to edit dashboards."))

    board = html.var("name")
    if not board:
        raise MKGeneralException(_("The name of the dashboard is missing."))

    try:
        ident = int(html.var("id"))
    except ValueError:
        raise MKGeneralException(_("Invalid dashlet id"))

    load_dashboards(lock=True)

    if board not in available_dashboards:
        raise MKGeneralException(_("The requested dashboard does not exist."))
    dashboard = available_dashboards[board]

    try:
        dashlet = dashboard["dashlets"][ident]
    except IndexError:
        raise MKGeneralException(_("The dashlet does not exist."))

    html.header(_("Confirm Dashlet Deletion"), stylesheets=["pages", "views"])

    html.begin_context_buttons()
    back_url = html.var("back", "dashboard.py?name=%s&edit=1" % board)
    html.context_button(_("Back"), back_url, "back")
    html.end_context_buttons()

    result = html.confirm(_("Do you really want to delete this dashlet?"), method="GET", add_transid=True)
    if result == False:
        html.footer()
        return  # confirm dialog shown
    elif result == True:  # do it!
        try:
            dashboard["dashlets"].pop(ident)
            dashboard["mtime"] = int(time.time())
            visuals.save("dashboards", dashboards)

            html.message(_("The dashlet has been deleted."))
        except MKUserError, e:
            html.write("<div class=error>%s</div>\n" % html.attrencode(e))
            return
예제 #7
0
def page_edit_dashlet():
    if not config.may("general.edit_dashboards"):
        raise MKAuthException(_("You are not allowed to edit dashboards."))

    board = html.var("name")
    if not board:
        raise MKGeneralException(_("The name of the dashboard is missing."))

    ty = html.var("type")

    if html.has_var("id"):
        try:
            ident = int(html.var("id"))
        except ValueError:
            raise MKGeneralException(_("Invalid dashlet id"))
    else:
        ident = None

    if ident == None and not ty:
        raise MKGeneralException(_("The ID of the dashlet is missing."))

    load_dashboards(lock=html.is_transaction())

    if board not in available_dashboards:
        raise MKGeneralException(_("The requested dashboard does not exist."))
    dashboard = available_dashboards[board]

    if ident == None:
        mode = "add"
        title = _("Add Dashlet")
        dashlet_type = dashlet_types[ty]
        # Initial configuration
        dashlet = {
            "position": (1, 1),
            "size": dashlet_type.get("size", dashlet_min_size),
            "single_infos": dashlet_type.get("single_infos", []),
            "type": ty,
        }
        ident = len(dashboard["dashlets"])
        dashboard["dashlets"].append(dashlet)

        single_infos_raw = html.var("single_infos")
        single_infos = []
        if single_infos_raw:
            single_infos = single_infos_raw.split(",")
            for key in single_infos:
                if key not in visuals.infos:
                    raise MKUserError("single_infos", _("The info %s does not exist.") % key)

        if not single_infos:
            single_infos = dashlet_types[ty].get("single_infos", [])

        dashlet["single_infos"] = single_infos
    else:
        mode = "edit"
        title = _("Edit Dashlet")

        try:
            dashlet = dashboard["dashlets"][ident]
        except IndexError:
            raise MKGeneralException(_("The dashlet does not exist."))

        ty = dashlet["type"]
        dashlet_type = dashlet_types[ty]
        single_infos = dashlet["single_infos"]

    html.header(title, stylesheets=["pages", "views"])

    html.begin_context_buttons()
    back_url = html.var("back", "dashboard.py?name=%s&edit=1" % board)
    next_url = html.var("next", back_url)
    html.context_button(_("Back"), back_url, "back")
    html.context_button(_("All Dashboards"), "edit_dashboards.py", "dashboard")
    html.end_context_buttons()

    vs_general = Dictionary(
        title=_("General Settings"),
        render="form",
        optional_keys=["title", "title_url"],
        elements=[
            ("type", FixedValue(ty, totext=dashlet_type["title"], title=_("Dashlet Type"))),
            visuals.single_infos_spec(single_infos),
            (
                "background",
                Checkbox(
                    title=_("Colored Background"),
                    label=_("Render background"),
                    help=_("Render gray background color behind the dashlets content."),
                    default_value=True,
                ),
            ),
            (
                "show_title",
                Checkbox(
                    title=_("Show Title"),
                    label=_("Render the titlebar above the dashlet"),
                    help=_("Render the titlebar including title and link above the dashlet."),
                    default_value=True,
                ),
            ),
            (
                "title",
                TextUnicode(
                    title=_("Custom Title") + "<sup>*</sup>",
                    help=_(
                        "Most dashlets have a hard coded default title. For example the view snapin "
                        "has even a dynamic title which defaults to the real title of the view. If you "
                        "like to use another title, set it here."
                    ),
                    size=50,
                ),
            ),
            (
                "title_url",
                TextUnicode(
                    title=_("Link of Title"),
                    help=_("The URL of the target page the link of the dashlet should link to."),
                    size=50,
                ),
            ),
        ],
    )

    context_specs = visuals.get_context_specs(
        dashlet, info_handler=lambda dashlet: dashlet_types[dashlet["type"]].get("infos")
    )

    vs_type = None
    params = dashlet_type.get("parameters")
    render_input_func = None
    handle_input_func = None
    if type(params) == list:
        vs_type = Dictionary(
            title=_("Properties"),
            render="form",
            optional_keys=dashlet_type.get("opt_params"),
            validate=dashlet_type.get("validate_params"),
            elements=params,
        )
    elif type(params) == type(lambda x: x):
        # It's a tuple of functions which should be used to render and parse the params
        render_input_func, handle_input_func = params()

    if html.var("save") and html.transaction_valid():
        try:
            general_properties = vs_general.from_html_vars("general")
            vs_general.validate_value(general_properties, "general")
            dashlet.update(general_properties)
            # Remove unset optional attributes
            if "title" not in general_properties and "title" in dashlet:
                del dashlet["title"]

            if vs_type:
                type_properties = vs_type.from_html_vars("type")
                vs_type.validate_value(type_properties, "type")
                dashlet.update(type_properties)

            elif handle_input_func:
                dashlet = handle_input_func(ident, dashlet)

            if context_specs:
                dashlet["context"] = visuals.process_context_specs(context_specs)

            visuals.save("dashboards", dashboards)

            html.immediate_browser_redirect(1, next_url)
            if mode == "edit":
                html.message(_("The dashlet has been saved."))
            else:
                html.message(_("The dashlet has been added to the dashboard."))
            html.reload_sidebar()
            html.footer()
            return

        except MKUserError, e:
            html.write("<div class=error>%s</div>\n" % e)
            html.add_user_error(e.varname, e)
예제 #8
0
def save_dashboards(us):
    visuals.save("dashboards", dashboards)
예제 #9
0
def add_dashlet(dashlet, dashboard):
    dashboard["dashlets"].append(dashlet)
    dashboard["mtime"] = int(time.time())
    visuals.save("dashboards", dashboards)
예제 #10
0
def page_edit_dashlet():
    if not config.may("general.edit_dashboards"):
        raise MKAuthException(_("You are not allowed to edit dashboards."))

    board = html.var('name')
    if not board:
        raise MKGeneralException(_('The name of the dashboard is missing.'))

    ty = html.var('type')

    if html.has_var('id'):
        try:
            ident = int(html.var('id'))
        except ValueError:
            raise MKGeneralException(_('Invalid dashlet id'))
    else:
        ident = None

    if ident == None and not ty:
        raise MKGeneralException(_('The ident of the dashlet is missing.'))

    load_dashboards()

    if board not in available_dashboards:
        raise MKGeneralException(_('The requested dashboard does not exist.'))
    dashboard = available_dashboards[board]

    if ident == None:
        mode         = 'add'
        title        = _('Add Dashlet')
        dashlet_type = dashlet_types[ty]
        # Initial configuration
        dashlet = {
            'position'     : (1, 1),
            'size'         : dashlet_type.get('size', dashlet_min_size),
            'single_infos' : dashlet_type.get('single_infos', []),
            'type'         : ty,
        }
        ident   =  len(dashboard['dashlets'])
        dashboard['dashlets'].append(dashlet)

        single_infos_raw = html.var('single_infos')
        single_infos = []
        if single_infos_raw:
            single_infos = single_infos_raw.split(',')
            for key in single_infos:
                if key not in visuals.infos:
                    raise MKUserError('single_infos', _('The info %s does not exist.') % key)

        if not single_infos:
            single_infos = dashlet_types[ty].get('single_infos', [])

        dashlet['single_infos'] = single_infos
    else:
        mode    = 'edit'
        title   = _('Edit Dashlet')

        try:
            dashlet = dashboard['dashlets'][ident]
        except IndexError:
            raise MKGeneralException(_('The dashlet does not exist.'))

        ty           = dashlet['type']
        dashlet_type = dashlet_types[ty]
        single_infos = dashlet['single_infos']

    html.header(title, stylesheets=["pages","views"])

    html.begin_context_buttons()
    back_url = html.var('back', 'dashboard.py?name=%s&edit=1' % board)
    next_url = html.var('next', back_url)
    html.context_button(_('Back'), back_url, 'back')
    html.context_button(_('All Dashboards'), 'edit_dashboards.py', 'dashboard')
    html.end_context_buttons()

    vs_general = Dictionary(
        title = _('General'),
        render = 'form',
        optional_keys = ['title', 'title_url'],
        elements = [
            ('type', FixedValue(ty,
                totext = dashlet_type['title'],
                title = _('Dashlet Type'),
            )),
            ('single_infos', FixedValue(single_infos,
                title = _('Show information of single'),
                totext = single_infos and ', '.join(single_infos) \
                                      or _('Not showing information for a specific object.'),
            )),
            ('background', Checkbox(
                title = _('Colored Background'),
                label = _('Render background'),
                help = _('Render gray background color behind the dashlets content.'),
                default_value = True,
            )),
            ('show_title', Checkbox(
                title = _('Show Title'),
                label = _('Render the titlebar above the dashlet'),
                help = _('Render the titlebar including title and link above the dashlet.'),
                default_value = True,
            )),
            ('title', TextUnicode(
                title = _('Custom Title') + '<sup>*</sup>',
                help = _('Most dashlets have a hard coded default title. For example the view snapin '
                         'has even a dynamic title which defaults to the real title of the view. If you '
                         'like to use another title, set it here.'),
                size = 50,
            )),
            ('title_url', TextUnicode(
                title = _('Link of Title'),
                help = _('The URL of the target page the link of the dashlet should link to.'),
                size = 50,
            )),
        ],
    )

    context_specs = visuals.get_context_specs(dashlet,
        info_handler=lambda dashlet: dashlet_types[dashlet['type']].get('infos'))

    vs_type = None
    params = dashlet_type.get('parameters')
    render_input_func = None
    handle_input_func = None
    if type(params) == list:
        vs_type = Dictionary(
            title = _('Properties'),
            render = 'form',
            optional_keys = dashlet_type.get('opt_params'),
            validate = dashlet_type.get('validate_params'),
            elements = params,
        )
    elif type(params) == type(lambda x: x):
        # It's a tuple of functions which should be used to render and parse the params
        render_input_func, handle_input_func = params()

    if html.var('save') and html.transaction_valid():
        try:
            general_properties = vs_general.from_html_vars('general')
            vs_general.validate_value(general_properties, 'general')
            dashlet.update(general_properties)
            # Remove unset optional attributes
            if 'title' not in general_properties and 'title' in dashlet:
                del dashlet['title']

            if vs_type:
                type_properties = vs_type.from_html_vars('type')
                vs_type.validate_value(type_properties, 'type')
                dashlet.update(type_properties)

            elif handle_input_func:
                dashlet = handle_input_func(ident, dashlet)

            if context_specs:
                dashlet['context'] = visuals.process_context_specs(context_specs)

            visuals.save('dashboards', dashboards)

            html.immediate_browser_redirect(1, next_url)
            if mode == 'edit':
                html.message(_('The dashlet has been saved.'))
            else:
                html.message(_('The dashlet has been added to the dashboard.'))
            html.reload_sidebar()
            html.footer()
            return

        except MKUserError, e:
            html.write("<div class=error>%s</div>\n" % e.message)
            html.add_user_error(e.varname, e.message)
예제 #11
0
def save_dashboards(us):
    visuals.save('dashboards', dashboards)
예제 #12
0
def add_dashlet(dashlet, dashboard):
    dashboard['dashlets'].append(dashlet)
    dashboard['mtime'] = int(time.time())
    visuals.save('dashboards', dashboards)