From 0092c9c48347b2f005516345070a70379a919cf4 Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Sat, 6 Sep 2014 16:38:19 +0200 Subject: [PATCH] * create a handlebars view for the profile header * unblock the user via ajax --- app/assets/javascripts/app/models/person.js | 12 ++++++++++ app/assets/javascripts/app/pages/profile.js | 22 +++++++++++++++++-- .../app/views/profile_stream_view.js | 10 +++++++++ .../templates/profile_sidebar_tpl.jst.hbs | 4 ++-- .../templates/profile_stream_tpl.jst.hbs | 22 +++++++++++++++++++ app/presenters/block_presenter.rb | 6 +++++ app/presenters/person_presenter.rb | 16 +++++++++++--- app/views/aspects/_aspect_stream.haml | 13 ++++++++++- config/locales/javascript/javascript.en.yml | 3 +++ 9 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/app/views/profile_stream_view.js create mode 100644 app/assets/templates/profile_stream_tpl.jst.hbs create mode 100644 app/presenters/block_presenter.rb diff --git a/app/assets/javascripts/app/models/person.js b/app/assets/javascripts/app/models/person.js index cae208afa..634f6b6f0 100644 --- a/app/assets/javascripts/app/models/person.js +++ b/app/assets/javascripts/app/models/person.js @@ -35,5 +35,17 @@ app.models.Person = Backbone.Model.extend({ // return the jqXHR with Promise interface return block.save() .done(function() { app.events.trigger('person:block:'+self.id); }); + }, + + unblock: function() { + var self = this; + if( !this.get('block') ) { + var def = $.Deferred(); + return def.reject(); + } + + var block = new app.models.Block({id: this.get('block').id}); + return block.destroy() + .done(function() { app.events.trigger('person:unblock:'+self.id); }); } }); diff --git a/app/assets/javascripts/app/pages/profile.js b/app/assets/javascripts/app/pages/profile.js index f856d2d48..86182b580 100644 --- a/app/assets/javascripts/app/pages/profile.js +++ b/app/assets/javascripts/app/pages/profile.js @@ -2,11 +2,13 @@ // TODO: update the aspect_membership dropdown, too, every time we render the view... app.pages.Profile = app.views.Base.extend({ events: { - 'click #block_user_button': 'blockPerson' + 'click #block_user_button': 'blockPerson', + 'click #unblock_user_button': 'unblockPerson' }, subviews: { - '#profile .badge': 'sidebarView' + '#profile .badge': 'sidebarView', + '.stream_container': 'streamView' }, tooltipSelector: '.profile_button div, .sharing_message_container', @@ -20,6 +22,7 @@ app.pages.Profile = app.views.Base.extend({ // bind to global events var id = this.model.get('id'); app.events.on('person:block:'+id, this.reload, this); + app.events.on('person:unblock:'+id, this.reload, this); app.events.on('aspect_membership:update', this.reload, this); }, @@ -27,6 +30,10 @@ app.pages.Profile = app.views.Base.extend({ return new app.views.ProfileSidebar({model: this.model}); }, + streamView: function() { + return new app.views.ProfileStream({model: this.model}); + }, + blockPerson: function(evt) { if( !confirm(Diaspora.I18n.t('ignore_user')) ) return; @@ -41,6 +48,17 @@ app.pages.Profile = app.views.Base.extend({ return false; }, + unblockPerson: function(evt) { + var block = this.model.unblock(); + block.fail(function() { + Diaspora.page.flashMessages.render({ + success: false, + notice: Diaspora.I18.t('unblock_failed') + }); + }); + return false; + }, + reload: function() { this.model.fetch(); } diff --git a/app/assets/javascripts/app/views/profile_stream_view.js b/app/assets/javascripts/app/views/profile_stream_view.js new file mode 100644 index 000000000..d11fc2047 --- /dev/null +++ b/app/assets/javascripts/app/views/profile_stream_view.js @@ -0,0 +1,10 @@ + +app.views.ProfileStream = app.views.Base.extend({ + templateName: 'profile_stream', + + presenter: function() { + return _.extend({}, this.defaultPresenter(), { + is_blocked: this.model.isBlocked() + }); + } +}); diff --git a/app/assets/templates/profile_sidebar_tpl.jst.hbs b/app/assets/templates/profile_sidebar_tpl.jst.hbs index 70240e169..a3a3b7bea 100644 --- a/app/assets/templates/profile_sidebar_tpl.jst.hbs +++ b/app/assets/templates/profile_sidebar_tpl.jst.hbs @@ -11,7 +11,7 @@ {{#if is_receiving}}
- +
@@ -19,7 +19,7 @@ {{#if is_mutual}}
- +
diff --git a/app/assets/templates/profile_stream_tpl.jst.hbs b/app/assets/templates/profile_stream_tpl.jst.hbs new file mode 100644 index 000000000..78572f9f1 --- /dev/null +++ b/app/assets/templates/profile_stream_tpl.jst.hbs @@ -0,0 +1,22 @@ +
+
+ {{#if loggedIn}} + {{#if is_own_profile}} + {{!-- can't block myself, so don't check it here --}} + {{t 'people.edit_my_profile'}} + {{/if}} + {{#if is_blocked}} + {{t 'people.stop_ignoring'}} + {{else}} +
+ {{/if}} + {{/if}} +
+ +

{{name}}

+ {{diaspora_id}} + +
+ +
+
diff --git a/app/presenters/block_presenter.rb b/app/presenters/block_presenter.rb new file mode 100644 index 000000000..937d057b6 --- /dev/null +++ b/app/presenters/block_presenter.rb @@ -0,0 +1,6 @@ + +class BlockPresenter < BasePresenter + def base_hash + { id: id } + end +end diff --git a/app/presenters/person_presenter.rb b/app/presenters/person_presenter.rb index 46b3839f1..cb48f5b20 100644 --- a/app/presenters/person_presenter.rb +++ b/app/presenters/person_presenter.rb @@ -10,6 +10,7 @@ class PersonPresenter < BasePresenter def full_hash base_hash.merge({ relationship: relationship, + block: is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false, is_own_profile: own_profile? }) end @@ -45,12 +46,11 @@ class PersonPresenter < BasePresenter def relationship contact = current_user.contact_for(@presentable) - is_blocked = current_user.blocks.where(person_id: id).limit(1).any? is_mutual = contact ? contact.mutual? : false is_sharing = contact ? contact.sharing? : false is_receiving = contact ? contact.receiving? : false - if is_blocked then :blocked + if is_blocked? then :blocked elsif is_mutual then :mutual elsif is_sharing then :sharing elsif is_receiving then :receiving @@ -59,6 +59,16 @@ class PersonPresenter < BasePresenter end def person_is_following_current_user - @presentable.shares_with(@current_user) + @presentable.shares_with(current_user) + end + + private + + def current_user_person_block + @block ||= current_user.blocks.where(person_id: id).limit(1).first + end + + def is_blocked? + current_user_person_block.present? end end diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 46528920c..2f6d7c72e 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -6,7 +6,18 @@ %h3#aspect_stream_header.stream_title = stream.title -= render 'publisher/publisher', :selected_aspects => stream.aspects, :aspect_ids => stream.aspect_ids, :aspect => stream.aspect +- aspects = current_user.aspects +- aspect = aspects.first +- aspect_ids = aspects.map { |a| a.id } +- if stream + - aspects = stream.aspects + - aspect = stream.aspect + - aspect_ids = stream.aspect_ids + += render 'publisher/publisher', + selected_aspects: aspects, + aspect_ids: aspect_ids, + aspect: aspect = render 'aspects/no_posts_message' #gs-shim{:title => popover_with_close_html("3. #{t('.stay_updated')}"), 'data-content' => t('.stay_updated_explanation')} diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 9adceca69..688568c1f 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -17,6 +17,7 @@ en: exists: "The report already exists" ignore_user: "Ignore this user?" ignore_failed: "Unable to ignore this user" + unblock_failed: "Unblocking this user has failed" and: "and" comma: "," edit: "Edit" @@ -117,6 +118,8 @@ en: not_found: "and no one was found..." mention: "Mention" message: "Message" + edit_my_profile: "Edit my profile" + stop_ignoring: "Stop ignoring" helper: is_sharing: "<%= name %> is sharing with you" is_not_sharing: "<%= name %> is not sharing with you"