[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' )
// 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-2/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( './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/test-4.css', fs.readFileSync( '../test-folder/folder-1/test-4.css', '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( './folder-test/test-1.html', fs.readFileSync( '../test-folder/test-1.html', 'utf8' ) )
project.files.create_version( './folder-test/test-2.php', fs.readFileSync( '../test-folder/test-2.php', 'utf8' ) )
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.html', 'Test icon' )
@@ -116,7 +116,7 @@ class App
let counting = 0
setInterval( function()
{
project.files.create_version( './multi-version.txt', 'test: ' + counting++ )
project.files.create_version( './folder-test/multi-version.txt', 'test: ' + counting++ )
}, 2000 )
// Creating and deleting file
@@ -124,16 +124,16 @@ class App
setInterval( function()
{
if( toggle )
project.files.create( './toggle.txt', 'content' )
project.files.create( './folder-test/toggle.txt', 'content' )
else
project.files.delete( './toggle.txt', 'content' )
project.files.delete( './folder-test/toggle.txt', 'content' )
toggle = !toggle
}, 3000 )
// Log
console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
// // Log
// console.log( util.inspect( project.files.describe(), { depth: null, colors: true } ) )
}
/**
+14 -1
View File
@@ -9,7 +9,9 @@ class Files
constructor( _options )
{
this.items = {}
this.count = 0
this.socket = _options.socket
this.last_version_date = new Date()
}
create( _path, _content )
@@ -35,6 +37,8 @@ class Files
// Save
this.items[ normalized_path ] = file
this.count++
this.last_version_date = new Date()
// Emit
this.socket.emit( 'create_file', file.describe() )
@@ -82,6 +86,9 @@ class Files
// Create version
file.create_version( _content )
// Save
this.last_version_date = new Date()
return file
}
@@ -99,6 +106,10 @@ class Files
// Delete file
file.destructor()
delete this.items[ normalized_path ]
this.count--
// Save
this.last_version_date = new Date()
// Emit
this.socket.emit( 'delete_file', file.describe() )
@@ -113,13 +124,15 @@ class Files
{
// Set up
let result = {}
result.count = this.count
result.items = {}
// Each file
for( let _file_path in this.items )
{
let _file = this.items[ _file_path ]
result[ _file_path ] = _file.describe()
result.items[ _file_path ] = _file.describe()
}
return result
+2
View File
@@ -12,6 +12,7 @@ class Project
this.set_socket( options.socket )
this.files = new Files( { socket: this.socket } )
this.date = new Date()
}
set_name( _name )
@@ -41,6 +42,7 @@ class Project
let result = {}
result.name = this.name
result.files = this.files.describe()
result.date = this.date
return result
}
+4 -1
View File
@@ -104,7 +104,10 @@ class Projects
result.all[ _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.on_update( function( data )
project.on_update = function( data )
{
$scope.$apply( function()
{
} );
} );
};
$scope.project = project;
$scope.file = null;
@@ -5,13 +5,13 @@ application.controller(
'projects',
function( $scope, projects )
{
projects.on_update( function( data )
projects.on_update = function( data )
{
$scope.$apply( function()
{
$scope.projects = Object.keys( data.all ).length ? data.all : null;
} );
} );
};
$scope.projects = projects.data.all
}
+11 -18
View File
@@ -105,14 +105,7 @@ application.factory(
result.name = '';
result.files = {};
result.tree = new Tree( { auto_wash: false } );
// Callback
var update_callback = null;
result.on_update = function( callback )
{
update_callback = callback;
};
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
+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 .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 .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 a.item:hover {background:#32374d;}
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
| Projects
a.item(href="/project/{{project.slug}}",ng-repeat="project in projects")
.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