File incremental update for new version
This commit is contained in:
+8
-8
@@ -49,18 +49,18 @@ class App
|
||||
// // Some file
|
||||
// project.files.create( './coucou/coco.txt', '1234' )
|
||||
// project.files.create( './test-1.txt', 'content 1' )
|
||||
// project.files.update( './test-1.txt', 'content 2' )
|
||||
// project.files.update( './test-1.txt', 'content 31298' )
|
||||
// project.files.update( './toto/tata/lorem.txt', '123456789' )
|
||||
// project.files.update( './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.delete( './toto/tata/ipsum.txt' )
|
||||
// project.files.create_version( './test-1.txt', 'content 2' )
|
||||
// project.files.create_version( './test-1.txt', 'content 31298' )
|
||||
// project.files.create_version( './toto/tata/lorem.txt', '123456789' )
|
||||
// project.files.create_version( './toto/tata/lorem.txt', '1aze' )
|
||||
// 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.create_version( './toto/tata/ipsum.txt' )
|
||||
|
||||
// // Adding file versions
|
||||
// let counting = 0
|
||||
// setInterval( function()
|
||||
// {
|
||||
// project.files.update( './coucou/coco.txt', 'test: ' + counting++ )
|
||||
// project.files.create_version( './coucou/coco.txt', 'test: ' + counting++ )
|
||||
// }, 2000 )
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ class App
|
||||
// Update file
|
||||
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 } ) )
|
||||
} )
|
||||
|
||||
@@ -17,6 +17,7 @@ class File
|
||||
this.path.full = this.path.directory + '/' + this.name
|
||||
this.path.parts = this.path.full.split( paths.separator )
|
||||
this.versions = []
|
||||
this.socket = _options.socket
|
||||
|
||||
// Create first version
|
||||
if( typeof _options.content !== 'undefined' )
|
||||
@@ -33,6 +34,9 @@ class File
|
||||
version.content = content
|
||||
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
|
||||
this.versions.push( version )
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ class Files
|
||||
file = new File( {
|
||||
name : parsed_path.base,
|
||||
path : parsed_path.dir,
|
||||
content: _content
|
||||
content: _content,
|
||||
socket : this.socket
|
||||
} )
|
||||
|
||||
// Save
|
||||
@@ -70,7 +71,7 @@ class Files
|
||||
return false
|
||||
}
|
||||
|
||||
update( _path, _content )
|
||||
create_version( _path, _content )
|
||||
{
|
||||
// Set up
|
||||
let normalized_path = paths.normalize( _path )
|
||||
@@ -81,9 +82,6 @@ class Files
|
||||
// Create version
|
||||
file.create_version( _content )
|
||||
|
||||
// Emit
|
||||
this.socket.emit( 'update_file', file.describe() )
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,6 @@ application.factory(
|
||||
{
|
||||
console.log('create_file');
|
||||
console.log(data);
|
||||
} );
|
||||
|
||||
socket.on( 'update_file', function( data )
|
||||
{
|
||||
// console.log('update_file');
|
||||
// console.log(data);
|
||||
|
||||
var existing_file = result.files[ data.path.full ];
|
||||
|
||||
@@ -49,9 +43,9 @@ application.factory(
|
||||
{
|
||||
existing_file = Object.assign( {}, data );
|
||||
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++;
|
||||
@@ -61,6 +55,26 @@ application.factory(
|
||||
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 )
|
||||
{
|
||||
console.log('delete_file');
|
||||
|
||||
Reference in New Issue
Block a user