mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: do not publish all categories when a category changes.
minor fixes to UI, still needs more work for live refresh of category listing
This commit is contained in:
@@ -26,13 +26,25 @@ export default ComboboxView.extend({
|
|||||||
}.property('scopedCategoryId', 'categories'),
|
}.property('scopedCategoryId', 'categories'),
|
||||||
|
|
||||||
_setCategories: function() {
|
_setCategories: function() {
|
||||||
this.set('categories', this.get('categories') || (
|
|
||||||
Discourse.SiteSettings.fixed_category_positions_on_create ?
|
if (!this.get('categories')) {
|
||||||
Discourse.Category.list() : Discourse.Category.listByActivity()
|
this.set('automatic', true);
|
||||||
)
|
}
|
||||||
);
|
|
||||||
|
this._updateCategories();
|
||||||
|
|
||||||
}.on('init'),
|
}.on('init'),
|
||||||
|
|
||||||
|
_updateCategories: function() {
|
||||||
|
|
||||||
|
if (this.get('automatic')) {
|
||||||
|
this.set('categories',
|
||||||
|
Discourse.SiteSettings.fixed_category_positions_on_create ?
|
||||||
|
Discourse.Category.list() : Discourse.Category.listByActivity()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}.observes('automatic', 'site.sortedCategories'),
|
||||||
|
|
||||||
none: function() {
|
none: function() {
|
||||||
if (Discourse.User.currentProp('staff') || Discourse.SiteSettings.allow_uncategorized_topics) {
|
if (Discourse.User.currentProp('staff') || Discourse.SiteSettings.allow_uncategorized_topics) {
|
||||||
if (this.get('rootNone')) {
|
if (this.get('rootNone')) {
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ export default {
|
|||||||
_.each(data.categories,function(c) {
|
_.each(data.categories,function(c) {
|
||||||
site.updateCategory(c);
|
site.updateCategory(c);
|
||||||
});
|
});
|
||||||
|
_.each(data.deleted_categories,function(id) {
|
||||||
|
site.removeCategory(id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!Ember.testing) {
|
if (!Ember.testing) {
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ Discourse.Mobile = {
|
|||||||
this.mobileView = $html.hasClass('mobile-view');
|
this.mobileView = $html.hasClass('mobile-view');
|
||||||
|
|
||||||
try{
|
try{
|
||||||
if (window.location.search.test(/mobile_view=1/)){
|
if (window.location.search.match(/mobile_view=1/)){
|
||||||
localStorage.mobileView = true;
|
localStorage.mobileView = true;
|
||||||
}
|
}
|
||||||
if (window.location.search.test(/mobile_view=0/)){
|
if (window.location.search.match(/mobile_view=0/)){
|
||||||
localStorage.mobileView = false;
|
localStorage.mobileView = false;
|
||||||
}
|
}
|
||||||
if (localStorage.mobileView) {
|
if (localStorage.mobileView) {
|
||||||
|
|||||||
@@ -18,9 +18,8 @@ const Site = Discourse.Model.extend({
|
|||||||
return postActionTypes.filterProperty('is_flag', true);
|
return postActionTypes.filterProperty('is_flag', true);
|
||||||
}.property('post_action_types.@each'),
|
}.property('post_action_types.@each'),
|
||||||
|
|
||||||
categoriesByCount: Ember.computed.sort('categories', function(a, b) {
|
topicCountDesc: ['topic_count:desc'],
|
||||||
return (b.get('topic_count') || 0) - (a.get('topic_count') || 0);
|
categoriesByCount: Ember.computed.sort('categories', 'topicCountDesc'),
|
||||||
}),
|
|
||||||
|
|
||||||
// Sort subcategories under parents
|
// Sort subcategories under parents
|
||||||
sortedCategories: function() {
|
sortedCategories: function() {
|
||||||
@@ -48,7 +47,7 @@ const Site = Discourse.Model.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}.property(),
|
}.property("categories.@each"),
|
||||||
|
|
||||||
postActionTypeById(id) {
|
postActionTypeById(id) {
|
||||||
return this.get("postActionByIdLookup.action" + id);
|
return this.get("postActionByIdLookup.action" + id);
|
||||||
@@ -58,13 +57,30 @@ const Site = Discourse.Model.extend({
|
|||||||
return this.get("topicFlagByIdLookup.action" + id);
|
return this.get("topicFlagByIdLookup.action" + id);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateCategory(newCategory) {
|
removeCategory(id) {
|
||||||
const existingCategory = this.get('categories').findProperty('id', Em.get(newCategory, 'id'));
|
const categories = this.get('categories');
|
||||||
|
const existingCategory = categories.findProperty('id', id);
|
||||||
if (existingCategory) {
|
if (existingCategory) {
|
||||||
// Don't update null permissions
|
categories.removeObject(existingCategory);
|
||||||
if (newCategory.permission === null) { delete newCategory.permission; }
|
delete this.get('categoriesById').categoryId;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateCategory(newCategory) {
|
||||||
|
const categories = this.get('categories');
|
||||||
|
const categoryId = Em.get(newCategory, 'id');
|
||||||
|
const existingCategory = categories.findProperty('id', categoryId);
|
||||||
|
|
||||||
|
// Don't update null permissions
|
||||||
|
if (newCategory.permission === null) { delete newCategory.permission; }
|
||||||
|
|
||||||
|
if (existingCategory) {
|
||||||
existingCategory.setProperties(newCategory);
|
existingCategory.setProperties(newCategory);
|
||||||
|
} else {
|
||||||
|
// TODO insert in right order?
|
||||||
|
newCategory = Discourse.Category.create(newCategory);
|
||||||
|
categories.pushObject(newCategory);
|
||||||
|
this.get('categoriesById')[categoryId] = newCategory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ class Category < ActiveRecord::Base
|
|||||||
before_save :downcase_email
|
before_save :downcase_email
|
||||||
before_save :downcase_name
|
before_save :downcase_name
|
||||||
after_create :create_category_definition
|
after_create :create_category_definition
|
||||||
after_create :publish_categories_list
|
|
||||||
after_destroy :publish_categories_list
|
after_save :publish_category
|
||||||
|
after_destroy :publish_category_deletion
|
||||||
|
|
||||||
after_update :rename_category_definition, if: :name_changed?
|
after_update :rename_category_definition, if: :name_changed?
|
||||||
|
|
||||||
after_save :publish_discourse_stylesheet
|
after_save :publish_discourse_stylesheet
|
||||||
@@ -233,8 +235,13 @@ SQL
|
|||||||
slug.present? ? self.slug : "#{self.id}-category"
|
slug.present? ? self.slug : "#{self.id}-category"
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_categories_list
|
def publish_category
|
||||||
MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest).as_json})
|
group_ids = self.groups.pluck(:id) if self.read_restricted
|
||||||
|
MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new([self]).as_json}, group_ids: group_ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
def publish_category_deletion
|
||||||
|
MessageBus.publish('/categories', {deleted_categories: [self.id]})
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent_category_validator
|
def parent_category_validator
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ test('create categories', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var categories = site.get('categories');
|
var categories = site.get('categories');
|
||||||
|
site.get('sortedCategories');
|
||||||
|
|
||||||
present(categories, "The categories are present");
|
present(categories, "The categories are present");
|
||||||
equal(categories.length, 3, "it loaded all three categories");
|
equal(categories.length, 3, "it loaded all three categories");
|
||||||
@@ -36,4 +37,11 @@ test('create categories', function() {
|
|||||||
present(subcategory, "it loaded the subcategory");
|
present(subcategory, "it loaded the subcategory");
|
||||||
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
||||||
|
|
||||||
|
// remove invalid category and child
|
||||||
|
categories.removeObject(categories[2]);
|
||||||
|
categories.removeObject(categories[1]);
|
||||||
|
|
||||||
|
equal(categories.length, site.get('categoriesByCount').length, "categories by count should change on removal");
|
||||||
|
equal(categories.length, site.get('sortedCategories').length, "sorted categories should change on removal");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user