-
Notifications
You must be signed in to change notification settings - Fork 148
Activity Stream #79
base: master
Are you sure you want to change the base?
Activity Stream #79
Changes from 2 commits
4697d54
d5345bf
ca1102c
23bc381
d9c02c6
f5d93b5
a72153b
367f88d
f6587d9
fd4a44f
3381368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ node_modules | |
tmp | ||
docs/api | ||
builds | ||
|
||
# ide | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,25 @@ Handlebars.registerHelper 'startsWith', (string1, string2, options) -> | |
options.fn @ | ||
else | ||
options.inverse @ | ||
|
||
Handlebars.registerHelper 'activityResourceLink', (resource) -> | ||
escapeExpression = (expression) -> | ||
Handlebars.Utils.escapeExpression expression | ||
id = escapeExpression resource.id | ||
type = escapeExpression resource.type | ||
name = escapeExpression resource.name | ||
email = escapeExpression resource.email | ||
bucketSlug = escapeExpression resource.bucket?.slug | ||
|
||
if resource.id | ||
switch resource.type | ||
when 'entry' then href = '/' + mediator.options.adminSegment + '/buckets/' + bucketSlug + '/' + id | ||
when 'bucket' then href = '/' + mediator.options.adminSegment + '/buckets/' + bucketSlug | ||
when 'user' then href = '/' + mediator.options.adminSegment + '/users/' + email | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the server-side, you could create a mongoose virtual that just provides an "actionLink," might be nicer for the API anyway (especially if we eventually do email triggers from these activities). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could do that and I thought about that, too, but Rails taught me that this does not belong into the model. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appreciate the thinking here, but would prefer to just go with the link virtual on the model for now. It would be a few lines of code and do what we need. I've spent a lot of time investigating client-server rendering patterns in JS, and IMO, it's a lot of trouble. If you'd like to create a separate bounty for this and push forward, I'm happy to award, but I think it would present a big blocker on this when it's already close. |
||
|
||
link = '<a href="' + href + '">' + name + '</a>' | ||
else | ||
link = name | ||
|
||
new Handlebars.SafeString link; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Collection = require 'lib/collection' | ||
Activity = require 'models/activity' | ||
|
||
module.exports = class Activities extends Collection | ||
url: '/api/activities' | ||
model: Activity |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Model = require 'lib/model' | ||
|
||
module.exports = class Activity extends Model | ||
urlRoot: '/api/activities' | ||
|
||
hello: -> | ||
'test' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
<div class="row"> | ||
<h1 class="page-title color-yellow">Buckets</h1> | ||
|
||
<div class="col-md-4 col-sm-6"> | ||
<div class="col-md-12 col-sm-6"> | ||
<div class="panel"> | ||
<div class="panel-body"> | ||
<p class="lead">Buckets is an open-source CMS, built in Node.js, which is being actively developed by <a href="https://assembly.com/buckets" target="_blank">the community at Assembly</a>.</p> | ||
<p class="lead">Buckets is an open-source CMS, built in Node.js, which is being actively developed by <a | ||
href="https://assembly.com/buckets" target="_blank">the community at Assembly</a>.</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<h1 class="page-title">Recent Activity</h1> | ||
|
||
<div class="col-md-12 col-sm-4"> | ||
<div class="activities"> | ||
{{#if activities}} | ||
{{#each activities}} | ||
<div class="activity"> | ||
<a class="link-with-avatar" href="/{{adminSegment}}/users/{{actor.email}}">{{gravatar actor.email_hash}} <span class="actor-name">{{actor.name}}</span></a> | ||
{{action}} {{kind}} | ||
{{activityResourceLink resource}} | ||
{{timeAgo publishDate}} | ||
</div> | ||
{{/each}} | ||
{{else}} | ||
<div class="activity"> | ||
There has been no activity yet. | ||
</div> | ||
{{/if}} | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
_ = require 'underscore' | ||
PageView = require 'views/base/page' | ||
|
||
tpl = require 'templates/buckets/dashboard' | ||
|
||
module.exports = class DashboardView extends PageView | ||
template: tpl | ||
|
||
getTemplateData: -> | ||
_.extend super, | ||
activities: @collection.toJSON() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
express = require 'express' | ||
|
||
Activity = require '../../models/activity' | ||
|
||
module.exports = app = express() | ||
|
||
|
||
app.route('/activities') | ||
.get (req, res) -> | ||
return res.status(401).end() unless req.user | ||
|
||
Activity.find({}).sort('-publishDate').limit(20).populate('actor').exec (err, activities) -> | ||
if err | ||
res.send err, 400 | ||
else if activities | ||
res.send activities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is all the escaping necessary? Since we're supplying the resource ourself, and it goes through SafeString below-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't like what I was doing here (or what I had to do here) either. In general I was hoping to have some link and url helpers available to do something like:
link_to admin_user_path user
. More on that in response to your other comment.Regarding the escaping and using SafeString, I understood that because I'm using SafeString, I need to do the escaping (since SafeString expects a safe string).
See the link helper example on http://handlebarsjs.com/, where it says:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, sorry, you're right. In that case, though, let's just escape
name
since I think it's the only one susceptible to invalid user input-