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
+46 -2
View File
@@ -3,13 +3,15 @@
// Dependencies
let paths = require( '../utils/paths.class.js' ),
util = require( 'util' ),
slug = require( 'slug' ),
File = require( './file.class.js' )
class Project
{
constructor( name )
constructor( options )
{
this.name = name
this.name = options.name
this.slug = slug( this.name )
this.folders = {
'.':
{
@@ -18,6 +20,23 @@ class Project
folders: {}
}
}
this.set_socket( options.socket )
}
set_socket( socket )
{
// Set up
this.original_socket = socket
this.socket = this.original_socket.of( '/project/' + this.slug )
// Connection event
this.socket.on( 'connection', ( socket ) =>
{
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
this.socket.emit( 'update_project', this.describe() )
} );
}
create_file( _path, _content )
@@ -44,6 +63,9 @@ class Project
if( _content )
file.create_version( _content )
// Emit
this.socket.emit( 'update_project', this.describe() )
return file
}
@@ -94,6 +116,9 @@ class Project
// Create version
file.create_version( _content )
// Emit
this.socket.emit( 'update_project', this.describe() )
}
delete_file( _path )
@@ -112,8 +137,12 @@ class Project
// File found
if( file )
{
// Delete file
file.destructor()
delete folder.files[ parsed_path.base ]
// Emit
this.socket.emit( 'update_project', this.describe() )
}
}
}
@@ -144,6 +173,9 @@ class Project
folder = _folder
}
// Emit
this.socket.emit( 'update_project', this.describe() )
return folder
}
@@ -216,8 +248,20 @@ class Project
delete_folder( folder )
// Emit
this.socket.emit( 'update_project', this.describe() )
return true
}
describe()
{
let result = {}
result.name = this.name
result.folders = this.folders
return result
}
}
module.exports = Project
+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
}
}