[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
+10 -10
View File
@@ -48,11 +48,11 @@ class App
// let project_5 = this.projects.create_project( 'dummy' ) // let project_5 = this.projects.create_project( 'dummy' )
// Some file // Some file
project.files.create_version( './folder-1/test-4.css', fs.readFileSync( '../test-folder/folder-1/test-4.css', 'utf8' ) ) project.files.create_version( './folder-test/test-4.css', fs.readFileSync( '../test-folder/folder-1/test-4.css', 'utf8' ) )
project.files.create_version( './folder-2/test-3.js', fs.readFileSync( '../test-folder/folder-2/test-3.js', 'utf8' ) ) project.files.create_version( './folder-test/depth-test/test-3.js', fs.readFileSync( '../test-folder/folder-2/test-3.js', 'utf8' ) )
project.files.create_version( './test-1.html', fs.readFileSync( '../test-folder/test-1.html', 'utf8' ) ) project.files.create_version( './folder-test/test-1.html', fs.readFileSync( '../test-folder/test-1.html', 'utf8' ) )
project.files.create_version( './test-2.php', fs.readFileSync( '../test-folder/test-2.php', 'utf8' ) ) project.files.create_version( './folder-test/test-2.php', fs.readFileSync( '../test-folder/test-2.php', 'utf8' ) )
project.files.create_version( './big-one.txt', 'content 4\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline' ) project.files.create_version( './folder-test/big-one.txt', 'content 4\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline\nline' )
project.files.create_version( './icons/test.js', 'Test icon' ) project.files.create_version( './icons/test.js', 'Test icon' )
project.files.create_version( './icons/test.html', 'Test icon' ) project.files.create_version( './icons/test.html', 'Test icon' )
@@ -116,7 +116,7 @@ class App
let counting = 0 let counting = 0
setInterval( function() setInterval( function()
{ {
project.files.create_version( './multi-version.txt', 'test: ' + counting++ ) project.files.create_version( './folder-test/multi-version.txt', 'test: ' + counting++ )
}, 2000 ) }, 2000 )
// Creating and deleting file // Creating and deleting file
@@ -124,16 +124,16 @@ class App
setInterval( function() setInterval( function()
{ {
if( toggle ) if( toggle )
project.files.create( './toggle.txt', 'content' ) project.files.create( './folder-test/toggle.txt', 'content' )
else else
project.files.delete( './toggle.txt', 'content' ) project.files.delete( './folder-test/toggle.txt', 'content' )
toggle = !toggle toggle = !toggle
}, 3000 ) }, 3000 )
// Log // // Log
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) ) // console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
} }
/** /**
+14 -1
View File
@@ -9,7 +9,9 @@ class Files
constructor( _options ) constructor( _options )
{ {
this.items = {} this.items = {}
this.count = 0
this.socket = _options.socket this.socket = _options.socket
this.last_version_date = new Date()
} }
create( _path, _content ) create( _path, _content )
@@ -35,6 +37,8 @@ class Files
// Save // Save
this.items[ normalized_path ] = file this.items[ normalized_path ] = file
this.count++
this.last_version_date = new Date()
// Emit // Emit
this.socket.emit( 'create_file', file.describe() ) this.socket.emit( 'create_file', file.describe() )
@@ -82,6 +86,9 @@ class Files
// Create version // Create version
file.create_version( _content ) file.create_version( _content )
// Save
this.last_version_date = new Date()
return file return file
} }
@@ -99,6 +106,10 @@ class Files
// Delete file // Delete file
file.destructor() file.destructor()
delete this.items[ normalized_path ] delete this.items[ normalized_path ]
this.count--
// Save
this.last_version_date = new Date()
// Emit // Emit
this.socket.emit( 'delete_file', file.describe() ) this.socket.emit( 'delete_file', file.describe() )
@@ -113,13 +124,15 @@ class Files
{ {
// Set up // Set up
let result = {} let result = {}
result.count = this.count
result.items = {}
// Each file // Each file
for( let _file_path in this.items ) for( let _file_path in this.items )
{ {
let _file = this.items[ _file_path ] let _file = this.items[ _file_path ]
result[ _file_path ] = _file.describe() result.items[ _file_path ] = _file.describe()
} }
return result return result
+2
View File
@@ -12,6 +12,7 @@ class Project
this.set_socket( options.socket ) this.set_socket( options.socket )
this.files = new Files( { socket: this.socket } ) this.files = new Files( { socket: this.socket } )
this.date = new Date()
} }
set_name( _name ) set_name( _name )
@@ -41,6 +42,7 @@ class Project
let result = {} let result = {}
result.name = this.name result.name = this.name
result.files = this.files.describe() result.files = this.files.describe()
result.date = this.date
return result return result
} }
+4 -1
View File
@@ -104,7 +104,10 @@ class Projects
result.all[ _slug ] = { result.all[ _slug ] = {
slug : _project.slug, slug : _project.slug,
name: _project.name name : _project.name,
files_count : _project.files.count,
date : _project.date,
last_update_date: _project.files.last_version_date,
} }
} }
@@ -69,12 +69,12 @@ application.controller(
project.connect( project_slug ); project.connect( project_slug );
}; };
project.on_update( function( data ) project.on_update = function( data )
{ {
$scope.$apply( function() $scope.$apply( function()
{ {
} ); } );
} ); };
$scope.project = project; $scope.project = project;
$scope.file = null; $scope.file = null;
@@ -5,13 +5,13 @@ application.controller(
'projects', 'projects',
function( $scope, projects ) function( $scope, projects )
{ {
projects.on_update( function( data ) projects.on_update = function( data )
{ {
$scope.$apply( function() $scope.$apply( function()
{ {
$scope.projects = Object.keys( data.all ).length ? data.all : null; $scope.projects = Object.keys( data.all ).length ? data.all : null;
} ); } );
} ); };
$scope.projects = projects.data.all $scope.projects = projects.data.all
} }
+11 -18
View File
@@ -105,14 +105,7 @@ application.factory(
result.name = ''; result.name = '';
result.files = {}; result.files = {};
result.tree = new Tree( { auto_wash: false } ); result.tree = new Tree( { auto_wash: false } );
result.on_update = null;
// Callback
var update_callback = null;
result.on_update = function( callback )
{
update_callback = callback;
};
// Connect // Connect
result.connect = function( project_name ) result.connect = function( project_name )
@@ -142,8 +135,8 @@ application.factory(
} }
// Apply callback // Apply callback
if( typeof update_callback === 'function' ) if( typeof result.on_update === 'function' )
update_callback.apply( this, [ data ] ); result.on_update.apply( this, [ data ] );
} ); } );
socket.on( 'create_version', function( data ) socket.on( 'create_version', function( data )
@@ -158,8 +151,8 @@ application.factory(
file.notif++; file.notif++;
// Apply callback // Apply callback
if( typeof update_callback === 'function' ) if( typeof result.on_update === 'function' )
update_callback.apply( this, [ data ] ); result.on_update.apply( this, [ data ] );
} }
} ); } );
@@ -175,8 +168,8 @@ application.factory(
delete result.files[ data.path.full ] delete result.files[ data.path.full ]
// Apply callback // Apply callback
if( typeof update_callback === 'function' ) if( typeof result.on_update === 'function' )
update_callback.apply( this, [ data ] ); result.on_update.apply( this, [ data ] );
} }
} ); } );
@@ -186,9 +179,9 @@ application.factory(
result.name = data.name; result.name = data.name;
// Duplicate files // 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 ]; file = result.files[ _file_key ];
// Doesn't exist yet // Doesn't exist yet
@@ -204,8 +197,8 @@ application.factory(
} }
// Apply callback // Apply callback
if( typeof update_callback === 'function' ) if( typeof result.on_update === 'function' )
update_callback.apply( this, [ data ] ); result.on_update.apply( this, [ data ] );
} ); } );
// Destruct event // Destruct event
+25 -7
View File
@@ -4,15 +4,26 @@ application.factory(
'config', 'config',
function( 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 // Result
var result = {}; var result = {};
result.data = {}; result.data = {};
result.on_update = function( callback ) result.on_update = null;
{
update_callback = callback;
};
// Socket // Socket
var socket = io( config.domain + '/projects' ); var socket = io( config.domain + '/projects' );
@@ -21,8 +32,15 @@ application.factory(
{ {
result.data = data; result.data = data;
if( typeof update_callback === 'function' ) for( var _project_key in result.data.all )
update_callback.apply( this, [ data ] ); {
var project = result.data.all[ _project_key ];
project = reformat_project( project );
}
if( typeof result.on_update === 'function' )
result.on_update.apply( this, [ data ] );
} ); } );
// Return // Return
+1 -1
View File
@@ -17,7 +17,7 @@ section.page-projects {padding-top:100px;}
section.page-projects .no-project {text-align:center;padding:180px 0;} section.page-projects .no-project {text-align:center;padding:180px 0;}
section.page-projects .projects {width:400px;margin:0 auto;background:#202124;box-shadow:0px 5px 10px rgba(0,0,0,0.1);border:1px solid #32374d;} section.page-projects .projects {width:400px;margin:0 auto;background:#202124;box-shadow:0px 5px 10px rgba(0,0,0,0.1);border:1px solid #32374d;}
section.page-projects .projects .title {height:40px;line-height:40px;text-align:center;} section.page-projects .projects .title {height:40px;line-height:40px;text-align:center;}
section.page-projects .projects .item {position:relative;padding:0 10px;display:block;height:40px;line-height:40px;} section.page-projects .projects .item {position:relative;padding:0 10px;display:block;line-height:32px;}
section.page-projects .projects .item:after {content:'';display:block;position:absolute;bottom:0;left:0;right:0;height:1px;background:#32374d;opacity:0.4;} section.page-projects .projects .item:after {content:'';display:block;position:absolute;bottom:0;left:0;right:0;height:1px;background:#32374d;opacity:0.4;}
section.page-projects .projects a.item:hover {background:#32374d;} section.page-projects .projects a.item:hover {background:#32374d;}
section.page-projects .projects .item:last-child:after {display:none;} section.page-projects .projects .item:last-child:after {display:none;}
+11
View File
@@ -5,7 +5,18 @@ section.page-projects(ng-controller="ProjectsController as controller")
.item.title .item.title
| Projects | Projects
a.item(href="/project/{{project.slug}}",ng-repeat="project in projects") a.item(href="/project/{{project.slug}}",ng-repeat="project in projects")
.name
| {{project.name}} | {{project.name}}
.file-count
| Files: {{project.files_count}}
.creation
| Creation: {{project.date_formated}}
.time-from-now
| {{project.time_from_now}}
.last-update-date
| Last update: {{project.last_update_date_formated}}
.time-from-now
| {{project.last_update_time_from_now}}
.no-project(ng-hide="projects") .no-project(ng-hide="projects")
| No project | No project