discourse/app/assets/javascripts/discourse/helpers/period-title.js.es6

74 lines
1.9 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import { htmlHelper } from "discourse-common/lib/helpers";
const TITLE_SUBS = {
2018-06-15 23:03:24 +08:00
all: "all_time",
yearly: "this_year",
quarterly: "this_quarter",
monthly: "this_month",
daily: "today"
};
export default htmlHelper((period, options) => {
2018-06-15 23:03:24 +08:00
const title = I18n.t("filters.top." + (TITLE_SUBS[period] || "this_week"));
if (options.hash.showDateRange) {
var dateString = "";
let finish;
if (options.hash.fullDay) {
2018-06-15 23:03:24 +08:00
finish = moment()
.utc()
.subtract(1, "days");
} else {
finish = moment();
}
2018-06-15 23:03:24 +08:00
switch (period) {
case "yearly":
dateString =
finish
.clone()
.subtract(1, "year")
.format(I18n.t("dates.long_with_year_no_time")) +
" - " +
finish.format(I18n.t("dates.long_with_year_no_time"));
break;
2018-06-15 23:03:24 +08:00
case "quarterly":
dateString =
finish
.clone()
.subtract(3, "month")
.format(I18n.t("dates.long_no_year_no_time")) +
" - " +
finish.format(I18n.t("dates.long_no_year_no_time"));
break;
2018-06-15 23:03:24 +08:00
case "weekly":
dateString =
finish
.clone()
.subtract(1, "week")
.format(I18n.t("dates.long_no_year_no_time")) +
" - " +
finish.format(I18n.t("dates.long_no_year_no_time"));
break;
2018-06-15 23:03:24 +08:00
case "monthly":
dateString =
finish
.clone()
.subtract(1, "month")
.format(I18n.t("dates.long_no_year_no_time")) +
" - " +
finish.format(I18n.t("dates.long_no_year_no_time"));
break;
2018-06-15 23:03:24 +08:00
case "daily":
dateString = finish
.clone()
.format(I18n.t("dates.full_no_year_no_time"));
break;
}
return `<span class="date-section">${title}</span><span class='top-date-string'>${dateString}</span>`;
} else {
return title;
}
});