🎨 Update files structure

This commit is contained in:
brunosimon
2017-07-18 03:47:13 +02:00
parent 5a7431a6b9
commit 2b49b8a847
29 changed files with 13 additions and 24 deletions
+76
View File
@@ -0,0 +1,76 @@
'use strict'
// Dependencies
const slug = require('slug')
const Files = require('./files.js')
class Project
{
constructor(_options)
{
this.setOptions(_options)
this.setName(_options.name)
this.setSocket(_options.socket)
this.files = new Files({ socket: this.socket })
this.date = new Date()
}
/**
* Set options
*/
setOptions(_options)
{
if(typeof _options.debug === 'undefined')
{
_options.debug = false
}
// Save
this.options = _options
}
setName(_name)
{
this.name = _name
this.slug = slug(this.name, { lower: true })
}
setSocket(socket)
{
// Set up
this.originalSocket = socket
this.socket = this.originalSocket.of('/project/' + this.slug)
// Connection event
this.socket.on('connection', (socket) =>
{
this.socket.emit('update_project', this.describe())
// Debug
if(this.options.debug)
{
console.log('socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan)
}
})
}
describe()
{
// Set up
const result = {}
result.name = this.name
result.files = this.files.describe()
result.date = this.date
return result
}
destructor()
{
this.socket.emit('destruct')
}
}
module.exports = Project