mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-23 21:30:21 -04: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.
|
// 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.
|
// This is used for keeping the `body` style in sync for the background image.
|
||||||
export default {
|
export default {
|
||||||
_enterView: function() { this.get('categorySlug'); }.on('init'),
|
_enterView: function() { this.get('categoryFullSlug'); }.on('init'),
|
||||||
|
|
||||||
_removeClasses: function() {
|
_removeClasses: function() {
|
||||||
$('body').removeClass(function(idx, css) {
|
$('body').removeClass(function(idx, css) {
|
||||||
|
@ -11,13 +11,13 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
_categoryChanged: function() {
|
_categoryChanged: function() {
|
||||||
var categorySlug = this.get('categorySlug');
|
var categoryFullSlug = this.get('categoryFullSlug');
|
||||||
this._removeClasses();
|
this._removeClasses();
|
||||||
|
|
||||||
if (categorySlug) {
|
if (categoryFullSlug) {
|
||||||
$('body').addClass('category-' + categorySlug);
|
$('body').addClass('category-' + categoryFullSlug);
|
||||||
}
|
}
|
||||||
}.observes('categorySlug'),
|
}.observes('categoryFullSlug'),
|
||||||
|
|
||||||
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
_leaveView: function() { this._removeClasses(); }.on('willDestroyElement')
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,6 +29,10 @@ Discourse.Category = Discourse.Model.extend({
|
||||||
return Discourse.getURL("/c/") + Discourse.Category.slugFor(this);
|
return Discourse.getURL("/c/") + Discourse.Category.slugFor(this);
|
||||||
}.property('name'),
|
}.property('name'),
|
||||||
|
|
||||||
|
fullSlug: function() {
|
||||||
|
return this.get("url").slice(3).replace("/", "-");
|
||||||
|
}.property("url"),
|
||||||
|
|
||||||
nameLower: function() {
|
nameLower: function() {
|
||||||
return this.get('name').toLowerCase();
|
return this.get('name').toLowerCase();
|
||||||
}.property('name'),
|
}.property('name'),
|
||||||
|
|
|
@ -85,15 +85,13 @@ Discourse.Site.reopenClass(Discourse.Singleton, {
|
||||||
if (result.categories) {
|
if (result.categories) {
|
||||||
result.categoriesById = {};
|
result.categoriesById = {};
|
||||||
result.categories = _.map(result.categories, function(c) {
|
result.categories = _.map(result.categories, function(c) {
|
||||||
result.categoriesById[c.id] = Discourse.Category.create(c);
|
return result.categoriesById[c.id] = Discourse.Category.create(c);
|
||||||
return result.categoriesById[c.id];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Associate the categories with their parents
|
// Associate the categories with their parents
|
||||||
result.categories.forEach(function (c) {
|
result.categories.forEach(function (c) {
|
||||||
if (c.get('parent_category_id')) {
|
if (c.get('parent_category_id')) {
|
||||||
c.set('parentCategory',
|
c.set('parentCategory', result.categoriesById[c.get('parent_category_id')]);
|
||||||
result.categoriesById[c.get('parent_category_id')]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ Discourse.Topic = Discourse.Model.extend({
|
||||||
}.property('category_id', 'categoryName'),
|
}.property('category_id', 'categoryName'),
|
||||||
|
|
||||||
categoryClass: function() {
|
categoryClass: function() {
|
||||||
return 'category-' + Discourse.Category.slugFor(this.get('category'));
|
return 'category-' + this.get('category.fullSlug');
|
||||||
}.property('category'),
|
}.property('category.fullSlug'),
|
||||||
|
|
||||||
shareUrl: function(){
|
shareUrl: function(){
|
||||||
var user = Discourse.User.current();
|
var user = Discourse.User.current();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
import AddCategoryClass from 'discourse/mixins/add-category-class';
|
||||||
|
|
||||||
export default Em.View.extend(AddCategoryClass, {
|
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'),
|
}.property('controller.selectedRow'),
|
||||||
|
|
||||||
unboundClassNames: function(){
|
unboundClassNames: function(){
|
||||||
var classes = [];
|
let classes = [];
|
||||||
var topic = this.get('topic');
|
const topic = this.get('topic');
|
||||||
|
|
||||||
|
|
||||||
if (topic.get('category')) {
|
if (topic.get('category')) {
|
||||||
classes.push("category-" + topic.get('category.slug'));
|
classes.push("category-" + topic.get('category.fullSlug'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(topic.get('hasExcerpt')){
|
if(topic.get('hasExcerpt')){
|
||||||
|
|
|
@ -341,9 +341,9 @@ SQL
|
||||||
self.where(id: parent_slug.to_i).pluck(:id).first
|
self.where(id: parent_slug.to_i).pluck(:id).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.query_category(slug, parent_category_id)
|
def self.query_category(slug_or_id, parent_category_id)
|
||||||
self.where(slug: slug, parent_category_id: parent_category_id).includes(:featured_users).first ||
|
self.where(slug: slug_or_id, 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
|
self.where(id: slug_or_id.to_i, parent_category_id: parent_category_id).includes(:featured_users).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_email(email)
|
def self.find_by_email(email)
|
||||||
|
@ -366,6 +366,10 @@ SQL
|
||||||
@@url_cache.clear
|
@@url_cache.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def full_slug
|
||||||
|
url[3..-1].gsub("/", "-")
|
||||||
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
url = @@url_cache[self.id]
|
url = @@url_cache[self.id]
|
||||||
unless url
|
unless url
|
||||||
|
|
|
@ -50,7 +50,7 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
|
||||||
contents = ""
|
contents = ""
|
||||||
Category.where('background_url IS NOT NULL').each do |c|
|
Category.where('background_url IS NOT NULL').each do |c|
|
||||||
if c.background_url.present?
|
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
|
||||||
end
|
end
|
||||||
return Sass::Engine.new(contents, options.merge(
|
return Sass::Engine.new(contents, options.merge(
|
||||||
|
|
Loading…
Add table
Reference in a new issue