BUGFIX: clicking the logo when the homepage was /categories or /top would fail

This commit is contained in:
Régis Hanol 2014-01-23 17:08:52 +01:00
parent 7b20079d85
commit ae06ea6323
5 changed files with 36 additions and 11 deletions

View File

@ -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');
});
}
},

View File

@ -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; }

View File

@ -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;
}

View File

@ -25,7 +25,7 @@ Discourse.DiscoveryCategoriesRoute = Discourse.Route.extend({
}
return list;
});
},
},
setupController: function(controller, model) {
controller.set('model', model);

View File

@ -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"));