From a929eda8baa393dcd5df220d39fb14042841a319 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 12 Feb 2014 14:23:10 -0500 Subject: [PATCH] NEW: Add user name and title to group posts. --- .../controllers/group_post_controller.js | 21 +++++++++++++++++++ .../templates/group/index.js.handlebars | 9 ++++++-- app/serializers/group_post_serializer.rb | 15 ++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/discourse/controllers/group_post_controller.js diff --git a/app/assets/javascripts/discourse/controllers/group_post_controller.js b/app/assets/javascripts/discourse/controllers/group_post_controller.js new file mode 100644 index 00000000000..45d4553d559 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/group_post_controller.js @@ -0,0 +1,21 @@ +Discourse.GroupPostController = Em.ObjectController.extend({ + + byName: function() { + var result = "", + longName = this.get('user_long_name'), + title = this.get('user_title'); + + if (!Em.isEmpty(longName)) { + result += longName; + } + if (!Em.isEmpty(title)) { + if (result.length > 0) { + result += ", "; + } + result += title; + } + return result; + }.property() + +}); + diff --git a/app/assets/javascripts/discourse/templates/group/index.js.handlebars b/app/assets/javascripts/discourse/templates/group/index.js.handlebars index 8e73e8e3ebb..afb673f8870 100644 --- a/app/assets/javascripts/discourse/templates/group/index.js.handlebars +++ b/app/assets/javascripts/discourse/templates/group/index.js.handlebars @@ -1,5 +1,5 @@
- {{#groupedEach model}} + {{#each model itemController="groupPost"}}
{{#link-to 'user' user class="avatar-link"}}
{{avatar user imageSize="large" extraClasses="actor" ignoreTitle="true"}}
{{/link-to}} @@ -7,10 +7,15 @@ {{unbound title}} + {{#if byName}} + + {{unbound byName}} + + {{/if}}

{{{unbound cooked}}}

- {{/groupedEach}} + {{/each}}
diff --git a/app/serializers/group_post_serializer.rb b/app/serializers/group_post_serializer.rb index db451432a94..cd234234013 100644 --- a/app/serializers/group_post_serializer.rb +++ b/app/serializers/group_post_serializer.rb @@ -3,7 +3,9 @@ class GroupPostSerializer < ApplicationSerializer :cooked, :created_at, :title, - :url + :url, + :user_title, + :user_long_name has_one :user, serializer: BasicUserSerializer, embed: :objects @@ -11,5 +13,16 @@ class GroupPostSerializer < ApplicationSerializer object.topic.title end + def user_long_name + object.user.try(:name) + end + + def user_title + object.user.try(:title) + end + + def include_user_long_name? + SiteSetting.enable_names? + end end