FIX: Triggering a refresh while subcategory lists was broken.

It would then list all categories isntead of the subcategory you were
viewing at that time.
This commit is contained in:
Robin Ward 2015-01-15 13:00:48 -05:00
parent b4e5937850
commit 6c4c542ae3
4 changed files with 74 additions and 72 deletions

View File

@ -8,7 +8,6 @@ export default DiscoveryController.extend({
actions: {
refresh: function() {
var self = this;
// Don't refresh if we're still loading
if (this.get('controllers.discovery.loading')) { return; }
@ -17,7 +16,17 @@ export default DiscoveryController.extend({
// router and ember throws an error due to missing `handlerInfos`.
// Lesson learned: Don't call `loading` yourself.
this.set('controllers.discovery.loading', true);
Discourse.CategoryList.list('categories').then(function(list) {
var parentCategory = this.get('model.parentCategory');
var promise;
if (parentCategory) {
promise = Discourse.CategoryList.listForParent(parentCategory);
} else {
promise = Discourse.CategoryList.list();
}
var self = this;
promise.then(function(list) {
self.set('model', list);
self.send('loadingComplete');
});

View File

@ -1,11 +1,3 @@
/**
A data model for containing a list of categories
@class CategoryList
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
Discourse.CategoryList = Ember.ArrayProxy.extend({
init: function() {
this.set('content', []);
@ -50,7 +42,8 @@ Discourse.CategoryList.reopenClass({
var self = this;
return Discourse.ajax('/categories.json?parent_category_id=' + category.get('id')).then(function(result) {
return Discourse.CategoryList.create({
categories: self.categoriesFrom(result)
categories: self.categoriesFrom(result),
parentCategory: category
});
});
},

View File

@ -10,71 +10,71 @@
</thead>
<tbody>
{{#each c in categories}}
<tr data-category_id='{{unbound c.id}}' {{bind-attr class="c.description_excerpt:has-description:no-description c.logo_url:has-logo:no-logo"}}>
<td class='category' style="border-color: #{{unbound c.color}}">
<div>
<div class="pull-left">
{{category-title-link category=c}}
{{#if c.unreadTopics}}
<a href={{unbound c.unreadUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.unread_topics' count=c.unreadTopics}}'>{{i18n 'filters.unread.lower_title_with_count' count=c.unreadTopics}}</a>
{{/if}}
{{#if c.newTopics}}
<a href={{unbound c.newUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.new_topics' count=c.newTopics}}'>{{i18n 'filters.new.lower_title_with_count' count=c.newTopics}}</a>
{{/if}}
</div>
<div class="clearfix"></div>
</div>
{{#if c.description_excerpt}}
<div class="category-description">
{{{c.description_excerpt}}}
</div>
{{/if}}
{{#if c.subcategories}}
<div class='subcategories'>
{{#each s in c.subcategories}}
{{category-link s showParent="true" onlyStripe="true"}}
{{#if s.unreadTopics}}
<a href={{unbound s.unreadUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.unread_topics' count=s.unreadTopics}}'>{{unbound s.unreadTopics}}</a>
<tr data-category_id='{{unbound c.id}}' {{bind-attr class="c.description_excerpt:has-description:no-description c.logo_url:has-logo:no-logo"}}>
<td class='category' style="border-color: #{{unbound c.color}}">
<div>
<div class="pull-left">
{{category-title-link category=c}}
{{#if c.unreadTopics}}
<a href={{unbound c.unreadUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.unread_topics' count=c.unreadTopics}}'>{{i18n 'filters.unread.lower_title_with_count' count=c.unreadTopics}}</a>
{{/if}}
{{#if s.newTopics}}
<a href={{unbound s.newUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.new_topics' count=s.newTopics}}'>{{unbound s.newTopics}}</a>
{{#if c.newTopics}}
<a href={{unbound c.newUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.new_topics' count=c.newTopics}}'>{{i18n 'filters.new.lower_title_with_count' count=c.newTopics}}</a>
{{/if}}
{{/each}}
</div>
<div class="clearfix"></div>
</div>
{{/if}}
</td>
<td {{bind-attr class="c.archived :latest"}}>
{{#each f in c.featuredTopics}}
<div class="featured-topic">
{{topic-status topic=f}}
<a class='title' href="{{unbound f.lastUnreadUrl}}">{{{unbound f.fancy_title}}}</a>
{{topic-post-badges newPosts=f.totalUnread unseen=f.unseen url=f.lastUnreadUrl}}
{{#if c.description_excerpt}}
<div class="category-description">
{{{c.description_excerpt}}}
</div>
{{/if}}
{{#if c.subcategories}}
<div class='subcategories'>
{{#each s in c.subcategories}}
{{category-link s showParent="true" onlyStripe="true"}}
{{#if s.unreadTopics}}
<a href={{unbound s.unreadUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.unread_topics' count=s.unreadTopics}}'>{{unbound s.unreadTopics}}</a>
{{/if}}
{{#if s.newTopics}}
<a href={{unbound s.newUrl}} class='badge new-posts badge-notification' title='{{i18n 'topic.new_topics' count=s.newTopics}}'>{{unbound s.newTopics}}</a>
{{/if}}
{{/each}}
</div>
{{/if}}
</td>
<td {{bind-attr class="c.archived :latest"}}>
{{#each f in c.featuredTopics}}
<div class="featured-topic">
{{topic-status topic=f}}
<a class='title' href="{{unbound f.lastUnreadUrl}}">{{{unbound f.fancy_title}}}</a>
{{topic-post-badges newPosts=f.totalUnread unseen=f.unseen url=f.lastUnreadUrl}}
{{#if controller.latestTopicOnly}}
<div class='last-user-info'>
{{i18n 'categories.latest_by'}} <a href="{{{unbound f.lastPosterUrl}}}">{{unbound f.last_poster.username}}</a>
<a href="{{unbound f.lastPostUrl}}">{{format-age f.last_posted_at}}</a>
</div>
{{else}}
&nbsp;
<a href="{{unbound f.lastPostUrl}}" class="last-posted-at">{{format-age f.last_posted_at}}</a>
{{/if}}
</div>
{{/each}}
</td>
<td class='stats' {{bind-attr title="c.topicStatsTitle"}}>
<table class="categoryStats">
<tbody>
{{#each s in c.topicCountStats}}
<tr>
<td class="value">{{s.value}}</td>
<td class="unit"> / {{s.unit}}</td>
</tr>
{{#if controller.latestTopicOnly}}
<div class='last-user-info'>
{{i18n 'categories.latest_by'}} <a href="{{{unbound f.lastPosterUrl}}}">{{unbound f.last_poster.username}}</a>
<a href="{{unbound f.lastPostUrl}}">{{format-age f.last_posted_at}}</a>
</div>
{{else}}
&nbsp;
<a href="{{unbound f.lastPostUrl}}" class="last-posted-at">{{format-age f.last_posted_at}}</a>
{{/if}}
</div>
{{/each}}
</tbody>
</table>
</td>
</tr>
</td>
<td class='stats' {{bind-attr title="c.topicStatsTitle"}}>
<table class="categoryStats">
<tbody>
{{#each s in c.topicCountStats}}
<tr>
<td class="value">{{s.value}}</td>
<td class="unit"> / {{s.unit}}</td>
</tr>
{{/each}}
</tbody>
</table>
</td>
</tr>
{{/each}}
</tbody>
</table>

View File

@ -16,7 +16,7 @@
{{#if selected}}
<div id='bulk-select'>
<button class='btn no-text' {{action "showBulkActions"}}><i class="fa fa-wrench"></i></button>
{{d-button action="showBulkActions" icon="wrench" class="no-text"}}
</div>
{{/if}}