FEATURE: Uploaded images to categories are shown when browsing

This commit is contained in:
Robin Ward 2014-06-27 17:06:59 -04:00
parent e22688a204
commit 952426d358
14 changed files with 68 additions and 13 deletions

View File

@ -0,0 +1,9 @@
export default Ember.Controller.extend({
styleCategory: null,
backgroundClass: function() {
var id = this.get('styleCategory.id');
if (Em.isNone(id)) { return; }
return "category-" + this.get('styleCategory.id');
}.property('styleCategory')
});

View File

@ -5,4 +5,3 @@ export default NavigationDefaultController.extend({
return Discourse.NavItem.buildList(this.get('category'), { noSubcategories: this.get('noSubcategories') }); return Discourse.NavItem.buildList(this.get('category'), { noSubcategories: this.get('noSubcategories') });
}.property('category', 'noSubcategories') }.property('category', 'noSubcategories')
}); });

View File

@ -103,6 +103,7 @@ function buildCategoryRoute(filter, params) {
this.replaceWith('/404'); this.replaceWith('/404');
return; return;
} }
this.controllerFor('application').set('styleCategory', model);
var self = this, var self = this,
noSubcategories = params && !!params.no_subcategories, noSubcategories = params && !!params.no_subcategories,
@ -166,6 +167,7 @@ function buildCategoryRoute(filter, params) {
deactivate: function() { deactivate: function() {
this._super(); this._super();
this.controllerFor('search').set('searchContext', null); this.controllerFor('search').set('searchContext', null);
this.controllerFor('application').set('styleCategory', null);
}, },
actions: { actions: {

View File

@ -1,6 +1,6 @@
{{render "header"}} {{render "header"}}
<div id='main-outlet'> <div id='main-outlet' {{bind-attr class=backgroundClass}}>
{{outlet}} {{outlet}}
</div> </div>

View File

@ -23,4 +23,3 @@
</div> </div>
</div> </div>
</div> </div>

View File

@ -7,6 +7,11 @@
{{custom-html "extraNavItem"}} {{custom-html "extraNavItem"}}
</ul> </ul>
<section class='category-heading'>
{{#if category.logo_url}}
<img {{bind-attr src=category.logo_url}} class="category-logo">
{{/if}}
{{#if canChangeCategoryNotificationLevel}} {{#if canChangeCategoryNotificationLevel}}
{{view 'category-notifications-button' category=category}} {{view 'category-notifications-button' category=category}}
{{/if}} {{/if}}
@ -18,3 +23,4 @@
{{#if canEditCategory}} {{#if canEditCategory}}
<button class='btn btn-default' {{action editCategory category}}><i class="fa fa-wrench"></i> {{i18n category.edit_long}}</button> <button class='btn btn-default' {{action editCategory category}}><i class="fa fa-wrench"></i> {{i18n category.edit_long}}</button>
{{/if}} {{/if}}
</section>

View File

@ -18,3 +18,4 @@
@import "plugins"; @import "plugins";
@import "plugins_desktop"; @import "plugins_desktop";
@import "category_backgrounds";

View File

@ -30,6 +30,8 @@
#main-outlet { #main-outlet {
padding-top: 82px; padding-top: 82px;
background-repeat: no-repeat;
background-position: 0 0;
} }
// Dropdowns // Dropdowns

View File

@ -282,3 +282,12 @@ button.dismiss-read {
bottom: auto; bottom: auto;
left: auto; left: auto;
} }
.category-heading {
clear: both;
}
.category-logo {
max-height: 150px;
float: left;
margin-bottom: 15px;
}

View File

@ -18,3 +18,4 @@
@import "plugins"; @import "plugins";
@import "plugins_mobile"; @import "plugins_mobile";
@import "category_backgrounds";

View File

@ -68,6 +68,9 @@ class Category < ActiveRecord::Base
# we may consider wrapping this in another spot # we may consider wrapping this in another spot
attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level
def self.last_updated_at
order('updated_at desc').limit(1).pluck(:updated_at).first.to_i
end
def self.scoped_to_permissions(guardian, permission_types) def self.scoped_to_permissions(guardian, permission_types)
if guardian && guardian.is_staff? if guardian && guardian.is_staff?

View File

@ -45,6 +45,21 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
end end
def find(name, options) def find(name, options)
if name == "category_backgrounds"
contents = ""
Category.where('background_url IS NOT NULL').each do |c|
if c.background_url.present?
contents << "#main-outlet.category-#{c.id} { background-image: url(#{c.background_url}) }\n"
end
end
return Sass::Engine.new(contents, options.merge(
filename: "#{name}.scss",
importer: self,
syntax: :scss
))
end
if special_imports.has_key? name if special_imports.has_key? name
if name == "theme_variables" if name == "theme_variables"
contents = "" contents = ""

View File

@ -107,7 +107,8 @@ class DiscourseStylesheets
def digest def digest
@digest ||= begin @digest ||= begin
theme = (cs = ColorScheme.enabled) ? "#{cs.id}-#{cs.version}" : 0 theme = (cs = ColorScheme.enabled) ? "#{cs.id}-#{cs.version}" : 0
Digest::SHA1.hexdigest("#{RailsMultisite::ConnectionManagement.current_db}-#{theme}-#{DiscourseStylesheets.last_file_updated}") category_updated = Category.last_updated_at
Digest::SHA1.hexdigest("#{RailsMultisite::ConnectionManagement.current_db}-#{theme}-#{DiscourseStylesheets.last_file_updated}-#{category_updated}")
end end
end end
end end

View File

@ -20,6 +20,14 @@ describe Category do
it { should have_many :featured_topics } it { should have_many :featured_topics }
it { should belong_to :parent_category} it { should belong_to :parent_category}
describe "last_updated_at" do
it "returns a number value of when the category was last updated" do
last = Category.last_updated_at
last.should be_present
last.to_i.should == last
end
end
describe "resolve_permissions" do describe "resolve_permissions" do
it "can determine read_restricted" do it "can determine read_restricted" do
read_restricted, resolved = Category.resolve_permissions(:everyone => :full) read_restricted, resolved = Category.resolve_permissions(:everyone => :full)