Connect data

This commit is contained in:
brunosimon
2016-06-05 01:14:23 +02:00
parent b61ddb5967
commit c8d111cf5c
10 changed files with 261 additions and 164 deletions
+6 -6
View File
@@ -77,7 +77,7 @@ class App
set_socket()
{
// Set up
this.socket = socket_io_client( `http://${this.options.domain}:${this.options.port}` )
this.socket = socket_io_client( `http://${this.options.domain}:${this.options.port}/app` )
// Connect event
this.socket.on( 'connect', () =>
@@ -106,7 +106,7 @@ class App
this.watcher.on( 'add', ( _path ) =>
{
// Set up
let relative_path = _path.replace( process.cwd() + '/', '' )
let relative_path = _path.replace( process.cwd(), '.' )
console.log( 'add:'.green.bold, relative_path )
@@ -122,7 +122,7 @@ class App
this.watcher.on( 'change', ( _path ) =>
{
// Set up
let relative_path = _path.replace( process.cwd() + '/', '' )
let relative_path = _path.replace( process.cwd(), '.' )
console.log( 'change:'.green.bold, relative_path )
@@ -138,7 +138,7 @@ class App
this.watcher.on( 'unlink', ( _path ) =>
{
// Set up
let relative_path = _path.replace( process.cwd() + '/', '' )
let relative_path = _path.replace( process.cwd(), '.' )
console.log( 'unlink:'.green.bold, relative_path )
@@ -150,7 +150,7 @@ class App
this.watcher.on( 'addDir', ( _path ) =>
{
// Set up
let relative_path = _path.replace( process.cwd() + '/', '' )
let relative_path = _path.replace( process.cwd(), '.' )
console.log( 'addDir:'.green.bold, relative_path )
@@ -162,7 +162,7 @@ class App
this.watcher.on( 'unlinkDir', ( _path ) =>
{
// Set up
let relative_path = _path.replace( process.cwd() + '/', '' )
let relative_path = _path.replace( process.cwd(), '.' )
console.log( 'unlinkDir:'.green.bold, relative_path )
+40 -14
View File
@@ -36,16 +36,16 @@ class App
// Set up
this.projects = new Projects()
// // Tests
// 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.update_file( 'toto/tutu/tete/tutu.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' )
// 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 } ) )
}
@@ -108,51 +108,77 @@ class App
set_socket()
{
// Set up
this.io = socket_io.listen( this.server )
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' )
let project = null
// Connection event
this.io.on( 'connection', ( socket ) =>
this.sockets.app.on( 'connection', ( socket ) =>
{
console.log( 'socket'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
let project = null
console.log( 'socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
socket.on( 'start_project', ( data ) =>
{
project = this.projects.create_project( data.slug )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'update_file', ( data ) =>
{
project.update_file( data.path, data.content )
this.sockets.site.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 )
this.sockets.site.emit( 'update_project', project )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'delete_file', ( data ) =>
{
project.delete_file( data.path )
this.sockets.site.emit( 'update_project', project )
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 )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'delete_folder', ( data ) =>
{
project.delete_folder( data.path )
this.sockets.site.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 )
socket.emit( 'update_project', project )
} )
}
}
+33 -35
View File
@@ -1,9 +1,9 @@
'use strict'
// Dependencies
let path = require( 'path' ),
util = require( 'util' ),
File = require( './file.class.js' )
let paths = require( '../utils/paths.class.js' ),
util = require( 'util' ),
File = require( './file.class.js' )
class Project
{
@@ -23,11 +23,11 @@ class Project
create_file( _path, _content )
{
// Set up
let normalize_path = path.normalize( _path ),
parsed_path = path.parse( normalize_path )
let normalized_path = paths.normalize( _path ),
parsed_path = paths.parse( normalized_path )
// Retrieve file
let file = this.get_file( normalize_path )
let file = this.get_file( normalized_path )
// File already exist
if( file )
@@ -54,8 +54,8 @@ class Project
_force_creation = false
// Set up
let normalize_path = path.normalize( _path ),
parsed_path = path.parse( normalize_path )
let normalized_path = paths.normalize( _path ),
parsed_path = paths.parse( normalized_path )
// Retrieve folder
let folder = this.get_folder( parsed_path.dir, _force_creation )
@@ -75,7 +75,7 @@ class Project
if( _force_creation )
{
// Create folders
file = this.create_file( normalize_path )
file = this.create_file( normalized_path )
return file
}
@@ -87,10 +87,10 @@ class Project
update_file( _path, _content )
{
// Set up
let normalize_path = path.normalize( _path )
let normalized_path = paths.normalize( _path )
// Retrieve file
let file = this.get_file( normalize_path, true )
let file = this.get_file( normalized_path, true )
// Create version
file.create_version( _content )
@@ -99,8 +99,7 @@ class Project
delete_file( _path )
{
// Set up
let normalize_path = path.normalize( _path ),
parsed_path = path.parse( normalize_path )
let parsed_path = paths.parse( _path )
// Retrieve folder
let folder = this.get_folder( parsed_path.dir )
@@ -122,27 +121,27 @@ class Project
create_folder( _path )
{
// Set up
let normalize_path = path.normalize( _path ),
path_parts = normalize_path.split( path.sep ),
folder = this
let normalized_path = paths.normalize( _path ),
path_folders = normalized_path.split( paths.separator ),
folder = this
for( let _path_part of path_parts )
for( let _path_folder of path_folders )
{
// Temporary folder
let __folder = folder.folders[ _path_part ]
let _folder = folder.folders[ _path_folder ]
// Folder doesn't exist
if( typeof __folder === 'undefined' )
if( typeof _folder === 'undefined' )
{
__folder = {}
__folder.name = _path_part
__folder.files = {}
__folder.folders = {}
_folder = {}
_folder.name = _path_folder
_folder.files = {}
_folder.folders = {}
folder.folders[ _path_part ] = __folder
folder.folders[ _path_folder ] = _folder
}
folder = __folder
folder = _folder
}
return folder
@@ -154,14 +153,14 @@ class Project
if( typeof _force_creation === 'undefined' )
_force_creation = false
let normalize_path = path.normalize( _path ),
path_parts = normalize_path.split( path.sep ),
folder = this,
found = true
let normalized_path = paths.normalize( _path ),
path_folders = normalized_path.split( paths.separator ),
folder = this,
found = true
for( let _path_part of path_parts )
for( let _path_folder of path_folders )
{
folder = folder.folders[ _path_part ]
folder = folder.folders[ _path_folder ]
// Folder not found
if(typeof folder === 'undefined')
@@ -179,7 +178,7 @@ class Project
if( _force_creation )
{
// Create folders
folder = this.create_folder( normalize_path )
folder = this.create_folder( normalized_path )
return folder
}
@@ -191,9 +190,8 @@ class Project
delete_folder( _path )
{
// Set up
let normalize_path = path.normalize( _path ),
path_parts = _path.split( path.sep ),
folder = this.get_folder( normalize_path )
let normalized_path = paths.normalize( _path ),
folder = this.get_folder( normalized_path )
// Folder not found
if( !folder )
@@ -4,17 +4,20 @@ angular_module.controller(
'ApplicationController',
[
'$scope',
'data',
function( $scope, data )
'project',
function( $scope, project )
{
console.log(data);
var that = this;
this.pwet = 'uh';
this.codes =
[
{ title: 'Title 1' },
{ title: 'Title 2' }
];
project.on_update( function( data )
{
$scope.$apply( function()
{
that.project = data;
} );
} );
this.project = project.data;
}
]
);
-12
View File
@@ -1,12 +0,0 @@
angular_module.factory(
'data',
[
function()
{
return function()
{
console.log( 'data' );
}
}
]
);
@@ -0,0 +1,37 @@
angular_module.factory(
'project',
[
'$timeout',
'$rootScope',
function( $timeout, $rootScope )
{
update_callback = null;
var result = {};
result.data = null;
result.on_update = function( callback )
{
update_callback = callback;
};
var socket = io( 'http://192.168.1.4:3000/site' );
socket.on( 'connect', function()
{
console.log('connected');
} );
socket.on( 'update_project', function( data )
{
result.data = data;
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
} );
result.data = {"name":"pwet","folders":{".":{"name":".","files":{"test-1.txt":{"name":"test-1.txt","versions":[{"date":"2016-06-03T21:16:35.574Z","content":"dsfsdf\n\naaaa\n\ndsfsdf\n\nbbbb\n\ndsfsdf\nsodifja\n","diff":false}]},"test-2.txt":{"name":"test-2.txt","versions":[{"date":"2016-06-03T21:16:38.667Z","content":"kqsdqsdjn\niudfgdfg\n\nqsdiuhqsdiuqhsd\n","diff":false}]}},"folders":{}},"folder-2":{"name":"folder-2","files":{"hey.txt":{"name":"hey.txt","versions":[{"date":"2016-06-03T21:16:32.742Z","content":"qdsqsdsq\n","diff":false}]}},"folders":{}}}};
return result;
}
]
);
+34
View File
@@ -0,0 +1,34 @@
'use strict'
// Dependencies
let path = require( 'path' )
class Paths
{
constructor()
{
this.separator = path.sep
}
normalize( _path )
{
if( _path === '.' || _path === '' )
return '.';
let normalized_path = './' + path.normalize( _path )
return normalized_path
}
parse( _path )
{
let normalized_path = this.normalize( _path ),
parsed_path = path.parse( normalized_path )
return parsed_path
}
}
let paths = new Paths()
module.exports = paths
+95 -86
View File
@@ -1,86 +1,95 @@
html(ng-app="application")
head
title
| Code Spectat
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js")
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js")
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-resource.js")
script(src="/javascript/application/application.js")
script(src="/javascript/services/data.js")
body
header.main-header
h1
| Code Spectat
aside
header.aside-header
| Project name
nav.aside-nav
ul
li
a(href="#")
| folder-1
ul
li
a(href="#")
| folder-1-1
li
a(href="#")
| folder-1-2
li
a(href="#")
| file-1-1
li
a(href="#")
| file-1-2
li
a(href="#")
| folder-2
ul
li
a(href="#")
| folder-2-1
ul
li
a(href="#")
| folder-2-1-1
li
a(href="#")
| file-2-1-1
li
a(href="#")
| file-2-1-2
li
a(href="#")
| file-2-1-3
li
a(href="#")
| file-2-1
li
a(href="#")
| file-2-2
li
a(href="#")
| file-2-3
section.file
section.historic
a.version(href="#")
div.date
| 14:23:14
div.differences
| Différences
a.version(href="#")
div.date
| 14:24:01
div.differences
| Différences
a.version(href="#")
div.date
| 14:27:42
div.differences
| Différences
section.code
pre
| <html>
div(ng-controller="ApplicationController as hoy")
span
{{ hoy.pwet }}
html(ng-app="application",ng-controller="ApplicationController as controller")
head
title
| Code Spectat
script(src="/socket.io/socket.io.js")
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js")
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js")
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-resource.js")
script(src="/javascript/application/application.js")
script(src="/javascript/services/project.js")
body
script(type="text/ng-template",id="tree_item_renderer.html")
| {{data.name}}
ul
li(ng-repeat="data in data.folders",ng-include="'tree_item_renderer.html'")
li(ng-repeat="file in data.files")
| {{file.name}}
header.main-header
h1
| Code Spectat
aside
header.aside-header
| {{ controller.project.name }}
nav.aside-nav
ul
li(ng-repeat="data in controller.project.folders",ng-include="'tree_item_renderer.html'")
//- ul
//- li
//- a(href="#")
//- | folder-1
//- ul
//- li
//- a(href="#")
//- | folder-1-1
//- li
//- a(href="#")
//- | folder-1-2
//- li
//- a(href="#")
//- | file-1-1
//- li
//- a(href="#")
//- | file-1-2
//- li
//- a(href="#")
//- | folder-2
//- ul
//- li
//- a(href="#")
//- | folder-2-1
//- ul
//- li
//- a(href="#")
//- | folder-2-1-1
//- li
//- a(href="#")
//- | file-2-1-1
//- li
//- a(href="#")
//- | file-2-1-2
//- li
//- a(href="#")
//- | file-2-1-3
//- li
//- a(href="#")
//- | file-2-1
//- li
//- a(href="#")
//- | file-2-2
//- li
//- a(href="#")
//- | file-2-3
section.file
section.historic
a.version(href="#")
div.date
| 14:23:14
div.differences
| Différences
a.version(href="#")
div.date
| 14:24:01
div.differences
| Différences
a.version(href="#")
div.date
| 14:27:42
div.differences
| Différences
section.code
pre
| <html>
+1
View File
@@ -0,0 +1 @@
sdnufoisdf
+3 -2
View File
@@ -4,7 +4,8 @@ aaaa
dsfsdf
bbbb
bbbbiuhsdfiuhsdfdsf
dsfsdf
sodifja
sodifja