diff --git a/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js b/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js index 24a45ec6af7..4779a53c9b6 100644 --- a/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js +++ b/app/assets/javascripts/discourse/controllers/discovery_categories_controller.js @@ -12,6 +12,15 @@ Discourse.DiscoveryCategoriesController = Discourse.DiscoveryController.extend({ actions: { toggleOrdering: function(){ this.set("ordering",!this.get("ordering")); + }, + + refresh: function() { + var self = this; + this.send('loading'); + Discourse.CategoryList.list('categories').then(function(list) { + self.set('model', list); + self.send('loadingComplete'); + }); } }, diff --git a/app/assets/javascripts/discourse/controllers/discovery_top_controller.js b/app/assets/javascripts/discourse/controllers/discovery_top_controller.js index 7405c6f977b..6b28a1fe817 100644 --- a/app/assets/javascripts/discourse/controllers/discovery_top_controller.js +++ b/app/assets/javascripts/discourse/controllers/discovery_top_controller.js @@ -7,6 +7,18 @@ @module Discourse **/ Discourse.DiscoveryTopController = Discourse.DiscoveryController.extend({ + + actions: { + refresh: function() { + var self = this; + this.send('loading'); + Discourse.TopList.find().then(function(top_lists) { + self.set('model', top_lists); + self.send('loadingComplete'); + }); + } + }, + redirectedToTopPageReason: function() { // no need for a reason if the default homepage is 'top' if (Discourse.Utilities.defaultHomepage() === 'top') { return null; } diff --git a/app/assets/javascripts/discourse/lib/url.js b/app/assets/javascripts/discourse/lib/url.js index 10bb4931fb1..d01bc76887d 100644 --- a/app/assets/javascripts/discourse/lib/url.js +++ b/app/assets/javascripts/discourse/lib/url.js @@ -95,7 +95,7 @@ Discourse.URL = Em.Object.createWithMixins({ window.location = Discourse.getURL(url); }, - /** + /** * Determines whether a URL is internal or not * * @method isInternal @@ -188,11 +188,15 @@ Discourse.URL = Em.Object.createWithMixins({ @param {String} path the path we're navigating to **/ navigatedToHome: function(oldPath, path) { - var defaultFilter = "/" + Discourse.Site.currentProp('filters')[0]; + var homepage = Discourse.User.current() ? Discourse.User.currentProp('homepage') : Discourse.Utilities.defaultHomepage(); - if (path === "/" && (oldPath === "/" || oldPath === defaultFilter)) { - // Refresh our list - this.controllerFor('discoveryTopics').send('refresh'); + if (path === "/" && (oldPath === "/" || oldPath === "/" + homepage)) { + // refresh the list + switch (homepage) { + case "top" : { this.controllerFor('discoveryTop').send('refresh'); break; } + case "categories": { this.controllerFor('discoveryCategories').send('refresh'); break; } + default: { this.controllerFor('discoveryTopics').send('refresh'); break; } + } return true; } diff --git a/app/assets/javascripts/discourse/routes/discovery_categories_route.js b/app/assets/javascripts/discourse/routes/discovery_categories_route.js index b4c6f32c1cd..f5801e95557 100644 --- a/app/assets/javascripts/discourse/routes/discovery_categories_route.js +++ b/app/assets/javascripts/discourse/routes/discovery_categories_route.js @@ -25,7 +25,7 @@ Discourse.DiscoveryCategoriesRoute = Discourse.Route.extend({ } return list; }); - }, + }, setupController: function(controller, model) { controller.set('model', model); diff --git a/test/javascripts/lib/url_test.js b/test/javascripts/lib/url_test.js index 4f1b06185ee..f0d8ee8c7d2 100644 --- a/test/javascripts/lib/url_test.js +++ b/test/javascripts/lib/url_test.js @@ -16,15 +16,15 @@ test("isInternal with a HTTPS url", function() { }); test("navigatedToHome", function() { - var fakeListController = { send: function() { return true; } }; - var mock = sinon.mock(fakeListController); - this.stub(Discourse.URL, "controllerFor").returns(fakeListController); + var fakeDiscoveryController = { send: function() { return true; } }; + var mock = sinon.mock(fakeDiscoveryController); + this.stub(Discourse.URL, "controllerFor").returns(fakeDiscoveryController); mock.expects("send").withArgs('refresh').twice(); ok(Discourse.URL.navigatedToHome("/", "/")); - var defaultFilter = "/" + Discourse.Site.currentProp('filters')[0]; - ok(Discourse.URL.navigatedToHome(defaultFilter, "/")); + var homepage = "/" + Discourse.Utilities.defaultHomepage(); + ok(Discourse.URL.navigatedToHome(homepage, "/")); ok(!Discourse.URL.navigatedToHome("/old", "/new"));