diff --git a/app/assets/javascripts/discourse/controllers/user-summary.js.es6 b/app/assets/javascripts/discourse/controllers/user-summary.js.es6 new file mode 100644 index 000000000..b8c414521 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/user-summary.js.es6 @@ -0,0 +1,13 @@ +export default Ember.Controller.extend({ + needs: ['user'], + user: Em.computed.alias('controllers.user.model'), + moreTopics: function(){ + return this.get('model.topics').length > 5; + }.property('model'), + moreReplies: function(){ + return this.get('model.replies').length > 5; + }.property('model'), + moreBadges: function(){ + return this.get('model.badges').length > 5; + }.property('model') +}); diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index 2dbeea576..eff6ef3d7 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -10,6 +10,7 @@ import UserBadge from 'discourse/models/user-badge'; import UserActionStat from 'discourse/models/user-action-stat'; import UserAction from 'discourse/models/user-action'; import Group from 'discourse/models/group'; +import Topic from 'discourse/models/topic'; const User = RestModel.extend({ @@ -355,6 +356,38 @@ const User = RestModel.extend({ }); } }); + }, + + summary() { + return Discourse.ajax(`/users/${this.get("username_lower")}/summary.json`) + .then(json => { + const topicMap = {}; + + json.topics.forEach(t => { + topicMap[t.id] = Topic.create(t); + }); + + const badgeMap = {}; + Badge.createFromJson(json).forEach(b => { + badgeMap[b.id] = b; + }); + const summary = json["user_summary"]; + + summary.replies.forEach(r => { + r.topic = topicMap[r.topic_id]; + r.url = r.topic.urlForPostNumber(r.post_number); + r.createdAt = new Date(r.created_at); + }); + + summary.topics = summary.topic_ids.map(id => topicMap[id]); + + summary.badges = summary.badges.map(ub => { + const badge = badgeMap[ub.badge_id]; + badge.count = ub.count; + return badge; + }); + return summary; + }); } }); diff --git a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 index ae3b2f05f..f8c278db1 100644 --- a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 +++ b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 @@ -58,6 +58,7 @@ export default function() { // User routes this.resource('users'); this.resource('user', { path: '/users/:username' }, function() { + this.route('summary'); this.resource('userActivity', { path: '/activity' }, function() { this.route('topics'); this.route('replies'); diff --git a/app/assets/javascripts/discourse/routes/user-statistics.js.es6 b/app/assets/javascripts/discourse/routes/user-statistics.js.es6 deleted file mode 100644 index 610a10489..000000000 --- a/app/assets/javascripts/discourse/routes/user-statistics.js.es6 +++ /dev/null @@ -1,2 +0,0 @@ -export default Discourse.Route.extend({ -}); diff --git a/app/assets/javascripts/discourse/routes/user-summary.js.es6 b/app/assets/javascripts/discourse/routes/user-summary.js.es6 new file mode 100644 index 000000000..4b24ecc6a --- /dev/null +++ b/app/assets/javascripts/discourse/routes/user-summary.js.es6 @@ -0,0 +1,5 @@ +export default Discourse.Route.extend({ + model() { + return this.modelFor("User").summary(); + } +}); diff --git a/app/assets/javascripts/discourse/templates/user/summary.hbs b/app/assets/javascripts/discourse/templates/user/summary.hbs new file mode 100644 index 000000000..d6736b63a --- /dev/null +++ b/app/assets/javascripts/discourse/templates/user/summary.hbs @@ -0,0 +1,62 @@ +{{#if model.replies.length}} +
+

{{i18n "user.summary.top_replies"}}

+{{#each reply in model.replies}} + +{{/each}} +{{#if moreReplies}} +{{#link-to "userActivity.replies" user class="more"}}{{i18n "user.summary.more_replies"}}{{/link-to}} +{{/if}} +
+{{/if}} + +{{#if model.topics.length}} +
+

{{i18n "user.summary.top_topics"}}

+{{#each topic in model.topics}} + +{{/each}} +{{#if moreTopics}} +{{#link-to "userActivity.topics" user class="more"}}{{i18n "user.summary.more_topics"}}{{/link-to}} +{{/if}} +
+{{/if}} + +
+

{{i18n "user.summary.stats"}}

+
+
{{i18n "user.summary.topic_count"}}
+
{{model.topic_count}}
+
{{i18n "user.summary.post_count"}}
+
{{model.post_count}}
+
{{i18n "user.summary.likes_given"}}
+
{{model.likes_given}}
+
{{i18n "user.summary.likes_received"}}
+
{{model.likes_received}}
+
{{i18n "user.summary.days_visited"}}
+
{{model.days_visited}}
+
{{i18n "user.summary.posts_read_count"}}
+
{{model.posts_read_count}}
+
+
+ +{{#if model.badges.length}} +
+

{{i18n "user.summary.top_badges"}}

+{{#each badge in model.badges}} + {{user-badge badge=badge count=badge.count}} +{{/each}} +{{#if moreBadges}} +{{#link-to "user.badges" user class="more"}}{{i18n "user.summary.more_badges"}}{{/link-to}} +{{/if}} +
+{{/if}} + diff --git a/app/assets/javascripts/discourse/templates/user/user.hbs b/app/assets/javascripts/discourse/templates/user/user.hbs index c8f5eec79..6d9ac7af3 100644 --- a/app/assets/javascripts/discourse/templates/user/user.hbs +++ b/app/assets/javascripts/discourse/templates/user/user.hbs @@ -149,7 +149,7 @@