mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: Couldn't access "Uncategorized" category from category list.
This commit is contained in:
parent
b1ef2ea1e1
commit
62a20f5655
10 changed files with 82 additions and 43 deletions
|
@ -10,12 +10,6 @@ Discourse.Category = Discourse.Model.extend({
|
|||
|
||||
init: function() {
|
||||
this._super();
|
||||
if (!this.get('id') && this.get('name')) {
|
||||
this.set('is_uncategorized', true);
|
||||
if (!this.get('color')) this.set('color', Discourse.SiteSettings.uncategorized_color);
|
||||
if (!this.get('text_color')) this.set('text_color', Discourse.SiteSettings.uncategorized_text_color);
|
||||
}
|
||||
|
||||
this.set("availableGroups", Em.A(this.get("available_groups")));
|
||||
this.set("groups", Em.A(this.groups));
|
||||
},
|
||||
|
@ -75,6 +69,19 @@ Discourse.Category = Discourse.Model.extend({
|
|||
|
||||
Discourse.Category.reopenClass({
|
||||
|
||||
uncategorizedInstance: function() {
|
||||
if (this.uncategorized) return this.uncategorized;
|
||||
|
||||
this.uncategorized = this.create({
|
||||
slug: 'uncategorized',
|
||||
name: Discourse.SiteSettings.uncategorized_name,
|
||||
isUncategorized: true,
|
||||
color: Discourse.SiteSettings.uncategorized_color,
|
||||
text_color: Discourse.SiteSettings.uncategorized_text_color
|
||||
});
|
||||
return this.uncategorized;
|
||||
},
|
||||
|
||||
list: function() {
|
||||
return Discourse.Site.instance().get('categories');
|
||||
},
|
||||
|
|
|
@ -11,9 +11,10 @@ Discourse.CategoryList = Discourse.Model.extend({});
|
|||
Discourse.CategoryList.reopenClass({
|
||||
|
||||
categoriesFrom: function(result) {
|
||||
var categories, users;
|
||||
categories = Em.A();
|
||||
users = this.extractByKey(result.featured_users, Discourse.User);
|
||||
var categories = Em.A();
|
||||
var users = this.extractByKey(result.featured_users, Discourse.User);
|
||||
|
||||
|
||||
result.category_list.categories.each(function(c) {
|
||||
if (c.featured_user_ids) {
|
||||
c.featured_users = c.featured_user_ids.map(function(u) {
|
||||
|
@ -25,7 +26,17 @@ Discourse.CategoryList.reopenClass({
|
|||
return Discourse.Topic.create(t);
|
||||
});
|
||||
}
|
||||
return categories.pushObject(Discourse.Category.create(c));
|
||||
|
||||
if (c.is_uncategorized) {
|
||||
var uncategorized = Discourse.Category.uncategorizedInstance();
|
||||
uncategorized.setProperties({
|
||||
topics: c.topics,
|
||||
featured_users: c.featured_users
|
||||
});
|
||||
categories.pushObject(uncategorized);
|
||||
} else {
|
||||
categories.pushObject(Discourse.Category.create(c));
|
||||
}
|
||||
});
|
||||
return categories;
|
||||
},
|
||||
|
|
|
@ -41,6 +41,7 @@ Discourse.Site.reopenClass({
|
|||
create: function(obj) {
|
||||
var _this = this;
|
||||
return Object.tap(this._super(obj), function(result) {
|
||||
|
||||
if (result.categories) {
|
||||
result.categories = result.categories.map(function(c) {
|
||||
return Discourse.Category.create(c);
|
||||
|
|
|
@ -8,26 +8,24 @@
|
|||
**/
|
||||
Discourse.ListCategoriesRoute = Discourse.Route.extend({
|
||||
|
||||
exit: function() {
|
||||
model: function() {
|
||||
var listTopicsController = this.controllerFor('listTopics');
|
||||
if (listTopicsController) listTopicsController.set('content', null);
|
||||
|
||||
return this.controllerFor('list').load('categories');
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
this._super();
|
||||
this.controllerFor('list').set('canCreateCategory', false);
|
||||
},
|
||||
|
||||
setupController: function(controller) {
|
||||
var listController,
|
||||
_this = this;
|
||||
listController = this.controllerFor('list');
|
||||
listController.set('filterMode', 'categories');
|
||||
listController.load('categories').then(function(categoryList) {
|
||||
_this.render('listCategories', {
|
||||
into: 'list',
|
||||
outlet: 'listView',
|
||||
controller: 'listCategories'
|
||||
});
|
||||
listController.set('canCreateCategory', categoryList.get('can_create_category'));
|
||||
listController.set('canCreateTopic', categoryList.get('can_create_topic'));
|
||||
listController.set('category', null);
|
||||
_this.controllerFor('listCategories').set('content', categoryList);
|
||||
setupController: function(controller, categoryList) {
|
||||
this.render('listCategories', { into: 'list', outlet: 'listView' });
|
||||
this.controllerFor('list').setProperties({
|
||||
canCreateCategory: categoryList.get('can_create_category'),
|
||||
canCreateTopic: categoryList.get('can_create_topic'),
|
||||
category: null
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ Discourse.ListCategoryRoute = Discourse.FilteredListRoute.extend({
|
|||
var categories = Discourse.Category.list();
|
||||
|
||||
var slug = Em.get(params, 'slug');
|
||||
|
||||
var uncategorized = Discourse.Category.uncategorizedInstance();
|
||||
if (slug === uncategorized.get('slug')) return uncategorized;
|
||||
|
||||
var category = categories.findProperty('slug', Em.get(params, 'slug'))
|
||||
|
||||
// In case the slug didn't work, try to find it by id instead.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<li {{bindAttr class="view.generalSelected:active"}}>
|
||||
<a href="#" {{action selectGeneral target="view"}}>{{i18n category.general}}</a>
|
||||
</li>
|
||||
{{#unless is_uncategorized}}
|
||||
{{#unless isUncategorized}}
|
||||
<li {{bindAttr class="view.securitySelected:active"}}>
|
||||
<a href="#" {{action selectSecurity target="view"}}>{{i18n category.security}}</a>
|
||||
</li>
|
||||
|
@ -23,7 +23,7 @@
|
|||
{{textField value=name placeholderKey="category.name_placeholder" maxlength="50"}}
|
||||
</section>
|
||||
|
||||
{{#unless is_uncategorized}}
|
||||
{{#unless isUncategorized}}
|
||||
<section class='field'>
|
||||
<label>{{i18n category.description}}</label>
|
||||
|
||||
|
@ -59,7 +59,7 @@
|
|||
</section>
|
||||
</form>
|
||||
</div>
|
||||
{{#unless is_uncategorized}}
|
||||
{{#unless isUncategorized}}
|
||||
<div {{bindAttr class=":modal-tab :options-tab view.securitySelected::invisible"}}>
|
||||
<section class='field'>
|
||||
<label>
|
||||
|
|
|
@ -70,7 +70,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
|
||||
title: function() {
|
||||
if (this.get('category.id')) return Em.String.i18n("category.edit_long");
|
||||
if (this.get('category.is_uncategorized')) return Em.String.i18n("category.edit_uncategorized");
|
||||
if (this.get('category.isUncategorized')) return Em.String.i18n("category.edit_uncategorized");
|
||||
return Em.String.i18n("category.create");
|
||||
}.property('category.id'),
|
||||
|
||||
|
@ -81,7 +81,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
|
||||
buttonTitle: function() {
|
||||
if (this.get('saving')) return Em.String.i18n("saving");
|
||||
if (this.get('category.is_uncategorized')) return Em.String.i18n("save");
|
||||
if (this.get('category.isUncategorized')) return Em.String.i18n("save");
|
||||
return (this.get('category.id') ? Em.String.i18n("category.save") : Em.String.i18n("category.create"));
|
||||
}.property('saving', 'category.id'),
|
||||
|
||||
|
@ -92,7 +92,7 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
didInsertElement: function() {
|
||||
this._super();
|
||||
|
||||
if( this.get('category.id') ) {
|
||||
if (this.get('category.id')) {
|
||||
this.set('loading', true);
|
||||
var categoryView = this;
|
||||
|
||||
|
@ -103,8 +103,8 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
categoryView.set('id', categoryView.get('category.slug'));
|
||||
categoryView.set('loading', false);
|
||||
});
|
||||
} else if( this.get('category.is_uncategorized') ) {
|
||||
this.set('category', this.get('category'));
|
||||
} else if( this.get('category.isUncategorized') ) {
|
||||
this.set('category', Discourse.Category.uncategorizedInstance());
|
||||
} else {
|
||||
this.set('category', Discourse.Category.create({ color: 'AB9364', text_color: 'FFFFFF', hotness: 5 }));
|
||||
}
|
||||
|
@ -129,15 +129,19 @@ Discourse.EditCategoryView = Discourse.ModalBodyView.extend({
|
|||
saveCategory: function() {
|
||||
var categoryView = this;
|
||||
this.set('saving', true);
|
||||
if( this.get('category.is_uncategorized') ) {
|
||||
|
||||
|
||||
if( this.get('category.isUncategorized') ) {
|
||||
$.when(
|
||||
Discourse.SiteSetting.update('uncategorized_color', this.get('category.color')),
|
||||
Discourse.SiteSetting.update('uncategorized_text_color', this.get('category.text_color')),
|
||||
Discourse.SiteSetting.update('uncategorized_name', this.get('category.name'))
|
||||
).then(function() {
|
||||
).then(function(result) {
|
||||
// success
|
||||
$('#discourse-modal').modal('hide');
|
||||
Discourse.URL.redirectTo("/category/" + categoryView.get('category.name'));
|
||||
// We can't redirect to the uncategorized category on save because the slug
|
||||
// might have changed.
|
||||
Discourse.URL.redirectTo("/categories");
|
||||
}, function(errors) {
|
||||
// errors
|
||||
if(errors.length === 0) errors.push(Em.String.i18n("category.save_error"));
|
||||
|
|
|
@ -36,10 +36,10 @@ class CategoryList
|
|||
|
||||
|
||||
uncategorized = Category.new({name: SiteSetting.uncategorized_name,
|
||||
slug: Slug.for(SiteSetting.uncategorized_name),
|
||||
color: SiteSetting.uncategorized_color,
|
||||
text_color: SiteSetting.uncategorized_text_color,
|
||||
featured_topics: uncategorized_topics}.merge(totals))
|
||||
slug: Slug.for(SiteSetting.uncategorized_name),
|
||||
color: SiteSetting.uncategorized_color,
|
||||
text_color: SiteSetting.uncategorized_text_color,
|
||||
featured_topics: uncategorized_topics}.merge(totals))
|
||||
|
||||
# Find the appropriate place to insert it:
|
||||
insert_at = nil
|
||||
|
|
|
@ -9,7 +9,8 @@ class CategoryDetailedSerializer < ApplicationSerializer
|
|||
:topics_week,
|
||||
:topics_month,
|
||||
:topics_year,
|
||||
:description
|
||||
:description,
|
||||
:is_uncategorized
|
||||
|
||||
has_many :featured_users, serializer: BasicUserSerializer
|
||||
has_many :featured_topics, serializer: CategoryTopicSerializer, embed: :objects, key: :topics
|
||||
|
@ -26,4 +27,12 @@ class CategoryDetailedSerializer < ApplicationSerializer
|
|||
object.topics_year || 0
|
||||
end
|
||||
|
||||
def is_uncategorized
|
||||
name == SiteSetting.uncategorized_name
|
||||
end
|
||||
|
||||
def include_is_uncategorized?
|
||||
is_uncategorized
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,8 @@ class SiteSerializer < ApplicationSerializer
|
|||
|
||||
attributes :default_archetype,
|
||||
:notification_types,
|
||||
:post_types
|
||||
:post_types,
|
||||
:uncategorized_slug
|
||||
|
||||
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
|
||||
has_many :post_action_types, embed: :objects
|
||||
|
@ -18,4 +19,8 @@ class SiteSerializer < ApplicationSerializer
|
|||
Post.types
|
||||
end
|
||||
|
||||
def uncategorized_slug
|
||||
Slug.for(SiteSetting.uncategorized_name)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue