Update structure + Add projects page
This commit is contained in:
+52
-40
@@ -37,15 +37,15 @@ class App
|
||||
this.projects = new Projects()
|
||||
|
||||
// Tests
|
||||
// var project = this.projects.create_project( 'test' )
|
||||
// project.create_folder( './toto' )
|
||||
// project.get_folder( './toto//tutu/tete', true )
|
||||
// project.create_file( './coucou/coco.txt', 'content 0' )
|
||||
// project.create_file( './test-1.txt', 'content 1' )
|
||||
// project.update_file( './toto/tata/lorem.txt', 'content 2' )
|
||||
// project.update_file( './toto/tata/ipsum.txt', 'content 3' )
|
||||
// project.delete_folder( './toto/tutu', true )
|
||||
// project.delete_file( './toto/tata/ipsum.txt' )
|
||||
var project = this.projects.create_project( 'dummy' )
|
||||
project.create_folder( './toto' )
|
||||
project.get_folder( './toto//tutu/tete', true )
|
||||
project.create_file( './coucou/coco.txt', 'content 0' )
|
||||
project.create_file( './test-1.txt', 'content 1' )
|
||||
project.update_file( './toto/tata/lorem.txt', 'content 2' )
|
||||
project.update_file( './toto/tata/ipsum.txt', 'content 3' )
|
||||
project.delete_folder( './toto/tutu', true )
|
||||
project.delete_file( './toto/tata/ipsum.txt' )
|
||||
// console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ class App
|
||||
// Set up
|
||||
this.express = express()
|
||||
this.express.use( helmet() )
|
||||
this.express.set( 'view engine', 'jade' );
|
||||
this.express.set( 'views', path.join( __dirname, 'views' ) );
|
||||
this.express.use( express.static( path.join( __dirname, 'public' ) ) );
|
||||
this.express.set( 'view engine', 'jade' )
|
||||
this.express.set( 'views', path.join( __dirname, 'views' ) )
|
||||
this.express.use( express.static( path.join( __dirname, 'public' ) ) )
|
||||
|
||||
// Controllers
|
||||
this.express.use( '/codes', require( './controllers/index.js' ) )
|
||||
this.express.use( '/', require( './controllers/index.js' ) )
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,57 +108,70 @@ class App
|
||||
set_socket()
|
||||
{
|
||||
// Set up
|
||||
this.sockets = {}
|
||||
this.sockets.main = socket_io.listen( this.server )
|
||||
this.sockets.app = this.sockets.main.of( '/app' )
|
||||
this.sockets.site = this.sockets.main.of( '/site' )
|
||||
this.sockets = {}
|
||||
this.sockets.main = socket_io.listen( this.server )
|
||||
this.sockets.app = this.sockets.main.of( '/app' )
|
||||
this.sockets.projects = this.sockets.main.of( '/projects' )
|
||||
|
||||
let project = null
|
||||
// Projects connection event
|
||||
this.sockets.projects.on( 'connection', ( socket ) =>
|
||||
{
|
||||
console.log( 'socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
|
||||
// Connection event
|
||||
socket.emit( 'update_projects', this.projects.describe() )
|
||||
} );
|
||||
|
||||
// App connection event
|
||||
this.sockets.app.on( 'connection', ( socket ) =>
|
||||
{
|
||||
// Set up
|
||||
let project = null
|
||||
|
||||
console.log( 'socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
|
||||
// Start project
|
||||
socket.on( 'start_project', ( data ) =>
|
||||
{
|
||||
project = this.projects.create_project( data.slug )
|
||||
// Create project
|
||||
project = this.projects.create_project( data.slug )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
// Create socket with specific namespace
|
||||
project.socket = this.sockets.main.of( '/project/' + project.name )
|
||||
|
||||
// Emit to projects socket
|
||||
this.sockets.projects.emit( 'update_projects', this.projects.describe() )
|
||||
|
||||
console.log( util.inspect( project.folders, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'update_file', ( data ) =>
|
||||
{
|
||||
project.update_file( data.path, data.content )
|
||||
|
||||
this.sockets.site.emit( 'update_project', project )
|
||||
project.socket.emit( 'update_project', project )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'create_file', ( data ) =>
|
||||
{
|
||||
project.create_file( data.path, data.content )
|
||||
project.create_file( data.path, data.content )
|
||||
project.socket.emit( 'update_project', project )
|
||||
|
||||
this.sockets.site.emit( 'update_project', project )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'delete_file', ( data ) =>
|
||||
{
|
||||
project.delete_file( data.path )
|
||||
project.delete_file( data.path )
|
||||
project.socket.emit( 'update_project', project )
|
||||
|
||||
this.sockets.site.emit( 'update_project', project )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
|
||||
socket.on( 'create_folder', ( data ) =>
|
||||
{
|
||||
project.create_folder( data.path, data.content )
|
||||
|
||||
this.sockets.site.emit( 'update_project', project )
|
||||
project.socket.emit( 'update_project', project )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
@@ -166,19 +179,18 @@ class App
|
||||
socket.on( 'delete_folder', ( data ) =>
|
||||
{
|
||||
project.delete_folder( data.path )
|
||||
|
||||
this.sockets.site.emit( 'update_project', project )
|
||||
project.socket.emit( 'update_project', project )
|
||||
|
||||
console.log( util.inspect( project, { depth: null, colors: true } ) )
|
||||
} )
|
||||
} )
|
||||
|
||||
this.sockets.site.on( 'connection', ( socket ) =>
|
||||
{
|
||||
console.log( 'socket site'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
// this.sockets.projects.on( 'connection', ( socket ) =>
|
||||
// {
|
||||
// console.log( 'socket site'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
|
||||
|
||||
socket.emit( 'update_project', project )
|
||||
} )
|
||||
// socket.emit( 'update_project', project )
|
||||
// } )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user