Skip to content

Commit

Permalink
different thumbnail appearance for documents; fix issue with Playgrou…
Browse files Browse the repository at this point in the history
…nd when default file shown; individualized hiding of flash messages; raise errors about invalid variable names
  • Loading branch information
jhpyle committed Sep 27, 2024
1 parent d66bfae commit e5f8692
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 47 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Change Log

## [1.5.11] - 2024-09-26

### Changed
- Different appearance when a document is reduced to a thumbnail
image.

### Fixed
- When a new Playground is initialized, the name of the YAML file was
missing in the sidebar dropdown and the share link.
- When a "flash" message with the Bootstap color "success" was shown
at the top of the screen, the timeout for removing the message
could remove messages that the user had not yet had the opportunity
to read.
- In a `review` screen, error messages about invalid variable names
were not shown in all cases where the variable name was invalid.

## [1.5.10] - 2024-09-19

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ attachment:
This is a complaint.
Blah, blah, blah
[PAGEBREAK]
This is the certificate of service.
valid formats:
- pdf
- pdf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ attachment:
This is a complaint.
Blah, blah, blah
[PAGEBREAK]
This is the certificate of service.
29 changes: 22 additions & 7 deletions docassemble_base/docassemble/base/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,10 @@ def image_url(file_reference, alt_text, width, emoji=False, question=None, exter
if 'extension' in file_info and file_info['extension'] is not None:
if re.match(r'.*%$', width):
width_string = "width:" + width
stack_width_string = width_string
else:
width_string = "max-width:" + width
stack_width_string = "width:" + width
if emoji:
width_string += ';vertical-align: middle'
alt_text = 'alt="" '
Expand Down Expand Up @@ -1056,22 +1058,35 @@ def image_url(file_reference, alt_text, width, emoji=False, question=None, exter
if the_image_url is None:
return '[ERROR: File reference ' + str(file_reference) + ' cannot be displayed]'
if 'filename' in file_info:
title = ' title="' + file_info['filename'] + '"'
title = ' title="' + file_info['filename']
if 'pages' in file_info and file_info['pages'] > 1:
title += " (" + str(file_info['pages']) + " " + word('pages') + ")"
title += '"'
else:
title = ''
if 'pages' in file_info and file_info['pages'] > 1:
title = ' title="' + str(file_info['pages']) + " " + word('pages') + '"'
else:
title = ''
if alt_text == '':
the_alt_text = 'alt=' + json.dumps(word("Thumbnail image of document")) + ' '
else:
the_alt_text = alt_text
try:
with Pdf.open(file_info['path'] + '.pdf') as reader:
layout_width = str(reader.pages[0].mediabox[2] - reader.pages[0].mediabox[0])
layout_height = str(reader.pages[0].mediabox[3] - reader.pages[0].mediabox[1])
output = '<a target="_blank"' + title + ' class="daimageref" href="' + the_url + '"><img ' + the_alt_text + 'class="daicon dapdfscreen' + extra_class + '" width=' + layout_width + ' height=' + layout_height + ' style="' + width_string + '; height: auto;" src="' + the_image_url + '"/></a>'
layout_width = reader.pages[0].mediabox[2] - reader.pages[0].mediabox[0]
layout_height = reader.pages[0].mediabox[3] - reader.pages[0].mediabox[1]
if width_string == 'width:100%':
output = '<a target="_blank"' + title + ' class="daimageref" href="' + the_url + '"><img ' + the_alt_text + 'class="daicon dapdfscreen' + extra_class + '" width=' + str(layout_width) + ' height=' + str(layout_height) + ' style="' + width_string + '; height: auto;" src="' + the_image_url + '"/></a>'
else:
if 'pages' in file_info and file_info['pages'] >= 1:
extra_pages = min(2, file_info['pages'] - 1)
else:
extra_pages = 2
aspect_ratio = 1.0*layout_width/layout_height
stack_width_string += "; height: auto; aspect-ratio: " + str(aspect_ratio) + ";"
output = '<div class="da-paper-stack" style="' + stack_width_string + '"><div class="da-paper"><a target="_blank"' + title + ' class="daimageref" href="' + the_url + '"><img ' + the_alt_text + 'class="daicon' + extra_class + '" width=' + str(layout_width) + ' height="' + str(layout_height) + '" style="width: 100%; height: auto" src="' + the_image_url + '"/></a></div>' + (('<div class="da-paper"></div>') * extra_pages) + '</div>'
except:
output = '<a target="_blank"' + title + ' class="daimageref" href="' + the_url + '"><img ' + the_alt_text + 'class="daicon dapdfscreen' + extra_class + '" style="' + width_string + '; height: auto;" src="' + the_image_url + '"/></a>'
if 'pages' in file_info and file_info['pages'] > 1:
output += " (" + str(file_info['pages']) + " " + word('pages') + ")"
return output
return '<a target="_blank" class="daimageref" href="' + the_url + '">' + file_info['filename'] + '</a>'
return '[Invalid image reference; reference=' + str(file_reference) + ', width=' + str(width) + ', filename=' + file_info.get('filename', 'unknown') + ']'
Expand Down
9 changes: 9 additions & 0 deletions docassemble_base/docassemble/base/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4123,11 +4123,16 @@ def force_ask(*pargs, **kwargs):
if 'event_stack' in this_thread.internal and unique_id in this_thread.internal['event_stack']:
this_thread.internal['event_stack'][unique_id] = []
if kwargs.get('persistent', True):
for item in the_pargs:
if isinstance(item, str) and illegal_variable_name(item):
raise DAError("Illegal variable name")
raise ForcedNameError(*the_pargs, user_dict=get_user_dict(), evaluate=kwargs.get('evaluate', False))
force_ask_nameerror(the_pargs[0])


def force_ask_nameerror(variable_name, priority=False):
if illegal_variable_name(variable_name):
raise DAError("Illegal variable name")
raise DANameError("name '" + str(variable_name) + "' is not defined")


Expand Down Expand Up @@ -4159,6 +4164,8 @@ def force_gather(*pargs, forget_prior=False, evaluate=False):
this_thread.internal['gather'].append({'var': variable_name, 'context': the_context})
last_variable_name = variable_name
if last_variable_name is not None:
if illegal_variable_name(last_variable_name):
raise DAError("Illegal variable name")
raise ForcedNameError(last_variable_name, gathering=True, user_dict=the_user_dict)


Expand Down Expand Up @@ -4872,6 +4879,8 @@ def dispatch(var):
"""Shows a menu screen."""
if not isinstance(var, str):
raise DAError("dispatch() must be given a string")
if illegal_variable_name(var):
raise DAError("Illegal variable name")
while value(var) != 'None':
value(value(var))
undefine(value(var))
Expand Down
3 changes: 0 additions & 3 deletions docassemble_base/docassemble/base/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10339,9 +10339,6 @@ def invalid_variable_name(varname):
return True
if re.search(r'[\n\r\(\)\{\}\*\^\#]', varname):
return True
varname = re.sub(r'[\.\[].*', '', varname)
if not valid_variable_match.match(varname):
return True
return illegal_variable_name(varname)


Expand Down
88 changes: 54 additions & 34 deletions docassemble_webapp/docassemble/webapp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9447,10 +9447,11 @@ def index(action_argument=None, refer=None):
$("#daflash").empty();
}
if (message != null){
$("#daflash").append(daSprintf(daNotificationMessage, priority, message));
var newElement = $(daSprintf(daNotificationMessage, priority, message));
$("#daflash").append(newElement);
if (priority == 'success'){
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
newElement.hide(300, function(){
$(this).remove();
});
}, 3000);
Expand Down Expand Up @@ -12558,11 +12559,14 @@ def index(action_argument=None, refer=None):
daInitialized = true;
daShowingHelp = 0;
daSubmitter = null;
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(self).remove();
});
}, 3000);
$("#daflash .alert-success").each(function(){
var oThis = this;
setTimeout(function(){
$(oThis).hide(300, function(){
$(self).remove();
});
}, 3000);
});
if (doScroll){
setTimeout(function () {
if (daJsEmbed){
Expand Down Expand Up @@ -14936,10 +14940,11 @@ def observer():
$("#daflash").empty();
}
if (message != null){
$("#daflash").append(daSprintf(daNotificationMessage, priority, message));
var newElement = daSprintf(daNotificationMessage, priority, message);
$("#daflash").append(newElement);
if (priority == 'success'){
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(newElement).hide(300, function(){
$(this).remove();
});
}, 3000);
Expand Down Expand Up @@ -15669,11 +15674,14 @@ def observer():
});
daInitialized = true;
daShowingHelp = 0;
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(self).remove();
});
}, 3000);
$("#daflash .alert-success").each(function(){
var oThis = this;
setTimeout(function(){
$(oThis).hide(300, function(){
$(self).remove();
});
}, 3000);
});
}
$( document ).ready(function(){
daInitialize(1);
Expand Down Expand Up @@ -20295,11 +20303,14 @@ def playground_files():
}
resetExpireSession();
saveCallback(data);
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(self).remove();
});
}, 3000);
$("#daflash .alert-success").each(function(){
var oThis = this;
setTimeout(function(){
$(oThis).hide(300, function(){
$(self).remove();
});
}, 3000);
});
},
dataType: 'json'
});
Expand Down Expand Up @@ -22414,6 +22425,7 @@ def playground_page():
with open(filename, 'w', encoding='utf-8') as fp:
fp.write(content)
playground.finalize()
files = sorted([{'name': f, 'modtime': os.path.getmtime(os.path.join(the_directory, f))} for f in os.listdir(the_directory) if os.path.isfile(os.path.join(the_directory, f)) and re.search(r'^[A-Za-z0-9].*[A-Za-z]$', f)], key=lambda x: x['name'])
console_messages = []
if request.method == 'POST' and the_file != '' and valid_form:
if form.delete.data:
Expand Down Expand Up @@ -22544,7 +22556,7 @@ def playground_page():
variables_html, vocab_list, vocab_dict, ac_list = get_vars_in_use(interview, interview_status, debug_mode=debug_mode, current_project=current_project)
pulldown_files = [x['name'] for x in files]
define_examples()
if is_fictitious or is_new or is_default:
if is_fictitious or is_new:
new_active_file = word('(New file)')
if new_active_file not in pulldown_files:
pulldown_files.insert(0, new_active_file)
Expand Down Expand Up @@ -22799,10 +22811,11 @@ def playground_page():
if (!$("#daflash").length){
$("body").append(""" + json.dumps(NOTIFICATION_CONTAINER % ('',)) + """);
}
$("#daflash").append(daSprintf(daNotificationMessage, priority, message));
var newElement = $(daSprintf(daNotificationMessage, priority, message));
$("#daflash").append(newElement);
if (priority == 'success'){
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(newElement).hide(300, function(){
$(self).remove();
});
}, 3000);
Expand Down Expand Up @@ -22918,11 +22931,14 @@ def playground_page():
enableButtons();
resetExpireSession();
saveCallback(data);
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(self).remove();
});
}, 3000);
$("#daflash .alert-success").each(function(){
var oThis = this;
setTimeout(function(){
$(oThis).hide(300, function(){
$(self).remove();
});
}, 3000);
});
},
dataType: 'json'
});
Expand Down Expand Up @@ -23011,11 +23027,14 @@ def playground_page():
else{
$("#playground_name").focus()
}
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(self).remove();
});
}, 3000);
$("#daflash .alert-success").each(function(){
var oThis = this;
setTimeout(function(){
$(oThis).hide(300, function(){
$(self).remove();
});
}, 3000);
});

