import { default as computed } from "ember-addons/ember-computed-decorators"; import { escapeExpression } from "discourse/lib/utilities"; export default Ember.Controller.extend({ sample: Ember.computed.alias("model.sample"), errors: Ember.computed.alias("model.errors"), count: Ember.computed.alias("model.grant_count"), @computed("count", "sample.length") countWarning(count, sampleLength) { if (count <= 10) { return sampleLength !== count; } else { return sampleLength !== 10; } }, @computed("model.query_plan") hasQueryPlan(queryPlan) { return !!queryPlan; }, @computed("model.query_plan") queryPlanHtml(queryPlan) { let output = `
`;

    queryPlan.forEach(linehash => {
      output += escapeExpression(linehash["QUERY PLAN"]);
      output += "
"; }); output += "
"; return output; }, 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"; i18nParams.link = ` ${Handlebars.Utils.escapeExpression(grant.title)} `; } 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); }) });