Added method for testing ember stuff

Collapse user actions in UI so it stops looking crazy
Removed dud dupe user action TOPIC_RESPONSE
Always show the owner of a post on the user page, actions by others at the bottom
This commit is contained in:
Sam Saffron
2013-02-13 20:38:43 +11:00
parent 4e9d9138d6
commit 161420fac0
19 changed files with 304 additions and 2129 deletions

View File

@@ -220,7 +220,6 @@ window.Discourse = Ember.Application.createWithMixins
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus)
Discourse.insertProbes()
# subscribe to any site customizations that are loaded
$('link.custom-css').each ->
split = @href.split("/")

View File

@@ -1,10 +1,3 @@
RESPONSE = "6"
MENTION = "7"
TOPIC_RESPONSE = "8"
QUOTE = "9"
NEW_PRIVATE_MESSAGE = "12"
GOT_PRIVATE_MESSAGE = "13"
window.Discourse.User = Discourse.Model.extend Discourse.Presence,
avatarLarge: (->
@@ -68,7 +61,7 @@ window.Discourse.User = Discourse.Model.extend Discourse.Presence,
callback(message)
filterStream: (filter)->
filter = Discourse.User.statGroups[filter].join(",") if Discourse.User.statGroups[filter]
filter = Discourse.UserAction.statGroups[filter].join(",") if Discourse.UserAction.statGroups[filter]
@set('streamFilter', filter)
@set('stream', Em.A())
@loadMoreUserActions()
@@ -97,6 +90,7 @@ window.Discourse.User = Discourse.Model.extend Discourse.Presence,
if result and result.user_actions and result.user_actions.each
result.user_actions.each (i)=>
stream.pushObject(Discourse.UserAction.create(i))
stream = Discourse.UserAction.collapseStream(stream)
@set('stream', stream)
callback() if callback
@@ -104,7 +98,7 @@ window.Discourse.User = Discourse.Model.extend Discourse.Presence,
total=0
return 0 unless stats = @get('stats')
@get('stats').each (s)->
total+= parseInt(s.count) unless s.action_type is NEW_PRIVATE_MESSAGE || s.action_type is GOT_PRIVATE_MESSAGE
total+= parseInt(s.count) unless s.get("isPM")
total
).property('stats.@each')
@@ -112,7 +106,7 @@ window.Discourse.User = Discourse.Model.extend Discourse.Presence,
r = []
return r if @blank('stats')
@get('stats').each (s)->
r.push s unless (s.action_type == NEW_PRIVATE_MESSAGE || s.action_type == GOT_PRIVATE_MESSAGE)
r.push s unless s.get('isPM')
r
).property('stats.@each')
@@ -120,14 +114,14 @@ window.Discourse.User = Discourse.Model.extend Discourse.Presence,
r = []
return r if @blank('stats')
@get('stats').each (s)->
r.push s if (s.action_type is NEW_PRIVATE_MESSAGE or s.action_type is GOT_PRIVATE_MESSAGE)
r.push s if s.get('isPM')
r
).property('stats.@each')
inboxCount: (->
r = 0
@get('stats').each (s)->
if s.action_type is GOT_PRIVATE_MESSAGE
if s.action_type == Discourse.UserAction.GOT_PRIVATE_MESSAGE
r = s.count
return false
return r
@@ -136,7 +130,7 @@ window.Discourse.User = Discourse.Model.extend Discourse.Presence,
sentItemsCount: (->
r = 0
@get('stats').each (s)->
if s.action_type is NEW_PRIVATE_MESSAGE
if s.action_type == Discourse.UserAction.NEW_PRIVATE_MESSAGE
r = s.count
return false
return r
@@ -155,10 +149,13 @@ window.Discourse.User.reopenClass
g = {}
stats.each (s) =>
found = false
for k,v of @statGroups
for k,v of Discourse.UserAction.statGroups
if v.contains(s.action_type)
found = true
g[k] = {count: 0} unless g[k]
g[k] = Em.Object.create(
description: Em.String.i18n("user_action_descriptions.#{k}")
count: 0
action_type: parseInt(k,10)) unless g[k]
g[k].count += parseInt(s.count)
c = g[k].count
if s.action_type == k
@@ -172,24 +169,26 @@ window.Discourse.User.reopenClass
).exclude (s)->
!s
statGroups: (->
g = {}
g[RESPONSE] = [RESPONSE,MENTION,TOPIC_RESPONSE,QUOTE]
g
)()
find: (username) ->
promise = new RSVP.Promise()
$.ajax
url: "/users/" + username + '.json',
success: (json) =>
json.user.stats = @groupStats(json.user.stats)
json.user.stream = json.user.stream.map (ua) -> Discourse.UserAction.create(ua) if json.user.stream
# todo: decompose to object
json.user.stats = @groupStats(json.user.stats.map (s)->
obj = Em.Object.create(s)
obj.isPM = obj.action_type == Discourse.UserAction.NEW_PRIVATE_MESSAGE ||
obj.action_type == Discourse.UserAction.GOT_PRIVATE_MESSAGE
obj
)
json.user.stream = Discourse.UserAction.collapseStream(json.user.stream.map (ua) ->
Discourse.UserAction.create(ua)) if json.user.stream
user = Discourse.User.create(json.user)
promise.resolve(user)
error: (xhr) -> promise.reject(xhr)
promise
createAccount: (name, email, password, username, passwordConfirm, challenge) ->
$.ajax
url: '/users'

View File

@@ -2,3 +2,104 @@ window.Discourse.UserAction = Discourse.Model.extend
postUrl:(->
Discourse.Utilities.postUrl(@get('slug'), @get('topic_id'), @get('post_number'))
).property()
isPM: (->
a = @get('action_type')
a == UserAction.NEW_PRIVATE_MESSAGE || UserAction.GOT_PRIVATE_MESSAGE
).property()
addChild: (action)->
groups = @get("childGroups")
unless groups
groups =
likes: Discourse.UserActionGroup.create(icon: "icon-heart")
stars: Discourse.UserActionGroup.create(icon: "icon-star")
edits: Discourse.UserActionGroup.create(icon: "icon-pencil")
bookmarks: Discourse.UserActionGroup.create(icon: "icon-bookmark")
@set("childGroups", groups)
ua = Discourse.UserAction
bucket = switch action.action_type
when ua.LIKE,ua.WAS_LIKED then "likes"
when ua.STAR then "stars"
when ua.EDIT then "edits"
when ua.BOOKMARK then "bookmarks"
current = groups[bucket]
current.push(action) if current
return
children:(->
g = @get("childGroups")
rval = []
if g
rval = [g.likes, g.stars, g.edits, g.bookmarks].filter((i) -> i.get("items") && i.get("items").length > 0)
rval
).property("childGroups")
switchToActing: ->
@set('username', @get('acting_username'))
@set('avatar_template', @get('acting_avatar_template'))
@set('name', @get('acting_name'))
window.Discourse.UserAction.reopenClass
collapseStream: (stream) ->
collapse = [@LIKE, @WAS_LIKED, @STAR, @EDIT, @BOOKMARK]
uniq = {}
collapsed = Em.A()
pos = 0
stream.each (item)->
key = "#{item.topic_id}-#{item.post_number}"
found = uniq[key]
if found == undefined
if collapse.indexOf(item.action_type) >= 0
current = Discourse.UserAction.create(item)
current.set('action_type',null)
current.set('description',null)
item.switchToActing()
current.addChild(item)
else
current = item
uniq[key] = pos
collapsed[pos] = current
pos += 1
else
if collapse.indexOf(item.action_type) >= 0
item.switchToActing()
collapsed[found].addChild(item)
else
collapsed[found].set('action_type', item.get('action_type'))
collapsed[found].set('description', item.get('description'))
collapsed
# in future we should be sending this through from the server
LIKE: 1
WAS_LIKED: 2
BOOKMARK: 3
NEW_TOPIC: 4
POST: 5
RESPONSE: 6
MENTION: 7
QUOTE: 9
STAR: 10
EDIT: 11
NEW_PRIVATE_MESSAGE: 12
GOT_PRIVATE_MESSAGE: 13
window.Discourse.UserAction.reopenClass
statGroups: (->
g = {}
g[Discourse.UserAction.RESPONSE] = [
Discourse.UserAction.RESPONSE,
Discourse.UserAction.MENTION,
Discourse.UserAction.QUOTE
]
g
)()

View File

@@ -0,0 +1,4 @@
window.Discourse.UserActionGroup = Discourse.Model.extend
push: (item)->
@items = [] unless @items
@items.push(item)

View File

@@ -12,6 +12,14 @@
<p class='excerpt'>
{{{unbound excerpt}}}
</p>
{{#each children}}
<div class='child-actions'>
<i class="icon {{unbound icon}}"></i>
{{#each items}}
<a href="/users/{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" avatarTemplatePath="avatar_template" ignoreTitle="true"}}</div></a>
{{/each}}
</div>
{{/each}}
{{/with}}
{{/collection}}
</div>