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

57 lines
1.5 KiB
Plaintext
Raw Normal View History

2019-02-19 16:30:52 +08:00
import { default as computed } from "ember-addons/ember-computed-decorators";
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"),
2019-02-19 16:30:52 +08:00
@computed("count", "sample.length")
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
},
2019-02-19 16:30:52 +08:00
@computed("model.query_plan")
hasQueryPlan(queryPlan) {
return !!queryPlan;
},
2019-02-19 16:30:52 +08:00
@computed("model.query_plan")
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;
},
2019-02-19 16:30:52 +08:00
processedSample: Ember.computed.map("model.sample", grant => {
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">
${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);
})
});