Project slug + Update projects sockets structure + Express to angular structure

This commit is contained in:
brunosimon
2016-06-06 21:52:58 +02:00
parent b2c68a7b73
commit e4ccca4fb6
13 changed files with 172 additions and 180 deletions
+30 -9
View File
@@ -4,27 +4,47 @@ let Project = require( './project.class.js' )
class Projects
{
constructor()
constructor( options )
{
this.all = {}
this.set_socket( options.socket )
}
set_socket( socket )
{
// Set up
this.original_socket = socket
this.socket = this.original_socket.of( '/projects' )
// Connection event
this.socket.on( 'connection', ( socket ) =>
{
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
this.socket.emit( 'update_projects', this.describe() )
} );
}
create_project( _name )
{
// Create project
let project = new Project( _name )
let project = new Project( { name: _name, socket: this.original_socket } )
// Save
this.all[ project.name ] = project
this.all[ project.slug ] = project
// Emit
this.socket.emit( 'update_projects', this.describe() )
// Return
return project
}
get_project_by_name( _name )
get_project_by_slug( _slug )
{
// Find project
let project = this.all[ _name ]
let project = this.all[ _slug ]
// Found
if( project )
@@ -39,12 +59,13 @@ class Projects
let result = {}
result.all = {}
for( let _name in this.all )
for( let _slug in this.all )
{
let _project = this.all[ _name ]
let _project = this.all[ _slug ]
result.all[ _name ] = {
name : _project.name
result.all[ _slug ] = {
slug: _project.slug,
name: _project.name
}
}