activateVariables();
updateRunLink();
Expand Down Expand Up @@ -23270,10 +23289,11 @@ def server_error(the_error):
if (!$("#daflash").length){
$("body").append(""" + json.dumps(NOTIFICATION_CONTAINER % ('',)) + """);
}
$("#daflash").append(daSprintf(daNotificationMessage, priority, message));
var newElement = $(daSprintf(daNotificationMessage, priority, message));
$("#daflash").append(newElement);
if (priority == 'success'){
setTimeout(function(){
$("#daflash .alert-success").hide(300, function(){
$(newElement).hide(300, function(){
$(self).remove();
});
}, 3000);
Expand Down
30 changes: 30 additions & 0 deletions docassemble_webapp/docassemble/webapp/static/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1961,3 +1961,33 @@ div.da-grid-container > div.dafieldpart > fieldset.da-field-checkboxes {
[data-bs-theme=dark] #dasigcanvas {
background-color: #777;
}

.da-paper-stack {
position: relative;
display: inline-block;
margin-right: 10px;
margin-bottom: 10px;
}
.da-paper {
position: absolute;
width: 100%;
height: 100%;
background-color: white;
border: 1px solid #ddd;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.da-paper:nth-child(1) {
z-index: 10;
}
.da-paper:nth-child(2) {
transform: translate(5px, 5px);
z-index: 9;
}
.da-paper:nth-child(3) {
transform: translate(10px, 10px);
z-index: 8;
}
.da-paper:nth-child(4) {
transform: translate(15px, 15px);
z-index: 7;
}

Large diffs are not rendered by default.

Loading

0 comments on commit e5f8692

Please sign in to comment.