Skip to content

Commit

Permalink
Add Settings page to let user enable complex text element editing. (#155
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jon-ide committed Jan 5, 2024
1 parent b1fed9e commit a20544c
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 11 deletions.
42 changes: 41 additions & 1 deletion webapp/auth/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,52 @@ def get_auth_token():
return user_properties.get('auth_token', '')


##############################################
# Handle complex text element editing settings
##############################################

def set_model_has_complex_texttypes(model_has_complex_texttypes=False):
user_properties = get_user_properties()
user_properties['model_has_complex_texttypes'] = model_has_complex_texttypes
user_properties['model_has_complex_texttypes'] = model_has_complex_texttypes or \
get_enable_complex_text_element_editing_global() or \
get_enable_complex_text_element_editing_document()
save_user_properties(user_properties)


def get_model_has_complex_texttypes():
user_properties = get_user_properties()
return user_properties.get('model_has_complex_texttypes', False)


def set_enable_complex_text_element_editing_global(enable_complex_text_element_editing_global=False):
user_properties = get_user_properties()
user_properties['enable_complex_text_element_editing_global'] = enable_complex_text_element_editing_global
save_user_properties(user_properties)


def get_enable_complex_text_element_editing_global():
user_properties = get_user_properties()
return user_properties.get('enable_complex_text_element_editing_global', False)


def set_enable_complex_text_element_editing_document(filename=None, enable_complex_text_element_editing_document=False):
user_properties = get_user_properties()
enabled_files = user_properties.get('enable_complex_text_element_editing_documents', [])
if filename is None:
filename = get_active_document()
if enable_complex_text_element_editing_document:
if filename not in enabled_files:
enabled_files.append(filename)
else:
if filename in enabled_files:
enabled_files.remove(filename)
user_properties['enable_complex_text_element_editing_documents'] = enabled_files
save_user_properties(user_properties)


def get_enable_complex_text_element_editing_document(filename=None):
user_properties = get_user_properties()
enabled_files = user_properties.get('enable_complex_text_element_editing_documents', [])
if filename is None:
filename = get_active_document()
return filename in enabled_files
2 changes: 2 additions & 0 deletions webapp/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
BTN_HIDDEN_PREVIEW_DATA_PORTAL = 'Hidden_Preview_Data_Portal'
BTN_HIDDEN_SAVE = 'Hidden_Save'
BTN_HIDDEN_SAVE_AS = 'Hidden_Save_As'
BTN_HIDDEN_SETTINGS = 'Hidden_Settings'
BTN_HIDDEN_USER_GUIDE = 'Hidden_User_Guide'
BTN_IMPORT = 'Import'
BTN_INVITE_COLLABORATOR = 'Invite a Collaborator'
Expand All @@ -63,6 +64,7 @@
BTN_SAVE_BACKUP = 'Save a Backup'
BTN_SEND_INVITATION = 'Send Invitation'
BTN_SEND_TO_OTHER = 'Prepare Package for Colleague'
BTN_SETTINGS = 'Settings'
BTN_SHOW_BACKUPS = 'Show Backups'
BTN_SUBMIT = 'Submit'
BTN_SUBMIT_PACKAGE_TO_EDI = 'Submit Package to EDI'
Expand Down
8 changes: 7 additions & 1 deletion webapp/home/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask_wtf import FlaskForm

from wtforms import (
StringField, SelectField, SelectMultipleField, HiddenField, RadioField, widgets
StringField, SelectField, SelectMultipleField, HiddenField, BooleanField, RadioField, widgets
)

from wtforms.validators import (
Expand Down Expand Up @@ -251,3 +251,9 @@ class InviteCollaboratorForm(FlaskForm):
user_email = StringField("Your Email Address *", validators=[DataRequired()])
collaborator_name = StringField("Collaborator's Name *", validators=[DataRequired()])
email_address = StringField("Collaborator's Email Address *", validators=[Email(), DataRequired()])


class SettingsForm(FlaskForm):
complex_text_editing_document = BooleanField('For the current EML document')
complex_text_editing_global = BooleanField('For all EML documents')
pass
1 change: 1 addition & 0 deletions webapp/home/log_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'SAVE_DOCUMENT': 'Save',
'SEND_TO_EDI': 'Send to EDI',
'SEND_TO_COLLEAGUE': 'Send to Colleague',
'SETTINGS': 'Settings',
'USER_GUIDE': 'User Guide'
}

Expand Down
10 changes: 10 additions & 0 deletions webapp/home/templates/_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<input id="hidden_open" style="display: none;" name="Hidden_Open" type="submit" value="Hidden_Open"/>
<input id="hidden_save" style="display: none;" name="Hidden_Save" type="submit" value="Hidden_Save"/>
<input id="hidden_save_as" style="display: none;" name="Hidden_Save_As" type="submit" value="Hidden_Save_As"/>
<input id="hidden_settings" style="display: none;" name="Hidden_Settings" type="submit" value="Hidden_Settings"/>
<input id="hidden_user_guide" style="display: none;" name="Hidden_User_Guide" type="submit" value="Hidden_User_Guide"/>
{# Buttons for Contents Menu #}
<input id="hidden_title" style="display: none;" name="Hidden_Title" type="submit" value="Hidden_Title"/>
Expand Down Expand Up @@ -246,4 +247,13 @@ <h5>Or select a template to import from:</h5>
{{ wtf.form_field(form.template) }}
<input class="btn btn-primary" name="Open Template" type="submit" value="Open Template for Import"/>
<input class="btn btn-primary" name="Cancel" type="submit" value="Cancel"/>
{% endmacro %}
{% macro please_stand_by() %}
<span id="stand_by_hint" style="visibility: hidden;"><i>Please stand by...</i></span>
<script>
function stand_by() {
let x = document.getElementById("stand_by_hint");
x.style.visibility = "visible";
}
</script>
{% endmacro %}
3 changes: 2 additions & 1 deletion webapp/home/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'/import_parties', '/import_geo_coverage',
'/import_taxonomic_coverage', '/import_funding_awards',
'about', 'news', 'user_guide', 'import_package', 'import_xml',
'export_package'] %}
'export_package', 'settings'] %}
{% set non_saving_contains = ['_select', '/check_metadata/', '/check_data_tables/',
'/data_table_errors/', '/fetch_xml', '/manage_packages',
'/import_parties_2/', '/import_geo_coverage_2/',
Expand Down Expand Up @@ -120,6 +120,7 @@
{{ macros.toolbar_menu_item(url_for('home.save'), 'hidden_save', 'Save', ns.is_non_saving) }}
{{ macros.toolbar_menu_item(url_for('home.save_as'), 'hidden_save_as', 'Save As...', ns.is_non_saving) }}
{% endif %}
{{ macros.toolbar_menu_item(url_for('home.settings'), 'hidden_settings', 'Settings...', ns.is_non_saving) }}
{{ macros.toolbar_menu_item(url_for('home.manage_packages'), 'hidden_manage', 'Manage...', ns.is_non_saving) }}
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion webapp/home/templates/file_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
{% block app_content %}
<b><a href="/eml/">Home</a></b>
<p>&nbsp;</p>
<h4>There was an error loading the EML for {{ filename }}</h4><p></p>
<h4>There was an error loading the EML for "{{ filename }}"</h4><p></p>
If needed, please contact [email protected] for assistance.
{% endblock %}
7 changes: 1 addition & 6 deletions webapp/home/templates/import_package.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h4>Select the ezEML data package file to import:</h4>
<input class="btn btn-primary" style="width: 100px;" onclick="stand_by();" name="Import" type="submit" value="Import"/>&nbsp;
<input class="btn btn-primary" style="width: 100px;" name="Cancel" type="submit" value="Cancel"/>
&nbsp;
<span id="stand_by_hint" style="visibility: hidden;"><i>Please stand by...</i></span>
{{ macros.please_stand_by() }}
{{ macros.hidden_buttons() }}
</form>
</div>
Expand All @@ -42,11 +42,6 @@ <h4>Select the ezEML data package file to import:</h4>
{
{{ macros.help_script(help_import_package_dialog, help_import_package_btn) }}
});

function stand_by() {
let x = document.getElementById("stand_by_hint");
x.style.visibility = "visible";
}
</script>
{% endblock %}

4 changes: 4 additions & 0 deletions webapp/home/texttype_node_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def model_has_complex_texttypes(eml_node):
For each TextType node, check if it has any children other than para. So, for example, if Project Abstract contains
a section, then it is complex, so the model has complex texttypes.
"""
if user_data.get_enable_complex_text_element_editing_global():
return True
if user_data.get_enable_complex_text_element_editing_document():
return True
if not eml_node:
raise ValueError
for texttype_node_name in TEXTTYPE_NODES:
Expand Down
1 change: 1 addition & 0 deletions webapp/home/utils/hidden_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
BTN_HIDDEN_PREVIEW_DATA_PORTAL: PAGE_PREVIEW_DATA_PORTAL,
BTN_HIDDEN_SAVE: PAGE_SAVE,
BTN_HIDDEN_SAVE_AS: PAGE_SAVE_AS,
BTN_HIDDEN_SETTINGS: PAGE_SETTINGS,
BTN_HIDDEN_USER_GUIDE: PAGE_USER_GUIDE,
# Hidden buttons based on Contents Menu
BTN_HIDDEN_TITLE: PAGE_TITLE,
Expand Down
27 changes: 26 additions & 1 deletion webapp/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
ImportEMLForm, ImportEMLItemsForm, ImportPartiesFromTemplateForm,
ImportItemsForm, ImportSingleItemForm,
SubmitToEDIForm, SendToColleagueForm, EDIForm,
SelectUserForm, SelectDataFileForm, SelectEMLFileForm
SelectUserForm, SelectDataFileForm, SelectEMLFileForm,
SettingsForm
)

import webapp.utils as utils
Expand Down Expand Up @@ -999,6 +1000,30 @@ def copy_uploads(from_package, to_package):
return render_template('index.html')


@home_bp.route('/settings', methods=['GET', 'POST'])
@login_required
@non_saving_hidden_buttons_decorator
def settings():
form = SettingsForm()

if request.method == 'POST':
if BTN_CANCEL in request.form:
return redirect(get_back_url())

if form.validate_on_submit():
current_document = current_user.get_filename()
user_data.set_enable_complex_text_element_editing_document(current_document, form.complex_text_editing_document.data)
user_data.set_enable_complex_text_element_editing_global(form.complex_text_editing_global.data)
log_usage(actions['SETTINGS'])
return redirect(get_back_url())

if request.method == 'GET':
form.complex_text_editing_document.data = user_data.get_enable_complex_text_element_editing_document()
form.complex_text_editing_global.data = user_data.get_enable_complex_text_element_editing_global()
help = get_helps(['settings_text'])
return render_template('settings.html', form=form, help=help)


@home_bp.route('/check_data_tables', methods=['GET', 'POST'])
@login_required
@non_saving_hidden_buttons_decorator
Expand Down
1 change: 1 addition & 0 deletions webapp/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
PAGE_SAVE_AS = 'home.save_as'
PAGE_SAVE_BACKUP = 'collab.save_backup'
PAGE_SEND_TO_OTHER = 'home.send_to_other'
PAGE_SETTINGS = 'home.settings'
PAGE_SHARE_SUBMIT_PACKAGE = 'home.share_submit_package'
PAGE_SHOW_BACKUPS = 'collab.show_backups'
PAGE_SUBMIT_TO_EDI = 'home.submit_package'
Expand Down
33 changes: 33 additions & 0 deletions webapp/static/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,39 @@ When you go to the Abstract page in ezEML, what you would see is the following:<
\&lt;/abstract\&gt;<br>
</pre>

The backslash "escape" characters before the &lt; and &gt; in each XML tag let ezEML distinguish XML tags from normal text that happens to contain &lt; or &gt; characters. If you edit the XML, you must adhere to this convention. Text elements requiring such handling are visually distinguished in two ways: 1) the text is displayed in a different (monospace) font, and 2) a checkmark button <svg style="position: relative;top:4px;" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.5163 8.93451L11.0597 14.7023L8.0959 11.8984" stroke="black" stroke-width="2"/><path d="M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z" stroke="black" stroke-width="1"/></svg> appears to the right of the element. Clicking the checkmark button causes the XML validity of the element's content to be checked. See also <a style="color: steelblue;" href="/static/user_guide/complex_text.pdf" target="_user_guide_ezeml">Editing Complex Text Elements in Imported XML</a> in the <a style="color: steelblue;" href="/eml/user_guide">User Guide</a>.

Watch a short demo video here:&nbsp;&nbsp;<a href="https://www.youtube.com/watch?v=PNhiBPXWAdA&t=348s" target="_ezeml_user_guide"><img src="/user-data/youtube.png" style="height:18px;width:auto;"></a>
--------------------
settings_text
Enable Complex Text Element Editing
The EML standard allows for substantial complexity in text elements like abstracts and method step descriptions. Such text elements may contain itemized lists, subscripts, markdown, etc.

Most users of ezEML will not need to employ these features, and ezEML does not support them by default. You can, however, enable them for the current EML document or for all EML documents. This will let you enter markdown tags, for example.

When complex text element editing is enabled, ezEML supports the editing of the relevant text elements as follows. Suppose, for example, the dataset's abstract element consists of the following XML:<br>
<pre>
&lt;abstract&gt;<br>
&nbsp;&nbsp;&lt;section&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Hypothetical Abstract&lt;/title&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;para&gt;This is &lt;emphasis&gt;only&lt;emphasis&gt; an example.&lt;/para&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;para&gt;Please note that 1 &amp;lt; 2.&lt;/para&gt;<br>
&nbsp;&nbsp;&lt;/section&gt;<br>
&lt;/abstract&gt;<br>
</pre>

When you go to the Abstract page when complex text element editing is enabled, what you would see is the following:<br>
<pre>
\&lt;abstract\&gt;<br>
&nbsp;&nbsp;\&lt;section\&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;\&lt;title\&gt;Hypothetical Abstract\&lt;/title\&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;\&lt;para\&gt;This is \&lt;emphasis\&gt;only\&lt;emphasis\&gt; an example.\&lt;/para\&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;\&lt;para\&gt;Please note that 1 &lt; 2.\&lt;/para\&gt;<br>
&nbsp;&nbsp;\&lt;/section\&gt;<br>
\&lt;/abstract\&gt;<br>
</pre>

The backslash "escape" characters before the &lt; and &gt; in each XML tag let ezEML distinguish XML tags from normal text that happens to contain &lt; or &gt; characters. If you edit the XML, you must adhere to this convention. Text elements requiring such handling are visually distinguished in two ways: 1) the text is displayed in a different (monospace) font, and 2) a checkmark button <svg style="position: relative;top:4px;" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.5163 8.93451L11.0597 14.7023L8.0959 11.8984" stroke="black" stroke-width="2"/><path d="M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z" stroke="black" stroke-width="1"/></svg> appears to the right of the element. Clicking the checkmark button causes the XML validity of the element's content to be checked. See also <a style="color: steelblue;" href="/static/user_guide/complex_text.pdf" target="_user_guide_ezeml">Editing Complex Text Elements in Imported XML</a> in the <a style="color: steelblue;" href="/eml/user_guide">User Guide</a>.

Expand Down

0 comments on commit a20544c

Please sign in to comment.