Refactor hovercards, fixes #8315

closes #8316
This commit is contained in:
flaburgan 2021-10-30 11:31:51 +02:00 committed by Benjamin Neff
parent 37f081959c
commit f6c885394d
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
4 changed files with 35 additions and 28 deletions

View file

@ -10,6 +10,7 @@
## Bug fixes ## Bug fixes
* Ensure the log folder exists [#8287](https://github.com/diaspora/diaspora/pull/8287) * Ensure the log folder exists [#8287](https://github.com/diaspora/diaspora/pull/8287)
* Limit name length in header [#8313] (https://github.com/diaspora/diaspora/pull/8313) * Limit name length in header [#8313] (https://github.com/diaspora/diaspora/pull/8313)
* Fix fallback avatar in hovercards [#8316](https://github.com/diaspora/diaspora/pull/8316)
## Features ## Features
* Add tags to tumblr posts [#8244](https://github.com/diaspora/diaspora/pull/8244) * Add tags to tumblr posts [#8244](https://github.com/diaspora/diaspora/pull/8244)

View file

@ -19,10 +19,15 @@ app.views.Hovercard = app.views.Base.extend({
this.showMe = false; this.showMe = false;
this.parent = null; // current 'hovercardable' element that caused HC to appear this.parent = null; // current 'hovercardable' element that caused HC to appear
this.active = true; this.active = true;
}, },
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
person: this.person
});
},
postRenderTemplate: function() { postRenderTemplate: function() {
this.$el.appendTo($("body")); this.$el.appendTo($("body"));
@ -106,10 +111,9 @@ app.views.Hovercard = app.views.Base.extend({
if (app.currentUser.authenticated()) { if (app.currentUser.authenticated()) {
self.aspectMembershipDropdown = new app.views.AspectMembership({person: new app.models.Person(person)}); self.aspectMembershipDropdown = new app.views.AspectMembership({person: new app.models.Person(person)});
} }
self.person = person;
self.render(); self.render();
self._populateHovercardWith(person);
if( !self.showMe ) { if( !self.showMe ) {
// mouse has left element // mouse has left element
return; return;
@ -118,23 +122,6 @@ app.views.Hovercard = app.views.Base.extend({
}); });
}, },
_populateHovercardWith: function(person) {
this.avatarLink.attr("href", this.href());
this.personLink.attr("href", this.href());
this.personLink.text(person.name);
this.personID.text(person.diaspora_id);
if (person.profile) {
this.avatar.attr("src", person.profile.avatar);
// set hashtags
this.hashtags.empty();
this.hashtags.html($(_.map(person.profile.tags, function(tag) {
return $("<a></a>", {href: Routes.tag(tag)}).text("#" + tag)[0];
})));
}
},
_positionHovercard: function() { _positionHovercard: function() {
var p_pos = this.parent.offset(); var p_pos = this.parent.offset();
var p_height = this.parent.height(); var p_height = this.parent.height();

View file

@ -1,15 +1,19 @@
{{#with person}}
<div id="hovercard"> <div id="hovercard">
<a class='person_avatar'> <a class="person_avatar" href="{{urlTo 'person' guid}}">
<img class="avatar"> <img class="avatar" src="{{profile.avatar}}" />
</a> </a>
<h4> <h4>
<a class="person"></a> <a class="person" href="{{urlTo 'person' guid}}">{{name}}</a>
</h4> </h4>
<div class="handle"></div> <div class="handle">{{diaspora_id}}</div>
<div id="hovercard_dropdown_container"></div> <div id="hovercard_dropdown_container"></div>
<div class="card-footer"> <div class="card-footer">
<div class="footer-container"> <div class="footer-container">
<div class="hashtags"></div> <div class="hashtags">
{{fmtTags profile.tags}}
</div> </div>
</div> </div>
</div> </div>
</div>
{{/with}}

View file

@ -16,7 +16,11 @@ describe("app.views.Hovercard", function() {
this.view._populateHovercard(); this.view._populateHovercard();
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
responseText: JSON.stringify({id: 1337}) responseText: JSON.stringify({
id: 1337,
guid: "ba64fce01b04013aa8db34c93d7886ce",
name: "Edward Snowden"
})
}); });
expect(this.view.aspectMembershipDropdown).toEqual(undefined); expect(this.view.aspectMembershipDropdown).toEqual(undefined);
}); });
@ -56,7 +60,11 @@ describe("app.views.Hovercard", function() {
this.view._populateHovercard(); this.view._populateHovercard();
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
responseText: JSON.stringify({id: 1337}) responseText: JSON.stringify({
id: 1337,
guid: "ba64fce01b04013aa8db34c93d7886ce",
name: "Edward Snowden"
})
}); });
expect(this.view.aspectMembershipDropdown).not.toEqual(undefined); expect(this.view.aspectMembershipDropdown).not.toEqual(undefined);
}); });
@ -65,7 +73,14 @@ describe("app.views.Hovercard", function() {
this.view._populateHovercard(); this.view._populateHovercard();
jasmine.Ajax.requests.mostRecent().respondWith({ jasmine.Ajax.requests.mostRecent().respondWith({
status: 200, status: 200,
responseText: JSON.stringify({id: 1337, profile: {tags: ["first", "second"]}}) responseText: JSON.stringify({
id: 1337,
guid: "ba64fce01b04013aa8db34c93d7886ce",
name: "Edward Snowden",
profile: {
tags: ["first", "second"]
}
})
}); });
var first = this.view.hashtags.find("a:contains('#first')"); var first = this.view.hashtags.find("a:contains('#first')");