Skip to content

Commit

Permalink
Merge pull request #135 from itsron717/master
Browse files Browse the repository at this point in the history
Tags Feature
  • Loading branch information
AdiChat authored Jun 11, 2018
2 parents ea29cb5 + c3c4483 commit 9438630
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 16 deletions.
1 change: 1 addition & 0 deletions search/templates/cosmos/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<a class="btn float-right" href="https://github.com/OpenGenus/cosmos-search">GitHub</a>
<a class="btn float-right" href="https://github.com/OpenGenus/cosmos">cosmos</a>
<a class="btn float-right" href="{% url 'query' %}?q=calculator">calculator</a>
<a class="btn float-right" href="{% url 'tags' %}">tags</a>
</div>
</div>
</br>
Expand Down
14 changes: 13 additions & 1 deletion search/templates/cosmos/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{% extends 'cosmos/header.html' %}
{% block body %}
{% load random_numbers %}

<!-- Style for Tags-->
<style>
ul#menu li {
display:inline-grid;
}
</style>
<!-- Styling Ends-->
<article>
<ul id="menu">
{% for tag in random %}
<li><a href="{% url 'query' %}?q={{tag}}">{{tag}}, </a></li>
{% endfor %}
<li><a href="{% url 'tags' %}">More...</a></li>
</ul>
<h1 style="text-align: center">Welcome to <em>cosmos-search</em></h1>
<hr>

Expand Down
41 changes: 41 additions & 0 deletions search/templates/cosmos/tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
{% extends 'cosmos/header.html' %}
{% block body %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--Code for the Search Filter-->
<script>
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myList li").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
<!--Code Ends-->
<!--Creating Columns for HTML List-->
<style>
ul {
columns: 3;
-webkit-columns: 3;
-moz-columns: 3;
}
</style>
<!--Styling Ends-->
<h1>Tags</h1>
<hr>
<h7>
A tag is a keyword or label that categorizes your search query with other, similar queries. Users can use these tags in exploring new topics and continue browsing without prior knowledge.
</h7>
<br><br>
<input id="myInput" type="text" placeholder="Search...">
<p><br></p>
<ul id="myList">
{% for tag in tags %}
<li class="list-group-item"><a href="{% url 'query' %}?q={{tag}}"/>{{ tag }}</li>
{% endfor %}
</ul>
{% endblock %}
</html>
1 change: 1 addition & 0 deletions search/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^tags/', views.tags, name='tags'),
url(r'^query/', views.query, name='query'),
url(r'^display', views.display, name='display'),
url(r'^calculator/', views.calculator, name='calculator'),
Expand Down
42 changes: 27 additions & 15 deletions search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
# Create your views here


# Tags page for users
def tags(request):
f = open(settings.TAGS_JSON, 'r')
jsonL = sorted(list(json.load(f)))
args = {"tags": jsonL}
return render(request, 'cosmos/tags.html', args)

# To prefill the searchbar


def get_random_tag():
jsonFile = open(settings.TAGS_JSON, 'r')
algo_list = json.load(jsonFile)
Expand Down Expand Up @@ -50,12 +59,15 @@ def searchSuggestion(request):


def index(request):
randomTags = []
for i in range(4):
randomTags.append(get_random_tag())
query = get_random_tag()
algo = searchSuggestion(request)
if request.is_ajax():
mimetype = 'application/json'
return HttpResponse(algo, mimetype)
return render(request, 'cosmos/index.html', {'query': query})
return render(request, 'cosmos/index.html', {'query': query, 'random': randomTags})


# Handlers for error pages
Expand Down Expand Up @@ -158,20 +170,20 @@ def code_search(request, query):
else:
d = folder_list[-3] + '/'
for i, j in data.items():
if d in i:
if query not in i:
only_contents_md = True
for f in j:
if not is_file_extension_ignored(f):
only_contents_md = False
break
if only_contents_md:
continue
p = i
p = p.split('/')
l = p[len(p) - 1]
codes['recommendations'].append(
{'recpath': i, 'recdirs': p, 'last': l})
if d in i:
if query not in i:
only_contents_md = True
for f in j:
if not is_file_extension_ignored(f):
only_contents_md = False
break
if only_contents_md:
continue
p = i
p = p.split('/')
l = p[len(p) - 1]
codes['recommendations'].append(
{'recpath': i, 'recdirs': p, 'last': l})
shuffle(codes['recommendations'])
codes['recommendations'] = codes['recommendations'][:5]

Expand Down

0 comments on commit 9438630

Please sign in to comment.