Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6cbca92

Browse files
logic for adding new search fields, and for doing the next search
1 parent fe5f8d0 commit 6cbca92

File tree

6 files changed

+95
-54
lines changed

6 files changed

+95
-54
lines changed

‎mpeds_coder.py‎

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import assign_lib
4646

4747
## db
48-
from sqlalchemy.exc import OperationalError
4948
from sqlalchemy import func, desc, distinct, or_, text
5049
from sqlalchemy.sql import select
5150

@@ -571,9 +570,7 @@ def eventCreator(aid):
571570
@app.route('/adj', methods = ['GET'])
572571
@login_required
573572
def adj():
574-
""" Rendering for adjudication page."""
575-
filter = request.form.get('filter')
576-
sort = request.form.get('sort')
573+
"""Initial rendering for adjudication page."""
577574

578575
## TODO: These are placeholders which will be gathered from queries later
579576
query1 = 'Chicago'
@@ -594,23 +591,9 @@ def adj():
594591
# join(CodeEventCreator, CanonicalEventLink.cec_id == CodeEventCreator.id).\
595592
# filter(CanonicalEvent.key == canonical_event_key).all()
596593

597-
#####
598-
## Data for search
599-
#####
600-
## TODO: Move this into YAML or base this off of EventMetadata fields
601-
filter_fields = [
602-
"---",
603-
"article_desc",
604-
"article_id",
605-
"desc",
606-
"event_id",
607-
"location",
608-
"start_date",
609-
"end_date",
610-
"publication",
611-
"pub_date",
612-
"title"
613-
]
594+
## TODO: Base this off EventMetadata for now. Eventually, we want to get rid of this.
595+
filter_fields = EventMetadata.__table__.columns.keys()
596+
filter_fields.remove('id')
614597

615598
## TODO: Do some checks in the template which don't force us to enter in empty variables
616599
## which will be initialized by load_adj_grid
@@ -630,6 +613,7 @@ def adj():
630613
@login_required
631614
def load_cand_search():
632615
"""Loads the candidate event search pane."""
616+
pass
633617

634618

635619
@app.route('/load_adj_grid', methods = ['GET'])
@@ -662,14 +646,50 @@ def load_adj_grid():
662646
## Search functions
663647
#####
664648

665-
@app.route('/adj_search/<function>')
649+
@app.route('/do_search', methods= ['GET'])
666650
@login_required
667-
def cand_search(function):
668-
"""Performs a search on the candidate events."""
669-
if function not in ['search', 'filter', 'sort']:
651+
def do_search():
652+
"""Takes the URL params and searches the candidate events for events
653+
which meet the search criteria."""
654+
search_params = request.args.to_dict()
655+
656+
filter_field = search_params.get('filter_field')
657+
filter_value = search_params.get('filter_value')
658+
filter_compare = search_params.get('filter_compare')
659+
660+
## TODO: Do the filtering. Find a way to translate the filter compare
661+
## to a SQLAlchemy expression.
662+
pass
663+
664+
@app.route('/adj_search/<function>', methods = ['POST'])
665+
@login_required
666+
def adj_search(function):
667+
"""Adds a search/filter/sort form row to the search pane.
668+
Will only do this if the prior search/filter/sort form rows are full."""
669+
670+
if function == 'search':
671+
search_str = request.form['adj-search-input']
672+
if search_str is None or search_str == '':
673+
return make_response('No search string provided', 400)
674+
elif function == 'filter':
675+
filter_field = request.form['adj-filter-field']
676+
filter_compare = request.form['adj-filter-compare']
677+
filter_value = request.form['adj-filter-value']
678+
679+
if filter_field is None or filter_compare is None or filter_value is None:
680+
return make_response('No filter provided', 400)
681+
elif function == 'sort':
682+
sort_field = request.form['adj-sort-field']
683+
sort_order = request.form['adj-sort-order']
684+
685+
if sort_field is None or sort_order is None:
686+
return make_response('No sort field provided', 400)
687+
else:
670688
return make_response("Invalid search function", 400)
671689

672-
return render_template('adj-{}.html'.format(function))
690+
is_addition = True if request.form['is_addition'] == 'true' else False
691+
692+
return render_template('adj-{}.html'.format(function), is_addition = is_addition)
673693

674694

675695
#####

‎static/adj.js‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,22 +537,41 @@ $(function () {
537537
});
538538

