[update] Project infos

This commit is contained in:
brunosimon
2016-08-15 12:51:42 +02:00
parent 030c078335
commit bcabfd7e6d
10 changed files with 91 additions and 51 deletions
+15 -22
View File
@@ -101,18 +101,11 @@ application.factory(
}
// Result
var result = {};
result.name = '';
result.files = {};
result.tree = new Tree( { auto_wash: false } );
// Callback
var update_callback = null;
result.on_update = function( callback )
{
update_callback = callback;
};
var result = {};
result.name = '';
result.files = {};
result.tree = new Tree( { auto_wash: false } );
result.on_update = null;
// Connect
result.connect = function( project_name )
@@ -142,8 +135,8 @@ application.factory(
}
// Apply callback
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
if( typeof result.on_update === 'function' )
result.on_update.apply( this, [ data ] );
} );
socket.on( 'create_version', function( data )
@@ -158,8 +151,8 @@ application.factory(
file.notif++;
// Apply callback
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
if( typeof result.on_update === 'function' )
result.on_update.apply( this, [ data ] );
}
} );
@@ -175,8 +168,8 @@ application.factory(
delete result.files[ data.path.full ]
// Apply callback
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
if( typeof result.on_update === 'function' )
result.on_update.apply( this, [ data ] );
}
} );
@@ -186,9 +179,9 @@ application.factory(
result.name = data.name;
// Duplicate files
for( var _file_key in data.files )
for( var _file_key in data.files.items )
{
var data_file = data.files[ _file_key ],
var data_file = data.files.items[ _file_key ],
file = result.files[ _file_key ];
// Doesn't exist yet
@@ -204,8 +197,8 @@ application.factory(
}
// Apply callback
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
if( typeof result.on_update === 'function' )
result.on_update.apply( this, [ data ] );
} );
// Destruct event
+25 -7
View File
@@ -4,15 +4,26 @@ application.factory(
'config',
function( config )
{
update_callback = null;
// Reformat project function
function reformat_project( _project )
{
// Date
_project.moment_date = moment( _project.date );
_project.date_formated = _project.moment_date.format( 'LTS' );
_project.time_from_now = _project.moment_date.fromNow();
// Last update date
_project.moment_date = moment( _project.last_update_date );
_project.last_update_date_formated = _project.moment_date.format( 'LTS' );
_project.last_update_time_from_now = _project.moment_date.fromNow();
return _project;
}
// Result
var result = {};
result.data = {};
result.on_update = function( callback )
{
update_callback = callback;
};
result.on_update = null;
// Socket
var socket = io( config.domain + '/projects' );
@@ -21,8 +32,15 @@ application.factory(
{
result.data = data;
if( typeof update_callback === 'function' )
update_callback.apply( this, [ data ] );
for( var _project_key in result.data.all )
{
var project = result.data.all[ _project_key ];
project = reformat_project( project );
}
if( typeof result.on_update === 'function' )
result.on_update.apply( this, [ data ] );
} );
// Return