Skip to content
Extraits de code Groupes Projets
Valider f7bd0bbb rédigé par Steffen van Bergerem's avatar Steffen van Bergerem Validation de Jonne Haß
Parcourir les fichiers

DRY app/router.js

parent dccad3f7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -10,17 +10,12 @@ app.Router = Backbone.Router.extend({
"user/edit": "settings",
"users/sign_up": "registration",
//new hotness
"posts/:id": "singlePost",
"p/:id": "singlePost",
//oldness
"activity": "stream",
"stream": "stream",
"participate": "stream",
"explore": "stream",
"aspects": "aspects",
"aspects/stream": "aspects_stream",
"commented": "stream",
"liked": "stream",
"mentions": "stream",
......@@ -86,24 +81,10 @@ app.Router = Backbone.Router.extend({
}
},
//below here is oldness
stream : function() {
if(app.page) {
app.page.unbindInfScroll();
app.page.remove();
}
app.stream = new app.models.Stream();
app.stream.fetch();
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();
this._initializeStreamView();
},
photos : function(guid) {
......@@ -137,10 +118,10 @@ app.Router = Backbone.Router.extend({
this._hideInactiveStreamLists();
},
aspects : function(){
app.aspects = new app.collections.Aspects(app.currentUser.get('aspects'));
this.aspects_list = new app.views.AspectsList({ collection: app.aspects });
this.aspects_list.render();
aspects: function() {
app.aspects = new app.collections.Aspects(app.currentUser.get("aspects"));
this.aspectsList = new app.views.AspectsList({ collection: app.aspects });
this.aspectsList.render();
this.aspects_stream();
},
......@@ -148,24 +129,8 @@ app.Router = Backbone.Router.extend({
var ids = app.aspects.selectedAspects('id');
app.stream = new app.models.StreamAspects([], { aspects_ids: ids });
app.stream.fetch();
app.page = new app.views.Stream({model : app.stream});
app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items});
this._initializeStreamView();
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() {
......@@ -179,6 +144,33 @@ app.Router = Backbone.Router.extend({
this.renderPage(function() { return new app.pages.Profile({
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
......@@ -50,9 +50,6 @@ Diaspora::Application.routes.draw do
end
# Streams
get "participate" => "streams#activity" # legacy
get "explore" => "streams#multi" # legacy
get "activity" => "streams#activity", :as => "activity_stream"
get "stream" => "streams#multi", :as => "stream"
get "public" => "streams#public", :as => "public_stream"
......
......@@ -43,7 +43,7 @@ describe('app.Router', function () {
factory.aspectAttrs()
]);
var aspectsListView = new app.views.AspectsList({collection: aspects}).render();
router.aspects_list = aspectsListView;
router.aspectsList = aspectsListView;
expect(aspectsListView.$el.html()).not.toBe("");
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() {
it('routes to bookmarklet even if params have linefeeds', function() {
var router = new app.Router();
......@@ -70,4 +78,63 @@ describe('app.Router', function () {
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();
});
});
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter