{# # _macros.html # # Copyright © 2013-2017 Antergos # # This file is part of The Antergos Build Server, (AntBS). # # AntBS is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # AntBS is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # The following additional terms are in effect as per Section 7 of the license: # # The preservation of all legal notices and author attributions in # the material or in the Appropriate Legal Notices displayed # by works containing it is required. # # You should have received a copy of the GNU General Public License # along with AntBS; If not, see . #} {# Macros (Reusable Code Snippets) #} {# # Generates navigation menu items and adds "active" class for current page. # # Args: # endpoint (str): The link url relative to root. # text: (str): The link text. # icon_class (str): The css class for the menu icon. # active_class (str): The css class applied to the active menu item. # _class (str): Optional extra css class to add to the menu item. #} {% macro nav_link(endpoint, text, icon_class='', active_class='', is_heading=False) %} {% if request.path == endpoint and not is_heading %} {% set active_class = 'active' %} {% elif is_heading %} {% set active_class = 'submenu_heading' %} {% endif %}
  • {% if not is_heading %} {% endif %} {{ text }}
  • {% endmacro %} {# # Generates page heading and breadcrumbs. # # Args: # pagetitle (str): The title text for the page. # #} {% macro page_heading(pagetitle) %} {% if request.path != "/" %}

    {{ pagetitle }}

    {% endif %} {% endmacro %} {# # Generates HTML (& JavaScript) for a calendar heatmap chart. # # Args: # data (list): The data for the chart as a list of dicts. # selector (str): CSS selector for the heatmap container. # #} {% macro calendar_heatmap(data, selector) %} {% endmacro %} {# # Generates HTML (& JavaScript) for activating custom toggles/switches. # #} {%- macro toggles_init() -%} {%- endmacro -%} {# # Generates HTML for a build activity timeline. # # Args: # tl_events (list): The data for the timeline as a list of `TimelineEvent` objects. # all_pages (int): Number of pages available. # page (int): The current page. # #} {% macro build_activity_timeline(tl_events, all_pages, page) %} {% set icons = ['fa-bolt', 'fa-github', 'phab', 'fa-rocket', 'fa-check', 'fa-times', 'fa-comment'] %}

    Timeline

    {% if all_pages > 1 %} {% endif %}
    {% endmacro %} {# # Generates HTML for simple counters like the ones on the package profile pages. # # Args: # number (int): The number for the counter to display. # title_text (str): The title for the counter. # color_class (str): Color class (primary, success, danger, etc) # column_size (str): The column size that the counter will be wrapped with. # #} {% macro simple_counter(number, title_text, color_class, column_size='4') %} {% if '' != color_class %} {% set color_class = 'text-' + color_class %} {% endif %}

    {{ title_text }}

    {{ number }}
    {% endmacro %} {# # Generates HTML for styled a label/tag link. # # Args: # url_base (str): The first part of the URL to link to. # url_end (str): The last part of the URL to link to. # text (str): The text for the tag/label. # color_class (str): Color class (primary, success, danger, etc) # #} {% macro label_tag_link(url_base, url_end, text, color_class) %} {{ text }} {% endmacro %} {# # Generates HTML for pagination links. # # Args: # pagination (Pagination): `Pagination` object for the table. # #} {% macro render_pagination(pagination) %} {% endmacro %} {# # Generates HTML for package/build/mirror listing table search box. # #} {% macro table_search_box() %}
    {% endmacro %} {# # Generates HTML for action/review_result dropdown (Logged-in users only). # # Args: # obj (Package|Build): The `Package` or `Build` object for the dropdown. # dd_info (dict): A dict containing info for dropdown: # dd_type (str): The type of dropdown ('Action' or 'Set Result'). # menu_items (list[dict]): List of dicts containing menu items' class, icon class, color, and label text. # dd_class (str): CSS class(es) for the menu. # #} {% macro table_dropdown(obj, dd_info) %} {% if current_user.is_authenticated %} {% if 'Action' == dd_type %} {% set bnum = obj._build.bnum %} {% else %} {% set bnum = obj.bnum %} {% endif %}
    {% endif %} {% endmacro %} {# # Generates HTML for text with icon. # # Args: # icon_info (dict): Dict which maps one or more icon_class(es) & icon_color(s) to possible `text` values. # text (str): The text to display next to the icon. Not required when calling this # macro from another macro. You should place text inside call block instead. #} {% macro text_with_icon(icon_info, text=None, icon_class_key=None) %} {% set icon_class = icon_info.class %} {% set icon_color = icon_info.color %} {% if icon_info.class is mapping and icon_class_key is not none %} {% set icon_class = icon_info.class[icon_class_key] %} {% elif icon_info.class is mapping %} {% set icon_class = icon_info.class[text] %} {% endif %} {% if icon_info.color is mapping and icon_class_key is not none %} {% set icon_color = icon_info.color[icon_class_key] %} {% elif icon_info.color is mapping %} {% set icon_color = icon_info.color[text] %} {% endif %} {{ text }} {% endmacro %} {# # Generates HTML for package/build/mirror listing table. # # Args: # columns_info (list[dict]): List of dicts containing info for each column. Dict keys expected # are heading_text, obj_attr, content_type, base_url, dd_info # objs (list[Package|Build|Mirror]): List of `Package`|`Build`|`Mirror` objects to be listed in table. # pagination (Pagination): The `Pagination` object for the table. # search_enabled (bool): Whether or not search box should be output for the table. #} {% macro listing_table(columns_info, objs, pagination, search_enabled=True) %} {% if search_enabled %} {{ table_search_box() }} {% endif %} {% for column in columns_info %} {% endfor %} {% if objs and objs is iterable %} {% for obj in objs %} {% for column in columns_info %} {% set _class = column.heading_text|replace(' ', '')|lower() %} {% endfor %} {% endfor %} {% endif %}
    {{ column.heading_text }}
    {% if column.obj_attr and '.' in column.obj_attr %} {% set obj_attr, nested_obj_attr = column.obj_attr.split('.') %} {% set value = obj|attr(obj_attr) %} {% set value = value|attr(nested_obj_attr) %} {% elif column.obj_attr is sequence and column.obj_attr is not string %} {% set value = [] %} {% for val in column.obj_attr %} {% do value.append(obj|attr(val)) %} {% endfor %} {% elif column.obj_attr %} {% set value = obj|attr(column.obj_attr) %} {% elif 'Group' == column.heading_text %} {% set value = column.group %} {% endif %} {%- if not value and 'dropdown' != column.content_type -%} - {%- elif 'link' == column.content_type %} {% if value is not string and value is sequence %} {{ value[1] }} {% else %} {{ value }} {% endif %} {% elif 'link_with_icon' == column.content_type %} {% if 'Last Build' == column.heading_text and True == value|int()|build_failed() %} {% set class_name_key = 'failed' %} {% elif 'Last Build' == column.heading_text %} {% set class_name_key = 'completed' %} {% else %} {% set class_name_key = None %} {% endif %} {{ text_with_icon(column.icon_info, value, class_name_key) }} {% elif 'text_with_icon' == column.content_type %} {{ text_with_icon(column.icon_info, value) }} {% elif 'text' == column.content_type %} {{ value }} {% elif 'dropdown' == column.content_type and 'dd_info' in column %} {{ table_dropdown(obj, column.dd_info) }} {% elif 'label_tag_link' == column.content_type %} {% if value is not string and value is sequence %} {% set url_end = '%s/%s'|format(value[0], value[1]) %} {{ label_tag_link(column.base_url, url_end, value, column.color_class) }} {% else %} {{ label_tag_link(column.base_url, value, value, column.color_class) }} {% endif %} {% endif %}
    {% if all_pages > 1 %} {{ render_pagination(pagination) }} {% endif %} {% endmacro %} {# # Generates JavaScript for listing table search box event handlers. # #} {% macro table_search_box_js() %} {% endmacro %} {# # Generates HTML for list groups with items containing two columns. # # Args: # items (list[tuples]): List of tuples which contain the column contents for each list group item. # #} {% macro list_group(items, column_sizes=['6', '6']) %} {% if items is iterable %}
    {% for item in items %}

    {{ item[0] }}:

    {% if 'Status' != item[0] %}

    {{ item[1] }}

    {% else %} {{ item[1] }} {% endif %}
    {% endfor %}
    {% endif %} {% endmacro %} {# # Outputs "readonly" if condition evaluates to a truthy value. # # Args: # condition (mixed): If condition is truthy, output "readonly". # #} {%- macro readonly(condition) -%} {%- if condition -%} readonly {%- endif -%} {%- endmacro -%} {# # Outputs `text` if condition evaluates to a truthy value. # # Args: # condition (mixed): If condition is truthy, output "checked". # text (str): The text to output. Not required when calling this macro from another macro; # you should place text inside call block instead. # #} {%- macro conditional_text(condition, text=None) -%} {% if text is none %} {% set text = caller() %} {% endif %} {%- if condition -%} {{ text }} {%- endif -%} {%- endmacro -%} {# # Outputs HTML for toggle switch (input) field. # # Args: # on_text (str): Text displayed when toggle is "checked". # off_text (str): Text displayed when toggle is not "checked". # ro_condition (mixed): If condition is truthy, mark the toggle input as "readonly". # checked_condition (mixed): If condition is truthy, mark the toggle input as "checked". # #} {%- macro toggle_switch(on_text='ON', off_text='OFF', ro_condition=False, checked_condition=False) -%} {%- endmacro -%}