Skip to content

Commit

Permalink
flushing out the rest of the core
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Breed committed Mar 3, 2012
1 parent b62c881 commit 5b0a25e
Show file tree
Hide file tree
Showing 20 changed files with 561 additions and 56 deletions.
46 changes: 45 additions & 1 deletion app.js
Expand Up @@ -13,6 +13,8 @@ var
models = require('./lib/models'),
mongooseAuth = models.mongooseAuth;

var sio = require('socket.io');

// Create server instance

var app = express.createServer(
Expand Down Expand Up @@ -48,17 +50,59 @@ app.configure('production', function(){

mongooseAuth.helpExpress( app );

// Web Sockets

var io = sio.listen( app );

io.sockets.on('connection', function( socket ){

socket.on('disconnect', function () {
io.sockets.emit('user disconnected');
});

});

// Routes

app.get('/', routes.index);

app.get('/admin', routes.admin);

app.get('/api/repos', routes.github.repos);
app.get('/hooks', routes.hooks);

app.get('/api/orgs', routes.github.orgs);

app.get('/api/orgs/:org/repos', routes.github.org_repos);

app.post('/api/hook', function( req, res ){

var data = JSON.parse( req.body.payload );

io.sockets.emit( 'hook', data );

var commit = new models.commit( data );

commit.save(function(err){
if( err )
throw new Error(err);

res.send({}, 202);
});
});

app.get('/api/hooks', routes.github.hooks.index);

app.get('/api/commits', routes.commit.index);

app.get('/api/repos', routes.github.repos);

app.get('/api/repos/:user/:repo/hooks', routes.github.hooks.show);

app.post('/api/repos/:user/:repo/hooks', routes.github.hooks.create);

app.del('/api/repos/:user/:repo/hooks/:id', routes.github.hooks.del);

app.post('/api/repos/:user/:repo/hooks/:id/test', routes.github.hooks.test);

app.listen( process.env.PORT || 3000 );
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
64 changes: 64 additions & 0 deletions app/dashboard.js
@@ -0,0 +1,64 @@
var nm = require('./modules/namespace');

var CommitView = Backbone.View.extend({

tagName: 'li',

initialize: function(){
this.render();
},

render: function(){
var content = JST.commit( this.model.toJSON() );
this.$el.html( content ).prependTo('#commits');
}

});

/* ------------------------------ Model ------------------------------ */

var Commit = Backbone.Model.extend({

initialize: function(){
console.log(this);
this.view = new CommitView({ model: this });
}

});

/* ------------------------------ Collection ------------------------------ */

var CommitsCollection = Backbone.Collection.extend({

url: '/api/commits/',

model: Commit,

initialize: function(){
this.deferred = this.fetch();
}

});

/* ------------------------------ Socket ------------------------------ */

nm.init = function( $ ){

nm.commits = new CommitsCollection();

var socket = io.connect();

socket.on('connect', function(){

socket.on('hook', function( body ){

nm.commits.add( new Commit( body ) );

});

});

};


jQuery( nm.init );
24 changes: 24 additions & 0 deletions app/hooks.js
@@ -0,0 +1,24 @@
var nm = require('./modules/namespace');

$('.remove-hook').on('click', function( e ){
var $this = $(this);

$.ajax({
type: 'delete',
url: $this.attr('href')
}).done(function(){
$this.parent().remove();
});

return false;
});

$('.test-hook').on('click', function( e ){

$.post( $(this).attr('href'), function( data ){
console.log(data);
});

return false;
});

Empty file added app/modules/repos.js
Empty file.
21 changes: 20 additions & 1 deletion app/repos.js
Expand Up @@ -11,6 +11,15 @@ var RepoView = Backbone.View.extend({
render: function(){
var content = JST.repo( this.model.toJSON() );
this.$el.html( content ).appendTo('#repos');
},

events: {
"click a": "createHook"
},

createHook: function( e ){
this.model.createHook();
return false;
}

});
Expand All @@ -27,6 +36,16 @@ var Repo = Backbone.Model.extend({
this.view.render();
}, this);

},

createHook: function(){
$.post('/api/repos/'+ this.get('owner').login +'/'+ this.get('name') +'/hooks', {
name: "web",
active: true,
config: {
url: "http://dev.wookiehangover.com/api/hook"
}
});
}

});
Expand All @@ -49,7 +68,7 @@ var ReposCollection = Backbone.Collection.extend({

nm.init = function( $ ){

new ReposCollection();
nm.repos = new ReposCollection();

};

Expand Down
7 changes: 7 additions & 0 deletions app/templates/commit.hbs
@@ -0,0 +1,7 @@
<h1><a href="{{repository.url}}" target="_blank">{{ repository.name }}</a></h1>
{{#with head_commit}}
{{author.username}}
{{timestamp}}
<a href="{{url}}" target="_blank">view</a>
<p>{{message}}</p>
{{/with}}
1 change: 1 addition & 0 deletions app/templates/repo.hbs
@@ -1,2 +1,3 @@
<h1>{{ name }}</h1>
<p>{{description}}</p>
<a href="#">Create Hook</a>
2 changes: 2 additions & 0 deletions assets/css/style.css
Expand Up @@ -217,7 +217,9 @@ td { vertical-align: top; }
/* ==|== primary styles =====================================================
Author:
========================================================================== */
#container { width: 960px; margin: 0 auto; }

#repos article { border-bottom: 1px solid #ccc; }



Expand Down
113 changes: 110 additions & 3 deletions assets/js/src/app.js
Expand Up @@ -48,7 +48,95 @@
};
}
return this.require.define;
}).call(this)({"modules/localstorage": function(exports, require, module) {/**
}).call(this)({"dashboard": function(exports, require, module) {var nm = require('./modules/namespace');

var CommitView = Backbone.View.extend({

tagName: 'li',

initialize: function(){
this.render();
},

render: function(){
var content = JST.commit( this.model.toJSON() );
this.$el.html( content ).prependTo('#commits');
}

});

/* ------------------------------ Model ------------------------------ */

var Commit = Backbone.Model.extend({

initialize: function(){
console.log(this);
this.view = new CommitView({ model: this });
}

});

/* ------------------------------ Collection ------------------------------ */

var CommitsCollection = Backbone.Collection.extend({

url: '/api/commits/',

model: Commit,

initialize: function(){
this.deferred = this.fetch();
}

});

/* ------------------------------ Socket ------------------------------ */

nm.init = function( $ ){

nm.commits = new CommitsCollection();

var socket = io.connect();

socket.on('connect', function(){

socket.on('hook', function( body ){

nm.commits.add( new Commit( body ) );

});

});

};


jQuery( nm.init );
}, "hooks": function(exports, require, module) {var nm = require('./modules/namespace');

$('.remove-hook').on('click', function( e ){
var $this = $(this);

$.ajax({
type: 'delete',
url: $this.attr('href')
}).done(function(){
$this.parent().remove();
});

return false;
});

$('.test-hook').on('click', function( e ){

$.post( $(this).attr('href'), function( data ){
console.log(data);
});

return false;
});

}, "modules/localstorage": function(exports, require, module) {/**
* Backbone localStorage Adapter v1.0
* https://github.com/jeromegn/Backbone.localStorage
*/
Expand Down Expand Up @@ -184,7 +272,7 @@ Backbone.Model.prototype.idAttribute = "_id";
//}

module.exports = this.QuickHub;
}, "repos": function(exports, require, module) {var nm = require('./modules/namespace');
}, "modules/repos": function(exports, require, module) {}, "repos": function(exports, require, module) {var nm = require('./modules/namespace');

var RepoView = Backbone.View.extend({

Expand All @@ -197,6 +285,15 @@ var RepoView = Backbone.View.extend({
render: function(){
var content = JST.repo( this.model.toJSON() );
this.$el.html( content ).appendTo('#repos');
},

events: {
"click a": "createHook"
},

createHook: function( e ){
this.model.createHook();
return false;
}

});
Expand All @@ -213,6 +310,16 @@ var Repo = Backbone.Model.extend({
this.view.render();
}, this);

},

createHook: function(){
$.post('/api/repos/'+ this.get('owner').login +'/'+ this.get('name') +'/hooks', {
name: "web",
active: true,
config: {
url: "http://dev.wookiehangover.com/api/hook"
}
});
}

});
Expand All @@ -235,7 +342,7 @@ var ReposCollection = Backbone.Collection.extend({

nm.init = function( $ ){

new ReposCollection();
nm.repos = new ReposCollection();

};

Expand Down

0 comments on commit 5b0a25e

Please sign in to comment.