Beispiel #1
0
def hierarchy_update(id_: int) -> Union[str, Response]:
    hierarchy = g.nodes[id_]
    if hierarchy.standard:
        abort(403)
    form = build_form('hierarchy', hierarchy)
    form.forms.choices = Node.get_form_choices(hierarchy)
    if hasattr(form, 'multiple') and form.multiple.data:
        form.multiple.render_kw = {'disabled': 'disabled'}
    if form.validate_on_submit():
        if form.name.data != hierarchy.name and Node.get_nodes(form.name.data):
            flash(_('error name exists'), 'error')
        else:
            save(form, hierarchy)
            flash(_('info update'), 'info')
        tab = 'value' if g.nodes[id_].value_type else 'custom'
        return redirect(
            f"{url_for('node_index')}#menu-tab-{tab}_collapse-{hierarchy.id}")
    form.multiple = hierarchy.multiple
    table = Table(paging=False)
    for form_id, form_ in hierarchy.forms.items():
        count = Node.get_form_count(hierarchy, form_id)
        table.rows.append([
            g.classes[form_['name']].label,
            format_number(count) if count else link(
                _('remove'),
                url_for('remove_form', id_=hierarchy.id, form_id=form_id))
        ])
    return render_template('display_form.html',
                           form=form,
                           table=table,
                           manual_page='entity/type',
                           title=_('types'),
                           crumbs=[[_('types'),
                                    url_for('node_index')], hierarchy,
                                   _('edit')])
Beispiel #2
0
 def get_node_overview() -> Dict[str, Dict[Entity, str]]:
     nodes: Dict[str, Any] = {
         'standard': {},
         'custom': {},
         'places': {},
         'value': {}}
     for node in g.nodes.values():
         if node.root:
             continue
         type_ = 'custom'
         if node.class_.name == 'administrative_unit':
             type_ = 'places'
         elif node.standard:
             type_ = 'standard'
         elif node.value_type:
             type_ = 'value'
         nodes[type_][node.name] = GetNodeOverview.walk_tree(
             Node.get_nodes(node.name))
     return nodes
Beispiel #3
0
def node_index() -> str:
    nodes: Dict[str, Dict[Entity, str]] = \
        {'standard': {}, 'custom': {}, 'places': {}, 'value': {}}
    for node in g.nodes.values():
        if node.root:
            continue
        type_ = 'custom'
        if node.class_.name == 'administrative_unit':
            type_ = 'places'
        elif node.standard:
            type_ = 'standard'
        elif node.value_type:
            type_ = 'value'
        nodes[type_][node] = render_template('forms/tree_select_item.html',
                                             name=sanitize(node.name),
                                             data=walk_tree(
                                                 Node.get_nodes(node.name)))
    return render_template('types/index.html',
                           nodes=nodes,
                           title=_('types'),
                           crumbs=[_('types')])
Beispiel #4
0
def tree_select(name: str) -> str:
    from openatlas.models.node import Node
    return """
        <div id="{name}-tree"></div>
        <script>
            $(document).ready(function () {{
                $("#{name}-tree").jstree({{
                    "search": {{ "case_insensitive": true, "show_only_matches": true }},
                    "plugins" : ["core", "html_data", "search"],
                    "core": {{ "data": {tree_data} }}
                }});
                $("#{name}-tree").on("select_node.jstree", function (e, data) {{
                    document.location.href = data.node.original.href;
                }});
                $("#{name}-tree-search").keyup(function() {{
                    if (this.value.length >= {min_chars}) {{
                        $("#{name}-tree").jstree("search", $(this).val());
                    }}
                }});
            }});
        </script>""".format(
        min_chars=session['settings']['minimum_jstree_search'],
        name=sanitize(name),
        tree_data=walk_tree(Node.get_nodes(name)))