Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust collapse and display templates' html. Was intended for plans I… #174

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2022 AssemblyLine
Copyright (c) 2023 AssemblyLine

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 10 additions & 1 deletion docassemble/ALToolbox/data/questions/collapse_template_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ subquestion: |
What is your favorite fruit? Everybody has a favorite fruit.

${ collapse_template(fruit_explanation, closed_icon="plus", open_icon="minus") }

Don't you have a favorite fruit?
${ collapse_template(favorite_explanation) }

${ collapse_template(favorite_explanation, container_classname="favorites_container") }

You must have a favorite.
fields:
- Favorite fruit: favorite_fruit
css: |
<style>
#about_favorites a {
text-decoration-style: double;
}
</style>
---
mandatory: True
question: |
Expand Down
49 changes: 31 additions & 18 deletions docassemble/ALToolbox/data/questions/display_template_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ subquestion: |
1. **copy** (default=False)
- It adds a copy button under the template for users to copy/share the template content.
- This feature applies the **copy_button_html()** function to template content. See [copy button demo](${interview_url(i=user_info().package + ":copy_button_demo.yml")}).
1. **class_name** (default=None)
- To style your template, include a class_name input in the call, and add your css rules either on the screen or to a .css file.
1. **classname** (default="bg-light")
- To style your template content, include a `classname` keyword argument when you call the function and add your css rules either on the screen or to a .css file.
1. **container_classname** (default=None)
- To style the whole container of your subject and content, include a `content_classname` keyword argument when you call the function and add your css rules either on the screen or to a .css file.

You can mix and match these features. The following screens will show you how.

Expand All @@ -44,37 +46,42 @@ question: |
Scrollable examples
subquestion: |
##### Srollable only
${ display_template(my_template1) }<br>
${ display_template(my_template1, container_classname="my_class") }

##### Style only
${ display_template(my_template2, scrollable=False, class_name="my_color")}
${ display_template(my_template2, scrollable=False, classname="my_color") }

##### Template with no subject
${ display_template(template_no_subject) }
---
id: collapse and scrollable examples
continue button field: collapse_n_scrollable_examples
question: |
Collase and scrollable examples
subquestion: |
##### Collapse only with a style
${ display_template(my_template1, scrollable=False, collapse=True, class_name="my_color") }
${ display_template(my_template1, scrollable=False, collapse=True, classname="my_color") }

##### Collapse and scrollable, without the copy button
${ display_template(my_template2, collapse=True) }
---
id: copy button examples
continue button field: copy_button_examples
event: copy_button_examples
question: |
Copy button examples
fields:
- html: <h5>Copy and scrollable</h5>
- note: |
${ display_template(my_template1, copy=True) }
- html: <h5>Copy and collapse but not scrollable</h5>
- note: |
_(Hover over the box to see the full template content. If this is annoying, keep the default value scrollable=True as shown in the very last example.)_<br><br>
${ display_template(my_template1, scrollable=False, collapse=True, copy=True) }
- html: <h5>Copy and collapse and scrollable</h5>
- note: |
${ display_template(my_template2, collapse=True, copy=True) }
subquestion: |
<h5>Copy and scrollable</h5>

${ display_template(my_template1, copy=True) }

<h5>Copy and collapse but not scrollable</h5>

_(Hover over the box to see the full template content. If this is annoying, keep the default value scrollable=True as shown in the very last example.)_

${ display_template(my_template1, scrollable=False, collapse=True, copy=True) }
<h5>Copy and collapse and scrollable</h5>

${ display_template(my_template2, collapse=True, copy=True) }
---
template: my_template1
subject: |
Expand All @@ -94,4 +101,10 @@ content: |

Est ad autem vitae, ius graeco delicata eu. Vim quod postea ad. Vero omnis iuvaret in ius. Eu noster volumus sed.

Qui eu dictas senserit. Ne affert doctus his. Eius dicta utinam ex pri, tota equidem vel at. Cu nec habemus definitiones, eos oratio impedit mediocrem ex, inermis necessitatibus duo et. Malis graeco dicunt ei mea. Ei idque cetero est.
Qui eu dictas senserit. Ne affert doctus his. Eius dicta utinam ex pri, tota equidem vel at. Cu nec habemus definitiones, eos oratio impedit mediocrem ex, inermis necessitatibus duo et. Malis graeco dicunt ei mea. Ei idque cetero est.
---
template: template_no_subject
content: |
Qui eu dictas senserit. Ne affert doctus his. Eius dicta utinam ex pri, tota equidem vel at. Cu nec habemus definitiones, eos oratio impedit mediocrem ex, inermis necessitatibus duo et. Malis graeco dicunt ei mea. Ei idque cetero est.

