Quick-Search: Added Quick-search in the topbar

Changed how and what we store in elastic to unify it with how we store
things in mongodb so we can have more generic javascript code
to render the data.

Elastic changes:
  Added:
  Node.project.url

  Altered to store id instead of url
  Node.picture

  Made Post searchable

./manage.py elastic reset_index
./manage.py elastic reindex

Thanks to Pablo and Sybren
This commit is contained in:
Tobias Johansson 2018-11-22 15:31:52 +01:00
parent 76a707e5bf
commit 2950a4347a
6 changed files with 53 additions and 41 deletions

View File

@ -35,6 +35,7 @@ html(lang="en")
script(src="{{ url_for('static_pillar', filename='assets/js/timeline.min.js') }}")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/jquery.typeahead-0.11.1.min.js')}}")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/js.cookie-2.0.3.min.js')}}")
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/hogan.common-3.0.0.js') }}")
| {% if current_user.is_authenticated %}
script(src="{{ url_for('static_pillar', filename='assets/js/vendor/clipboard.min.js')}}")
| {% endif %}
@ -80,9 +81,8 @@ html(lang="en")
| {% block navigation_tabs %}
| {% endblock navigation_tabs %}
| {% block navigation_search %}
| {% endblock navigation_search %}
+nav-secondary()(class="m-auto keep-when-overlay")
div.nav-item.quick-search.qs-input#qs-input
+nav-secondary()(class="ml-auto")
| {% if node and node.properties and node.properties.category %}
@ -90,17 +90,9 @@ html(lang="en")
| {% else %}
| {% set category = title %}
| {% endif %}
li.nav-item.quick-search.cursor-pointer.px-3.pi-search#qs-toggle
| {% block navigation_sections %}
+nav-secondary-link(
href="{{ url_for('main.nodes_search_index') }}",
title="Search Blender Cloud",
data-toggle="tooltip",
data-placement="bottom",
class="py-2 px-2 text-muted")
i.pi-search
| {% endblock navigation_sections %}
| {% block navigation_user %}
@ -118,7 +110,10 @@ html(lang="en")
.loading-bar
.page-content
#search-overlay
.quick-search.container-fluid.m-auto.p-5#search-overlay
ul.qs-loading.text-center
i.h1.pi-spin.spinner
h2 Loading
| {% block page_overlay %}
#page-overlay
| {% endblock page_overlay %}
@ -168,6 +163,38 @@ html(lang="en")
$('[data-toggle="tooltip"]').tooltip({'delay' : {'show': 0, 'hide': 0}});
}
// Enable Quick Search
let searches = {
{% if project and not project.is_private %}
project: {
name: 'Project',
uiUrl: '{{ url_for("projects.search", project_url=project.url)}}',
apiUrl: '/api/newsearch/multisearch',
searchParams: [
{name: 'Assets', params: {project: '{{ project._id }}', node_type: 'asset'}},
{name: 'Blog', params: {project: '{{ project._id }}', node_type: 'post'}},
{name: 'Groups', params: {project: '{{ project._id }}', node_type: 'group'}},
]
},
{% endif %}
cloud: {
name: 'Cloud',
uiUrl: '/search',
apiUrl: '/api/newsearch/multisearch',
searchParams: [
{name: 'Assets', params: {node_type: 'asset'}},
{name: 'Blog', params: {node_type: 'post'}},
{name: 'Groups', params: {node_type: 'group'}},
]
},
}
$('#qs-toggle').quickSearch({
resultTarget: '#search-overlay',
inputTarget: '#qs-input',
searches: searches,
});
| {% block footer_scripts_pre %}{% endblock %}
| {% block footer_scripts %}{% endblock %}

View File

@ -4,7 +4,7 @@ include ../../../../pillar/src/templates/mixins/components
ul.dropdown-menu.nav-main
+nav-secondary()(
class="nav-secondary-vertical float-left bg-light border-left rounded-left")
class="nav-secondary-vertical float- bg-light border-left rounded-left")
| {{ navigation.dropdown_main_root(title) }}
.dropdown-menu-tab(data-dropdown-tab='home')

View File

@ -46,13 +46,13 @@ include ../../../../../../pillar/src/templates/mixins/components
//- ******************************************************* -//
| {% macro render_blog_list_item(node) %}
a.card.asset.card-image-fade.pr-0.mx-0.mb-4(
a.card.asset.card-image-fade(
href="{{ node.url }}")
.embed-responsive.embed-responsive-16by9
.card-thumbnail
| {% if node.picture %}
.card-img-top.embed-responsive-item(style="background-image: url({{ node.picture.thumbnail('m', api=api) }})")
img.card-img-top(src="background-image: url({{ node.picture.thumbnail('m', api=api) }})", alt="{{ node.name }}")
| {% else %}
.card-img-top.card-icon.embed-responsive-item
.card-img-top
i.pi-document-text
| {% endif %}
@ -100,7 +100,7 @@ a.card.asset.card-image-fade.pr-0.mx-0.mb-4(
| More from {{ project.name }} blog
| {% endif %}
+card-deck(class="px-2 justify-content-center")
+card-deck(class="px-2")
| {% for node in posts %}
| {# Skip listing the current post #}
| {% if node._id != current_post._id %}

View File

@ -9,7 +9,7 @@ mixin group(title, tag)
h4.title-underline.mt-2.mb-4
a.text-muted(href="#" + tag)= title
+card-deck(data-asset-tag=tag, class="js-asset-list py-3")
+card-deck(data-asset-tag=tag, class="js-asset-list p-3")
| {% block page_title %}Production Lessons{% endblock %}
| {% set page_header_text = "Tips and tricks by the Open Projects crew." %}

View File

@ -101,24 +101,7 @@ link(href="{{ url_for('static_cloud', filename='assets/css/project-main.css') }}
data-placement="right")
a(href="{{url_for('projects.view', project_url=project.url, _external=True)}}")
i.pi-folder
| {% if not project.is_private %}
| {% if current_user_is_subscriber %}
li.tabs-search(
title="Search",
data-toggle="tooltip",
data-placement="right")
a(href="{{ url_for('projects.search', project_url=project.url, _external=True)}} ")
i.pi-search
| {% else %}
li.tabs-search(
title="Search (subscribers only)",
data-toggle="tooltip",
data-placement="right")
a(href="{{ url_for('cloud.join') }}")
i.pi-search
| {% endif %}
| {% endif %}
| {{ extension_sidebar_links }}
| {% if project.has_method('PUT') %}

View File

@ -85,17 +85,19 @@ meta(name="twitter:image", content="{{ page_header_image }}")
hr.pb-2
+card-deck(3)
+card-deck()
| {% for project in projects %}
| {% if project.url not in projects_in_production %}
| {% if (project.status == 'published') or (project.status == 'pending' and current_user.is_authenticated) and project._id != config.MAIN_PROJECT_ID %}
+card(
class='js-project-go card-fade cursor-pointer mb-4 mx-0',
class='js-project-go card-fade cursor-pointer mb-4',
style="min-width: 30%",
data-url="{{ url_for('projects.view', project_url=project.url) }}",
tabindex='{{ loop.index }}')
| {% if project.picture_header %}
a(href="{{ url_for('projects.view', project_url=project.url) }}")
a.card-thumbnail(href="{{ url_for('projects.view', project_url=project.url) }}")
img.card-img-top(
src="{{ project.picture_header.thumbnail('l', api=api) }}", alt="{{ project.name }}")
| {% endif %}