FEATURE: advanced search help

This commit is contained in:
Sam 2014-10-18 14:27:33 +11:00
parent 6e0b5f7231
commit 742c5e29c9
12 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,7 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import DiscourseController from 'discourse/controllers/controller';
export default DiscourseController.extend(ModalFunctionality, {
needs: ['modal']
});

View File

@ -59,6 +59,12 @@ export default function searchForTerm(term, opts) {
} }
}); });
// a bit awkward, but we need to get the help link in
// somehow
if(results.resultTypes && results.resultTypes[0]) {
results.resultTypes[0].showHelp = true;
}
var noResults = !!(results.topics.length === 0 && var noResults = !!(results.topics.length === 0 &&
results.posts.length === 0 && results.posts.length === 0 &&
results.users.length === 0 && results.users.length === 0 &&

View File

@ -90,6 +90,16 @@ var ApplicationRoute = Discourse.Route.extend({
Discourse.Route.showModal(this, 'keyboardShortcutsHelp'); Discourse.Route.showModal(this, 'keyboardShortcutsHelp');
}, },
showSearchHelp: function() {
var self = this;
// TODO: @EvitTrout how do we get a loading indicator here?
Discourse.ajax("/static/search_help.html", { dataType: 'html' }).then(function(html){
Discourse.Route.showModal(self, 'searchHelp', html);
});
},
/** /**
Close the current modal, and destroy its state. Close the current modal, and destroy its state.

View File

@ -0,0 +1,3 @@
<div id="search-help" class="modal-body">
{{{model}}}
</div>

View File

@ -22,6 +22,9 @@
<a href='#' class='filter' {{action "moreOfType" resultType.type bubbles=false}}>{{i18n show_more}} <i class="fa fa-chevron-down"></i></a> <a href='#' class='filter' {{action "moreOfType" resultType.type bubbles=false}}>{{i18n show_more}} <i class="fa fa-chevron-down"></i></a>
{{else}} {{else}}
{{/if}} {{/if}}
{{#if resultType.showHelp}}
<a href="#" class="show-help" {{action "showSearchHelp" bubbles=false}}>{{i18n show_help}}</a>
{{/if}}
</div> </div>
{{/each}} {{/each}}
{{else}} {{else}}

View File

@ -0,0 +1,4 @@
export default Discourse.ModalBodyView.extend({
templateName: 'modal/search_help',
title: I18n.t('search_help.title')
});

View File

@ -71,3 +71,14 @@ and (max-width : 570px) {
.d-dropdown .searching { .d-dropdown .searching {
right: 30px; right: 30px;
} }
// leave room for scroll bar
.d-dropdown input[type='text'] {
width: 505px;
}
.d-dropdown .no-results .show-help {
position: absolute;
right: 15px;
}

View File

@ -74,3 +74,8 @@
.search-link .topic-statuses .topic-status i { .search-link .topic-statuses .topic-status i {
font-size: 14px; font-size: 14px;
} }
.d-dropdown .no-results .show-help {
display: none;
}

View File

@ -35,6 +35,11 @@ class StaticController < ApplicationController
return return
end end
if I18n.exists?("static.#{@page}")
render text: PrettyText.cook(I18n.t("static.#{@page}")), layout: !request.xhr?, formats: [:html]
return
end
file = "static/#{@page}.#{I18n.locale}" file = "static/#{@page}.#{I18n.locale}"
file = "static/#{@page}.en" if lookup_context.find_all("#{file}.html").empty? file = "static/#{@page}.en" if lookup_context.find_all("#{file}.html").empty?
file = "static/#{@page}" if lookup_context.find_all("#{file}.html").empty? file = "static/#{@page}" if lookup_context.find_all("#{file}.html").empty?

View File

@ -117,6 +117,7 @@ en:
admin_title: "Admin" admin_title: "Admin"
flags_title: "Flags" flags_title: "Flags"
show_more: "show more" show_more: "show more"
show_help: "help"
links: "Links" links: "Links"
links_lowercase: "links" links_lowercase: "links"
faq: "FAQ" faq: "FAQ"
@ -2140,6 +2141,9 @@ en:
lightbox: lightbox:
download: "download" download: "download"
search_help:
title: 'Search Help'
keyboard_shortcuts_help: keyboard_shortcuts_help:
title: 'Keyboard Shortcuts' title: 'Keyboard Shortcuts'
jump_to: jump_to:

View File

@ -2120,3 +2120,14 @@ en:
If we decide to change our privacy policy, we will post those changes on this page. If we decide to change our privacy policy, we will post those changes on this page.
This document is CC-BY-SA. It was last updated May 31, 2013. This document is CC-BY-SA. It was last updated May 31, 2013.
static:
search_help: |
You may include special search operators in your terms, available operators are:
`order:latest` Results will be ordered by last post time (as opposed to relevence)
`status:open` Only show open topics
`status:closed` Only show closed topics
`category:foo` Only show topics in the category `foo`
Example: `bears category:test status:open order:latest` will search for topics in the category bears that are not closed or archived ordered by last post date.

View File

@ -2,7 +2,7 @@
# Sprockets::SassImporter implementation provided in sass-rails since that is used # Sprockets::SassImporter implementation provided in sass-rails since that is used
# during asset precompilation. # during asset precompilation.
class DiscourseSassImporter < Sass::Importers::Filesystem class DiscourseSassImporter < Sass::Importers::Filesystem
GLOB = /\*|\[.+\]/ GLOB = /\*|\[.+\]/ unless defined? GLOB
# Depending upon where this is passed we might either be passed a string as the # Depending upon where this is passed we might either be passed a string as the
# first argument or a sprockets context. If the first argument is a sprockets # first argument or a sprockets context. If the first argument is a sprockets