FEATURE: show header search results on search log term details page

This commit is contained in:
Arpit Jalan 2018-01-16 15:59:22 +05:30
parent 3c0296c625
commit 79eb9d7086
9 changed files with 70 additions and 2 deletions
app
assets
javascripts/admin
stylesheets/common/admin
controllers/admin
config/locales
lib
spec
components
requests/admin
test/javascripts/acceptance

@ -1,5 +1,6 @@
import { ajax } from 'discourse/lib/ajax';
import { fillMissingDates } from 'discourse/lib/utilities';
import { translateResults } from "discourse/lib/search";
export default Discourse.Route.extend({
queryParams: {
@ -22,6 +23,9 @@ export default Discourse.Route.extend({
const endDate = moment(json.term.end_date).format('YYYY-MM-DD');
json.term.data = fillMissingDates(json.term.data, startDate, endDate);
}
if (json.term.search_result) {
json.term.search_result = translateResults(json.term.search_result)
}
const model = Ember.Object.create({ type: "search_log_term" });
model.setProperties(json.term);

@ -10,4 +10,53 @@
{{#conditional-loading-spinner condition=refreshing}}
{{admin-graph model=model}}
<br><br>
<h2> {{i18n "admin.logs.search_logs.header_search_results"}} </h2>
<br>
<div class='header-search-results'>
{{#each model.search_result.posts as |result|}}
<div class='fps-result'>
<div class='author'>
<a href={{result.userPath}} data-user-card="{{unbound result.username}}">
{{avatar result imageSize="large"}}
</a>
</div>
<div class='fps-topic'>
<div class='topic'>
<a class='search-link' href='{{unbound result.url}}'>
{{topic-status topic=result.topic disableActions=true}}<span class='topic-title'>{{#highlight-text highlight=term}}{{{unbound result.topic.fancyTitle}}}{{/highlight-text}}</span>
</a>
<div class='search-category'>
{{#if result.topic.category.parentCategory}}
{{category-link result.topic.category.parentCategory}}
{{/if}}
{{category-link result.topic.category hideParent=true}}
{{#each result.topic.tags as |tag|}}
{{discourse-tag tag}}
{{/each}}
</div>
</div>
<div class='blurb container'>
<span class='date'>
{{format-age result.created_at}}
{{#if result.blurb}}
-
{{/if}}
</span>
{{#if result.blurb}}
{{#highlight-text highlight=term}}
{{{unbound result.blurb}}}
{{/highlight-text}}
{{/if}}
</div>
</div>
</div>
{{/each}}
</div>
{{/conditional-loading-spinner}}

@ -237,6 +237,10 @@ $mobile-breakpoint: 700px;
width: 200px;
float: right;
}
.header-search-results {
clear: both;
padding: 4px;
}
}
.admin-container .controls {
@ -368,7 +372,7 @@ $mobile-breakpoint: 700px;
}
.d-editor-textarea-wrapper {
max-width: 60%;
max-width: 60%;
.d-editor-button-bar {
overflow: hidden;
}

@ -16,6 +16,8 @@ class Admin::SearchLogsController < Admin::AdminController
details = SearchLog.term_details(term, period&.to_sym, search_type&.to_sym)
raise Discourse::NotFound if details.blank?
result = Search.execute(params[:term], { guardian: guardian })
details[:search_result] = serialize_data(result, GroupedSearchResultSerializer, result: result)
render_json_dump(term: details)
end

@ -3258,6 +3258,7 @@ en:
header: "Header"
full_page: "Full Page"
click_through_only: "All (click through only)"
header_search_results: "Header Search Results"
logster:
title: "Error Logs"

@ -180,7 +180,7 @@ class Search
# Query a term
def execute
if SiteSetting.log_search_queries?
if SiteSetting.log_search_queries? && @opts[:search_type].present?
status, search_log_id = SearchLog.log(
term: @term,
search_type: @opts[:search_type],

@ -915,6 +915,12 @@ describe Search do
results = s.execute
expect(results.search_log_id).to be_present
end
it "does not log search if search_type is not present" do
s = Search.new('foo bar',ip_address: '127.0.0.1')
results = s.execute
expect(results.search_log_id).not_to be_present
end
end
context 'pagination' do

@ -52,6 +52,7 @@ RSpec.describe Admin::SearchLogsController do
json = ::JSON.parse(response.body)
expect(json['term']['type']).to eq('search_log_term')
expect(json['term']['search_result']).to be_present
end
end
end

@ -6,5 +6,6 @@ QUnit.test("show search log term details", assert => {
andThen(() => {
assert.ok($('div.search-logs-filter').length, "has the search type filter");
assert.ok(exists('canvas.chartjs-render-monitor'), "has graph canvas");
assert.ok(exists('div.header-search-results'), "has header search results");
});
});