Skip to content

Commit

Permalink
Añadido creación de empleados, POST
Browse files Browse the repository at this point in the history
Retocado también el html.
  • Loading branch information
Jesús Mur Fontanals committed Nov 29, 2014
1 parent 58bdfdc commit 121a2e1
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.idea/
46 changes: 39 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@
var express = require('express');
var path = require('path');
var app = module.exports = express();

var morgan = require('morgan');
var swig = require('swig');
var methodOverride = require('method-override');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var app = module.exports = express();

app.engine('html', swig.renderFile);
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.set('view engine', 'html');
app.set('views', __dirname + '/views');

app.use(express.static(path.join(__dirname, 'public')));

app.use(morgan('dev'));

app.get('/', function (req, res) {
debugger;
res.render('index', {message: 'hola mundo'});
});

mongoose.connect('mongodb://localhost:27017/employees');
var Employee = require('./models/employees.js');

app.post('/add',function(req, res) {
var employee = new Employee({
first: req.body.first,
last: req.body.last,
street: req.body.street,
city: req.body.city,
state: req.body.state,
country: req.body.country,
postal_code: req.body.postal_code,
abilities: req.body.abilities,
data: {
worked_hours: req.body.worked_hours,
worked_hpd: req.body.worked_hpd,
salary: req.body.salary
}
});

employee.save(function(err, employee) {
if (err)
res.send(err);
console.log(employee);
res.json({employee: employee, message: 'Employee created!' });
});
});

var port = 3000;
app.listen(port, function (err) {
if (err) {
console.log('Error del servidor ' + err);
} else {
console.log('servidor corriendo en el puerto ' + port);
};
});
console.log('Servidor corriendo en el puerto ' + port);
}
});
5 changes: 2 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ gulp.task('develop', function () {
nodemon({ script: 'app.js', ext: 'html js', ignore: [] })
.on('change', [])
.on('restart', function () {
console.log('restarted!')
console.log('restarted!');
});
});

gulp.task('watch', function (){

gulp.watch('public/styl/**.styl', function (){
gulp.run('styl');
});
Expand All @@ -26,4 +25,4 @@ gulp.task('watch', function (){
});


gulp.task('default',['develop', 'watch']);
gulp.task('default',['develop', 'watch']);
20 changes: 20 additions & 0 deletions models/employees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var mongoose = require('mongoose');

var EmployeesSchema = new mongoose.Schema({
first: String,
last: String,
street: String,
city: String,
state: String,
country: String,
postal_code: Number,
abilities: Array,
data: {
worked_hours: Number,
worked_hpd: Number,
salary: Number
}

});

module.exports = mongoose.model('Employees', EmployeesSchema);
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"description": "Angular learning",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"author": "Jesús Mur Fontanals",
"license": "MIT",
"dependencies": {
"body-parser": "^1.9.3",
"express": "^4.10.1",
"method-override": "^2.3.0",
"mongoose": "^3.8.19",
"morgan": "^1.4.1",
"swig": "^1.4.2"
},
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
street: 'Los Planetas nº22',
city: 'Madrid',
state: 'Madrid',
cp: 28080,
postal_code: 28080,
abilities: ['Javascript', 'Python'],
data: {
worked_hours: 40,
Expand Down
2 changes: 1 addition & 1 deletion public/partials/user-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<li class="list-group-item"><strong>Calle: </strong><span class="pull-right">{{ UserCtrl.user.street }}</span></li>
<li class="list-group-item"><strong>Población: </strong><span class="pull-right">{{ UserCtrl.user.city }}</span></li>
<li class="list-group-item"><strong>Provincia: </strong><span class="pull-right">{{ UserCtrl.user.state }}</span></li>
<li class="list-group-item"><strong>Código postal: </strong><span class="pull-right">{{ UserCtrl.user.cp }}</span></li>
<li class="list-group-item"><strong>Código postal: </strong><span class="pull-right">{{ UserCtrl.user.postal_code }}</span></li>
<li class="list-group-item"><strong>Habilidades: </strong><span ng-repeat="ability in UserCtrl.user.abilities" class="label ability-{{ ability | lowercase }} pull-right">{{ ability }}</span></li>
</ul>
33 changes: 18 additions & 15 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,37 @@
{% raw %}
<div class="row">
<h1>Agenda de usuarios</h1>
<div class="col-md-4 panel panel-body">
<h2 class="text-center">{{ UserCtrl.user.first }} {{ UserCtrl.user.last }}</h2>
<div class="panel panel-default">
<h2 class="text-center">{{ UserCtrl.user.first }} {{ UserCtrl.user.last }}</h2>
<figure class="text-center">
<img src="images/jesus.jpg" width="200" height="200" class="img-circle" alt="{{ UserCtrl.user.first }} {{ UserCtrl.user.last }}">
<img src="images/jesus.jpg" width="150" height="150" class="img-rounded" alt="{{ UserCtrl.user.first }} {{ UserCtrl.user.last }}">
</figure>
<br>
<!-- tabs -->
<div ng-controller="TabsController as tabs">
<div ng-controller="TabsController as tabs">
<ul class="nav nav-tabs nav-justified">
<li ng-class="{ active: tabs.tab === 1 }"><a ng-click="tabs.selectTab(1)">Estado</a></li>
<li ng-class="{ active: tabs.tab === 2 }"><a ng-click="tabs.selectTab(2)">Datos</a></li>
<li ng-class="{ active: tabs.tab === 3 }"><a ng-click="tabs.selectTab(3)">Comentarios <span class="badge">2</span></a></li>
</ul>
<br>
<!-- user info -->
<div ng-show="tabs.tab === 1">
<user-data></user-data>
</div>
<!-- user work info -->
<div ng-show="tabs.tab === 2">
<user-work></user-work>
</div>
<!-- comments -->
<div ng-show="tabs.tab === 3">
<user-comments></user-comments>
<div class="col-md-4 panel-body">
<!-- user info -->
<div ng-show="tabs.tab === 1">
<user-data></user-data>
</div>
<!-- user work info -->
<div ng-show="tabs.tab === 2">
<user-work></user-work>
</div>
<!-- comments -->
<div ng-show="tabs.tab === 3">
<user-comments></user-comments>
</div>
</div>
</div>
</div>
</div>
{% endraw %}
</div>
</body>
Expand Down

0 comments on commit 121a2e1

Please sign in to comment.