DRY app/router.js
This commit is contained in:
parent
dccad3f7e1
commit
f7bd0bbb24
3 changed files with 101 additions and 45 deletions
|
|
@ -10,17 +10,12 @@ app.Router = Backbone.Router.extend({
|
||||||
"user/edit": "settings",
|
"user/edit": "settings",
|
||||||
"users/sign_up": "registration",
|
"users/sign_up": "registration",
|
||||||
|
|
||||||
//new hotness
|
|
||||||
"posts/:id": "singlePost",
|
"posts/:id": "singlePost",
|
||||||
"p/:id": "singlePost",
|
"p/:id": "singlePost",
|
||||||
|
|
||||||
//oldness
|
|
||||||
"activity": "stream",
|
"activity": "stream",
|
||||||
"stream": "stream",
|
"stream": "stream",
|
||||||
"participate": "stream",
|
|
||||||
"explore": "stream",
|
|
||||||
"aspects": "aspects",
|
"aspects": "aspects",
|
||||||
"aspects/stream": "aspects_stream",
|
|
||||||
"commented": "stream",
|
"commented": "stream",
|
||||||
"liked": "stream",
|
"liked": "stream",
|
||||||
"mentions": "stream",
|
"mentions": "stream",
|
||||||
|
|
@ -86,24 +81,10 @@ app.Router = Backbone.Router.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//below here is oldness
|
|
||||||
|
|
||||||
stream : function() {
|
stream : function() {
|
||||||
if(app.page) {
|
|
||||||
app.page.unbindInfScroll();
|
|
||||||
app.page.remove();
|
|
||||||
}
|
|
||||||
app.stream = new app.models.Stream();
|
app.stream = new app.models.Stream();
|
||||||
app.stream.fetch();
|
app.stream.fetch();
|
||||||
app.page = new app.views.Stream({model : app.stream});
|
this._initializeStreamView();
|
||||||
app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items});
|
|
||||||
app.shortcuts = app.shortcuts || new app.views.StreamShortcuts({el: $(document)});
|
|
||||||
|
|
||||||
var streamFacesView = new app.views.StreamFaces({collection : app.stream.items});
|
|
||||||
|
|
||||||
$("#main_stream").html(app.page.render().el);
|
|
||||||
$('#selected_aspect_contacts .content').html(streamFacesView.render().el);
|
|
||||||
this._hideInactiveStreamLists();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
photos : function(guid) {
|
photos : function(guid) {
|
||||||
|
|
@ -137,10 +118,10 @@ app.Router = Backbone.Router.extend({
|
||||||
this._hideInactiveStreamLists();
|
this._hideInactiveStreamLists();
|
||||||
},
|
},
|
||||||
|
|
||||||
aspects : function(){
|
aspects: function() {
|
||||||
app.aspects = new app.collections.Aspects(app.currentUser.get('aspects'));
|
app.aspects = new app.collections.Aspects(app.currentUser.get("aspects"));
|
||||||
this.aspects_list = new app.views.AspectsList({ collection: app.aspects });
|
this.aspectsList = new app.views.AspectsList({ collection: app.aspects });
|
||||||
this.aspects_list.render();
|
this.aspectsList.render();
|
||||||
this.aspects_stream();
|
this.aspects_stream();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -148,24 +129,8 @@ app.Router = Backbone.Router.extend({
|
||||||
var ids = app.aspects.selectedAspects('id');
|
var ids = app.aspects.selectedAspects('id');
|
||||||
app.stream = new app.models.StreamAspects([], { aspects_ids: ids });
|
app.stream = new app.models.StreamAspects([], { aspects_ids: ids });
|
||||||
app.stream.fetch();
|
app.stream.fetch();
|
||||||
|
this._initializeStreamView();
|
||||||
app.page = new app.views.Stream({model : app.stream});
|
|
||||||
app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items});
|
|
||||||
app.publisher.setSelectedAspects(ids);
|
app.publisher.setSelectedAspects(ids);
|
||||||
|
|
||||||
var streamFacesView = new app.views.StreamFaces({collection : app.stream.items});
|
|
||||||
|
|
||||||
$("#main_stream").html(app.page.render().el);
|
|
||||||
$('#selected_aspect_contacts .content').html(streamFacesView.render().el);
|
|
||||||
this._hideInactiveStreamLists();
|
|
||||||
},
|
|
||||||
|
|
||||||
_hideInactiveStreamLists: function() {
|
|
||||||
if(this.aspects_list && Backbone.history.fragment !== "aspects")
|
|
||||||
this.aspects_list.hideAspectsList();
|
|
||||||
|
|
||||||
if(this.followedTagsView && Backbone.history.fragment !== "followed_tags")
|
|
||||||
this.followedTagsView.hideFollowedTags();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
bookmarklet: function() {
|
bookmarklet: function() {
|
||||||
|
|
@ -179,6 +144,33 @@ app.Router = Backbone.Router.extend({
|
||||||
this.renderPage(function() { return new app.pages.Profile({
|
this.renderPage(function() { return new app.pages.Profile({
|
||||||
el: $('body > .container-fluid')
|
el: $('body > .container-fluid')
|
||||||
}); });
|
}); });
|
||||||
|
},
|
||||||
|
|
||||||
|
_hideInactiveStreamLists: function() {
|
||||||
|
if(this.aspectsList && Backbone.history.fragment !== "aspects") {
|
||||||
|
this.aspectsList.hideAspectsList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.followedTagsView && Backbone.history.fragment !== "followed_tags") {
|
||||||
|
this.followedTagsView.hideFollowedTags();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_initializeStreamView: function() {
|
||||||
|
if(app.page) {
|
||||||
|
app.page.unbindInfScroll();
|
||||||
|
app.page.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.page = new app.views.Stream({model : app.stream});
|
||||||
|
app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items});
|
||||||
|
app.shortcuts = app.shortcuts || new app.views.StreamShortcuts({el: $(document)});
|
||||||
|
|
||||||
|
var streamFacesView = new app.views.StreamFaces({collection : app.stream.items});
|
||||||
|
|
||||||
|
$("#main_stream").html(app.page.render().el);
|
||||||
|
$("#selected_aspect_contacts .content").html(streamFacesView.render().el);
|
||||||
|
this._hideInactiveStreamLists();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,6 @@ Diaspora::Application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Streams
|
# Streams
|
||||||
get "participate" => "streams#activity" # legacy
|
|
||||||
get "explore" => "streams#multi" # legacy
|
|
||||||
|
|
||||||
get "activity" => "streams#activity", :as => "activity_stream"
|
get "activity" => "streams#activity", :as => "activity_stream"
|
||||||
get "stream" => "streams#multi", :as => "stream"
|
get "stream" => "streams#multi", :as => "stream"
|
||||||
get "public" => "streams#public", :as => "public_stream"
|
get "public" => "streams#public", :as => "public_stream"
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ describe('app.Router', function () {
|
||||||
factory.aspectAttrs()
|
factory.aspectAttrs()
|
||||||
]);
|
]);
|
||||||
var aspectsListView = new app.views.AspectsList({collection: aspects}).render();
|
var aspectsListView = new app.views.AspectsList({collection: aspects}).render();
|
||||||
router.aspects_list = aspectsListView;
|
router.aspectsList = aspectsListView;
|
||||||
|
|
||||||
expect(aspectsListView.$el.html()).not.toBe("");
|
expect(aspectsListView.$el.html()).not.toBe("");
|
||||||
router.stream();
|
router.stream();
|
||||||
|
|
@ -61,6 +61,14 @@ describe('app.Router', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("aspects", function() {
|
||||||
|
it("calls _initializeStreamView", function() {
|
||||||
|
spyOn(app.router, "_initializeStreamView");
|
||||||
|
app.router.aspects();
|
||||||
|
expect(app.router._initializeStreamView).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("bookmarklet", function() {
|
describe("bookmarklet", function() {
|
||||||
it('routes to bookmarklet even if params have linefeeds', function() {
|
it('routes to bookmarklet even if params have linefeeds', function() {
|
||||||
var router = new app.Router();
|
var router = new app.Router();
|
||||||
|
|
@ -70,4 +78,63 @@ describe('app.Router', function () {
|
||||||
expect(route).toHaveBeenCalled();
|
expect(route).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("stream", function() {
|
||||||
|
it("calls _initializeStreamView", function() {
|
||||||
|
spyOn(app.router, "_initializeStreamView");
|
||||||
|
app.router.stream();
|
||||||
|
expect(app.router._initializeStreamView).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("_initializeStreamView", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
delete app.page;
|
||||||
|
delete app.publisher;
|
||||||
|
delete app.shortcuts;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets app.page", function() {
|
||||||
|
expect(app.page).toBeUndefined();
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(app.page).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets app.publisher", function() {
|
||||||
|
expect(app.publisher).toBeUndefined();
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(app.publisher).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("doesn't set app.publisher if already defined", function() {
|
||||||
|
app.publisher = { jasmineTestValue: 42 };
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(app.publisher.jasmineTestValue).toEqual(42);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets app.shortcuts", function() {
|
||||||
|
expect(app.shortcuts).toBeUndefined();
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(app.shortcuts).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("doesn't set app.shortcuts if already defined", function() {
|
||||||
|
app.shortcuts = { jasmineTestValue: 42 };
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(app.shortcuts.jasmineTestValue).toEqual(42);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("unbinds inf scroll for old instances of app.page", function() {
|
||||||
|
var pageSpy = jasmine.createSpyObj("page", ["remove", "unbindInfScroll"]);
|
||||||
|
app.page = pageSpy;
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(pageSpy.unbindInfScroll).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls _hideInactiveStreamLists", function() {
|
||||||
|
spyOn(app.router, "_hideInactiveStreamLists");
|
||||||
|
app.router._initializeStreamView();
|
||||||
|
expect(app.router._hideInactiveStreamLists).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue