Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Add search functionality #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lincoln/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<script>
$(document).ready(function() {
// Action stats form based on input val
$('#search').submit(function(){
var query = $('#query').val();
$(this).attr('action', "/search/" + query);
});
});
</script>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using JS here? We should probably just use GET method if we want it to make a nice history entry for users.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy pasta code from simple multi. Idk what you mean about a history entry, please elaborate?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three options I suppose

  1. Use POST. This means that going backward then forward usually prompts for form resubmission. We don't really want that here.
  2. Use GET. No prompt when going through history. It also will cause google and the like to not index/cache these pages I believe.
  3. Use canoncial URLs. This is probably not what we want here since google will index and cache the page.

Just switch method to GET and toss the JS I think.

</head>

<body>
Expand All @@ -40,10 +50,14 @@
<a class="navbar-brand" href="/">Lincoln</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<ul class="nav navbar-nav navbar-left">
<li{% if page == "blocks" %} class="active"{% endif %}><a href="/"><i class="fa fa-cubes"></i> Blocks</a></li>
<li{% if page == "transactions" %} class="active"{% endif %}><a href="/transactions"><i class="fa fa-sitemap"></i> Transactions</a></li>
</ul>
<form class="navbar-form navbar-right" id="search">
<input type="text" class="form-control col-lg-8" placeholder="Search" id="query">
<button type="submit" class="btn btn-success">Go</button>
</form>
</div><!--/.nav-collapse -->
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions lincoln/templates/search_results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% set title = "Search results" %}
{% set page = "search_results" %}
{% extends "base.html" %}
{% block content %}
<h3 style="margin-top:0px;"><i class="fa fa-search text-warning"></i> Search results</h3>
<h5 style="margin-top:0px;"><i class="fa fa-cubes text-warning"></i> Blocks</h5>
{% include "blocks_table.html" %}
<h3 style="margin-top:0px;"><i class="fa fa-sitemap text-warning"></i> Transactions</h3>
{% include "transaction_table.html" %}
{% endblock %}

11 changes: 11 additions & 0 deletions lincoln/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ def favicon():
return send_from_directory(
os.path.join(root, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')

@main.route('/search/<query>')
def search(query):
blob = core.lx(query)

# Query for items
blocks = m.Block.query.filter(m.Block.hash.like(blob)).limit(10)
transactions = m.Transaction.query.filter(m.Transaction.txid.like(blob)).limit(10)
return render_template('search_results.html',
blocks=blocks,
transactions=transactions)