-
Notifications
You must be signed in to change notification settings - Fork 4
MicroCommunity Draft API
The current model behind MicroCommunity is about allowing you to create collections of content and users called containers. You can customize those collections by defining new content types, and assigning new membership roles to those users. The model also has the flexibility to allow you to to customize the organization, creation and appearance of those containers.
You can as well consider your website as a one global container. You can have a hybrid approach where you allow a global context next to containers which could be of several types as well.
The final goal is to allow you as a developer to easily develop social experience that exactly match the needs of your community/organization with ease and joy.
Defininig a module:
var microcommunity = require('microcommunity')
var app = module.exports = microcommunity.plugin(__dirname)Using that module:
var microcommunity = require('microcommunity')
, example = require('microcommunity-example')
var app = microcommunity.core()
//instaling plugins
app.use(example)
app = app.listen(3000)Your social network is a collection of SPAs, where each app represents a space where you can create custom interaction.
Each App consists of three parts: The first part is the part declared at the server. Here you declare the routes for your app, and fetch the needed data and pass it to the client app.
//main app
app.get('/', function(req, res){
res.loadPage('myapp', { message : 'Hello, World!'})
})A jade template that represents the server template of your app. Here you declare the main regions of your app. Your template is going to be integrated with the main layout of the website.
h1 Hello, World!A javascript app object. Here you place your logic. You should place the app module in the client/apps, so the system can identify it and run it in the web page once it is loaded.
define(['app'], function(App){
App.addInitializer(function(){
console.log(server.data.message)
})
return App
})Basically the backbone of the framework consists of items that are explored throughout streams and walls. Such items are posts, photos, polls. Every item can belong to a group of streams and a group of walls, and in case it belongs to a group of walls, it belongs to a main wall.
When you declare a model as an item. That means that you can make this item appear in the streams and walls you want. You should create that item in a separate collection, and the system will take care of the rest.
var mongoose = require('mongoose')
, models = require('microcommunity/models')
, itemable = require('microcommunity/models/plugins/itemable')
var photoSchema = new mongoose.Schema({
content: String
})
photoSchema.plugin(itemable)
Photo = models.define('Photo', 'photo', 'photos', photoSchema)
models.items.addItem('Photo', 'models/items/photo')
models.items.addPublisher('views/publishers/photo')The client item:
define([
'bb',
'models/item',
'views/items/photo',
'text!templates/items/post/message.html'
], function(Backbone, Item, PhotoView, messageTemplate){
var Photo = Item.extend({
collection : 'photos',
contentView : PhotoView,
messageTemplate : messageTemplate
})
return Photo
})App.addRegions({
publisher : '#publisher-region',
stream : '#stream-region'
})var Stream = streamModule(App, { items : server.data.items, type : 'wall' }, function(view){
App.stream.show(view)
})if (App.currentUser.id){
var profileUser = Models.User.findOrCreate(server.data.user)
var options = {
wall : profileUser.get('wall'),
identifier : 'user-wall'
}
var Publisher = publiserhModule(App, options, function(view){
App.publisher.show(view)
})
App.vent.on('publisher:newitem', function(item){
Stream.add(item)
})
}The publisher allows you to integrate new publisher modules
Those modules are used for you to display stream and walls passed from the server.
Activity types are special type of items. You need to declare the server model. You also need to define a item view on the client that the system.
ItemView has two entries: messageTemplate and contentView. You can also define custome actions on your defined items.
A stream is a collection of items ordered chronologically by the published field.
A wall is a collection of items in which they are ordered by the update field of the item, rather than the published field.
You can define a wall or stream for anything you want.
var mongoose = require('mongoose')
, models = require('./index')
, hasWall = require('./plugins/haswall')
, hasStream = require('./plugins/has-stream')
var userSchema = new mongoose.Schema({
displayName: String,
password : String,
email : String,
openId : String
})
userSchema.statics.findByEmail = function(email, callback){
this.model('User').findOne({ email : email }, function(err, user){
callback(err, user)
})
}
userSchema.plugin(hasWall, { displayNameAttribute : 'displayName' })
userSchema.plugin(hasStream)
var User = models.define('User', 'user', 'users', userSchema)A container is simply an analogy to a Facebook group. It has a wall, a stream and a home page. It also supports memberships and assining roles to these memberships. It can be extended by new activity types and new content types. In addition to the ability to freely customize and control how a class of containers is organized.
var mongoose = require('mongoose')
, models = require('microcommunity/models/index')
, isContainer = require('microcommunity/models/plugins/is-container')
var childrenGroupSchema = new mongoose.Schema({
thumbnailPath : String,
})
var containerOptions = {
containerType : 'childrengroups',
defaultRoles : [ 'child', 'mom' ]
}
childrenGroupSchema.plugin(isContainer, containerOptions)
models.define('ChildrenGroup', 'childrengroup', 'childrengroups', childrenGroupSchema)Defining a container type is by creating a new container schema
container.newMembership(req.user)
container.addRole(req.user, 'mc:admin')
container.addRole(req.user, 'mc:member') Now you can use middleware to control your app functional security.
var auth = require('microcommunity').auth
app.get('/some/path', auth.ensureAuthenticated, function(req, res){
//action code
})
app.get('/some/path', auth.ensureContainerRole('child'), function(req, res){
//action code
})app.get('/some/path', auth.ensureContainerAdmin, function(req, res){
//action code
})
app.get('/some/path', auth.ensureContainerMember, function(req, res){
//action code
})There is an API on the client app that you can use as well:
App.isLoggedIn()
App.isContainerMember()
App.isContainerAmin()
App.hasContainerRole('mom')You can create custome types of content. Those content can appear on new special pages (throughout custom apps). You can integrate those items with the container types you want. That means events and activities relating to your content type can appear a cross the streams and walls. You can also leverate the membership and role system and extend it.