From 1f724dd12313aaf2fdcef313a91332ee57a4c2fd Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Mon, 8 Sep 2014 17:45:44 +0200 Subject: [PATCH] * add a (hash)tag helper for handlebars * re-add stream on profile page * more controller refactoring --- .../app/helpers/handlebars-helpers.js | 9 ++++++ app/assets/javascripts/app/models/stream.js | 7 ++-- app/assets/javascripts/app/pages/profile.js | 17 +++++++++- app/assets/javascripts/app/router.js | 1 - .../app/views/profile_header_view.js | 7 +++- .../templates/profile_header_tpl.jst.hbs | 32 +++++++++++++------ app/controllers/people_controller.rb | 6 +++- app/presenters/person_presenter.rb | 5 +-- app/presenters/profile_presenter.rb | 2 +- app/views/people/_profile_sidebar.html.haml | 2 +- app/views/people/show.html.haml | 4 +-- config/locales/javascript/javascript.en.yml | 6 +++- 12 files changed, 76 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/app/helpers/handlebars-helpers.js b/app/assets/javascripts/app/helpers/handlebars-helpers.js index 3affa6cdc..bfc718ba3 100644 --- a/app/assets/javascripts/app/helpers/handlebars-helpers.js +++ b/app/assets/javascripts/app/helpers/handlebars-helpers.js @@ -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 '' + + ' #' + tag + + ''; + }).join(' '); + return new Handlebars.SafeString(links); +}); + Handlebars.registerHelper('fmtText', function(text) { return new Handlebars.SafeString(app.helpers.textFormatter(text, null)); }); diff --git a/app/assets/javascripts/app/models/stream.js b/app/assets/javascripts/app/models/stream.js index d38806f51..e38b1bf35 100644 --- a/app/assets/javascripts/app/models/stream.js +++ b/app/assets/javascripts/app/models/stream.js @@ -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(){ diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index 65bb87eb0..6d07d5271 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -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( + '
'+ + Diaspora.I18n.t('profile.ignoring', {name: this.model.get('name')}) + + '
'); + 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; diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 706eecf1a..89e0fa8ac 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -144,7 +144,6 @@ app.Router = Backbone.Router.extend({ this.renderPage(function() { return new app.pages.Profile({ el: $('body > .container') }); }); - // TODO call `this.stream()` } }); diff --git a/app/assets/javascripts/app/views/profile_header_view.js b/app/assets/javascripts/app/views/profile_header_view.js index 2c3271224..e0ecdf522 100644 --- a/app/assets/javascripts/app/views/profile_header_view.js +++ b/app/assets/javascripts/app/views/profile_header_view.js @@ -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'); diff --git a/app/assets/templates/profile_header_tpl.jst.hbs b/app/assets/templates/profile_header_tpl.jst.hbs index 64ddda0db..9b2832d27 100644 --- a/app/assets/templates/profile_header_tpl.jst.hbs +++ b/app/assets/templates/profile_header_tpl.jst.hbs @@ -1,6 +1,6 @@
-
- {{#if loggedIn}} + {{#if loggedIn}} +
{{#if is_own_profile}} {{!-- can't block myself, so don't check it here --}} {{t 'people.edit_my_profile'}} @@ -9,17 +9,31 @@ {{else}}
{{/if}}{{/if}} - {{/if}} -
+
+ {{/if}}

{{name}}

{{diaspora_id}} -
- {{#if loggedIn}} - TODO - {{/if}} -
+ {{#if loggedIn}} +
+ {{#if has_tags}} + {{fmtTags profile.tags}} + {{#if is_own_profile}} + + {{t 'profile.edit'}} + + {{/if}} + {{else}} + {{#if is_own_profile}} + {{t 'profile.you_have_no_tags'}} + + {{t 'profile.add_some'}} + + {{/if}} + {{/if}} +
+ {{/if}}

diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index bdef09e2c..814675819 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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 diff --git a/app/presenters/person_presenter.rb b/app/presenters/person_presenter.rb index 2b15f4d4e..5c5dc23fd 100644 --- a/app/presenters/person_presenter.rb +++ b/app/presenters/person_presenter.rb @@ -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? diff --git a/app/presenters/profile_presenter.rb b/app/presenters/profile_presenter.rb index 24f8624f7..047955e71 100644 --- a/app/presenters/profile_presenter.rb +++ b/app/presenters/profile_presenter.rb @@ -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, diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index f94dd9aec..46730119a 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -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? diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 54a37c870..88971289a 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -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) diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index d9a783c35..e84e0b4a8 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -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"