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

57 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import { escapeExpression } from "discourse/lib/utilities";
export default Ember.Controller.extend({
2018-06-15 23:03:24 +08:00
sample: Ember.computed.alias("model.sample"),
errors: Ember.computed.alias("model.errors"),
count: Ember.computed.alias("model.grant_count"),
count_warning: function() {
2018-06-15 23:03:24 +08:00
if (this.get("count") <= 10) {
return this.get("sample.length") !== this.get("count");
} else {
2018-06-15 23:03:24 +08:00
return this.get("sample.length") !== 10;
}
2018-06-15 23:03:24 +08:00
}.property("count", "sample.length"),
has_query_plan: function() {
2018-06-15 23:03:24 +08:00
return !!this.get("model.query_plan");
}.property("model.query_plan"),
query_plan_html: function() {
2018-06-15 23:03:24 +08:00
var raw = this.get("model.query_plan"),
returned = "<pre class='badge-query-plan'>";
_.each(raw, function(linehash) {
returned += escapeExpression(linehash["QUERY PLAN"]);
returned += "<br>";
});
returned += "</pre>";
return returned;
2018-06-15 23:03:24 +08:00
}.property("model.query_plan"),
2018-06-15 23:03:24 +08:00
processed_sample: Ember.computed.map("model.sample", function(grant) {
var i18nKey = "admin.badges.preview.grant.with",
i18nParams = { username: escapeExpression(grant.username) };
if (grant.post_id) {
i18nKey += "_post";
2018-06-15 23:03:24 +08:00
i18nParams.link =
"<a href='/p/" +
grant.post_id +
"' data-auto-route='true'>" +
Handlebars.Utils.escapeExpression(grant.title) +
"</a>";
}
if (grant.granted_at) {
i18nKey += "_time";
2018-06-15 23:03:24 +08:00
i18nParams.time = escapeExpression(
moment(grant.granted_at).format(I18n.t("dates.long_with_year"))
);
}
return I18n.t(i18nKey, i18nParams);
})
});