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'),
site: container.lookup('site:main'),
session: container.lookup('session:main'),
topicTrackingState: container.lookup('topic-tracking-state:main')
};
}
if (!_injections) {
_injections = {
siteSettings: container.lookup('site-settings: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,17 +1,17 @@
{{#unless skipHeader}}
<thead>
{{raw "topic-list-header" currentUser=currentUser
canBulkSelect=canBulkSelect
toggleInTitle=toggleInTitle
hideCategory=hideCategory
showPosters=showPosters
showLikes=showLikes
showOpLikes=showOpLikes
showParticipants=showParticipants
order=order
ascending=ascending
sortable=sortable
bulkSelectEnabled=bulkSelectEnabled}}
{{raw "topic-list-header"
canBulkSelect=canBulkSelect
toggleInTitle=toggleInTitle
hideCategory=hideCategory
showPosters=showPosters
showLikes=showLikes
showOpLikes=showOpLikes
showParticipants=showParticipants
order=order
ascending=ascending
sortable=sortable
bulkSelectEnabled=bulkSelectEnabled}}
</thead>
{{/unless}}
<tbody>

View File

@ -32,24 +32,23 @@
{{/if}}
{{#if hasTopics}}
{{topic-list
highlightLastVisited=true
top=top
showTopicPostBadges=showTopicPostBadges
showPosters=true
currentUser=currentUser
canBulkSelect=canBulkSelect
changeSort="changeSort"
toggleBulkSelect="toggleBulkSelect"
hideCategory=model.hideCategory
order=order
ascending=ascending
bulkSelectEnabled=bulkSelectEnabled
selected=selected
expandGloballyPinned=expandGloballyPinned
expandAllPinned=expandAllPinned
category=category
topics=model.topics}}
{{topic-list
highlightLastVisited=true
top=top
showTopicPostBadges=showTopicPostBadges
showPosters=true
canBulkSelect=canBulkSelect
changeSort="changeSort"
toggleBulkSelect="toggleBulkSelect"
hideCategory=model.hideCategory
order=order
ascending=ascending
bulkSelectEnabled=bulkSelectEnabled
selected=selected
expandGloballyPinned=expandGloballyPinned
expandAllPinned=expandAllPinned
category=category
topics=model.topics}}
{{/if}}
{{/discovery-topics-list}}

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"}}