Allow `currentUser` to be passed into raw templates automatically

This commit is contained in:
Robin Ward 2017-10-11 12:08:08 -04:00
parent ba5635f3fc
commit 8a8d3a3a7e
6 changed files with 44 additions and 43 deletions

View File

@ -69,7 +69,7 @@ export default Ember.Component.extend({
return;
}
let user = Discourse.User.current();
let user = this.currentUser;
if (!user || !user.previous_visit_at) {
return;
}

View File

@ -7,17 +7,17 @@ function renderRaw(ctx, container, template, templateName, params) {
params = jQuery.extend({}, params);
params.parent = params.parent || ctx;
if (!params.view) {
if (!_injections) {
_injections = {
siteSettings: container.lookup('site-settings:main'),
currentUser: container.lookup('currentUser:main'),
currentUser: container.lookup('current-user:main'),
site: container.lookup('site:main'),
session: container.lookup('session:main'),
topicTrackingState: container.lookup('topic-tracking-state:main')
};
}
if (!params.view) {
const module = `discourse/raw-views/${templateName}`;
if (requirejs.entries[module]) {
const viewClass = requirejs(module, null, null, true);
@ -25,6 +25,10 @@ function renderRaw(ctx, container, template, templateName, params) {
params.view = viewClass.default.create(params, _injections);
}
}
if (!params.view) {
params = jQuery.extend({}, params, _injections);
}
}
return new Handlebars.SafeString(template(params));

View File

@ -1,6 +1,6 @@
{{#unless skipHeader}}
<thead>
{{raw "topic-list-header" currentUser=currentUser
{{raw "topic-list-header"
canBulkSelect=canBulkSelect
toggleInTitle=toggleInTitle
hideCategory=hideCategory

View File

@ -37,7 +37,6 @@
top=top
showTopicPostBadges=showTopicPostBadges
showPosters=true
currentUser=currentUser
canBulkSelect=canBulkSelect
changeSort="changeSort"
toggleBulkSelect="toggleBulkSelect"

View File

@ -16,7 +16,6 @@
{{topic-list
highlightLastVisited=true
showPosters=true
currentUser=currentUser
hideCategory=model.hideCategory
order=order
ascending=ascending

View File

@ -55,7 +55,6 @@
bulkSelectEnabled=bulkSelectEnabled
selected=selected
showPosters=true
currentUser=currentUser
order=order
ascending=ascending
changeSort="changeSort"}}