* add a (hash)tag helper for handlebars
* re-add stream on profile page * more controller refactoring
This commit is contained in:
parent
2572fb77fc
commit
1f724dd123
12 changed files with 76 additions and 22 deletions
|
|
@ -77,6 +77,15 @@ Handlebars.registerHelper('localTime', function(timestamp) {
|
|||
return new Date(timestamp).toLocaleString();
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('fmtTags', function(tags) {
|
||||
var links = _.map(tags, function(tag) {
|
||||
return '<a class="tag" href="' + Routes.tag_path(tag) + '">' +
|
||||
' #' + tag +
|
||||
'</a>';
|
||||
}).join(' ');
|
||||
return new Handlebars.SafeString(links);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('fmtText', function(text) {
|
||||
return new Handlebars.SafeString(app.helpers.textFormatter(text, null));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
//= require ../collections/photos
|
||||
app.models.Stream = Backbone.Collection.extend({
|
||||
initialize : function(models, options){
|
||||
var collectionClass = options && options.collection || app.collections.Posts;
|
||||
if( options ) {
|
||||
var collectionClass = options.collection || app.collections.Posts;
|
||||
this.streamPath = options.basePath;
|
||||
}
|
||||
this.items = new collectionClass([], this.collectionOptions());
|
||||
},
|
||||
|
||||
|
|
@ -42,7 +45,7 @@ app.models.Stream = Backbone.Collection.extend({
|
|||
},
|
||||
|
||||
basePath : function(){
|
||||
return document.location.pathname;
|
||||
return this.streamPath || document.location.pathname;
|
||||
},
|
||||
|
||||
timeFilteredPath : function(){
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ app.pages.Profile = app.views.Base.extend({
|
|||
|
||||
subviews: {
|
||||
'#profile': 'sidebarView',
|
||||
'.profile_header': 'headerView'
|
||||
'.profile_header': 'headerView',
|
||||
'#main_stream': 'streamView'
|
||||
},
|
||||
|
||||
tooltipSelector: '.profile_button div, .sharing_message_container',
|
||||
|
|
@ -41,6 +42,20 @@ app.pages.Profile = app.views.Base.extend({
|
|||
return new app.views.ProfileHeader({model: this.model});
|
||||
},
|
||||
|
||||
streamView: function() {
|
||||
if( this.model.isBlocked() ) {
|
||||
$('#main_stream').empty().html(
|
||||
'<div class="dull">'+
|
||||
Diaspora.I18n.t('profile.ignoring', {name: this.model.get('name')}) +
|
||||
'</div>');
|
||||
return false;
|
||||
}
|
||||
|
||||
app.stream = new app.models.Stream(null, {basePath: Routes.person_stream_path(app.page.model.get('guid'))});
|
||||
app.stream.fetch();
|
||||
return new app.views.Stream({model: app.stream});
|
||||
},
|
||||
|
||||
blockPerson: function(evt) {
|
||||
if( !confirm(Diaspora.I18n.t('ignore_user')) ) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ app.Router = Backbone.Router.extend({
|
|||
this.renderPage(function() { return new app.pages.Profile({
|
||||
el: $('body > .container')
|
||||
}); });
|
||||
// TODO call `this.stream()`
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,15 @@ app.views.ProfileHeader = app.views.Base.extend({
|
|||
|
||||
presenter: function() {
|
||||
return _.extend({}, this.defaultPresenter(), {
|
||||
is_blocked: this.model.isBlocked()
|
||||
is_blocked: this.model.isBlocked(),
|
||||
has_tags: this._hasTags()
|
||||
});
|
||||
},
|
||||
|
||||
_hasTags: function() {
|
||||
return (this.model.get('profile')['tags'].length > 0);
|
||||
},
|
||||
|
||||
postRenderTemplate: function() {
|
||||
var self = this;
|
||||
var dropdownEl = this.$('.aspect_membership_dropdown.placeholder');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<div id="author_info">
|
||||
<div class="right">
|
||||
{{#if loggedIn}}
|
||||
{{#if loggedIn}}
|
||||
<div class="right">
|
||||
{{#if is_own_profile}}
|
||||
{{!-- can't block myself, so don't check it here --}}
|
||||
<a href="{{urlTo 'edit_profile'}}" class="button creation">{{t 'people.edit_my_profile'}}</a>
|
||||
|
|
@ -9,17 +9,31 @@
|
|||
{{else}}
|
||||
<div class="placeholder aspect_membership_dropdown"></div>
|
||||
{{/if}}{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<h2>{{name}}</h2>
|
||||
<span class="diaspora_handle">{{diaspora_id}}</span>
|
||||
|
||||
<div class="description">
|
||||
{{#if loggedIn}}
|
||||
TODO
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if loggedIn}}
|
||||
<div class="description">
|
||||
{{#if has_tags}}
|
||||
{{fmtTags profile.tags}}
|
||||
{{#if is_own_profile}}
|
||||
<span class="hover_edit">
|
||||
<a href="{{urlTo 'edit_profile'}}">{{t 'profile.edit'}}</a>
|
||||
</span>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{#if is_own_profile}}
|
||||
<i>{{t 'profile.you_have_no_tags'}}</i>
|
||||
<span class="add_tags">
|
||||
<a href="{{urlTo 'edit_profile'}}">{{t 'profile.add_some'}}</a>
|
||||
</span>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
|
|
|||
|
|
@ -185,7 +185,8 @@ class PeopleController < ApplicationController
|
|||
private
|
||||
|
||||
def find_person
|
||||
@person = Person.find_from_guid_or_username(params)
|
||||
person_id = params[:id] || params[:person_id]
|
||||
@person = Person.find_from_guid_or_username({id: person_id})
|
||||
|
||||
# view this profile on the home pod, if you don't want to sign in...
|
||||
authenticate_user! if remote_profile_with_no_user_session?
|
||||
|
|
@ -219,6 +220,7 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
|
||||
def photos_from(person)
|
||||
return Photo.none unless user_signed_in?
|
||||
@photos ||= if user_signed_in?
|
||||
current_user.photos_from(person)
|
||||
else
|
||||
|
|
@ -230,6 +232,8 @@ class PeopleController < ApplicationController
|
|||
# or use your own contacts if it's yourself
|
||||
# see: `Contact#contacts`
|
||||
def contact_contacts
|
||||
return Contact.none unless user_signed_in?
|
||||
|
||||
@contact_contacts ||= if @person == current_user.person
|
||||
current_user.contact_people
|
||||
else
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class PersonPresenter < BasePresenter
|
|||
end
|
||||
|
||||
def relationship
|
||||
return false unless current_user
|
||||
contact = current_user_person_contact
|
||||
|
||||
is_mutual = contact ? contact.mutual? : false
|
||||
|
|
@ -66,11 +67,11 @@ class PersonPresenter < BasePresenter
|
|||
private
|
||||
|
||||
def current_user_person_block
|
||||
@block ||= current_user.blocks.where(person_id: id).limit(1).first
|
||||
@block ||= (current_user ? current_user.blocks.where(person_id: id).limit(1).first : Block.none)
|
||||
end
|
||||
|
||||
def current_user_person_contact
|
||||
@contact ||= current_user.contact_for(@presentable)
|
||||
@contact ||= (current_user ? current_user.contact_for(@presentable) : Contact.none)
|
||||
end
|
||||
|
||||
def has_contact?
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class ProfilePresenter < BasePresenter
|
|||
|
||||
def base_hash
|
||||
{ id: id,
|
||||
tags: tag_string,
|
||||
tags: tags.pluck(:name),
|
||||
bio: bio,
|
||||
location: location,
|
||||
gender: gender,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
.profile_button
|
||||
= link_to content_tag(:div, nil, :class => 'icons-ignoreuser block_user', :title => t('ignore'), :id => 'block_user_button', :data => { :person_id => @person.id }), '#', :rel => "nofollow" if @block.blank?
|
||||
|
||||
-if contact.sharing? || person == current_user.person
|
||||
-if user_signed_in? && (contact.sharing? || person == current_user.person)
|
||||
%ul#profile_information
|
||||
|
||||
- unless person.bio.blank?
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
|
||||
.span-18.last
|
||||
.profile_header
|
||||
= render 'people/sub_header', :person => @person, :contact => @contact
|
||||
-# = render 'people/sub_header', :person => @person, :contact => @contact
|
||||
|
||||
.stream_container
|
||||
|
||||
#main_stream.stream
|
||||
- if @block.present?
|
||||
-# - if @block.present?
|
||||
.dull
|
||||
= t('.ignoring', :name => @person.first_name)
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,11 @@ en:
|
|||
is_sharing: "<%= name %> is sharing with you"
|
||||
is_not_sharing: "<%= name %> is not sharing with you"
|
||||
profile:
|
||||
bio: 'Bio'
|
||||
edit: "edit"
|
||||
add_some: "add some"
|
||||
you_have_no_tags: "you have no tags!"
|
||||
ignoring: "You are ignoring all posts from <%= name %>."
|
||||
bio: "Bio"
|
||||
location: "Location"
|
||||
gender: "Gender"
|
||||
born: "Birthday"
|
||||
|
|
|
|||
Loading…
Reference in a new issue