From 952426d358d0eeaa9ea8aa3569640c9003d0c1b9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 27 Jun 2014 17:06:59 -0400 Subject: [PATCH] FEATURE: Uploaded images to categories are shown when browsing --- .../discourse/controllers/application.js.es6 | 9 +++++++ .../controllers/navigation/category.js.es6 | 1 - .../routes/discovery_route_builders.js | 2 ++ .../templates/application.js.handlebars | 2 +- .../templates/discovery.js.handlebars | 1 - .../navigation/category.js.handlebars | 24 ++++++++++++------- app/assets/stylesheets/desktop.scss | 1 + app/assets/stylesheets/desktop/header.scss | 2 ++ .../stylesheets/desktop/topic-list.scss | 9 +++++++ app/assets/stylesheets/mobile.scss | 1 + app/models/category.rb | 3 +++ lib/sass/discourse_sass_importer.rb | 15 ++++++++++++ lib/sass/discourse_stylesheets.rb | 3 ++- spec/models/category_spec.rb | 8 +++++++ 14 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 app/assets/javascripts/discourse/controllers/application.js.es6 diff --git a/app/assets/javascripts/discourse/controllers/application.js.es6 b/app/assets/javascripts/discourse/controllers/application.js.es6 new file mode 100644 index 00000000000..0d1ccdad0c5 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/application.js.es6 @@ -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') +}); diff --git a/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 index 29596b84dc0..3f9289cd0f8 100644 --- a/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 +++ b/app/assets/javascripts/discourse/controllers/navigation/category.js.es6 @@ -5,4 +5,3 @@ export default NavigationDefaultController.extend({ return Discourse.NavItem.buildList(this.get('category'), { noSubcategories: this.get('noSubcategories') }); }.property('category', 'noSubcategories') }); - diff --git a/app/assets/javascripts/discourse/routes/discovery_route_builders.js b/app/assets/javascripts/discourse/routes/discovery_route_builders.js index 8e03658debe..c5fc8ebe754 100644 --- a/app/assets/javascripts/discourse/routes/discovery_route_builders.js +++ b/app/assets/javascripts/discourse/routes/discovery_route_builders.js @@ -103,6 +103,7 @@ function buildCategoryRoute(filter, params) { this.replaceWith('/404'); return; } + this.controllerFor('application').set('styleCategory', model); var self = this, noSubcategories = params && !!params.no_subcategories, @@ -166,6 +167,7 @@ function buildCategoryRoute(filter, params) { deactivate: function() { this._super(); this.controllerFor('search').set('searchContext', null); + this.controllerFor('application').set('styleCategory', null); }, actions: { diff --git a/app/assets/javascripts/discourse/templates/application.js.handlebars b/app/assets/javascripts/discourse/templates/application.js.handlebars index 8319dc7b42c..4a624f7071e 100644 --- a/app/assets/javascripts/discourse/templates/application.js.handlebars +++ b/app/assets/javascripts/discourse/templates/application.js.handlebars @@ -1,6 +1,6 @@ {{render "header"}} -
+
{{outlet}}
diff --git a/app/assets/javascripts/discourse/templates/discovery.js.handlebars b/app/assets/javascripts/discourse/templates/discovery.js.handlebars index 047b977a513..14b79688c8a 100644 --- a/app/assets/javascripts/discourse/templates/discovery.js.handlebars +++ b/app/assets/javascripts/discourse/templates/discovery.js.handlebars @@ -23,4 +23,3 @@
- diff --git a/app/assets/javascripts/discourse/templates/navigation/category.js.handlebars b/app/assets/javascripts/discourse/templates/navigation/category.js.handlebars index 74d4e7eb3c9..7a257de142f 100644 --- a/app/assets/javascripts/discourse/templates/navigation/category.js.handlebars +++ b/app/assets/javascripts/discourse/templates/navigation/category.js.handlebars @@ -7,14 +7,20 @@ {{custom-html "extraNavItem"}} -{{#if canChangeCategoryNotificationLevel}} - {{view 'category-notifications-button' category=category}} -{{/if}} +
+ {{#if category.logo_url}} + + {{/if}} -{{#if canCreateTopic}} - -{{/if}} + {{#if canChangeCategoryNotificationLevel}} + {{view 'category-notifications-button' category=category}} + {{/if}} -{{#if canEditCategory}} - -{{/if}} + {{#if canCreateTopic}} + + {{/if}} + + {{#if canEditCategory}} + + {{/if}} +
diff --git a/app/assets/stylesheets/desktop.scss b/app/assets/stylesheets/desktop.scss index 05eefb4bcc3..238ac9ed908 100644 --- a/app/assets/stylesheets/desktop.scss +++ b/app/assets/stylesheets/desktop.scss @@ -18,3 +18,4 @@ @import "plugins"; @import "plugins_desktop"; +@import "category_backgrounds"; diff --git a/app/assets/stylesheets/desktop/header.scss b/app/assets/stylesheets/desktop/header.scss index b8300e459c4..d8cf985229a 100644 --- a/app/assets/stylesheets/desktop/header.scss +++ b/app/assets/stylesheets/desktop/header.scss @@ -30,6 +30,8 @@ #main-outlet { padding-top: 82px; + background-repeat: no-repeat; + background-position: 0 0; } // Dropdowns diff --git a/app/assets/stylesheets/desktop/topic-list.scss b/app/assets/stylesheets/desktop/topic-list.scss index 38c58d9a4e0..9870560d27b 100644 --- a/app/assets/stylesheets/desktop/topic-list.scss +++ b/app/assets/stylesheets/desktop/topic-list.scss @@ -282,3 +282,12 @@ button.dismiss-read { bottom: auto; left: auto; } + +.category-heading { + clear: both; +} +.category-logo { + max-height: 150px; + float: left; + margin-bottom: 15px; +} diff --git a/app/assets/stylesheets/mobile.scss b/app/assets/stylesheets/mobile.scss index e01438a4f63..6a0a5597e7b 100644 --- a/app/assets/stylesheets/mobile.scss +++ b/app/assets/stylesheets/mobile.scss @@ -18,3 +18,4 @@ @import "plugins"; @import "plugins_mobile"; +@import "category_backgrounds"; diff --git a/app/models/category.rb b/app/models/category.rb index 867f91d09c7..d8898f12256 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -68,6 +68,9 @@ class Category < ActiveRecord::Base # we may consider wrapping this in another spot 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) if guardian && guardian.is_staff? diff --git a/lib/sass/discourse_sass_importer.rb b/lib/sass/discourse_sass_importer.rb index 05e03230bb7..00b081ecc4f 100644 --- a/lib/sass/discourse_sass_importer.rb +++ b/lib/sass/discourse_sass_importer.rb @@ -45,6 +45,21 @@ class DiscourseSassImporter < Sass::Importers::Filesystem end 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 name == "theme_variables" contents = "" diff --git a/lib/sass/discourse_stylesheets.rb b/lib/sass/discourse_stylesheets.rb index 94d18886cc1..0c994ee7973 100644 --- a/lib/sass/discourse_stylesheets.rb +++ b/lib/sass/discourse_stylesheets.rb @@ -107,7 +107,8 @@ class DiscourseStylesheets def digest @digest ||= begin 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 diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 29aabc0bc08..520d383ff7b 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -20,6 +20,14 @@ describe Category do it { should have_many :featured_topics } 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 it "can determine read_restricted" do read_restricted, resolved = Category.resolve_permissions(:everyone => :full)