Project slug + Update projects sockets structure + Express to angular structure
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user