Est ad autem vitae, ius graeco delicata eu. Vim quod postea ad. Vero omnis iuvaret in ius. Eu noster volumus sed.
4 changes: 4 additions & 0 deletions docassemble/ALToolbox/data/static/collapse_template.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.al_collapse_template {
padding-bottom: 1rem;
}

a span.pdcaretopen {
display: inline;
}
Expand Down
6 changes: 5 additions & 1 deletion docassemble/ALToolbox/data/static/display_template.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.al_display_template {
padding-bottom: 1rem;
}

.scrollable-panel{
height:200px;
max-height:200px;
overflow-y:scroll;
width:100%;
}
Expand Down
3 changes: 2 additions & 1 deletion docassemble/ALToolbox/data/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
background: lightcyan;
color: darkgreen;
}
h5 {

h5, .h5 {
color: brown;
}
38 changes: 31 additions & 7 deletions docassemble/ALToolbox/display_template.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import re
from .copy_button import *
from base64 import b64encode


def display_template(
template, scrollable=True, collapse=False, copy=False, class_name="bg-light"
template,
scrollable=True,
collapse=False,
copy=False,
classname="bg-light",
container_classname=None,
class_name=None # depricated
) -> str:
# 1. Initialize
if scrollable:
Expand All @@ -14,10 +21,22 @@ def display_template(
adjust_height = (
f"onmouseover=\"this.style.height = (this.scrollHeight) + 'px';\""
)


# Introducing `classname` to try to align with `collapse_template`
if not class_name:
class_name = classname
class_name = class_name.strip()

container_classname_plus = "al_display_template"
if container_classname:
container_classname_plus += f" { container_classname }"

the_id = re.sub(r"[^A-Za-z0-9]", "", template.instanceName)
container_id = b64encode(str(template.instanceName).encode()).decode().replace('=', '')
contents_id = f"{ container_id }_contents"

subject_html = ''
if not template.subject == "":
subject_html = f'<div class="panel-heading"><h3 class="subject">{template.subject_as_html(trim=True)}</h3></div>'

# 2. If copiable, call copy_button_html() to generate the template content along with a copy button
if copy:
Expand All @@ -31,16 +50,21 @@ def display_template(

# 2.1 If collapsible, add collapsible elements to the output
if collapse:
return f'<a class="collapsed" data-bs-toggle="collapse" href="#{the_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="pdcaretclosed"><i class="fas fa-caret-right"></i></span> {template.subject_as_html(trim=True)}</a><div class="collapse" id="{the_id}">{text}</div>'
return f'<div id="{container_id}" class="{container_classname_plus}"><a class="collapsed" data-bs-toggle="collapse" href="#{contents_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="toggle-icon pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="toggle-icon pdcaretclosed"><i class="fas fa-caret-right"></i></span><span class="subject">{template.subject_as_html(trim=True)}</span></a><div class="collapse" id="{contents_id}">{text}</div></div>'

# 2.2 If not collapsible, simply return output from copy_button_html()
else:
return text
return f"""
<div id="{container_id}" class="{container_classname_plus}">
{subject_html}
{text}
</div>
"""

# 3. If not copiable, generate the whole output
else:
if not collapse:
return f'<div class="{scroll_class} card card-body {class_name} pb-1" id="{the_id}"><div class="panel-heading"><h3>{template.subject_as_html(trim=True)}</h3></div>{template.content_as_html()}</div>'
return f'<div id="{container_id}" class="{container_classname_plus} {scroll_class} card card-body {class_name} pb-1" id="{contents_id}">{subject_html}<div>{template.content_as_html()}</div></div>'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does class_name belong around the content as opposed to surrounding both the title and the content? The element currently using class_name has the container classname already.


else:
return f'<a class="collapsed" data-bs-toggle="collapse" href="#{the_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="pdcaretclosed"><i class="fas fa-caret-right"></i></span>{template.subject_as_html(trim=True)}</a><div class="collapse" id="{the_id}"><div class="{scroll_class} card card-body {class_name} pb-1">{template.content_as_html()}</div></div>'
return f'<div id="{container_id}" class="{container_classname_plus}"><a class="collapsed" data-bs-toggle="collapse" href="#{contents_id}" role="button" aria-expanded="false" aria-controls="collapseExample"><span class="toggle-icon pdcaretopen"><i class="fas fa-caret-down"></i></span><span class="toggle-icon pdcaretclosed"><i class="fas fa-caret-right"></i></span><span class="subject">{template.subject_as_html(trim=True)}</span></a><div class="collapse" id="{contents_id}"><div class="{scroll_class} card card-body {class_name} pb-1">{template.content_as_html()}</div></div></div>'
23 changes: 18 additions & 5 deletions docassemble/ALToolbox/misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional, Union

from base64 import b64encode
from decimal import Decimal
import docassemble.base.functions
from docassemble.base.util import (
Expand Down Expand Up @@ -158,11 +159,11 @@ def number_to_letter(n: Optional[int]) -> str:
string = chr(65 + remainder) + string
return string


def collapse_template(
template,
classname=None,
closed_icon="caret-right",
container_classname=None,
closed_icon="caret-right",
open_icon="caret-down",
):
"""
Expand All @@ -175,14 +176,26 @@ def collapse_template(
"""
if not template.subject_as_html(trim=True) and not template.content_as_html():
return ""

if classname is None:
classname = " bg-light"
else:
classname = " " + classname.strip()
the_id = re.sub(r"[^A-Za-z0-9]", "", template.instanceName)
container_classes_plus = "al_collapse_template"
if container_classname:
container_classes_plus += f" { container_classname }"

container_id = b64encode(str(template.instanceName).encode()).decode().replace('=', '')
contents_id = f'{ container_id }_contents'

return f"""\
<a class="collapsed" data-bs-toggle="collapse" href="#{ the_id }" role="button" aria-expanded="false" aria-controls="{ the_id }"><span class="pdcaretopen">{ fa_icon(open_icon) }</span><span class="pdcaretclosed">{ fa_icon(closed_icon) }</span> { template.subject_as_html(trim=True) }</a>
<div class="collapse" id="{ the_id }"><div class="card card-body pb-1{ classname }">{ template.content_as_html() }</div></div>\
<div id="{ container_id }" class="{ container_classes_plus }">
<a class="collapsed al_toggle" data-bs-toggle="collapse" href="#{ contents_id }" role="button" aria-expanded="false" aria-controls="{ contents_id }"><span class="toggle-icon pdcaretopen">{ fa_icon(open_icon) }</span><span class="toggle-icon pdcaretclosed">{ fa_icon(closed_icon) }</span>
<span class="subject">{ template.subject_as_html(trim=True) }</span></a>
<div class="collapse" id="{ contents_id }">
<div class="card card-body pb-1{ classname }">{ template.content_as_html() }</div>
</div>
</div>\
"""


Expand Down
5 changes: 1 addition & 4 deletions docassemble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__import__('pkg_resources').declare_namespace(__name__)

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
setup(name='docassemble.ALToolbox',
version='0.7.1',
description=('Collection of small utility functions, classes, and web components for Docassemble interviews'),
long_description='# ALToolbox\r\n\r\nThis repository is used to host small Python modules, widgets, and JavaScript web components js files that enhance Docassemble interviews. These modules were\r\nbuilt as part of the Suffolk University Law School LIT Lab\'s [Document Assembly Line project](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/).\r\nThey are placed here\r\nrather than in https://github.com/SuffolkLitLab/docassemble-AssemblyLine because we believe these small components can easily be used\r\nby anyone, regardless of whether they use any other code from the Document Assembly Line project.\r\n\r\nIf you want to add a small fuction to this project, consider adding it to the existing misc.py to avoid creating too many module files.\r\n\r\n## Documentation\r\n\r\nRead the [documentation for the functions and components](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/docs/framework/altoolbox) to learn\r\nhow to use these components in your own [Docassemble](https://github.com/jhpyle/docassemble) projects.\r\n\r\n## Suffolk LIT Lab Document Assembly Line\r\n\r\n<img src="https://user-images.githubusercontent.com/7645641/142245862-c2eb02ab-3090-4e97-9653-bb700bf4c54d.png" alt="drawing" width="300" alt="work together" style="align: center;"/>\r\n\r\nThe Assembly Line Project is a collection of volunteers, students, and institutions who joined together\r\nduring the COVID-19 pandemic to help increase access to the court system. Our vision is mobile-friendly,\r\neasy to use **guided** online forms that help empower litigants to access the court remotely.\r\n\r\nOur signature project is [CourtFormsOnline.org](https://courtformsonline.org).\r\n\r\nWe designed a step-by-step, assembly line style process for automating court forms on top of Docassemble\r\nand built several tools along the way that **you** can use in your home jurisdiction.\r\n\r\nThis package contains **runtime code** and **pre-written questions** to support authoring robust, \r\nconsistent, and attractive Docassemble interviews that help complete court forms.\r\n\r\nRead more on our [documentation page](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/).\r\n\r\n\r\n# Related repositories\r\n\r\n* https://github.com/SuffolkLitLab/docassemble-AssemblyLine\r\n* https://github.com/SuffolkLitLab/docassemble-ALWeaver\r\n* https://github.com/SuffolkLitLab/docassemble-ALMassachusetts\r\n* https://github.com/SuffolkLitLab/docassemble-MassAccess\r\n* https://github.com/SuffolkLitLab/docassemble-ALThemeTemplate\r\n* https://github.com/SuffolkLitLab/EfileProxyServer\r\n\r\n## Contributors: \r\n* @plocket \r\n* @nonprofittechy\r\n* @purplesky2016\r\n* @brycestevenwilley\r\n',
long_description='# ALToolbox\r\n\r\n[![PyPI version](https://badge.fury.io/py/docassemble-ALToolbox.svg)](https://badge.fury.io/py/docassemble-ALToolbox)\r\n\r\nThis repository is used to host small Python modules, widgets, and JavaScript web components js files that enhance Docassemble interviews. These modules were\r\nbuilt as part of the Suffolk University Law School LIT Lab\'s [Document Assembly Line project](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/).\r\nThey are placed here\r\nrather than in https://github.com/SuffolkLitLab/docassemble-AssemblyLine because we believe these small components can easily be used\r\nby anyone, regardless of whether they use any other code from the Document Assembly Line project.\r\n\r\nIf you want to add a small fuction to this project, consider adding it to the existing misc.py to avoid creating too many module files.\r\n\r\n## Documentation\r\n\r\nRead the [documentation for the functions and components](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/docs/framework/altoolbox) to learn\r\nhow to use these components in your own [Docassemble](https://github.com/jhpyle/docassemble) projects.\r\n\r\n## Suffolk LIT Lab Document Assembly Line\r\n\r\n<img src="https://user-images.githubusercontent.com/7645641/142245862-c2eb02ab-3090-4e97-9653-bb700bf4c54d.png" alt="drawing" width="300" alt="work together" style="align: center;"/>\r\n\r\nThe Assembly Line Project is a collection of volunteers, students, and institutions who joined together\r\nduring the COVID-19 pandemic to help increase access to the court system. Our vision is mobile-friendly,\r\neasy to use **guided** online forms that help empower litigants to access the court remotely.\r\n\r\nOur signature project is [CourtFormsOnline.org](https://courtformsonline.org).\r\n\r\nWe designed a step-by-step, assembly line style process for automating court forms on top of Docassemble\r\nand built several tools along the way that **you** can use in your home jurisdiction.\r\n\r\nThis package contains **runtime code** and **pre-written questions** to support authoring robust, \r\nconsistent, and attractive Docassemble interviews that help complete court forms.\r\n\r\nRead more on our [documentation page](https://suffolklitlab.org/docassemble-AssemblyLine-documentation/).\r\n\r\n\r\n# Related repositories\r\n\r\n* https://github.com/SuffolkLitLab/docassemble-AssemblyLine\r\n* https://github.com/SuffolkLitLab/docassemble-ALWeaver\r\n* https://github.com/SuffolkLitLab/docassemble-ALMassachusetts\r\n* https://github.com/SuffolkLitLab/docassemble-MassAccess\r\n* https://github.com/SuffolkLitLab/docassemble-ALThemeTemplate\r\n* https://github.com/SuffolkLitLab/EfileProxyServer\r\n\r\n## Contributors:\r\n* @plocket \r\n* @nonprofittechy\r\n* @purplesky2016\r\n* @brycestevenwilley\r\n',
long_description_content_type='text/markdown',
author='AssemblyLine',
author_email='52798256+plocket@users.noreply.github.com',
license='The MIT License (MIT)',
url='https://suffolklitlab.org/docassemble-AssemblyLine-documentation/docs/framework/altoolbox',
packages=find_packages(),
namespace_packages=['docassemble'],
install_requires=['holidays>=0.14.2', 'pandas>=1.4.2'],
install_requires=['holidays>=0.27.1', 'pandas>=1.5.3'],
zip_safe=False,
package_data=find_package_data(where='docassemble/ALToolbox/', package='docassemble.ALToolbox'),
)
Expand Down