diff --git a/site/app.class.js b/site/app.class.js index dd661e3..3e9ed6f 100644 --- a/site/app.class.js +++ b/site/app.class.js @@ -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 } ) ) } /** diff --git a/site/models/files.class.js b/site/models/files.class.js index d26f596..3f968a2 100644 --- a/site/models/files.class.js +++ b/site/models/files.class.js @@ -8,8 +8,10 @@ class Files { constructor( _options ) { - this.items = {} - this.socket = _options.socket + 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() ) @@ -112,14 +123,16 @@ class Files describe() { // Set up - let result = {} + 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 diff --git a/site/models/project.class.js b/site/models/project.class.js index aac32dd..d145a9d 100644 --- a/site/models/project.class.js +++ b/site/models/project.class.js @@ -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 } diff --git a/site/models/projects.class.js b/site/models/projects.class.js index de6e40e..3b8da55 100644 --- a/site/models/projects.class.js +++ b/site/models/projects.class.js @@ -103,8 +103,11 @@ class Projects let _project = this.all[ _slug ] result.all[ _slug ] = { - slug: _project.slug, - name: _project.name + slug : _project.slug, + name : _project.name, + files_count : _project.files.count, + date : _project.date, + last_update_date: _project.files.last_version_date, } } diff --git a/site/public/javascript/controllers/project.js b/site/public/javascript/controllers/project.js index f319c31..b4a1730 100644 --- a/site/public/javascript/controllers/project.js +++ b/site/public/javascript/controllers/project.js @@ -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; diff --git a/site/public/javascript/controllers/projects.js b/site/public/javascript/controllers/projects.js index 1c027da..222409e 100644 --- a/site/public/javascript/controllers/projects.js +++ b/site/public/javascript/controllers/projects.js @@ -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 } diff --git a/site/public/javascript/services/project.js b/site/public/javascript/services/project.js index 721ef96..ba39cc1 100644 --- a/site/public/javascript/services/project.js +++ b/site/public/javascript/services/project.js @@ -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 diff --git a/site/public/javascript/services/projects.js b/site/public/javascript/services/projects.js index e4918b6..61130cf 100644 --- a/site/public/javascript/services/projects.js +++ b/site/public/javascript/services/projects.js @@ -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 diff --git a/site/public/stylesheets/style.css b/site/public/stylesheets/style.css index 2484887..8cd28a2 100644 --- a/site/public/stylesheets/style.css +++ b/site/public/stylesheets/style.css @@ -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;} diff --git a/site/views/pages/index/projects.jade b/site/views/pages/index/projects.jade index 12a824d..e8ea7fc 100644 --- a/site/views/pages/index/projects.jade +++ b/site/views/pages/index/projects.jade @@ -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") - | {{project.name}} + .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