forked from mape/node-express-boilerplate
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activity Streams Boilerplate App Part 3 #4
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
1497600
Fix to be able to use MongoLab
4216be3
Merge branch 'master' of github.com:ciberch/node-activities-boilerpla…
aff18ec
Changes to support offline mode
86228b1
Modal and Create Activity
550c923
Before backbone
efe3881
Bump version of activity-streams-mongoose
78d43c2
Defaults for Backbone Models - still not sure if I like having to def…
28e591c
Link the new activity-streams-mongoose which supports location. Testi…
d3c479f
Use a Backbone View for the activity list
637de99
Fix for bad glyphicons paths
573739f
Like event not firing yet
bf9766d
In progress synching via backbone models via socket.io
79246d7
Add user friendly date
b5417fd
Remove separator because it messes up with filters
0135d8e
Add a photo upload form to test with
041419c
Woohoo endpoints to upload and download pics via Mongo Grid. TODO: Ad…
0b08a50
Sample JSON response for stream
507c006
Make it work on Cloud Foundry
4673fca
Add GUIDs so there are no conflicts with file names
f16962a
ImageMagick never ceases to impress me - This is an initial commit wh…
e980d64
Cleanup code for photo ingestion
60f6ecc
Added code to resize to sm and xs using ImageMagick
7fa299f
Only authenticated users can upload photos
0569f6e
fix deprecation warning
a07f221
Switch to use Mongoose Auth so we persist the users
4be5e4b
Display a user friendly date
003a039
Use Backbone's model events for triggering re render of view. Leverag…
42d27c0
Lock down the everyauth gem to 2.x to it works with Mongoose-Auth
9471b92
Mongoose-Auth now fully working and saving common attributes to db
6cff8af
In case there is no object
109e12c
Use the new version of activity-streams-mongoose
fa5060a
Refactor MongoDB use to a separate module
fdc6b4c
Further cleanup to encapsulate all the asms logic
acc5f61
Normalized the data from the 3 different providers
3cc5c59
Reduce the number of start activities
10f7a4e
Make it Cloud Foundry ready
db37380
Get the user location from Twitter and Email from Facebook
8001e2d
Add validator for model
d353fc1
Reduce the number of options so I dont have to create so many jade te…
11df1c0
Use a more specific message so we can add handling other types of mes…
de83bb5
Use the latest activity-stream-mongoose module and shrinkwrap it to l…
2fb0314
Change the activity create form to render client side via Backbone so…
79af1d0
Handle trimming strings directly
5dba60e
Bubble up errors reading the stream and add more .js files to get min…
598a00e
Move the check for the user being logged in to index.jade
df9703a
Make it clear to users that they can also sign up with Twitter, Faceb…
8b8ba0f
Make the name only show on hover
48a0ed6
New jade templates for object types used in this app
fbd7263
New file to submit the photos via ajax
89e5b4b
Update default backbone sync to use socket.io and replace activity cr…
deb8ef6
Compiled jade and how to generate it
b3b2445
No need for that
4fb1255
Switch to using regular MongoDB now in version 2.0
0d5bd62
Fixed bug with object Types and actor types
835dabe
New grpahics
29334c8
New hero unit look and better photo uploader
d91081c
Better Sizes
f47c6da
Better instructions
2522723
Fix to align Like and Post button better as well as Timestamp
333378c
Switch to have filters which query the backend
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| TESTS = $(shell find test/ -name '*.tobi.js' -o -name '*.test.js') | ||
|
|
||
| test: | ||
| @node_modules/.bin/mocha --reporter spec $(TESTS) | ||
|
|
||
| .PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,13 @@ npm install | |
| ``` | ||
|
|
||
| * Edit siteConfig.js if needed | ||
| * If you change the activities templates you need to regenerate the client side version of them, you can do this with `clientjade` | ||
|
|
||
| ```bash | ||
| npm install -g clientjade | ||
| clientjade views/*.* > public/js/templates.js | ||
| ``` | ||
|
|
||
| * Run locally | ||
|
|
||
| ``` bash | ||
|
|
@@ -80,6 +87,7 @@ vmc env-add $APP_NAME facebook_app_secret=fb_secret | |
| vmc env-add $APP_NAME NODE_ENV=production | ||
| vmc env-add $APP_NAME twitter_consumer_key=twitter_key | ||
| vmc env-add $APP_NAME twitter_consumer_secret=twitter_secret | ||
| vmc env-add $APP_NAME TMP=tmp | ||
|
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. Used by https://github.com/felixge/node-formidable which is used for processing uploaded photos |
||
| ``` | ||
|
|
||
| ## Finally | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "ignoreNodeModules" : true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| module.exports = function(app, cf) { | ||
| var https = require('https'); | ||
|
|
||
| var getUri = function(path) { | ||
| return app.siteConf.uri + path; | ||
| } | ||
|
|
||
| var defaultStream = "firehose"; | ||
|
|
||
| // Setup the Asms DB and User Schema and Auth | ||
| var defaultAvatar = getUri('/img/codercat-sm.jpg'); | ||
|
|
||
| var actorTypes = ['Person', 'Group', 'Application', 'Service']; | ||
| var objectTypes = ['Photo', 'Application', 'Article', 'Person', 'Place', 'Service']; | ||
| var verbs = ['Post', 'Favorite', 'Follow', 'Join', 'Like', 'Friend', 'Play', 'Save', 'Share', 'Tag', 'Create', 'Update', 'Read', 'Delete', 'Check In']; | ||
|
|
||
| var githubHash = {objectType: 'Service', displayName: 'GitHub', url: 'http://github.com', icon : {url: 'http://github.com/favicon.ico'}}; | ||
| var facebookHash = {objectType: 'Service', displayName: 'Facebook', url: 'http://facebook.com', icon : {url: 'http://facebook.com/favicon.ico'}}; | ||
| var twitterHash = {objectType: 'Service', displayName: 'Twitter', url: 'http://twitter.com', icon : {url: 'http://twitter.com/favicon.ico'}}; | ||
|
|
||
| var streamLib = require('activity-streams-mongoose')({ | ||
| mongoUrl: app.siteConf.mongoUrl, | ||
| redis: app.siteConf.redisOptions, | ||
| defaultActor: defaultAvatar | ||
| }); | ||
|
|
||
| var authentication = new require('./authentication.js')(streamLib, app.siteConf); | ||
|
|
||
| // Moved normalization to only be done on pre save | ||
| streamLib.types.UserSchema.pre('save', function (next) { | ||
| var user = this; | ||
| var svcUrl = null; | ||
| if (user.fb && user.fb.id) { | ||
| user.displayName = user.fb.name.full; | ||
| asmsDB.ActivityObject.findOne().where('url', facebookHash.url).exec(function(err, doc){ | ||
| if (err) throw err; | ||
| user.author = doc._id; | ||
| // Need to fetch the users image... | ||
| https.get({ | ||
| 'host': 'graph.facebook.com' | ||
| , 'path': '/me/picture?access_token='+ user.fb.accessToken | ||
| }, function(response) { | ||
| user.image = {url: response.headers.location}; | ||
| next(); | ||
| }).on('error', function(e) { | ||
| next(); | ||
| }); | ||
| }) | ||
| } else { | ||
| if (user.github && user.github.id) { | ||
| user.displayName = user.github.name; | ||
| var avatar = 'http://1.gravatar.com/avatar/'+ user.github.gravatarId + '?s=48' | ||
| user.image = {url: avatar}; | ||
| svcUrl = githubHash.url; | ||
| } else if (user.twit && user.twit.id) { | ||
| if (user.twit.geoEnabled && user.twit.location){ | ||
| //"ÜT: 34.075755,-118.393416" | ||
| var parts = user.twit.location.substr(4).split(','); | ||
| user.location = {position: {latitude: parts[0],longitude: parts[1]}}; | ||
| } | ||
| user.displayName = user.twit.name; | ||
| user.image = {url: user.twit.profileImageUrl}; | ||
| user.url = user.twit.url; | ||
| svcUrl = twitterHash.url; | ||
| } | ||
|
|
||
| if(!user.actor) { | ||
| asmsDB.ActivityObject.findOne().where('url', svcUrl).exec(function(err, doc){ | ||
| user.author = doc; | ||
| next(); | ||
| }); | ||
| } else { | ||
| next(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| var asmsDB = new streamLib.DB(streamLib.db, streamLib.types); | ||
| streamLib.asmsDB = asmsDB; | ||
|
|
||
| // Setup default Objects | ||
| // TODO: Change to find or create by | ||
| var thisInstance = {objectType : "AppInstance"}; | ||
| if (cf.app) { | ||
| thisInstance.image = {url: getUri('/img/cf-process.jpg')}; | ||
| thisInstance.url = "http://" + cf.host + ":" + cf.port; | ||
| thisInstance.displayName = "App Instance " + cf.app['instance_index'] + " at " + thisInstance.url; | ||
| thisInstance.content = cf.app['instance_id'] | ||
| } else { | ||
| thisInstance.displayName = "Instance 0 -- Local"; | ||
| } | ||
|
|
||
| var appOwner = {displayName: app.siteConf.user_email, image:{url: getUri("/img/me.jpg")}}; | ||
|
|
||
| var thisApp = new asmsDB.ActivityObject({ | ||
| objectType: 'Application', | ||
| displayName: 'Activity Streams App', | ||
| url: app.siteConf.uri, | ||
| image:{url: getUri('/img/as-logo-sm.png')} | ||
| }); | ||
|
|
||
| thisApp.save(function (err) { | ||
| if (err) throw err; | ||
| }); | ||
|
|
||
| var thisProvider = new asmsDB.ActivityObject({ | ||
| objectType: 'Service', | ||
| 'displayName': 'Cloud Foundry', | ||
| icon:{url: 'http://www.cloudfoundry.com/images/favicon.ico'} | ||
| }); | ||
| thisProvider.save(function(err){if (err) throw err}); | ||
|
|
||
| var github = new asmsDB.ActivityObject(githubHash); | ||
| github.save(function(err){if (err) throw err}); | ||
| var facebook = new asmsDB.ActivityObject(facebookHash); | ||
| facebook.save(function(err){if (err) throw err}); | ||
| var twitter = new asmsDB.ActivityObject(twitterHash); | ||
| twitter.save(function(err){if (err) throw err}); | ||
|
|
||
| var getCurrentUserObject = function(session) { | ||
| if (session.user) { | ||
| return session.user; | ||
| } else if(session.uid) { | ||
| var currentUser = {}; | ||
| currentUser.displayName = session.uid; | ||
| currentUser.image = { url: defaultAvatar}; | ||
| return currentUser; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| var publishActivity = function(desiredStream, currentUser, actHash) { | ||
|
|
||
| if (!currentUser) throw("Cannot publish activity without an actor"); | ||
| if (actHash && actHash.object && actHash.object.objectType && actHash.verb) { | ||
| actHash.actor = currentUser; | ||
|
|
||
| if (!actHash.title) { | ||
| actHash.title = actHash.verb + "ed a new " + actHash.object.objectType; | ||
| } | ||
|
|
||
| var act = new asmsDB.Activity(actHash); | ||
| // Send back the message to the users room. | ||
| act.publish(desiredStream); | ||
| } else { | ||
| console.log("Missing required parameters"); | ||
| console.log(actHash); | ||
| throw(new Error("Missing required parameters")); | ||
| } | ||
| }; | ||
|
|
||
| var getDistinct = function (req, res, next, term, init){ | ||
| var key = 'used.' + term; | ||
| req[key] = init ? init : []; | ||
| asmsDB.Activity.distinct(term, {streams: req.session.desiredStream}, function(err, docs) { | ||
| if (!err && docs) { | ||
| _.each(docs, function(result){ | ||
| req[key].push(result); | ||
| }); | ||
| next(); | ||
| } else { | ||
| next(new Error('Failed to fetch distinct ' + term)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| return { | ||
| helpers: { | ||
| getUri: getUri, | ||
| getCurrentUserObject : getCurrentUserObject, | ||
| publishActivity : publishActivity, | ||
| getDistinct : getDistinct | ||
| }, | ||
| default :{ | ||
| owner: appOwner, | ||
| provider : thisProvider, | ||
| app: thisApp, | ||
| instance: thisInstance, | ||
| avatar: defaultAvatar, | ||
| stream : defaultStream | ||
| }, | ||
| users : { | ||
| providers :{ | ||
| facebook: facebook, | ||
| twitter: twitter, | ||
| github : github | ||
| } | ||
| }, | ||
| streamLib : streamLib, | ||
| asmsDB: asmsDB, | ||
| authentication : authentication, | ||
| metadata: { | ||
| actorTypes: actorTypes, | ||
| objectTypes: objectTypes, | ||
| verbs: verbs | ||
| } | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Compile all jade templates into one js file for client side rendering