2018-06-15 23:03:24 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { fillMissingDates } from "discourse/lib/utilities";
|
2018-01-16 18:29:22 +08:00
|
|
|
import { translateResults } from "discourse/lib/search";
|
2017-12-20 10:41:31 +08:00
|
|
|
|
|
|
|
export default Discourse.Route.extend({
|
|
|
|
queryParams: {
|
|
|
|
period: { refreshModel: true },
|
|
|
|
searchType: { refreshModel: true }
|
|
|
|
},
|
|
|
|
|
|
|
|
model(params) {
|
|
|
|
this._params = params;
|
|
|
|
|
|
|
|
return ajax(`/admin/logs/search_logs/term/${params.term}.json`, {
|
|
|
|
data: {
|
|
|
|
period: params.period,
|
|
|
|
search_type: params.searchType
|
|
|
|
}
|
|
|
|
}).then(json => {
|
2018-01-13 10:43:49 +08:00
|
|
|
// Add zero values for missing dates
|
|
|
|
if (json.term.data.length > 0) {
|
2018-06-15 23:03:24 +08: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-13 10:43:49 +08:00
|
|
|
json.term.data = fillMissingDates(json.term.data, startDate, endDate);
|
|
|
|
}
|
2018-01-16 18:29:22 +08:00
|
|
|
if (json.term.search_result) {
|
2018-01-17 15:19:52 +08:00
|
|
|
json.term.search_result = translateResults(json.term.search_result);
|
2018-01-16 18:29:22 +08:00
|
|
|
}
|
2018-01-13 10:43:49 +08:00
|
|
|
|
2017-12-20 10:41:31 +08: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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|