Skip to content

Commit

Permalink
Let user set default thumbnail universally or per category
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Aug 2, 2016
1 parent cf23fcc commit 74f19f3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@
{{i18n 'category.list_category_badge_move'}}
</label>
</section>

<section class='field'>
<label>{{i18n 'category.list_default_thumbnail'}}</label>
{{text-field value=category.custom_fields.list_default_thumbnail placeholderKey="category.list_default_thumbnail_placeholder"}}
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#if context.showThumbnail}}
<div class="topic-thumbnail">
<a href='{{context.topic.url}}'>
{{preview-unbound context.topic.thumbnails}}
{{preview-unbound context.thumbnails}}
</a>
</div>
{{/if}}
Expand Down
15 changes: 13 additions & 2 deletions assets/javascripts/discourse/initializers/preview-edits.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,19 @@ export default {

@computed()
showThumbnail() {
return this.get('topic.thumbnails') && (Discourse.SiteSettings.topic_list_thumbnails ||
(this.get('category') && this.get('category.list_thumbnails')))
return this.get('thumbnails') && (Discourse.SiteSettings.topic_list_thumbnails ||
(this.get('category') && this.get('category.list_thumbnails')))
},

@computed()
defaultThumbnail(){
let defaultThumbnail = this.get('category.list_default_thumbnail') || Discourse.SiteSettings.topic_list_default_thumbnail
return defaultThumbnail ? defaultThumbnail : false
},

@computed()
thumbnails(){
return this.get('topic.thumbnails') || this.get('defaultThumbnail')
},

@computed()
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/lib/render-preview.js.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var renderUnboundPreview = function(thumbnails) {
var previewUrl = window.devicePixelRatio >= 2 ? thumbnails.retina : thumbnails.normal
let previewUrl = thumbnails.retina ? (window.devicePixelRatio >= 2 ? thumbnails.retina : thumbnails.normal) : thumbnails
return '<img class="thumbnail" src="' + previewUrl + '" onError="this.onerror=null;this.src=\'\';this.className=\'no-thumbnail\';" />';
};

Expand Down
2 changes: 2 additions & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ en:
list_excerpts: "Show topic excerpts in topic list items from this category."
list_actions: "Show like and bookmark buttons in topic list items from this category."
list_category_badge_move: "Show category badge under title in topic list from this category."
list_default_thumbnail: "Image URL for thumbnail shown if topic in this category has no preview thumbnail set."
list_default_thumbnail_placeholder: "Default thumbnail URL"
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ en:
topic_list_category_badge_move: "Show the category badge under the title of all topic list items."
topic_list_show_like_on_current_users_posts: "Show an inactive like button in topic list items previewing a post created by the current user (non-default Discourse behavior)."
topic_list_excerpt_length: "Character length of topic excerpts."
topic_list_default_thumbnail: "Image URL for thumbnail shown if topic has no preview thumbnail set."
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ plugins:
topic_list_excerpt_length:
default: 200
client: true
topic_list_default_thumbnail:
default: ''
client: true
1 change: 1 addition & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,5 @@ def topic_post_can_unlike
add_to_serializer(:basic_category, :list_thumbnails) {object.custom_fields["list_thumbnails"]}
add_to_serializer(:basic_category, :list_actions) {object.custom_fields["list_actions"]}
add_to_serializer(:basic_category, :list_category_badge_move) {object.custom_fields["list_category_badge_move"]}
add_to_serializer(:basic_category, :list_default_thumbnail) {object.custom_fields["list_default_thumbnail"]}
end

0 comments on commit 74f19f3

Please sign in to comment.