mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: sub-categories with the same name had the same background image
This commit is contained in:
parent
8ec4d07bf2
commit
7b8c7ff3ef
8 changed files with 26 additions and 21 deletions
|
@ -1,8 +1,8 @@
|
|||
// Mix this in to a view that has a `categorySlug` property to automatically
|
||||
// Mix this in to a view that has a `categoryFullSlug` property to automatically
|
||||
// add it to the body as the view is entered / left / model is changed.
|
||||
// This is used for keeping the `body` style in sync for the background image.
|
||||
export default {
|
||||
_enterView: function() { this.get('categorySlug'); }.on('init'),
|
||||
_enterView: function() { this.get('categoryFullSlug'); }.on('init'),
|
||||
|
||||
_removeClasses: function() {
|
||||
$('body').removeClass(function(idx, css) {
|
||||
|
@ -11,13 +11,13 @@ export default {
|
|||
},
|
||||
|
||||
_categoryChanged: function() {
|
||||
var categorySlug = this.get('categorySlug');
|
||||
var categoryFullSlug = this.get('categoryFullSlug');
|
||||
this._removeClasses();
|
||||
|
||||
if (categorySlug) {
|
||||
$('body').addClass('category-' + categorySlug);
|
||||
if (categoryFullSlug) {
|
||||
$('body').addClass('category-' + categoryFullSlug);
|
||||
}
|
||||
}.observes('categorySlug'),
|
||||
}.observes('categoryFullSlug'),
|
||||
|
||||
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
||||
};
|
||||
|
|
|
@ -29,6 +29,10 @@ Discourse.Category = Discourse.Model.extend({
|
|||
return Discourse.getURL("/c/") + Discourse.Category.slugFor(this);
|
||||
}.property('name'),
|
||||
|
||||
fullSlug: function() {
|
||||
return this.get("url").slice(3).replace("/", "-");
|
||||
}.property("url"),
|
||||
|
||||
nameLower: function() {
|
||||
return this.get('name').toLowerCase();
|
||||
}.property('name'),
|
||||
|
|
|
@ -85,15 +85,13 @@ Discourse.Site.reopenClass(Discourse.Singleton, {
|
|||
if (result.categories) {
|
||||
result.categoriesById = {};
|
||||
result.categories = _.map(result.categories, function(c) {
|
||||
result.categoriesById[c.id] = Discourse.Category.create(c);
|
||||
return result.categoriesById[c.id];
|
||||
return result.categoriesById[c.id] = Discourse.Category.create(c);
|
||||
});
|
||||
|
||||
// Associate the categories with their parents
|
||||
result.categories.forEach(function (c) {
|
||||
if (c.get('parent_category_id')) {
|
||||
c.set('parentCategory',
|
||||
result.categoriesById[c.get('parent_category_id')]);
|
||||
c.set('parentCategory', result.categoriesById[c.get('parent_category_id')]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ Discourse.Topic = Discourse.Model.extend({
|
|||
}.property('category_id', 'categoryName'),
|
||||
|
||||
categoryClass: function() {
|
||||
return 'category-' + Discourse.Category.slugFor(this.get('category'));
|
||||
}.property('category'),
|
||||
return 'category-' + this.get('category.fullSlug');
|
||||
}.property('category.fullSlug'),
|
||||
|
||||
shareUrl: function(){
|
||||
var user = Discourse.User.current();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
||||
|
||||
export default Em.View.extend(AddCategoryClass, {
|
||||
categorySlug: Em.computed.alias('controller.category.slug')
|
||||
categoryFullSlug: Em.computed.alias('controller.category.fullSlug')
|
||||
});
|
||||
|
|
|
@ -27,12 +27,11 @@ export default Discourse.View.extend(StringBuffer, {
|
|||
}.property('controller.selectedRow'),
|
||||
|
||||
unboundClassNames: function(){
|
||||
var classes = [];
|
||||
var topic = this.get('topic');
|
||||
|
||||
let classes = [];
|
||||
const topic = this.get('topic');
|
||||
|
||||
if (topic.get('category')) {
|
||||
classes.push("category-" + topic.get('category.slug'));
|
||||
classes.push("category-" + topic.get('category.fullSlug'));
|
||||
}
|
||||
|
||||
if(topic.get('hasExcerpt')){
|
||||
|
|
|
@ -341,9 +341,9 @@ SQL
|
|||
self.where(id: parent_slug.to_i).pluck(:id).first
|
||||
end
|
||||
|
||||
def self.query_category(slug, parent_category_id)
|
||||
self.where(slug: slug, parent_category_id: parent_category_id).includes(:featured_users).first ||
|
||||
self.where(id: slug.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
|
||||
def self.query_category(slug_or_id, parent_category_id)
|
||||
self.where(slug: slug_or_id, parent_category_id: parent_category_id).includes(:featured_users).first ||
|
||||
self.where(id: slug_or_id.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
|
||||
end
|
||||
|
||||
def self.find_by_email(email)
|
||||
|
@ -366,6 +366,10 @@ SQL
|
|||
@@url_cache.clear
|
||||
end
|
||||
|
||||
def full_slug
|
||||
url[3..-1].gsub("/", "-")
|
||||
end
|
||||
|
||||
def url
|
||||
url = @@url_cache[self.id]
|
||||
unless url
|
||||
|
|
|
@ -50,7 +50,7 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
|
|||
contents = ""
|
||||
Category.where('background_url IS NOT NULL').each do |c|
|
||||
if c.background_url.present?
|
||||
contents << "body.category-#{c.slug} { background-image: url(#{c.background_url}) }\n"
|
||||
contents << "body.category-#{c.full_slug} { background-image: url(#{c.background_url}) }\n"
|
||||
end
|
||||
end
|
||||
return Sass::Engine.new(contents, options.merge(
|
||||
|
|
Loading…
Reference in a new issue