FIX: ensures backward compat with previous findRawTemplate (#48)

To my knowledge we don't implement `requirejs.defined` so I rely on the __DISCOURSE_RAW_TEMPLATES constant which has been introduced in the commit where we moved from discourse/lib/raw-template to discourse-common/lib/raw-templates.
This commit is contained in:
Joffrey JAFFEUX 2020-05-06 15:20:37 +02:00 committed by GitHub
parent 676dc40031
commit 9297885629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -1,6 +1,5 @@
import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge";
import { getOwner } from "discourse-common/lib/get-owner";
import { default as computed } from "discourse-common/utils/decorators";
function randomIdShort() {
@ -32,6 +31,22 @@ const QueryResultComponent = Ember.Component.extend({
explainText: Ember.computed.alias("content.explain"),
hasExplain: Ember.computed.notEmpty("content.explain"),
init() {
this._super(...arguments);
// TODO: After `__DISCOURSE_RAW_TEMPLATES` is in stable this should be updated
// to use only `import { findRawTemplate } from "discourse-common/lib/raw-templates"`
if (window.__DISCOURSE_RAW_TEMPLATES) {
this.findRawTemplate = requirejs(
"discourse-common/lib/raw-templates"
).findRawTemplate;
} else {
this.findRawTemplate = requirejs(
"discourse/lib/raw-templates"
).findRawTemplate;
}
},
@computed("content.result_count")
resultCount(count) {
if (count === this.get("content.default_limit")) {
@ -80,7 +95,7 @@ const QueryResultComponent = Ember.Component.extend({
@computed
fallbackTemplate() {
return getOwner(this).lookup("template:explorer/text.raw");
return this.findRawTemplate("javascripts/explorer/text");
},
@computed("content", "columns.[]")
@ -94,11 +109,7 @@ const QueryResultComponent = Ember.Component.extend({
viewName = this.get("content.colrender")[idx];
}
// After `findRawTemplates` is in stable this should be updated to use that
let template = getOwner(this).lookup(`template:explorer/${viewName}.raw`);
if (!template) {
template = Discourse.RAW_TEMPLATES[`javascripts/explorer/${viewName}`];
}
const template = this.findRawTemplate(`javascripts/explorer/${viewName}`);
return { name: viewName, template };
});