* add a (hash)tag helper for handlebars

* re-add stream on profile page
* more controller refactoring
This commit is contained in:
Florian Staudacher 2014-09-08 17:45:44 +02:00
parent 2572fb77fc
commit 1f724dd123
12 changed files with 76 additions and 22 deletions

View file

@ -77,6 +77,15 @@ Handlebars.registerHelper('localTime', function(timestamp) {
return new Date(timestamp).toLocaleString(); 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) { Handlebars.registerHelper('fmtText', function(text) {
return new Handlebars.SafeString(app.helpers.textFormatter(text, null)); return new Handlebars.SafeString(app.helpers.textFormatter(text, null));
}); });

View file

@ -2,7 +2,10 @@
//= require ../collections/photos //= require ../collections/photos
app.models.Stream = Backbone.Collection.extend({ app.models.Stream = Backbone.Collection.extend({
initialize : function(models, options){ 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()); this.items = new collectionClass([], this.collectionOptions());
}, },
@ -42,7 +45,7 @@ app.models.Stream = Backbone.Collection.extend({
}, },
basePath : function(){ basePath : function(){
return document.location.pathname; return this.streamPath || document.location.pathname;
}, },
timeFilteredPath : function(){ timeFilteredPath : function(){

View file

@ -7,7 +7,8 @@ app.pages.Profile = app.views.Base.extend({
subviews: { subviews: {
'#profile': 'sidebarView', '#profile': 'sidebarView',
'.profile_header': 'headerView' '.profile_header': 'headerView',
'#main_stream': 'streamView'
}, },
tooltipSelector: '.profile_button div, .sharing_message_container', 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}); 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) { blockPerson: function(evt) {
if( !confirm(Diaspora.I18n.t('ignore_user')) ) return; if( !confirm(Diaspora.I18n.t('ignore_user')) ) return;

View file

@ -144,7 +144,6 @@ app.Router = Backbone.Router.extend({
this.renderPage(function() { return new app.pages.Profile({ this.renderPage(function() { return new app.pages.Profile({
el: $('body > .container') el: $('body > .container')
}); }); }); });
// TODO call `this.stream()`
} }
}); });

View file

@ -4,10 +4,15 @@ app.views.ProfileHeader = app.views.Base.extend({
presenter: function() { presenter: function() {
return _.extend({}, this.defaultPresenter(), { 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() { postRenderTemplate: function() {
var self = this; var self = this;
var dropdownEl = this.$('.aspect_membership_dropdown.placeholder'); var dropdownEl = this.$('.aspect_membership_dropdown.placeholder');

View file

@ -1,6 +1,6 @@
<div id="author_info"> <div id="author_info">
<div class="right">
{{#if loggedIn}} {{#if loggedIn}}
<div class="right">
{{#if is_own_profile}} {{#if is_own_profile}}
{{!-- can't block myself, so don't check it here --}} {{!-- can't block myself, so don't check it here --}}
<a href="{{urlTo 'edit_profile'}}" class="button creation">{{t 'people.edit_my_profile'}}</a> <a href="{{urlTo 'edit_profile'}}" class="button creation">{{t 'people.edit_my_profile'}}</a>
@ -9,17 +9,31 @@
{{else}} {{else}}
<div class="placeholder aspect_membership_dropdown"></div> <div class="placeholder aspect_membership_dropdown"></div>
{{/if}}{{/if}} {{/if}}{{/if}}
{{/if}}
</div> </div>
{{/if}}
<h2>{{name}}</h2> <h2>{{name}}</h2>
<span class="diaspora_handle">{{diaspora_id}}</span> <span class="diaspora_handle">{{diaspora_id}}</span>
<div class="description">
{{#if loggedIn}} {{#if loggedIn}}
TODO <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}} {{/if}}
</div> </div>
{{/if}}
</div> </div>
<hr /> <hr />

View file

@ -185,7 +185,8 @@ class PeopleController < ApplicationController
private private
def find_person 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... # view this profile on the home pod, if you don't want to sign in...
authenticate_user! if remote_profile_with_no_user_session? authenticate_user! if remote_profile_with_no_user_session?
@ -219,6 +220,7 @@ class PeopleController < ApplicationController
end end
def photos_from(person) def photos_from(person)
return Photo.none unless user_signed_in?
@photos ||= if user_signed_in? @photos ||= if user_signed_in?
current_user.photos_from(person) current_user.photos_from(person)
else else
@ -230,6 +232,8 @@ class PeopleController < ApplicationController
# or use your own contacts if it's yourself # or use your own contacts if it's yourself
# see: `Contact#contacts` # see: `Contact#contacts`
def contact_contacts def contact_contacts
return Contact.none unless user_signed_in?
@contact_contacts ||= if @person == current_user.person @contact_contacts ||= if @person == current_user.person
current_user.contact_people current_user.contact_people
else else

View file

@ -45,6 +45,7 @@ class PersonPresenter < BasePresenter
end end
def relationship def relationship
return false unless current_user
contact = current_user_person_contact contact = current_user_person_contact
is_mutual = contact ? contact.mutual? : false is_mutual = contact ? contact.mutual? : false
@ -66,11 +67,11 @@ class PersonPresenter < BasePresenter
private private
def current_user_person_block 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 end
def current_user_person_contact def current_user_person_contact
@contact ||= current_user.contact_for(@presentable) @contact ||= (current_user ? current_user.contact_for(@presentable) : Contact.none)
end end
def has_contact? def has_contact?

View file

@ -3,7 +3,7 @@ class ProfilePresenter < BasePresenter
def base_hash def base_hash
{ id: id, { id: id,
tags: tag_string, tags: tags.pluck(:name),
bio: bio, bio: bio,
location: location, location: location,
gender: gender, gender: gender,

View file

@ -27,7 +27,7 @@
.profile_button .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? = 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 %ul#profile_information
- unless person.bio.blank? - unless person.bio.blank?

View file

@ -16,12 +16,12 @@
.span-18.last .span-18.last
.profile_header .profile_header
= render 'people/sub_header', :person => @person, :contact => @contact -# = render 'people/sub_header', :person => @person, :contact => @contact
.stream_container .stream_container
#main_stream.stream #main_stream.stream
- if @block.present? -# - if @block.present?
.dull .dull
= t('.ignoring', :name => @person.first_name) = t('.ignoring', :name => @person.first_name)

View file

@ -124,7 +124,11 @@ en:
is_sharing: "<%= name %> is sharing with you" is_sharing: "<%= name %> is sharing with you"
is_not_sharing: "<%= name %> is not sharing with you" is_not_sharing: "<%= name %> is not sharing with you"
profile: 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" location: "Location"
gender: "Gender" gender: "Gender"
born: "Birthday" born: "Birthday"