Skip to content

Commit

Permalink
Merge pull request #16 from /issues/11-empty_search
Browse files Browse the repository at this point in the history
Simple empty search
  • Loading branch information
MarekSuchanek committed Sep 29, 2017
2 parents 403e837 + 0743070 commit fabf937
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
11 changes: 4 additions & 7 deletions repocribro/controllers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ def search(query=''):
ext_master = flask.current_app.container.get('ext_master')

tabs = {}
active_tab = ''
if query != '':
ext_master.call('view_core_search_tabs',
query=query, tabs_dict=tabs)
tabs = sorted(tabs.values())
active_tab = flask.request.args.get('tab', tabs[0].id)

ext_master.call('view_core_search_tabs',
query=query, tabs_dict=tabs)
tabs = sorted(tabs.values())
active_tab = flask.request.args.get('tab', tabs[0].id)
return flask.render_template(
'core/search.html', query=query, tabs=tabs, active_tab=active_tab
)
Expand Down
23 changes: 14 additions & 9 deletions repocribro/ext_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,20 @@ def view_core_search_tabs(self, query, tabs_dict):
:type tabs_dict: dict of str: ``repocribro.extending.helpers.ViewTab``
"""
from .models import User, Organization, Repository
users = User.fulltext_query(
query, self.db.session.query(User)
).all()
orgs = Organization.fulltext_query(
query, self.db.session.query(Organization)
).all()
repos = Repository.fulltext_query(
query, self.db.session.query(Repository)
).all()
if query == '':
users = self.db.session.query(User).all()
orgs = self.db.session.query(Organization).all()
repos = self.db.session.query(Repository).all()
else:
users = User.fulltext_query(
query, self.db.session.query(User)
).all()
orgs = Organization.fulltext_query(
query, self.db.session.query(Organization)
).all()
repos = Repository.fulltext_query(
query, self.db.session.query(Repository)
).all()

tabs_dict['repositories'] = ViewTab(
'repositories', 'Repositories', 0,
Expand Down
4 changes: 4 additions & 0 deletions repocribro/templates/core/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ <h1>Search</h1>
</div>
{% else %}
<div class="alert alert-info">Use search field for exploring what are you interested in!</div>

<div class="search-results">
{{ tabzone(tabs, active_tab) }}
</div>
{% endif %}
{% endblock %}

Expand Down

0 comments on commit fabf937

Please sign in to comment.