2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2017-12-20 10:41:31 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2018-01-16 18:29:22 +08:00
|
|
|
import { translateResults } from "discourse/lib/search";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { fillMissingDates } from "discourse/lib/utilities";
|
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2017-12-20 10:41:31 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
export default class AdminSearchLogsTermRoute extends DiscourseRoute {
|
|
|
|
queryParams = {
|
2019-03-29 10:39:44 +08:00
|
|
|
term: { refreshModel: true },
|
2017-12-20 10:41:31 +08:00
|
|
|
period: { refreshModel: true },
|
|
|
|
searchType: { refreshModel: true },
|
2023-03-15 21:17:51 +08:00
|
|
|
};
|
2017-12-20 10:41:31 +08:00
|
|
|
|
2024-07-06 04:25:42 +08:00
|
|
|
async model(params) {
|
2017-12-20 10:41:31 +08:00
|
|
|
this._params = params;
|
|
|
|
|
2024-07-06 04:25:42 +08:00
|
|
|
const json = await ajax(`/admin/logs/search_logs/term.json`, {
|
2017-12-20 10:41:31 +08:00
|
|
|
data: {
|
|
|
|
period: params.period,
|
2019-03-29 09:48:20 +08:00
|
|
|
search_type: params.searchType,
|
|
|
|
term: params.term,
|
2017-12-20 10:41:31 +08:00
|
|
|
},
|
|
|
|
});
|
2024-07-06 04:25:42 +08:00
|
|
|
|
|
|
|
// Add zero values for missing dates
|
|
|
|
if (json.term.data.length > 0) {
|
|
|
|
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");
|
|
|
|
json.term.data = fillMissingDates(json.term.data, startDate, endDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (json.term.search_result) {
|
|
|
|
json.term.search_result = await translateResults(json.term.search_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
const model = EmberObject.create({ type: "search_log_term" });
|
|
|
|
model.setProperties(json.term);
|
|
|
|
|
|
|
|
return model;
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-12-20 10:41:31 +08:00
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
const params = this._params;
|
|
|
|
controller.setProperties({
|
|
|
|
model,
|
|
|
|
term: params.term,
|
|
|
|
period: params.period,
|
|
|
|
searchType: params.searchType,
|
|
|
|
});
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
|
|
|
}
|