Skip to content

Commit

Permalink
Merge pull request #118 from SuffolkLITLab/bug-dashboard-answer-viewer
Browse files Browse the repository at this point in the history
Pass the filename to the view answers JSON event when not selected
  • Loading branch information
nonprofittechy authored Dec 1, 2023
2 parents 5946b56 + 9335728 commit ea1192e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
20 changes: 20 additions & 0 deletions docassemble/ALDashboard/aldashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"install_fonts",
"list_installed_fonts",
"dashboard_get_session_variables",
"nicer_interview_filename",
]


Expand Down Expand Up @@ -327,3 +328,22 @@ def list_installed_fonts():
# From server.py
# subq = db.session.query(db.func.max(UserDict.indexno).label('indexno'), UserDict.filename, UserDict.key).group_by(UserDict.filename, UserDict.key).subquery()
# interview_query = db.session.query(UserDictKeys.user_id, UserDictKeys.temp_user_id, UserDictKeys.filename, UserDictKeys.key, UserDict.dictionary, UserDict.encrypted, UserModel.email).join(subq, and_(subq.c.filename == UserDictKeys.filename, subq.c.key == UserDictKeys.key)).join(UserDict, and_(UserDict.indexno == subq.c.indexno, UserDict.key == UserDictKeys.key, UserDict.filename == UserDictKeys.filename)).join(UserModel, UserModel.id == UserDictKeys.user_id).filter(UserDictKeys.user_id == user_id, UserDictKeys.filename == filename, UserDictKeys.key == session).group_by(UserModel.email, UserDictKeys.user_id, UserDictKeys.temp_user_id, UserDictKeys.filename, UserDictKeys.key, UserDict.dictionary, UserDict.encrypted, UserDictKeys.indexno).order_by(UserDictKeys.indexno)

def nicer_interview_filename(filename: str) -> str:
"""
Given a filename like docassemble.playground10ALWeaver:data/questions/assembly_line.yml,
return a less cluttered name like: playground10ALWeaver:assembly_line
"""
filename_parts = filename.split(":")

# Fixing the slicing for the first part of the filename
if filename_parts[0].startswith("docassemble."):
filename_parts[0] = filename_parts[0][len("docassemble."):]

# Check if there are two parts and modify the second part
if len(filename_parts) > 1:
if filename_parts[1].startswith("data/questions/"):
filename_parts[1] = filename_parts[1][len("data/questions/"):]
return f"{filename_parts[0]}:{filename_parts[1].replace('.yml', '')}"

return filename_parts[0]
22 changes: 16 additions & 6 deletions docassemble/ALDashboard/data/questions/list_sessions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fields:
speedy_get_users()
- Filter out interviews that are on the first page: filter_step1
required: False
datatype: yesno
datatype: yesno
default: True
---
# next((item.get('title') for item in interviews if item.get('filename') == interview['filename']), interview['filename'] )
Expand All @@ -42,7 +42,13 @@ code: |
mandatory: True
event: load_answer
question: |
Recently started sessions for ${ interviews.get(filename, {"title": filename}).get('title', filename) }
% if filename:
Recently started sessions for ${ nicer_interview_filename(interviews.get(filename, {"title": filename}).get('title', filename)) }
% elif chosen_user:
Recently started sessions for User ID ${ chosen_user}
% else:
Recently started sessions for all users
% endif
subquestion: |
<table class="table">
<thead>
Expand All @@ -57,8 +63,12 @@ subquestion: |
% for interview in sessions_list:
<tr>
<td>
${ interview.key }
<td class="text-wrap text-break">
${ interview.key }
% if not filename:
<br/>
${ nicer_interview_filename(interview.filename) }
% endif
</td>
<td>${ interview.user_id }</td>
<td>${ format_date(interview.modtime, "MMM d YYYY") }</td>
Expand All @@ -67,7 +77,7 @@ subquestion: |
<a href="${ interview_url(i=interview.filename, session=interview.key) }">
<i class="fa-solid fa-folder-open"></i>&nbsp;Join</a>
<br/>
<a href="${ interview_url_action('view_session_variables', session_id=interview.key) }"><i class="fa-solid fa-eye"></i>&nbsp;Vars</a>
<a href="${ interview_url_action('view_session_variables', session_id=interview.key, filename=interview.filename) }"><i class="fa-solid fa-eye"></i>&nbsp;Vars</a>
</td>
</tr>
% endfor
Expand All @@ -76,4 +86,4 @@ question back button: True
---
event: view_session_variables
code: |
response(binaryresponse=json.dumps(dashboard_get_session_variables(session_id=action_argument('session_id'), filename=filename)).encode('utf-8'), content_type="application/json", response_code=200)
response(binaryresponse=json.dumps(dashboard_get_session_variables(session_id=action_argument('session_id'), filename=action_argument('filename'))).encode('utf-8'), content_type="application/json", response_code=200)

0 comments on commit ea1192e

Please sign in to comment.