Merge pull request #6487 from svbergerem/move-reshare-count
Move reshare count
This commit is contained in:
commit
77295ffcfb
13 changed files with 166 additions and 75 deletions
|
|
@ -81,6 +81,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure.
|
||||||
* Redesign and unify error pages [#6428](https://github.com/diaspora/diaspora/pull/6428)
|
* Redesign and unify error pages [#6428](https://github.com/diaspora/diaspora/pull/6428)
|
||||||
* Redesign and refactor report admin interface [#6378](https://github.com/diaspora/diaspora/pull/6378)
|
* Redesign and refactor report admin interface [#6378](https://github.com/diaspora/diaspora/pull/6378)
|
||||||
* Add permalink icon to stream elements [#6457](https://github.com/diaspora/diaspora/pull/6457)
|
* Add permalink icon to stream elements [#6457](https://github.com/diaspora/diaspora/pull/6457)
|
||||||
|
* Move reshare count to interactions for stream elements [#6487](https://github.com/diaspora/diaspora/pull/6487)
|
||||||
|
|
||||||
# 0.5.4.0
|
# 0.5.4.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,26 +5,32 @@ app.views.LikesInfo = app.views.Base.extend({
|
||||||
templateName : "likes-info",
|
templateName : "likes-info",
|
||||||
|
|
||||||
events : {
|
events : {
|
||||||
"click .expand_likes" : "showAvatars"
|
"click .expand-likes" : "showAvatars"
|
||||||
},
|
},
|
||||||
|
|
||||||
tooltipSelector : ".avatar",
|
tooltipSelector : ".avatar",
|
||||||
|
|
||||||
initialize : function() {
|
initialize : function() {
|
||||||
this.model.interactions.bind('change', this.render, this);
|
this.model.interactions.bind('change', this.render, this);
|
||||||
|
this.displayAvatars = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
presenter : function() {
|
presenter : function() {
|
||||||
return _.extend(this.defaultPresenter(), {
|
return _.extend(this.defaultPresenter(), {
|
||||||
likes : this.model.interactions.likes.toJSON(),
|
likes : this.model.interactions.likes.toJSON(),
|
||||||
likesCount : this.model.interactions.likesCount(),
|
likesCount : this.model.interactions.likesCount(),
|
||||||
likes_fetched : this.model.interactions.get("fetched"),
|
displayAvatars : this.model.interactions.get("fetched") && this.displayAvatars
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
showAvatars : function(evt){
|
showAvatars : function(evt){
|
||||||
if(evt) { evt.preventDefault() }
|
if(evt) { evt.preventDefault() }
|
||||||
this.model.interactions.fetch();
|
this.displayAvatars = true;
|
||||||
|
if(!this.model.interactions.get("fetched")){
|
||||||
|
this.model.interactions.fetch();
|
||||||
|
} else {
|
||||||
|
this.model.interactions.trigger("change");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
36
app/assets/javascripts/app/views/reshares_info_view.js
Normal file
36
app/assets/javascripts/app/views/reshares_info_view.js
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
||||||
|
|
||||||
|
app.views.ResharesInfo = app.views.Base.extend({
|
||||||
|
|
||||||
|
templateName : "reshares-info",
|
||||||
|
|
||||||
|
events : {
|
||||||
|
"click .expand-reshares" : "showAvatars"
|
||||||
|
},
|
||||||
|
|
||||||
|
tooltipSelector : ".avatar",
|
||||||
|
|
||||||
|
initialize : function() {
|
||||||
|
this.model.interactions.bind("change", this.render, this);
|
||||||
|
this.displayAvatars = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
presenter : function() {
|
||||||
|
return _.extend(this.defaultPresenter(), {
|
||||||
|
reshares : this.model.interactions.reshares.toJSON(),
|
||||||
|
resharesCount : this.model.interactions.resharesCount(),
|
||||||
|
displayAvatars : this.model.interactions.get("fetched") && this.displayAvatars
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
showAvatars : function(evt){
|
||||||
|
if(evt) { evt.preventDefault() }
|
||||||
|
this.displayAvatars = true;
|
||||||
|
if(!this.model.interactions.get("fetched")){
|
||||||
|
this.model.interactions.fetch();
|
||||||
|
} else {
|
||||||
|
this.model.interactions.trigger("change");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// @license-end
|
||||||
|
|
@ -7,6 +7,7 @@ app.views.StreamPost = app.views.Post.extend({
|
||||||
subviews : {
|
subviews : {
|
||||||
".feedback" : "feedbackView",
|
".feedback" : "feedbackView",
|
||||||
".likes" : "likesInfoView",
|
".likes" : "likesInfoView",
|
||||||
|
".reshares" : "resharesInfoView",
|
||||||
".comments" : "commentStreamView",
|
".comments" : "commentStreamView",
|
||||||
".post-content" : "postContentView",
|
".post-content" : "postContentView",
|
||||||
".oembed" : "oEmbedView",
|
".oembed" : "oEmbedView",
|
||||||
|
|
@ -55,6 +56,10 @@ app.views.StreamPost = app.views.Post.extend({
|
||||||
return new app.views.LikesInfo({model : this.model});
|
return new app.views.LikesInfo({model : this.model});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resharesInfoView : function(){
|
||||||
|
return new app.views.ResharesInfo({model : this.model});
|
||||||
|
},
|
||||||
|
|
||||||
feedbackView : function(){
|
feedbackView : function(){
|
||||||
if(!app.currentUser.authenticated()) { return null }
|
if(!app.currentUser.authenticated()) { return null }
|
||||||
return new app.views.Feedback({model : this.model});
|
return new app.views.Feedback({model : this.model});
|
||||||
|
|
|
||||||
|
|
@ -65,31 +65,6 @@
|
||||||
font-size: $font-size-small;
|
font-size: $font-size-small;
|
||||||
line-height: $font-size-small;
|
line-height: $font-size-small;
|
||||||
}
|
}
|
||||||
.likes {
|
|
||||||
margin-top: 10px;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 16px;
|
|
||||||
.author-name, .bd { display: inline-block; }
|
|
||||||
.author-name { margin-right: 3px; }
|
|
||||||
.entypo-heart {
|
|
||||||
display: inline-block;
|
|
||||||
font-size: 16px;
|
|
||||||
vertical-align: top;
|
|
||||||
margin-top: -2px;
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.stream_photo {
|
|
||||||
float: left;
|
|
||||||
margin-top: 6px;
|
|
||||||
}
|
|
||||||
.status-message-location {
|
|
||||||
font-size: $font-size-small;
|
|
||||||
color: $text-grey;
|
|
||||||
}
|
|
||||||
.leaflet-control-zoom {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.post-content p:last-of-type { margin-bottom: 0; }
|
.post-content p:last-of-type { margin-bottom: 0; }
|
||||||
.nsfw-shield {
|
.nsfw-shield {
|
||||||
color: $text-grey;
|
color: $text-grey;
|
||||||
|
|
@ -158,3 +133,37 @@
|
||||||
border: 1px solid $brand-primary;
|
border: 1px solid $brand-primary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stream_element {
|
||||||
|
.likes,
|
||||||
|
.reshares {
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 16px;
|
||||||
|
margin-top: 10px;
|
||||||
|
|
||||||
|
.author-name,
|
||||||
|
.bd {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.author-name { margin-right: 3px; }
|
||||||
|
|
||||||
|
.entypo-heart,
|
||||||
|
.entypo-reshare {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: $line-height-computed;
|
||||||
|
margin-right: 5px;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-message-location {
|
||||||
|
color: $text-grey;
|
||||||
|
font-size: $font-size-small;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-control-zoom {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
<i class="entypo-heart"></i>
|
<i class="entypo-heart"></i>
|
||||||
|
|
||||||
<div class="bd">
|
<div class="bd">
|
||||||
{{#unless likes_fetched}}
|
{{#unless displayAvatars}}
|
||||||
<a href="#" class="expand_likes gray">
|
<a href="#" class="expand-likes gray">
|
||||||
{{t "stream.likes" count=likesCount}}
|
{{t "stream.likes" count=likesCount}}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,6 @@
|
||||||
<a href="/posts/{{id}}">
|
<a href="/posts/{{id}}">
|
||||||
<time class="timeago" datetime="{{created_at}}"/>
|
<time class="timeago" datetime="{{created_at}}"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{#if interactions.reshares_count}}
|
|
||||||
-
|
|
||||||
{{t "stream.reshares" count=interactions.reshares_count}}
|
|
||||||
{{/if}}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{{/with}}
|
{{/with}}
|
||||||
|
|
|
||||||
23
app/assets/templates/reshares-info_tpl.jst.hbs
Normal file
23
app/assets/templates/reshares-info_tpl.jst.hbs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{{#if resharesCount}}
|
||||||
|
<div class="comment">
|
||||||
|
<div class="media">
|
||||||
|
<i class="entypo-reshare"></i>
|
||||||
|
|
||||||
|
<div class="bd">
|
||||||
|
{{#unless displayAvatars}}
|
||||||
|
<a href="#" class="expand-reshares gray">
|
||||||
|
{{t "stream.reshares" count=resharesCount}}
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
|
||||||
|
{{#each reshares}}
|
||||||
|
{{#linkToAuthor author}}
|
||||||
|
{{{personImage this 'small' 'micro'}}}
|
||||||
|
{{/linkToAuthor}}
|
||||||
|
{{/each}}
|
||||||
|
{{/unless}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
@ -49,11 +49,6 @@
|
||||||
<a href="/posts/{{id}}" class="permalink" title="{{t "stream.permalink"}}">
|
<a href="/posts/{{id}}" class="permalink" title="{{t "stream.permalink"}}">
|
||||||
<i class="entypo-link"></i>
|
<i class="entypo-link"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{{#if interactions.reshares_count}}
|
|
||||||
-
|
|
||||||
{{t "stream.reshares" count=interactions.reshares_count}}
|
|
||||||
{{/if}}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -62,6 +57,7 @@
|
||||||
|
|
||||||
<div class="feedback nsfw-hidden"> </div>
|
<div class="feedback nsfw-hidden"> </div>
|
||||||
<div class="likes nsfw-hidden"> </div>
|
<div class="likes nsfw-hidden"> </div>
|
||||||
|
<div class="reshares nsfw-hidden"> </div>
|
||||||
<div class="comments nsfw-hidden"> </div>
|
<div class="comments nsfw-hidden"> </div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
-# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
||||||
-# licensed under the Affero General Public License version 3 or later. See
|
|
||||||
-# the COPYRIGHT file.
|
|
||||||
|
|
||||||
= link_to (image_tag post.url(:thumb_large)), person_photo_path(post.author, post), class: 'stream_photo'
|
|
||||||
|
|
||||||
%h1
|
|
||||||
= post.pending
|
|
||||||
|
|
||||||
%p.photo_description
|
|
||||||
= post.text
|
|
||||||
|
|
||||||
= link_to t('.view_all', name: post.author_name), person_photos_path(post.author), class: "small_text"
|
|
||||||
|
|
@ -1,14 +1,6 @@
|
||||||
describe("app.views.LikesInfo", function(){
|
describe("app.views.LikesInfo", function(){
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||||
|
|
||||||
Diaspora.I18n.load({stream : {
|
|
||||||
pins : {
|
|
||||||
zero : "<%= count %> Pins",
|
|
||||||
one : "<%= count %> Pin"}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var posts = $.parseJSON(spec.readFixture("stream_json"));
|
var posts = $.parseJSON(spec.readFixture("stream_json"));
|
||||||
this.post = new app.models.Post(posts[0]); // post with a like
|
this.post = new app.models.Post(posts[0]); // post with a like
|
||||||
this.view = new app.views.LikesInfo({model: this.post});
|
this.view = new app.views.LikesInfo({model: this.post});
|
||||||
|
|
@ -18,7 +10,7 @@ describe("app.views.LikesInfo", function(){
|
||||||
it("displays a the like count if it is above zero", function() {
|
it("displays a the like count if it is above zero", function() {
|
||||||
spyOn(this.view.model.interactions, "likesCount").and.returnValue(3);
|
spyOn(this.view.model.interactions, "likesCount").and.returnValue(3);
|
||||||
this.view.render();
|
this.view.render();
|
||||||
expect($(this.view.el).find(".expand_likes").length).toBe(1);
|
expect($(this.view.el).find(".expand-likes").length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not display the like count if it is zero", function() {
|
it("does not display the like count if it is zero", function() {
|
||||||
|
|
@ -44,12 +36,10 @@ describe("app.views.LikesInfo", function(){
|
||||||
expect(this.post.interactions.fetch).toHaveBeenCalled();
|
expect(this.post.interactions.fetch).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets the fetched response to the model's likes", function(){
|
it("sets 'displayAvatars' to true", function(){
|
||||||
//placeholder... not sure how to test done functionalty here
|
this.view.displayAvatars = false;
|
||||||
});
|
this.view.showAvatars();
|
||||||
|
expect(this.view.displayAvatars).toBeTruthy();
|
||||||
it("re-renders the view", function(){
|
|
||||||
//placeholder... not sure how to test done functionalty here
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
46
spec/javascripts/app/views/reshares_info_view_spec.js
Normal file
46
spec/javascripts/app/views/reshares_info_view_spec.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
describe("app.views.ResharesInfo", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
loginAs({id : -1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||||
|
|
||||||
|
var posts = $.parseJSON(spec.readFixture("stream_json"));
|
||||||
|
this.post = new app.models.Post(posts[0]); // post with a like
|
||||||
|
this.view = new app.views.ResharesInfo({model: this.post});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe(".render", function(){
|
||||||
|
it("displays a the reshare count if it is above zero", function() {
|
||||||
|
spyOn(this.view.model.interactions, "resharesCount").and.returnValue(3);
|
||||||
|
this.view.render();
|
||||||
|
expect($(this.view.el).find(".expand-reshares").length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not display the reshare count if it is zero", function() {
|
||||||
|
spyOn(this.view.model.interactions, "resharesCount").and.returnValue(0);
|
||||||
|
this.view.render();
|
||||||
|
expect($(this.view.el).html().trim()).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fires on a model change", function(){
|
||||||
|
spyOn(this.view, "postRenderTemplate");
|
||||||
|
this.view.model.interactions.trigger("change");
|
||||||
|
expect(this.view.postRenderTemplate).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("showAvatars", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
spyOn(this.post.interactions, "fetch").and.callThrough();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls fetch on the model's reshare collection", function(){
|
||||||
|
this.view.showAvatars();
|
||||||
|
expect(this.post.interactions.fetch).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets 'displayAvatars' to true", function(){
|
||||||
|
this.view.displayAvatars = false;
|
||||||
|
this.view.showAvatars();
|
||||||
|
expect(this.view.displayAvatars).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -66,18 +66,16 @@ describe("app.views.StreamPost", function(){
|
||||||
}});
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
context("reshare", function(){
|
context("reshares", function(){
|
||||||
it("displays a reshare count", function(){
|
it("displays a reshare count", function(){
|
||||||
this.statusMessage.set({ interactions: {reshares_count : 2 }});
|
this.statusMessage.interactions.set({"reshares_count": 2});
|
||||||
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
||||||
|
|
||||||
expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.reshares', {count: 2}));
|
expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.reshares', {count: 2}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not display a reshare count for 'zero'", function(){
|
it("does not display a reshare count for 'zero'", function(){
|
||||||
this.statusMessage.interactions.set({ interactions: { reshares_count : 0}} );
|
this.statusMessage.interactions.set({"reshares_count": 0});
|
||||||
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
||||||
|
|
||||||
expect($(view.el).html()).not.toContain("0 Reshares");
|
expect($(view.el).html()).not.toContain("0 Reshares");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -86,13 +84,12 @@ describe("app.views.StreamPost", function(){
|
||||||
it("displays a like count", function(){
|
it("displays a like count", function(){
|
||||||
this.statusMessage.interactions.set({likes_count : 1});
|
this.statusMessage.interactions.set({likes_count : 1});
|
||||||
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
||||||
|
|
||||||
expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.likes', {count: 1}));
|
expect($(view.el).html()).toContain(Diaspora.I18n.t('stream.likes', {count: 1}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not display a like count for 'zero'", function(){
|
it("does not display a like count for 'zero'", function(){
|
||||||
this.statusMessage.interactions.set({likes_count : 0});
|
this.statusMessage.interactions.set({likes_count : 0});
|
||||||
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
var view = new this.PostViewClass({model : this.statusMessage}).render();
|
||||||
|
|
||||||
expect($(view.el).html()).not.toContain("0 Likes");
|
expect($(view.el).html()).not.toContain("0 Likes");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue