From 21ad9b7df6d45e778b47445c3e03715a0c24515e Mon Sep 17 00:00:00 2001 From: hasansezertasan Date: Wed, 10 Jul 2024 19:41:47 +0300 Subject: [PATCH 1/5] Initial attempt for Tabler Template Mode --- flask_admin/static/admin/js/tabler_filters.js | 197 ++++++++++++ flask_admin/static/admin/js/tabler_modal.js | 12 + flask_admin/templates/tabler/actions.html | 39 +++ flask_admin/templates/tabler/base.html | 159 ++++++++++ flask_admin/templates/tabler/file/form.html | 23 ++ flask_admin/templates/tabler/file/list.html | 226 ++++++++++++++ .../templates/tabler/file/modals/form.html | 26 ++ flask_admin/templates/tabler/index.html | 3 + flask_admin/templates/tabler/layout.html | 94 ++++++ flask_admin/templates/tabler/lib.html | 291 ++++++++++++++++++ flask_admin/templates/tabler/master.html | 1 + .../templates/tabler/model/create.html | 52 ++++ .../templates/tabler/model/details.html | 85 +++++ flask_admin/templates/tabler/model/edit.html | 73 +++++ .../tabler/model/inline_field_list.html | 11 + .../templates/tabler/model/inline_form.html | 3 + .../tabler/model/inline_list_base.html | 55 ++++ .../templates/tabler/model/layout.html | 108 +++++++ flask_admin/templates/tabler/model/list.html | 230 ++++++++++++++ .../templates/tabler/model/modals/create.html | 37 +++ .../tabler/model/modals/details.html | 57 ++++ .../templates/tabler/model/modals/edit.html | 37 +++ .../templates/tabler/model/row_actions.html | 55 ++++ .../templates/tabler/rediscli/console.html | 38 +++ .../templates/tabler/rediscli/response.html | 33 ++ flask_admin/templates/tabler/static.html | 3 + 26 files changed, 1948 insertions(+) create mode 100644 flask_admin/static/admin/js/tabler_filters.js create mode 100644 flask_admin/static/admin/js/tabler_modal.js create mode 100644 flask_admin/templates/tabler/actions.html create mode 100644 flask_admin/templates/tabler/base.html create mode 100644 flask_admin/templates/tabler/file/form.html create mode 100644 flask_admin/templates/tabler/file/list.html create mode 100644 flask_admin/templates/tabler/file/modals/form.html create mode 100644 flask_admin/templates/tabler/index.html create mode 100644 flask_admin/templates/tabler/layout.html create mode 100644 flask_admin/templates/tabler/lib.html create mode 100644 flask_admin/templates/tabler/master.html create mode 100644 flask_admin/templates/tabler/model/create.html create mode 100644 flask_admin/templates/tabler/model/details.html create mode 100644 flask_admin/templates/tabler/model/edit.html create mode 100644 flask_admin/templates/tabler/model/inline_field_list.html create mode 100644 flask_admin/templates/tabler/model/inline_form.html create mode 100644 flask_admin/templates/tabler/model/inline_list_base.html create mode 100644 flask_admin/templates/tabler/model/layout.html create mode 100644 flask_admin/templates/tabler/model/list.html create mode 100644 flask_admin/templates/tabler/model/modals/create.html create mode 100644 flask_admin/templates/tabler/model/modals/details.html create mode 100644 flask_admin/templates/tabler/model/modals/edit.html create mode 100644 flask_admin/templates/tabler/model/row_actions.html create mode 100644 flask_admin/templates/tabler/rediscli/console.html create mode 100644 flask_admin/templates/tabler/rediscli/response.html create mode 100644 flask_admin/templates/tabler/static.html diff --git a/flask_admin/static/admin/js/tabler_filters.js b/flask_admin/static/admin/js/tabler_filters.js new file mode 100644 index 000000000..08dfd81dd --- /dev/null +++ b/flask_admin/static/admin/js/tabler_filters.js @@ -0,0 +1,197 @@ +/* +This file is from Flask-Admin project with a slight modification to work with Tabler. +*/ +var AdminFilters = function(element, filtersElement, filterGroups, activeFilters) { + var $root = $(element); + var $container = $('.filters', $root); + var lastCount = 0; + + function getCount(name) { + var idx = name.indexOf('_'); + + if (idx === -1) { + return 0; + } + + return parseInt(name.substr(3, idx - 3), 10); + } + + function makeName(name) { + var result = 'flt' + lastCount + '_' + name; + lastCount += 1; + return result; + } + + function removeFilter() { + $(this).closest('tr').remove(); + if($('.filters tr').length == 0) { + $('button', $root).hide(); + $('a[class=btn]', $root).hide(); + $('.filters tbody').remove(); + } else { + $('button', $root).show(); + } + + return false; + } + + // triggered when the filter operation (equals, not equals, etc) is changed + function changeOperation(subfilters, $el, filter, $select) { + // get the filter_group subfilter based on the index of the selected option + var selectedFilter = subfilters[$select.select2('data').element[0].index]; + var $inputContainer = $el.find('td').last(); + + // recreate and style the input field (turn into date range or select2 if necessary) + var $field = createFilterInput($inputContainer, null, selectedFilter); + styleFilterInput(selectedFilter, $field); + + $('button', $root).show(); + } + + // generate HTML for filter input - allows changing filter input type to one with options or tags + function createFilterInput(inputContainer, filterValue, filter) { + if (filter.type == "select2-tags") { + var $field = $('').attr('name', makeName(filter.arg)); + $field.val(filterValue); + } else if (filter.options) { + var $field = $('').attr('name', makeName(filter.arg)); + $field.val(filterValue); + } + inputContainer.replaceWith($('').append($field)); + + return $field; + } + + // add styling to input field, accommodates filters that change the input field's HTML + function styleFilterInput(filter, field) { + if (filter.type) { + if ((filter.type == "datepicker") || (filter.type == "daterangepicker")) { + field.attr('data-date-format', "YYYY-MM-DD"); + } else if ((filter.type == "datetimepicker") || (filter.type == "datetimerangepicker")) { + field.attr('data-date-format', "YYYY-MM-DD HH:mm:ss"); + } else if ((filter.type == "timepicker") || (filter.type == "timerangepicker")) { + field.attr('data-date-format', "HH:mm:ss"); + } else if (filter.type == "select2-tags") { + var options = []; + if (filter.options) { + filter.options.forEach(function(option) { + options.push({id:option[0], text:option[1]}); + }); + // save tag options as json on data attribute + field.attr('data-tags', JSON.stringify(options)); + } + } + faForm.applyStyle(field, filter.type); + } else if (filter.options) { + filter.type = "select2"; + faForm.applyStyle(field, filter.type); + } + + return field; + } + + function addFilter(name, subfilters, selectedIndex, filterValue) { + var $el = $('').appendTo($container); + + // Filter list + $el.append( + $('').append( + $('') + .append($('×')) + .append(' ') + .append(name) + .click(removeFilter) + ) + ); + + // Filter operation '); + + // if one of the subfilters are selected, use that subfilter to create the input field + var filterSelection = 0; + $.each(subfilters, function( subfilterIndex, subfilter ) { + if (this.index == selectedIndex) { + $select.append($(' + +{% endmacro %} +{% macro form(actions, url) %} + {% if actions %} + + {% endif %} +{% endmacro %} +{% macro script(message, actions, actions_confirmation) %} + {% if actions %} + + + + {% endif %} +{% endmacro %} diff --git a/flask_admin/templates/tabler/base.html b/flask_admin/templates/tabler/base.html new file mode 100644 index 000000000..9e39e09d2 --- /dev/null +++ b/flask_admin/templates/tabler/base.html @@ -0,0 +1,159 @@ +{% import "admin/layout.html" as layout with context -%} +{% import "admin/static.html" as admin_static with context %} + + + + {% block title %}{% if admin_view.category %}{{ admin_view.category }} - {% endif %}{{ admin_view.name }} - {{ admin_view.admin.name }}{% endblock %} + {% block head_meta %} + + + + + + {% endblock head_meta %} + {% block head_css %} + + + + {% if admin_view.extra_css %} + {% for css_url in admin_view.extra_css %}{% endfor %} + {% endif %} + + {% endblock head_css %} + {% block head %} + {% endblock head %} + {% block head_tail %} + {% endblock head_tail %} + + + {% block page_body %} +
+ {% block sidebar %} + + {% endblock sidebar %} + {% block navbar %} + + {% endblock navbar %} +
+
+ +
+
+
+
+ {% block messages %} + {{ layout.messages() }} + {% endblock messages %} + {# store the jinja2 context for form_rules rendering logic #} + {% set render_ctx = h.resolve_ctx() %} + {% block body %} + {% endblock body %} +
+
+
+
+
+ {% endblock page_body %} + {% block tail_js %} + + + + + + + {% if admin_view.extra_js %} + {% for js_url in admin_view.extra_js %}{% endfor %} + {% endif %} + {% endblock tail_js %} + {% block tail %} + {% endblock tail %} + + diff --git a/flask_admin/templates/tabler/file/form.html b/flask_admin/templates/tabler/file/form.html new file mode 100644 index 000000000..6f74d5e36 --- /dev/null +++ b/flask_admin/templates/tabler/file/form.html @@ -0,0 +1,23 @@ +{% extends "admin/master.html" %} +{% import "admin/lib.html" as lib with context %} +{% block header %} +
+
+
{{ admin_view.category if admin_view.category else _gettext("Admin") }}
+

{{ admin_view.name }} - {{ header_text }}

+
+
+{% endblock header %} +{% block body %} +
+
+

{{ admin_view.name }} - {{ header_text }}

+
+ {% block fa_form %} + {% call lib.form_tag(action=request.url) %} +
{{ lib.render_form_fields(form) }}
+ + {% endcall %} + {% endblock fa_form %} +
+{% endblock body %} diff --git a/flask_admin/templates/tabler/file/list.html b/flask_admin/templates/tabler/file/list.html new file mode 100644 index 000000000..9db49d167 --- /dev/null +++ b/flask_admin/templates/tabler/file/list.html @@ -0,0 +1,226 @@ +{% extends "admin/master.html" %} +{% import "admin/lib.html" as lib with context %} +{% import 'admin/actions.html' as actionslib with context %} +{% import "admin/static.html" as admin_static with context %} +{% block header %} +
+
+
{{ admin_view.category if admin_view.category else _gettext("Admin") }}
+

{{ admin_view.name }}

+
+
+{% endblock header %} +{% block body %} +
+
+ {% block breadcrums %} + + {% endblock breadcrums %} +
+
+ {% block file_list_table %} +
+ + + + {% block list_header scoped %} + {% if actions %} + + {% endif %} + + {% for column in admin_view.column_list %} + + {% endfor %} + {% endblock list_header %} + + + {% for name, path, is_dir, size, date in items %} + + {% block list_row scoped %} + {% if actions %} + + {% endif %} + + {% if is_dir %} + + {% else %} + + {% if admin_view.is_column_visible('size') %}{% endif %} + {% endif %} + {% if admin_view.is_column_visible('date') %}{% endif %} + {% endblock list_row %} + + {% endfor %} +
+ +   + {% if admin_view.is_column_sortable(column) %} + {% if sort_column == column %} + + {{ admin_view.column_label(column) }} + {% if sort_desc %} + + {% else %} + + {% endif %} + + {% else %} + {{ admin_view.column_label(column) }} + {% endif %} + {% else %} + {{ _gettext(admin_view.column_label(column) ) }} + {% endif %} +
+ {% if not is_dir %} + + {% endif %} + + {% if name != ".." %} + + {% endif %} + + + {{ name }} + + + {% if admin_view.can_download %} + {%- if admin_view.edit_modal and admin_view.is_file_editable(path) -%} + {{ lib.add_modal_button(url=get_file_url(path, modal=True) |safe, btn_class="", content=name) }} + {% else %} + {{ name }} + {%- endif -%} + {% else %} + {{ name }} + {% endif %} + {{ size|filesizeformat }}{{ timestamp_format(date) }}
+
+ {% endblock file_list_table %} +
+ +
+{% endblock body %} +{% block tail %} + {{ super() }} + {{ actionslib.script(_gettext('Please select at least one file.') , + actions, + actions_confirmation) }} + {{ lib.form_js() }} + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/file/modals/form.html b/flask_admin/templates/tabler/file/modals/form.html new file mode 100644 index 000000000..b2057af73 --- /dev/null +++ b/flask_admin/templates/tabler/file/modals/form.html @@ -0,0 +1,26 @@ +{% import "admin/lib.html" as lib with context %} +{% block body %} + + {% block fa_form %} + {% call lib.form_tag(action=request.url) %} + + + {% endcall %} + {% endblock fa_form %} +{% endblock body %} +{% block tail %} + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/index.html b/flask_admin/templates/tabler/index.html new file mode 100644 index 000000000..8acdb58b2 --- /dev/null +++ b/flask_admin/templates/tabler/index.html @@ -0,0 +1,3 @@ +{% extends "admin/master.html" %} +{% block body %} +{% endblock body %} diff --git a/flask_admin/templates/tabler/layout.html b/flask_admin/templates/tabler/layout.html new file mode 100644 index 000000000..e9a2d1a27 --- /dev/null +++ b/flask_admin/templates/tabler/layout.html @@ -0,0 +1,94 @@ +{% macro menu_icon(item) -%} + {% set icon_type = item.get_icon_type() %} + {%- if icon_type %} + {% set icon_value = item.get_icon_value() %} + {% if icon_type == 'glyph' %} + + {% elif icon_type == 'fa' %} + + {% elif icon_type == 'image' %} + menu image + {% elif icon_type == 'image-url' %} + menu image + {% endif %} + {% endif %} +{%- endmacro %} +{% macro item_block(item) -%} + {{ menu_icon(item) }} + {{ item.name }} +{%- endmacro %} +{% macro menu(menu_root=None) %} + {% set is_main_nav = menu_root == None %} + {% if menu_root is none %} + {% set menu_root = admin_view.admin.menu() %} + {% endif %} + {%- for item in menu_root %} + {%- if item.is_category() -%} + {% set children = item.get_children() %} + {%- if children %} + + {% endif %} + {%- else %} + {%- if item.is_accessible() and item.is_visible() -%} + + {%- endif -%} + {% endif -%} + {% endfor %} +{% endmacro %} +{% macro menu_links(links=None) %} + {% if links is none %} + {% set links = admin_view.admin.menu_links() %} + {% endif %} + {% for item in links %} + {% if item.is_accessible() and item.is_visible() %} +
  • + {{ item_block(item) }} +
  • + {% endif %} + {% endfor %} +{% endmacro %} +{% macro messages() %} + {% with messages = get_flashed_messages(with_categories=True) %} + {% if messages %} + {% set mapping = {"message": "success", "error": "danger"} %} + {% set icon_mapping = {"message": "check", "error": "circle-exclamation", "info": "circle-info", "warning": "circle-exclamation"} %} + {% for category, m in messages %} + + {% endfor %} + {% endif %} + {% endwith %} +{% endmacro %} diff --git a/flask_admin/templates/tabler/lib.html b/flask_admin/templates/tabler/lib.html new file mode 100644 index 000000000..90d31a829 --- /dev/null +++ b/flask_admin/templates/tabler/lib.html @@ -0,0 +1,291 @@ +{% import "admin/static.html" as admin_static with context %} +{# ---------------------- Pager -------------------------- #} +{% macro pager(page, pages, generator) -%} + {% if pages > 1 %} + + {% endif %} +{%- endmacro %} +{% macro simple_pager(page, have_next, generator) -%} + +{%- endmacro %} +{# ---------------------- Modal Window ------------------- #} +{% macro add_modal_window(modal_window_id='fa_modal_window', modal_label_id='fa_modal_label') %} + +{% endmacro %} +{% macro add_modal_button(url="", title="", content="", modal_window_id="fa_modal_window", btn_class="icon") %} + {{ content|safe }} +{% endmacro %} +{# ---------------------- Forms -------------------------- #} +{% macro render_field(form, field, kwargs={}, caller=None) %} + {% set direct_error = h.is_field_error(field.errors) %} + {% set prepend = kwargs.pop('prepend', None) %} + {% set append = kwargs.pop('append', None) %} +
    + + {% if prepend or append %} +
    + {%- if prepend -%} +
    {{ prepend }}
    + {%- endif -%} + {% endif %} + {% if field.widget.input_type == 'checkbox' %} + {% set _class = kwargs.setdefault('class', "") %} + {% elif field.widget.input_type == 'file' %} + {% set _class = kwargs.setdefault('class', 'form-control-file') %} + {% else %} + {% set _class = kwargs.setdefault('class', 'form-control') %} + {% endif %} + {%- if direct_error %} {% set _ = kwargs.update({'class': kwargs['class'] ~ ' is-invalid'}) %} + {% endif -%} + {{ field(**kwargs) | safe }} + {%- if append -%} +
    {{ append }}
    + {%- endif -%} + {% if direct_error %} +
    +
      + {% for e in field.errors if e is string %}
    • {{ e }}
    • {% endfor %} +
    +
    + {% elif field.description %} + + {{ field.description|safe }} + + {% endif %} + {% if prepend or append %}
    {% endif %} + {% if caller %}{{ caller(form, field, direct_error, kwargs) }}{% endif %} +
    +{% endmacro %} +{% macro render_header(form, text) %} +

    {{ text }}

    +{% endmacro %} +{% macro render_form_fields(form, form_opts=None) %} + {% if form.hidden_tag is defined %} + {{ form.hidden_tag() }} + {% else %} + {% if csrf_token %}{% endif %} + {% for f in form if f.widget.input_type == 'hidden' %}{{ f }}{% endfor %} + {% endif %} + {% if form_opts and form_opts.form_rules %} + {% for r in form_opts.form_rules %}{{ r(form, form_opts=form_opts) }}{% endfor %} + {% else %} + {% for f in form if f.widget.input_type != 'hidden' %} + {% if form_opts %} + {% set kwargs = form_opts.widget_args.get(f.short_name, {}) %} + {% else %} + {% set kwargs = {} %} + {% endif %} + {{ render_field(form, f, kwargs) }} + {% endfor %} + {% endif %} +{% endmacro %} +{% macro form_tag(form=None, action=None) %} +
    +
    + {{ caller() }} +
    +
    +{% endmacro %} +{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %} + {% if is_modal %} + + {% if extra %}{{ extra }}{% endif %} + {% if cancel_url %} + {{ _gettext("Cancel") }} + {% endif %} + {% else %} +
    +
    +
    + + {% if extra %}{{ extra }}{% endif %} + {% if cancel_url %} + {{ _gettext("Cancel") }} + {% endif %} +
    +
    + {% endif %} +{% endmacro %} +{% macro render_form(form, cancel_url, extra=None, form_opts=None, action=None, is_modal=False) -%} + {% call form_tag(action=action) %} + {{ render_form_fields(form, form_opts=form_opts) }} + {{ render_form_buttons(cancel_url, extra, is_modal) }} + {% endcall %} +{% endmacro %} +{% macro form_css() %} + + + + {% if config.MAPBOX_MAP_ID %} + + + {% endif %} + {% if editable_columns %} + + {% endif %} +{% endmacro %} +{% macro form_js() %} + {# djlint:off #} +{% if config.MAPBOX_MAP_ID %} + + + +{% if config.MAPBOX_SEARCH %} + + +{% endif %} +{% endif %} + {# djlint:on #} + + {% if editable_columns %} + + {% endif %} + +{% endmacro %} +{% macro extra() %} + {% if admin_view.can_create %} + + {% endif %} + {% if admin_view.can_edit %} + + {% endif %} +{% endmacro %} diff --git a/flask_admin/templates/tabler/master.html b/flask_admin/templates/tabler/master.html new file mode 100644 index 000000000..8f27dad00 --- /dev/null +++ b/flask_admin/templates/tabler/master.html @@ -0,0 +1 @@ +{% extends admin_base_template %} diff --git a/flask_admin/templates/tabler/model/create.html b/flask_admin/templates/tabler/model/create.html new file mode 100644 index 000000000..d7aa97a6e --- /dev/null +++ b/flask_admin/templates/tabler/model/create.html @@ -0,0 +1,52 @@ +{% extends "admin/master.html" %} +{% import "admin/lib.html" as lib with context %} +{% from "admin/lib.html" import extra with context %} {# backward compatible #} +{% block head %} + {{ super() }} + {{ lib.form_css() }} +{% endblock head %} +{% block header %} +
    +
    +
    {{ admin_view.category if admin_view.category else _gettext("Admin") }}
    +

    {{ admin_view.name }}

    +
    +
    +{% endblock header %} +{% block body %} +
    +
    + {% block navlinks %} + + {% endblock navlinks %} +
    +
    + {% block create_form %} + {{ lib.render_form(form, return_url, extra() , form_opts) }} + {% endblock create_form %} +
    +
    +{% endblock body %} +{% block tail %} + {{ super() }} + {{ lib.form_js() }} +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/details.html b/flask_admin/templates/tabler/model/details.html new file mode 100644 index 000000000..c73981ba7 --- /dev/null +++ b/flask_admin/templates/tabler/model/details.html @@ -0,0 +1,85 @@ +{% extends "admin/master.html" %} +{% block header %} +
    +
    +
    {{ admin_view.category if admin_view.category else _gettext("Admin") }}
    +

    {{ admin_view.name }}

    +
    +
    +{% endblock header %} +{% block body %} +
    +
    + {% block navlinks %} + + {% endblock navlinks %} +
    +
    + {% block details_table %} + + {% for c, name in details_columns %} + + + + + {% endfor %} +
    + {{ name }} + {{ get_value(model, c) }}
    + {% endblock details_table %} +
    +
    +{% endblock body %} +{% block tail %} + {{ super() }} + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/edit.html b/flask_admin/templates/tabler/model/edit.html new file mode 100644 index 000000000..576cab6a3 --- /dev/null +++ b/flask_admin/templates/tabler/model/edit.html @@ -0,0 +1,73 @@ +{% extends "admin/master.html" %} +{% import "admin/lib.html" as lib with context %} +{% from 'admin/lib.html' import extra with context %} {# backward compatible #} +{% block head %} + {{ super() }} + {{ lib.form_css() }} +{% endblock head %} +{% block header %} +
    +
    +
    {{ admin_view.category if admin_view.category else _gettext("Admin") }}
    +

    {{ admin_view.name }}

    +
    +
    +{% endblock header %} +{% block body %} +
    +
    + {% block navlinks %} + + {% endblock navlinks %} +
    +
    + {% block edit_form %} + {{ lib.render_form(form, return_url, extra() , form_opts) }} + {% endblock edit_form %} +
    +
    +{% endblock body %} +{% block tail %} + {{ super() }} + {{ lib.form_js() }} +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/inline_field_list.html b/flask_admin/templates/tabler/model/inline_field_list.html new file mode 100644 index 000000000..f44deeeb3 --- /dev/null +++ b/flask_admin/templates/tabler/model/inline_field_list.html @@ -0,0 +1,11 @@ +{# TODO: Update Inline Fields Interface #} +{% import 'admin/model/inline_list_base.html' as base with context %} +{% macro render_field(field) %} + {{ field }} + {% if h.is_field_error(field.errors) %} + + {% endif %} +{% endmacro %} +{{ base.render_inline_fields(field, template, render_field, check) }} diff --git a/flask_admin/templates/tabler/model/inline_form.html b/flask_admin/templates/tabler/model/inline_form.html new file mode 100644 index 000000000..71160f411 --- /dev/null +++ b/flask_admin/templates/tabler/model/inline_form.html @@ -0,0 +1,3 @@ +{# TODO: Update Inline Fields Interface #} +{% import "admin/lib.html" as lib with context %} +
    {{ lib.render_form_fields(field.form, form_opts=form_opts) }}
    diff --git a/flask_admin/templates/tabler/model/inline_list_base.html b/flask_admin/templates/tabler/model/inline_list_base.html new file mode 100644 index 000000000..64f818de5 --- /dev/null +++ b/flask_admin/templates/tabler/model/inline_list_base.html @@ -0,0 +1,55 @@ +{# TODO: Update Inline Fields Interface #} +{% macro render_inline_fields(field, template, render, check=None) %} +
    + {# existing inline form fields #} +
    + {% for subfield in field %} +
    + {%- if not check or check(subfield) %} + + + {{ field.label.text }} #{{ loop.index }} +
    + {% if subfield.get_pk and subfield.get_pk() %} + + + {% else %} + + {% endif %} +
    +
    +
    +
    + {%- endif -%} + {{ render(subfield) }} +
    + {% endfor %} +
    + {# template for new inline form fields #} +
    + {% filter forceescape %} +
    + + {{ _gettext("New") }} {{ field.label.text }} +
    + +
    +
    +
    + {{ render(template) }} +
    + {% endfilter %} +
    + {{ _gettext("Add") }} {{ field.label.text }} +
    +{% endmacro %} diff --git a/flask_admin/templates/tabler/model/layout.html b/flask_admin/templates/tabler/model/layout.html new file mode 100644 index 000000000..acae11a86 --- /dev/null +++ b/flask_admin/templates/tabler/model/layout.html @@ -0,0 +1,108 @@ +{% macro filter_options(btn_class="nav-link dropdown-toggle") %} + + +{% endmacro %} +{% macro export_options(btn_class="nav-link dropdown-toggle") %} + {% if admin_view.export_types|length > 1 %} + + {% else %} + + {% endif %} +{% endmacro %} +{% macro filter_form() %} +
    + {% if sort_column is not none %}{% endif %} + {% if sort_desc %}{% endif %} + {% if search %}{% endif %} + {% if page_size != default_page_size %}{% endif %} + +
    +
    + + {% if active_filters %} + {{ _gettext("Reset Filters") }} + {% endif %} +
    +
    +
    +{% endmacro %} +{% macro search_form(input_class="col-auto") %} + +{% endmacro %} +{% macro page_size_form(generator, btn_class="nav-link dropdown-toggle") %} + + +{% endmacro %} diff --git a/flask_admin/templates/tabler/model/list.html b/flask_admin/templates/tabler/model/list.html new file mode 100644 index 000000000..818e3662e --- /dev/null +++ b/flask_admin/templates/tabler/model/list.html @@ -0,0 +1,230 @@ +{% extends "admin/master.html" %} +{% import "admin/lib.html" as lib with context %} +{% import "admin/static.html" as admin_static with context %} +{% import "admin/model/layout.html" as model_layout with context %} +{% import "admin/actions.html" as actionlib with context %} +{% import "admin/model/row_actions.html" as row_actions with context %} +{% block head %} + {{ super() }} + {{ lib.form_css() }} +{% endblock head %} +{% block header %} +
    +
    +
    {{ admin_view.category if admin_view.category else _gettext("Admin") }}
    +

    {{ admin_view.name }}

    +
    + +
    +
    + + {% if admin_view.can_create %} + {%- if admin_view.create_modal -%} + {{ lib.add_modal_button(url=get_url('.create_view', url=return_url, modal=True) , btn_class="nav-link", title=_gettext('Create New Record'), content=_gettext('Create')) }} + {% else %} + {{ _gettext("Create") }} + {%- endif -%} + {% endif %} + +
    +
    +
    +{% endblock header %} +{% block body %} +
    +
    + {% block model_menu_bar %} + + {% endblock model_menu_bar %} +
    +
    + {% if filters %} + {{ model_layout.filter_form() }} +
    + {% endif %} +
    +
    + {% block model_list_table %} +
    + + + + {% block list_header scoped %} + {% if actions %} + + {% endif %} + {% block list_row_actions_header %} + {% if admin_view.column_display_actions and list_row_actions %}{% endif %} + {% endblock list_row_actions_header %} + {% for c, name in list_columns %} + {% set column = loop.index0 %} + + {% endfor %} + {% endblock list_header %} + + + {% for row in data %} + + {% block list_row scoped %} + {% if actions %} + + {% endif %} + {% block list_row_actions_column scoped %} + {% if admin_view.column_display_actions %} + {% block list_row_actions scoped %} + {% if list_row_actions %} + + {% endif %} + {% endblock list_row_actions %} + {%- endif -%} + {% endblock list_row_actions_column %} + {% for c, name in list_columns %} + + {% endfor %} + {% endblock list_row %} + + {% else %} + + + + {% endfor %} +
    + +   + {% if admin_view.is_sortable(c) %} + {% if sort_column == column %} + + {{ name }} + {% if sort_desc %} + + {% else %} + + {% endif %} + + {% else %} + {{ name }} + {% endif %} + {% else %} + {{ name }} + {% endif %} + {% if admin_view.column_descriptions.get(c) %} + ? + {% endif %} +
    + + + + + {% if admin_view.is_editable(c) %} + {% set form = list_forms[get_pk_value(row)] %} + {% if form.csrf_token %} + {{ form[c](pk=get_pk_value(row) , display_value=get_value(row, c), csrf=form.csrf_token._value()) }} + {% elif csrf_token %} + {{ form[c](pk=get_pk_value(row) , display_value=get_value(row, c), csrf=csrf_token()) }} + {% else %} + {{ form[c](pk=get_pk_value(row) , display_value=get_value(row, c)) }} + {% endif %} + {% else %} + {{ get_value(row, c) }} + {% endif %} +
    + {% block empty_list_message %} +
    {{ admin_view.get_empty_list_message() }}
    + {% endblock empty_list_message %} +
    +
    +
    + + {% endblock model_list_table %} + {% block actions %} + {{ actionlib.form(actions, get_url('.action_view') ) }} + {% endblock actions %} + {%- if admin_view.edit_modal or admin_view.create_modal or admin_view.details_modal -%} + {{ lib.add_modal_window() }} + {%- endif -%} +
    +{% endblock body %} +{% block tail %} + {{ super() }} + {% if filter_groups %} + + + {% endif %} + {{ lib.form_js() }} + + + {{ actionlib.script(_gettext('Please select at least one record.') , + actions, + actions_confirmation) }} +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/modals/create.html b/flask_admin/templates/tabler/model/modals/create.html new file mode 100644 index 000000000..99acae537 --- /dev/null +++ b/flask_admin/templates/tabler/model/modals/create.html @@ -0,0 +1,37 @@ +{% import "admin/static.html" as admin_static with context %} +{% import "admin/lib.html" as lib with context %} +{% block body %} + + {% call lib.form_tag(action=url_for('.create_view', url=return_url)) %} + + + {% endcall %} +{% endblock body %} +{% block tail %} + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/modals/details.html b/flask_admin/templates/tabler/model/modals/details.html new file mode 100644 index 000000000..f8ade48ab --- /dev/null +++ b/flask_admin/templates/tabler/model/modals/details.html @@ -0,0 +1,57 @@ +{% import "admin/static.html" as admin_static with context %} +{% import "admin/lib.html" as lib with context %} +{% block body %} + + +{% endblock body %} +{% block tail %} + + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/modals/edit.html b/flask_admin/templates/tabler/model/modals/edit.html new file mode 100644 index 000000000..c467bf8cf --- /dev/null +++ b/flask_admin/templates/tabler/model/modals/edit.html @@ -0,0 +1,37 @@ +{% import "admin/static.html" as admin_static with context %} +{% import "admin/lib.html" as lib with context %} +{% block body %} + + {% call lib.form_tag(action=url_for('.edit_view', id=request.args.get('id'), url=return_url)) %} + + + {% endcall %} +{% endblock body %} +{% block tail %} + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/model/row_actions.html b/flask_admin/templates/tabler/model/row_actions.html new file mode 100644 index 000000000..f2bc14362 --- /dev/null +++ b/flask_admin/templates/tabler/model/row_actions.html @@ -0,0 +1,55 @@ +{% import "admin/lib.html" as lib with context %} +{% macro link(action, url, icon_class=None) %} + + + + + {{ action.title or '' }} + +{% endmacro %} +{% macro view_row(action, row_id, row) %} + + + + + {{ _gettext("View Record") }} + +{% endmacro %} +{% macro view_row_popup(action, row_id, row) %} + {# djlint:off #} + {% set content = "" | safe + _gettext("View Record") %} + {# djlint:on #} + {{ lib.add_modal_button(url=get_url('.details_view', id=row_id, url=return_url, modal=True) , title=action.title, content=content, btn_class="dropdown-item") }} +{% endmacro %} +{% macro edit_row(action, row_id, row) %} + {{ link(action, get_url('.edit_view', id=row_id, url=return_url) , 'fa fa-edit') }} +{% endmacro %} +{% macro edit_row_popup(action, row_id, row) %} + {# djlint:off #} + {% set content = "" | safe + action.title %} + {# djlint:on #} + {{ lib.add_modal_button(url=get_url('.edit_view', id=row_id, url=return_url, modal=True) , title=action.title, content=content, btn_class="dropdown-item") }} +{% endmacro %} +{% macro delete_row(action, row_id, row) %} +
    + {{ delete_form.id(value=get_pk_value(row) ) }} + {{ delete_form.url(value=return_url) }} + {% if delete_form.csrf_token %} + {{ delete_form.csrf_token }} + {% elif csrf_token %} + + {% endif %} + {% set confirmation = _gettext('Are you sure you want to delete this record?') %} + +
    +{% endmacro %} diff --git a/flask_admin/templates/tabler/rediscli/console.html b/flask_admin/templates/tabler/rediscli/console.html new file mode 100644 index 000000000..fcc9569fe --- /dev/null +++ b/flask_admin/templates/tabler/rediscli/console.html @@ -0,0 +1,38 @@ +{% extends "admin/master.html" %} +{% import "admin/lib.html" as lib with context %} +{% import "admin/static.html" as admin_static with context %} +{% block head %} + {{ super() }} + +{% endblock head %} +{% block header %} +
    +
    +
    {{ admin_view.category if admin_view.category else _gettext("Admin") }}
    +

    {{ admin_view.name }}

    +
    +
    +{% endblock header %} +{% block body %} +
    +
    +

    {{ admin_view.name }}

    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +{% endblock body %} +{% block tail %} + {{ super() }} + + +{% endblock tail %} diff --git a/flask_admin/templates/tabler/rediscli/response.html b/flask_admin/templates/tabler/rediscli/response.html new file mode 100644 index 000000000..58883a9fd --- /dev/null +++ b/flask_admin/templates/tabler/rediscli/response.html @@ -0,0 +1,33 @@ +{% macro render(item, depth=0) %} + {% set type = type_name(item) %} + {% if type == 'tuple' or type == 'list' %} + {% if not item %} + Empty {{ type }}. + {% else %} + {% for n in item %} + {{ loop.index }}) {{ render(n, depth + 1) }} +
    + {% endfor %} + {% endif %} + {% elif type == 'bool' %} + {% if depth == 0 and item %} + OK + {% else %} + {{ item }} + {% endif %} + {% elif type == 'str' or type == 'unicode' %} + "{{ item }}" + {% elif type == 'bytes' %} + "{{ item.decode("utf-8") }}" + {% elif type == 'TextWrapper' %} +
    {{ item }}
    + {% elif type == 'dict' %} + {% for k, v in item.items() %} + {{ loop.index }}) {{ k }} - {{ render(v, depth + 1) }} +
    + {% endfor %} + {% else %} + {{ item }} + {% endif %} +{% endmacro %} +{{ render(result) }} diff --git a/flask_admin/templates/tabler/static.html b/flask_admin/templates/tabler/static.html new file mode 100644 index 000000000..de632ee14 --- /dev/null +++ b/flask_admin/templates/tabler/static.html @@ -0,0 +1,3 @@ +{% macro url() -%} + {{ get_url('{admin_endpoint}.static'.format(admin_endpoint=admin_view.admin.endpoint), *varargs, **kwargs) }} +{%- endmacro %} From a7d0813ee93ad26955b1254ece42b2c47bd7f841 Mon Sep 17 00:00:00 2001 From: hasansezertasan Date: Fri, 19 Jul 2024 15:31:40 +0300 Subject: [PATCH 2/5] Replace 'tabler_url' with 'get_url' --- flask_admin/templates/tabler/base.html | 10 +++++----- flask_admin/templates/tabler/file/list.html | 2 +- flask_admin/templates/tabler/lib.html | 4 ++-- flask_admin/templates/tabler/model/list.html | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/flask_admin/templates/tabler/base.html b/flask_admin/templates/tabler/base.html index 9e39e09d2..968a10720 100644 --- a/flask_admin/templates/tabler/base.html +++ b/flask_admin/templates/tabler/base.html @@ -12,11 +12,11 @@ {% endblock head_meta %} {% block head_css %} - - - {% if admin_view.extra_css %} {% for css_url in admin_view.extra_css %}{% endfor %} @@ -137,9 +137,9 @@

    {{ admin_view.admin.name }}

    {% endblock page_body %} {% block tail_js %} - - diff --git a/flask_admin/templates/tabler/file/list.html b/flask_admin/templates/tabler/file/list.html index 9db49d167..e0f5bd8ca 100644 --- a/flask_admin/templates/tabler/file/list.html +++ b/flask_admin/templates/tabler/file/list.html @@ -221,6 +221,6 @@

    {{ admin_view.name }}

    actions, actions_confirmation) }} {{ lib.form_js() }} - {% endblock tail %} diff --git a/flask_admin/templates/tabler/lib.html b/flask_admin/templates/tabler/lib.html index 90d31a829..59fc5350a 100644 --- a/flask_admin/templates/tabler/lib.html +++ b/flask_admin/templates/tabler/lib.html @@ -241,7 +241,7 @@

    {{ text }}

    rel="stylesheet"> {% endif %} {% if editable_columns %} - {% endif %} {% endmacro %} @@ -269,7 +269,7 @@

    {{ text }}

    {% if editable_columns %} - {% endif %} - {{ actionlib.script(_gettext('Please select at least one record.') , actions, From 443f183c4f9a3983322e753fcd8667f1619a8162 Mon Sep 17 00:00:00 2001 From: hasansezertasan Date: Fri, 19 Jul 2024 15:37:57 +0300 Subject: [PATCH 3/5] Move x-editable assets. --- flask_admin/templates/tabler/lib.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flask_admin/templates/tabler/lib.html b/flask_admin/templates/tabler/lib.html index 59fc5350a..20f495584 100644 --- a/flask_admin/templates/tabler/lib.html +++ b/flask_admin/templates/tabler/lib.html @@ -241,7 +241,7 @@

    {{ text }}

    rel="stylesheet"> {% endif %} {% if editable_columns %} - {% endif %} {% endmacro %} @@ -269,7 +269,7 @@

    {{ text }}

    {% if editable_columns %} - {% endif %}