2018-06-15 11:03:24 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { fillMissingDates } from "discourse/lib/utilities";
|
2018-01-16 05:29:22 -05:00
|
|
|
import { translateResults } from "discourse/lib/search";
|
2017-12-19 21:41:31 -05:00
|
|
|
|
|
|
|
export default Discourse.Route.extend({
|
|
|
|
queryParams: {
|
2019-03-28 22:39:44 -04:00
|
|
|
term: { refreshModel: true },
|
2017-12-19 21:41:31 -05:00
|
|
|
period: { refreshModel: true },
|
|
|
|
searchType: { refreshModel: true }
|
|
|
|
},
|
|
|
|
|
|
|
|
model(params) {
|
|
|
|
this._params = params;
|
|
|
|
|
2019-03-28 21:48:20 -04:00
|
|
|
return ajax(`/admin/logs/search_logs/term.json`, {
|
2017-12-19 21:41:31 -05:00
|
|
|
data: {
|
|
|
|
period: params.period,
|
2019-03-28 21:48:20 -04:00
|
|
|
search_type: params.searchType,
|
|
|
|
term: params.term
|
2017-12-19 21:41:31 -05:00
|
|
|
}
|
|
|
|
}).then(json => {
|
2018-01-12 21:43:49 -05:00
|
|
|
// Add zero values for missing dates
|
|
|
|
if (json.term.data.length > 0) {
|
2018-06-15 11:03:24 -04:00
|
|
|
const startDate =
|
|
|
|
json.term.period === "all"
|
|
|
|
? moment(json.term.data[0].x).format("YYYY-MM-DD")
|
|
|
|
: moment(json.term.start_date).format("YYYY-MM-DD");
|
|
|
|
const endDate = moment(json.term.end_date).format("YYYY-MM-DD");
|
2018-01-12 21:43:49 -05:00
|
|
|
json.term.data = fillMissingDates(json.term.data, startDate, endDate);
|
|
|
|
}
|
2018-01-16 05:29:22 -05:00
|
|
|
if (json.term.search_result) {
|
2018-01-17 02:19:52 -05:00
|
|
|
json.term.search_result = translateResults(json.term.search_result);
|
2018-01-16 05:29:22 -05:00
|
|
|
}
|
2018-01-12 21:43:49 -05:00
|
|
|
|
2017-12-19 21:41:31 -05:00
|
|
|
const model = Ember.Object.create({ type: "search_log_term" });
|
|
|
|
model.setProperties(json.term);
|
|
|
|
return model;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
const params = this._params;
|
|
|
|
controller.setProperties({
|
|
|
|
model,
|
|
|
|
term: params.term,
|
|
|
|
period: params.period,
|
|
|
|
searchType: params.searchType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|