Skip to content

Commit

Permalink
Merge pull request #79 from emxsys/search
Browse files Browse the repository at this point in the history
Added ability to generate call history based on a caller's name
  • Loading branch information
emxsys authored Aug 20, 2020
2 parents 2d70ca5 + df3d839 commit 84fcf11
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
26 changes: 24 additions & 2 deletions src/userinterface/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,18 @@
</li>
</ul>
<form class="form-inline my-2 my-lg-0" action="/calls" method="get">
<input class="form-control mr-sm-2" type="search" name="search" placeholder="Phone number" aria-label="Search">
<button class="btn btn-success my-2 my-sm-0" name="submit" type="submit">Search</button>
<input class="form-control mr-sm-2" type="search" name="search" id="input-search" placeholder="Phone number" aria-label="Search">
<div class="btn-group">
<button type="submit" class="btn btn-success my-2 my-sm-0" id="btn-search" name="submit" value="phone">Search</button>
<button type="button" class="btn btn-success my-2 my-sm-0 dropdown-toggle dropdown-toggle-split" data-toggle="dropdown">
<span class="caret"></span>
</button>
<div class="dropdown-menu">
<div class="dropdown-header">SEARCH TYPE</div>
<a class="dropdown-item" id="menu-phone" href="#">Phone Search</a>
<a class="dropdown-item" id="menu-name" href="#">Name Search</a>
</div>
</div>
</form>
</div>
</div>
Expand Down Expand Up @@ -82,6 +92,18 @@
{% block js %}{% endblock %}

<script>
// Set the search type
$('#menu-name').on('click', function() {
$('#btn-search').val('name')
$('#input-search').attr('placeholder',"Enter Text")
})
$('#menu-phone').on('click', function() {
$('#btn-search').val('phone')
$('#input-search').attr('placeholder',"Phone Number")
})



// Highlight the nav-item in the navbar with the matching "active_nav_item" id
$(document).ready( function () {
{% if active_nav_item %}
Expand Down
14 changes: 9 additions & 5 deletions src/userinterface/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,20 @@ def calls():
# Get GET request args, if available
number = request.args.get('number')
search_text = request.args.get('search')
search_type = request.args.get('submit')

# Get search criteria, if applicable
search_criteria = ""
if search_text:
num_list = re.findall('[0-9]+', search_text)
number = "".join(num_list) # override GET arg if we're searching
search_criteria = "WHERE Number='{}'".format(number)
if search_type == "phone":
num_list = re.findall('[0-9]+', search_text)
number = "".join(num_list) # override GET arg if we're searching
search_criteria = "WHERE Number='{}'".format(number)
else:
search_criteria = "WHERE Caller LIKE '%{}%'".format(search_text)

# Get values used for pagination of the call log
sql = "SELECT COUNT(*) FROM CallLog {}".format(search_criteria)
sql = "SELECT COUNT(*), Number, Name Caller FROM CallLog {}".format(search_criteria)
g.cur.execute(sql)
total = g.cur.fetchone()[0]
page, per_page, offset = get_page_args(
Expand All @@ -291,7 +295,7 @@ def calls():
WHEN b.PhoneNo is not null then b.Name
WHEN c.PhoneNo is not null then c.Name
ELSE a.Name
END Name,
END Caller,
a.Number Number,
a.Date,
a.Time,
Expand Down

0 comments on commit 84fcf11

Please sign in to comment.