File incremental update for new version

This commit is contained in:
brunosimon
2016-08-11 21:57:07 +02:00
parent bdda23cc43
commit a73a484d2a
4 changed files with 37 additions and 21 deletions
+8 -8
View File
@@ -49,18 +49,18 @@ class App
// // Some file // // Some file
// project.files.create( './coucou/coco.txt', '1234' ) // project.files.create( './coucou/coco.txt', '1234' )
// project.files.create( './test-1.txt', 'content 1' ) // project.files.create( './test-1.txt', 'content 1' )
// project.files.update( './test-1.txt', 'content 2' ) // project.files.create_version( './test-1.txt', 'content 2' )
// project.files.update( './test-1.txt', 'content 31298' ) // project.files.create_version( './test-1.txt', 'content 31298' )
// project.files.update( './toto/tata/lorem.txt', '123456789' ) // project.files.create_version( './toto/tata/lorem.txt', '123456789' )
// project.files.update( './toto/tata/lorem.txt', '1aze' ) // project.files.create_version( './toto/tata/lorem.txt', '1aze' )
// project.files.update( './toto/tata/ipsum.txt', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia asperiores iure, animi voluptatibus ut officiis. Molestias, quod perferendis hic totam doloremque, porro aperiam enim tenetur, maxime inventore consequuntur nisi in?' ) // project.files.create_version( './toto/tata/ipsum.txt', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia asperiores iure, animi voluptatibus ut officiis. Molestias, quod perferendis hic totam doloremque, porro aperiam enim tenetur, maxime inventore consequuntur nisi in?' )
// project.files.delete( './toto/tata/ipsum.txt' ) // project.files.create_version( './toto/tata/ipsum.txt' )
// // Adding file versions // // Adding file versions
// let counting = 0 // let counting = 0
// setInterval( function() // setInterval( function()
// { // {
// project.files.update( './coucou/coco.txt', 'test: ' + counting++ ) // project.files.create_version( './coucou/coco.txt', 'test: ' + counting++ )
// }, 2000 ) // }, 2000 )
@@ -160,7 +160,7 @@ class App
// Update file // Update file
socket.on( 'update_file', ( data ) => socket.on( 'update_file', ( data ) =>
{ {
project.files.update( data.path, data.content ) project.files.create_version( data.path, data.content )
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) ) console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
} ) } )
+4
View File
@@ -17,6 +17,7 @@ class File
this.path.full = this.path.directory + '/' + this.name this.path.full = this.path.directory + '/' + this.name
this.path.parts = this.path.full.split( paths.separator ) this.path.parts = this.path.full.split( paths.separator )
this.versions = [] this.versions = []
this.socket = _options.socket
// Create first version // Create first version
if( typeof _options.content !== 'undefined' ) if( typeof _options.content !== 'undefined' )
@@ -33,6 +34,9 @@ class File
version.content = content version.content = content
version.diff = last_version ? diff.diffChars( last_version.content, version.content ) : false version.diff = last_version ? diff.diffChars( last_version.content, version.content ) : false
// Emit
this.socket.emit( 'create_version', { file: this.path.full, version: version } )
// Save // Save
this.versions.push( version ) this.versions.push( version )
} }
+3 -5
View File
@@ -29,7 +29,8 @@ class Files
file = new File( { file = new File( {
name : parsed_path.base, name : parsed_path.base,
path : parsed_path.dir, path : parsed_path.dir,
content: _content content: _content,
socket : this.socket
} ) } )
// Save // Save
@@ -70,7 +71,7 @@ class Files
return false return false
} }
update( _path, _content ) create_version( _path, _content )
{ {
// Set up // Set up
let normalized_path = paths.normalize( _path ) let normalized_path = paths.normalize( _path )
@@ -81,9 +82,6 @@ class Files
// Create version // Create version
file.create_version( _content ) file.create_version( _content )
// Emit
this.socket.emit( 'update_file', file.describe() )
return file return file
} }
+22 -8
View File
@@ -35,12 +35,6 @@ application.factory(
{ {
console.log('create_file'); console.log('create_file');
console.log(data); console.log(data);
} );
socket.on( 'update_file', function( data )
{
// console.log('update_file');
// console.log(data);
var existing_file = result.files[ data.path.full ]; var existing_file = result.files[ data.path.full ];
@@ -49,9 +43,9 @@ application.factory(
{ {
existing_file = Object.assign( {}, data ); existing_file = Object.assign( {}, data );
existing_file.notif = 0; existing_file.notif = 0;
result.files[ _file_key ] = existing_file; result.files[ data.path.full ] = existing_file;
result.tree.add_file( _file_key, existing_file ) result.tree.add_file( data.path.full, existing_file )
} }
existing_file.notif++; existing_file.notif++;
@@ -61,6 +55,26 @@ application.factory(
update_callback.apply( this, [ data ] ); update_callback.apply( this, [ data ] );
} ); } );
socket.on( 'create_version', function( data )
{
console.log('create_version');
console.log(data);
var existing_file = result.files[ data.file ];
// Doesn't exist yet
if( typeof existing_file !== 'undefined' )
{
existing_file.versions.push( data.version );
existing_file.notif++;
// Apply callback
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
}
} );
socket.on( 'delete_file', function( data ) socket.on( 'delete_file', function( data )
{ {
console.log('delete_file'); console.log('delete_file');