539539
// Listener for searches additions
540-
$('#cand-search').click(function() {
540+
$('#adj-search-button').click(function() {
541541
var req = $.ajax({
542542
url: $SCRIPT_ROOT + '/adj_search/search',
543-
type: "GET"
543+
type: "POST",
544+
data: {
545+
is_addition: true,
546+
search_str: $('#adj-search-input').val()
547+
}
544548
})
545-
.done($('#adj-search').append(req.responseText))
546-
.fail(makeError("Could not add search block."));
549+
.done(function(){$('#adj-search-form').append(req.responseText);})
550+
.fail(function(){returnmakeError(req.responseText);});
547551
});
548552

549-
$('#cand-filter').click(function() {
553+
$('#adj-filter-button').click(function() {
550554
var req = $.ajax({
551555
url: $SCRIPT_ROOT + '/adj_search/filter',
552-
type: "GET"
556+
type: "POST",
557+
data: {
558+
is_addition: true
559+
}
560+
})
561+
.done(function() {$('#adj-filter-form').append(req.responseText); })
562+
.fail(function() { return makeError(req.responseText); });
563+
});
564+
565+
$('#adj-sort-button').click(function() {
566+
var req = $.ajax({
567+
url: $SCRIPT_ROOT + '/adj_search/sort',
568+
type: "POST",
569+
data: {
570+
is_addition: true
571+
}
553572
})
554-
.done($('#adj-filter').append(req.responseText))
555-
.fail(makeError("Could not add filter block."));
573+
.done(function(){$('#adj-sort-form').append(req.responseText);})
574+
.fail(function(){returnmakeError(req.responseText);});
556575
});
557576

558577
loadSearch();

‎templates/adj-filter.html‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
<div class="row form-row">
22
<div class="col-sm-4">
33
<select class="form-control"
4-
name="filter-field" />
4+
name="adj-filter-field"
5+
id="adj-filter-field">
6+
<option value="">---</option>
57
{% for field in filter_fields %}
6-
<option>{{ field }}</option>
8+
<option>{{ field }}</option>
79
{% endfor %}
810
</select>
911
</div>
1012
<div class="col-sm-4">
1113
<select class="form-control"
12-
name="filter-compare">
14+
name="adj-filter-compare"
15+
id="adj-filter-compare">
1316
<option>equals</option>
1417
<option>is greater than</option>
1518
<option>is greater than or equal to</option>
@@ -22,13 +25,12 @@
2225
</div>
2326
<div class="col-sm-3">
2427
<input class="form-control"
25-
name="filter-value"
28+
name="adj-filter-value"
29+
id="adj-filter-value"
2630
type="text"
2731
placeholder = "Value..."/>
2832
</div>
2933
<div class="col-sm-1">
30-
<button type="submit" class="btn btm-primary" id="cand-filter">
31-
<span class="glyphicon glyphicon-plus"></span>
32-
</button>
34+
<a id="adj-filter-button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
3335
</div>
3436
</div>

‎templates/adj-search.html‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<div class="row form-row">
22
<div class="col-sm-11">
33
<input class="form-control"
4-
name="filter-value"
4+
name="search_value"
5+
id="adj-search-input"
56
type="text"
67
placeholder = "Value..."/>
78
</div>
89
<div class="col-sm-1">
9-
<button id="cand-search" class="btn btm-primary">
10-
<span class="glyphicon glyphicon-plus"></span>
11-
</button>
10+
<a id="adj-search-button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
1211
</div>
1312
</div>

‎templates/adj-sort.html‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<div class="row form-row">
22
<div class="col-sm-4">
33
<select class="form-control"
4-
name="sort-field" />
4+
name="adj-sort-field"
5+
id="adj-sort-field">
6+
<option value="">---</option>
57
{% for field in filter_fields %}
6-
<option>{{ field }}</option>
8+
<option>{{ field }}</option>
79
{% endfor %}
810
</select>
911
</div>
1012
<div class="col-sm-4">
1113
<select class="form-control"
12-
name="sort-field-asc">
14+
name="adj-sort-order"
15+
id="adj-sort-order">
1316
<option>ascending</option>
1417
<option>descending</option>
1518
</select>
1619
</div>
1720
<div class="col-sm-1">
18-
<button class="btn btm-primary" id="cand-sort">
19-
<span class="glyphicon glyphicon-plus"></span>
20-
</button>
21+
<a id="adj-sort-button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
2122
</div>
2223
</div>

‎templates/adj.html‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ <h4>Event Selection</h4>
4242
<div class="tab-pane" id="search_block">
4343
<div class="adj-variable-group">
4444
<h5>Search</h5>
45-
<form id="adj-search">
45+
<form id="adj-search-form">
4646
{% include 'adj-search.html' %}
4747
</form>
4848
</div>
4949
<hr/>
5050
<div class="adj-variable-group">
5151
<h5>Filter</h5>
52-
<form id="adj-filter">
52+
<form id="adj-filter-form">
5353
{% include 'adj-filter.html' %}
5454
</form>
5555
</div>
5656
<hr/>
5757
<div class="adj-variable-group">
5858
<h5>Sort</h5>
59-
<form id="adj-sort">
59+
<form id="adj-sort-form">
6060
{% include 'adj-sort.html' %}
6161
</form>
6262
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /