We can now limit the list of studies to a particular user.

Created a new route /user_studies in __init__.py that takes a uva_id.
Pulled out some dupllcate code into a new method; render_study_template

In index.html, added a pulldown to select the user. I pull the list of users from the studies so we only show users that have studies.
Added a script to process the selection.
This commit is contained in:
mike cullerton 2021-02-19 10:55:21 -05:00
parent 60bd0f22ef
commit 81457c2b7c
2 changed files with 44 additions and 6 deletions

View File

@ -161,16 +161,32 @@ from pb.models import Study, RequiredDocument, Investigator, StudySchema, Requir
from pb.ldap.ldap_service import LdapService
def render_study_template(studies):
table = StudyTable(studies)
users = []
[users.append(study.NETBADGEID) for study in studies if study.NETBADGEID not in users]
return render_template(
'index.html',
table=table,
base_href=BASE_HREF,
users=users
)
@app.route('/', methods=['GET', 'POST'])
def index():
# display results
studies = db.session.query(Study).order_by(Study.DATE_MODIFIED.desc()).all()
table = StudyTable(studies)
return render_template(
'index.html',
table=table,
base_href=BASE_HREF
)
return render_study_template(studies)
@app.route('/user_studies/', defaults={'uva_id': 'all'})
@app.route('/user_studies/<uva_id>', methods=['GET'])
def user_studies(uva_id):
if uva_id == 'all':
return redirect(f"/")
studies = db.session.query(Study).filter(Study.NETBADGEID == uva_id).order_by(Study.DATE_MODIFIED.desc()).all()
return render_study_template(studies)
@app.route('/new_study', methods=['GET', 'POST'])

View File

@ -16,6 +16,18 @@
<p>
<a class="btn btn-primary" href="{{ url_for('.new_study') }}"> New Study </a>
</p>
<p>
<label>User Studies</label>
<select name="uva_id" id="uva_id" onclick="selectStudies()">
<option value="">Select User</option>
<option value="all">All Users</option>
{% if users %}
{% for user in users %}
<option value="{{ user }}">{{ user }}</option>
{% endfor %}
{% endif %}
</select>
</p>
{% with messages = get_flashed_messages(with_categories=True) %}
{% if messages %}
@ -43,5 +55,15 @@
setTimeout(() => hideElement(alert), 3000);
}
</script>
<script>
function selectStudies() {
let uva_id = document.getElementById('uva_id').value;
if (uva_id == 'all') {
window.location.href = '/'
} else {
window.location.href = "/user_studies/" + uva_id;
}
}
</script>
</body>
</html>