discourse/app/assets/javascripts/admin/controllers/modals/admin-badge-preview.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.6 KiB
JavaScript
Raw Normal View History

import I18n from "I18n";
import { alias, map } from "@ember/object/computed";
import Controller from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import { escapeExpression } from "discourse/lib/utilities";
export default Controller.extend({
sample: alias("model.sample"),
errors: alias("model.errors"),
count: alias("model.grant_count"),
@discourseComputed("count", "sample.length")
2019-02-19 16:30:52 +08:00
countWarning(count, sampleLength) {
if (count <= 10) {
return sampleLength !== count;
} else {
2019-02-19 16:30:52 +08:00
return sampleLength !== 10;
}
2019-02-19 16:30:52 +08:00
},
@discourseComputed("model.query_plan")
2019-02-19 16:30:52 +08:00
hasQueryPlan(queryPlan) {
return !!queryPlan;
},
@discourseComputed("model.query_plan")
2019-02-19 16:30:52 +08:00
queryPlanHtml(queryPlan) {
let output = `<pre class="badge-query-plan">`;
2019-02-19 16:30:52 +08:00
queryPlan.forEach(linehash => {
output += escapeExpression(linehash["QUERY PLAN"]);
output += "<br>";
});
2019-02-19 16:30:52 +08:00
output += "</pre>";
return output;
},
processedSample: map("model.sample", grant => {
2019-02-19 16:30:52 +08:00
let i18nKey = "admin.badges.preview.grant.with";
const i18nParams = { username: escapeExpression(grant.username) };
if (grant.post_id) {
i18nKey += "_post";
2019-02-19 16:30:52 +08:00
i18nParams.link = `<a href="/p/${grant.post_id}" data-auto-route="true">
${escapeExpression(grant.title)}
2019-02-19 16:30:52 +08:00
</a>`;
}
if (grant.granted_at) {
i18nKey += "_time";
i18nParams.time = escapeExpression(
moment(grant.granted_at).format(I18n.t("dates.long_with_year"))
);
}
return I18n.t(i18nKey, i18nParams);
})
});