fix: Field rendering of every field

This commit is contained in:
Faris Ansari 2021-10-22 19:20:42 +05:30
parent 04e10c4c9e
commit c1053bea93
13 changed files with 123 additions and 27 deletions

View file

@ -1,4 +1,5 @@
{% macro render_field(df, doc) %}
{%- set value = doc.get(df.fieldname) -%}
{% include ['templates/print_format/macros/' + df.renderer + '.html', 'templates/print_format/macros/Data.html'] ignore missing %}
{% endmacro %}

View file

@ -0,0 +1,7 @@
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
<a href="{{ value }}">{{ value.rsplit('/', 1)[1] }}</a>
</div>
{%- endblock -%}

View file

@ -0,0 +1,7 @@
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
<img class="w-100" src="{{ value }}" alt="{{ df.label }}">
</div>
{%- endblock -%}

View file

@ -0,0 +1,9 @@
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
<svg viewBox="0 0 16 16" fill="transparent" stroke="#1F272E" stroke-width="2" xmlns="http://www.w3.org/2000/svg" id="icon-tick">
<path d="M2 9.66667L5.33333 13L14 3" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</div>
{%- endblock -%}

View file

@ -0,0 +1,7 @@
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
<pre><code>{{ value }}</code></pre>
</div>
{%- endblock -%}

View file

@ -0,0 +1,8 @@
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
<div class="color-square" style="background-color: {{ value }};"></div>
{{ value }}
</div>
{%- endblock -%}

View file

@ -1,21 +1,10 @@
{% if doc.get(df.fieldname) %}
{%- if df.section.field_orientation == 'left-right' -%}
<div class="field row">
<div class="col-6 label" {{ field_attributes(df) }}>
{{ df.label }}
</div>
<div class="col-6 value {{ 'text-right' if df.fieldtype in ['Int', 'Float', 'Currency'] else '' }}" {{ field_attributes(df) }}>
{{ doc.get_formatted(df.fieldname) }}
</div>
{% if value %}
<div class="field {{ df.section.field_orientation or '' }}" {{ field_attributes(df) }}>
{%- block label -%}
<div class="label">{{ df.label }}</div>
{%- endblock -%}
{%- block value -%}
<div class="value">{{ doc.get_formatted(df.fieldname) }}</div>
{%- endblock -%}
</div>
{%- else -%}
<div class="field">
<div class="label" {{ field_attributes(df) }}>
{{ df.label }}
</div>
<div class="value" {{ field_attributes(df) }}>
{{ doc.get_formatted(df.fieldname) }}
</div>
</div>
{%- endif -%}
{% endif %}

View file

@ -1,3 +1,3 @@
<div class="custom-html">
<div class="custom-html" {{ field_attributes(df) }}>
{{ frappe.render_template(df.html, {'doc': doc}) }}
</div>

View file

@ -1,3 +1,9 @@
<div class="value" {{ field_attributes(df) }}>
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
{{ frappe.utils.md_to_html(doc.get(df.fieldname)) }}
</div>
{%- endblock -%}

View file

@ -0,0 +1,22 @@
{% extends "templates/print_format/macros/Data.html" %}
{% macro star(is_active=false) %}
<svg id="icon-star" class="rating-star {{ is_active and 'active' or '' }}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
{%- set color = '#f6c35e' if is_active else '#dce0e3' -%}
<path
fill="{{ color }}" stroke="{{ color }}"
d="M11.5516 2.90849C11.735 2.53687 12.265 2.53687 12.4484 2.90849L14.8226 7.71919C14.8954 7.86677 15.0362 7.96905 15.1991 7.99271L20.508 8.76415C20.9181 8.82374 21.0818 9.32772 20.7851 9.61699L16.9435 13.3616C16.8257 13.4765 16.7719 13.642 16.7997 13.8042L17.7066 19.0916C17.7766 19.5001 17.3479 19.8116 16.9811 19.6187L12.2327 17.1223C12.087 17.0457 11.913 17.0457 11.7673 17.1223L7.01888 19.6187C6.65207 19.8116 6.22335 19.5001 6.29341 19.0916L7.20028 13.8042C7.2281 13.642 7.17433 13.4765 7.05648 13.3616L3.21491 9.61699C2.91815 9.32772 3.08191 8.82374 3.49202 8.76415L8.80094 7.99271C8.9638 7.96905 9.10458 7.86677 9.17741 7.71919L11.5516 2.90849Z"
/>
</svg>
{% endmacro %}
{%- block value -%}
<div class="value">
{%- for i in range(value) -%}
{{ star(true) }}
{%- endfor -%}
{%- for i in range(5 - value) -%}
{{ star() }}
{%- endfor -%}
</div>
{%- endblock -%}

View file

@ -0,0 +1,7 @@
{% extends "templates/print_format/macros/Data.html" %}
{%- block value -%}
<div class="value">
<img src="{{ value }}" alt="{{ df.label }}">
</div>
{%- endblock -%}

View file

@ -76,6 +76,18 @@ body {
font-weight: bold;
}
.field.left-right {
display: flex;
}
.field.left-right .label {
width: 50%;
}
.field.left-right .value {
width: 50%;
}
.child-table [data-fieldtype="Currency"] {
text-align: right;
}
@ -93,3 +105,27 @@ body {
border-bottom-style: solid;
border-bottom-color: var(--gray-300);
}
.field[data-fieldtype="Rating"] .rating-star {
width: 1.5rem;
}
.field[data-fieldtype="Long Text"] .value, .field[data-fieldtype="Text"] .value {
white-space: pre-line;
}
.field[data-fieldtype="Color"] .value {
display: flex;
align-items: center;
}
.field[data-fieldtype="Color"] .color-square {
width: 1rem;
height: 1rem;
margin-right: 0.3rem;
border-radius: var(--border-radius);
}
.field[data-fieldtype="Check"] #icon-tick {
width: 1rem;
}

View file

@ -204,16 +204,13 @@ class PrintFormatGenerator:
return layout
def set_field_renderers(self, layout):
renderers = {
"HTML Editor": "HTML",
"Markdown Editor": "Markdown",
"Field Template": "FieldTemplate",
}
renderers = {"HTML Editor": "HTML", "Markdown Editor": "Markdown"}
for section in layout["sections"]:
for column in section["columns"]:
for df in column["fields"]:
fieldtype = df["fieldtype"]
df["renderer"] = renderers.get(fieldtype) or fieldtype
renderer_name = fieldtype.replace(" ", "")
df["renderer"] = renderers.get(fieldtype) or renderer_name
df["section"] = section
return layout