`
19 | - **M** – Comment ` `
20 |
21 | ### Replace
22 | Indica si el elemento al que se aplica debe ser sustituído por el resultado de la ejecución
23 |
24 | ### Transclude
25 | Indica si el elemento al que se aplicaca incluirá el resultado de la ejecución de la directiva en su interior
26 |
27 | ### Template y template URL
28 | Cadena de texto o enlace a fichero que contine el HTML que va a devolver la directiva
29 |
30 | ### Scope
31 | Intercambio de datos con el elemento que declara la directiva.
32 | Valores posibles:
33 |
34 | - **@** Interpolating, para enlazar un texto dentro de la directiva. ` scope: { soloLectura: '@' } `
35 | - **=** Data bind, un objeto para doble-enlace que la directiva pueda cambiar ` scope: { valor: '=alias' } `
36 | - **&** Expression `scope: { onEvaluado: '&' } `
37 |
38 |
39 | ### Link
40 | Una función que enlazará la directiva con el scope
41 |
42 | ### Compile
43 | Una función que podrá manipular el DOM creando una función link
44 |
45 | ### Controller
46 | Una función que actuará como contrlador para esta directiva
47 |
--------------------------------------------------------------------------------
/19-directivas/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "express": "~4.12.1",
13 | "body-parser": "~1.0.2"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/19-directivas/recursos.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EscuelaIt/Curso-angularjs-FS-2015/913a55f705c5bbc3191ae30e54ac09a9aa94941e/19-directivas/recursos.md
--------------------------------------------------------------------------------
/20-e2e/Protractor.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EscuelaIt/Curso-angularjs-FS-2015/913a55f705c5bbc3191ae30e54ac09a9aa94941e/20-e2e/Protractor.pdf
--------------------------------------------------------------------------------
/20-e2e/conf.js:
--------------------------------------------------------------------------------
1 | var HtmlReporter = require('protractor-html-screenshot-reporter');
2 |
3 | // configuración de reporter para generar screenshots e informes
4 | var reporter = new HtmlReporter({
5 | baseDirectory: './screenshots',
6 | // takeScreenShotsOnlyForFailedSpecs: true,
7 | docName: 'protractor-report.html'
8 | });
9 |
10 | // configuración básica del protractor
11 | exports.config = {
12 | // ruta del web driver
13 | seleniumAddress: 'http://localhost:4444/wd/hub',
14 |
15 |
16 | // Array de pruebas secuenciales
17 | specs: ['./index/spec.js','./registro/spec.js','./ingreso/spec.js'],
18 |
19 |
20 |
21 | // Agregar el reporte html
22 | onPrepare: function () {
23 | jasmine.getEnv().addReporter(reporter);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/20-e2e/index/conf.js:
--------------------------------------------------------------------------------
1 | exports.config = {
2 | seleniumAddress: 'http://localhost:4444/wd/hub',
3 | specs: ['spec.js']
4 | }
--------------------------------------------------------------------------------
/20-e2e/index/spec.js:
--------------------------------------------------------------------------------
1 | // host que vamos a probar
2 | var host = 'http://localhost:3000/#/';
3 | // Cada describe es un grupo de pruebas
4 | describe('index elements', function () {
5 |
6 | // cada it es una prueba
7 | it('should have a title', function () {
8 | // se pide y espera por una página
9 | browser.get(host);
10 | // condición que se prueba
11 | var theTitle = browser.getTitle();
12 | expect(theTitle).toEqual('Control de Caja');
13 | });
14 |
15 | it('should have navbar', function () {
16 | browser.get(host);
17 | // se usa un api propio para acceder al DOM
18 | var navbar = element(by.name('navbar'));
19 | // comprobaciones de existencia
20 | expect(navbar.isPresent()).toBe(true);
21 | });
22 |
23 | it('should have three menu items', function() {
24 | browser.get(host);
25 | var listItems = element.all(by.tagName ('li'));
26 | // comprobaciones de número
27 | expect(listItems.count()).toBe(3);
28 | });
29 | });
--------------------------------------------------------------------------------
/20-e2e/ingreso/conf.js:
--------------------------------------------------------------------------------
1 | exports.config = {
2 | seleniumAddress: 'http://localhost:4444/wd/hub',
3 | specs: ['spec.js']
4 | }
--------------------------------------------------------------------------------
/20-e2e/ingreso/spec.js:
--------------------------------------------------------------------------------
1 | var host = 'http://localhost:3000/#/';
2 | describe('ingreso |', function () {
3 | it('should save an ingreso', function () {
4 | browser.get(host);
5 | var menuNuevo = element(by.name('menu-nuevo'));
6 | // Navegación a otra página
7 | menuNuevo.click()
8 | .then(function () {
9 | // función asíncrona
10 | var importe = element(by.name('importe'));
11 | importe.clear();
12 | importe.sendKeys('2000');
13 | element(by.name('guardar')).click();
14 | // comprobar en totales
15 | var menutotal = element(by.name('menu-total'));
16 | menutotal.click()
17 | .then(function () {
18 | var ingresos = element(by.name('ingresos'));
19 | // comprobamos el texto, incluído el formato...
20 | expect(ingresos.getText()).toEqual('2,000.00 €');
21 | });
22 | });
23 | });
24 | });
--------------------------------------------------------------------------------
/20-e2e/registro/conf.js:
--------------------------------------------------------------------------------
1 | exports.config = {
2 | seleniumAddress: 'http://localhost:4444/wd/hub',
3 | specs: ['spec.js']
4 | }
--------------------------------------------------------------------------------
/20-e2e/registro/spec.js:
--------------------------------------------------------------------------------
1 | var host = 'http://localhost:3000/#/';
2 | describe('registro |', function () {
3 | it('should perform a registro', function () {
4 | browser.get(host);
5 | var email = element(by.name('email'));
6 | email.clear();
7 | email.sendKeys('albertobasalo@agorabinaria.com');
8 | var password = element(by.name('password'));
9 | password.clear();
10 | password.sendKeys('1234');
11 | var registrar = element(by.name('registrar'));
12 | registrar.click()
13 | .then(function () {
14 | var ingresos = element(by.name('ingresos'));
15 | // comprobamos el texto, incluído el formato...
16 | expect(ingresos.getText()).toEqual('0.00 €');
17 | });
18 | });
19 |
20 |
21 | it('should not allow to re-registro', function () {
22 | browser.get(host+"#/registro");
23 | var email = element(by.name('email'));
24 | email.clear();
25 | email.sendKeys('albertobasalo@agorabinaria.com');
26 | var password = element(by.name('password'));
27 | password.clear();
28 | password.sendKeys('1234');
29 | var registrar = element(by.name('registrar'));
30 | registrar.click()
31 | .then(function () {
32 | var email = element(by.name('email'));
33 | expect(email.isPresent()).toBe(true);
34 | });
35 | });
36 | });
--------------------------------------------------------------------------------
/21-organizacion/client/app.js:
--------------------------------------------------------------------------------
1 | angular.module('controlCajaApp', ['ui.router','ngCookies', 'ngResource', 'abFiltros','abDirectivas']);
2 |
3 | angular.module('controlCajaApp').config(function ($stateProvider,$locationProvider) {
4 | $stateProvider
5 | .state('total', {
6 | url: '/',
7 | controller: 'CajaCtrl as caja',
8 | templateUrl: 'total.html'
9 | })
10 | .state('nuevo', {
11 | url: '/nuevo',
12 | controller: 'CajaCtrl as caja',
13 | templateUrl: 'nuevo.html'
14 | })
15 | .state('lista', {
16 | url: '/lista',
17 | controller: 'CajaCtrl as caja',
18 | templateUrl: 'lista.html'
19 | })
20 | .state('movimiento', {
21 | url: '/movimiento/:id',
22 | controller: 'MovimientoCtrl as vm',
23 | templateUrl: 'movimiento.html'
24 | })
25 | .state('registro', {
26 | url: '/registro',
27 | controller: 'RegistroCtrl as registro',
28 | templateUrl: 'registro.html'
29 | })
30 | .state('not-found', {
31 | url: '*path',
32 | controller: 'CajaCtrl as caja',
33 | templateUrl: 'total.html'
34 | });
35 | });
--------------------------------------------------------------------------------
/21-organizacion/client/appHttpLog.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function configuradorInterceptores($httpProvider) {
4 | $httpProvider.interceptors.push(funcionInterceptoraLog);
5 | }
6 |
7 | function funcionInterceptoraLog($log) {
8 |
9 | var interceptor = {};
10 | interceptor.request = function (request) {
11 | $log.info('request:' + request.url);
12 | return request ;
13 | };
14 | interceptor.responseError = function (response) {
15 | $log.error("excepción: " + response.status + " de :" + response.config.url);
16 | }
17 | return interceptor;
18 | }
19 |
20 | angular.module('controlCajaApp').config(configuradorInterceptores);
21 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/appSecurity.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | function configuradorInterceptores($httpProvider) {
3 | $httpProvider.interceptors.push(funcionInterceptoraSeguridad);
4 | }
5 |
6 | function funcionInterceptoraSeguridad($q, $injector, $cookieStore, $rootScope) {
7 |
8 | var interceptor = {};
9 | interceptor.request = function (request) {
10 | request.headers["sessionId"] = $cookieStore.get("sessionId");
11 | return request || $q.when(request);
12 | };
13 | interceptor.responseError = function (response) {
14 | var state = $injector.get('$state');
15 | if (response.status === 401) {
16 | $rootScope.mensaje = "No hay derecho!!!";
17 | state.go('registro');
18 | } else if (response.status === 419) {
19 | $rootScope.mensaje = "Estoy caduco!!!";
20 | $cookieStore.remove("sessionId")
21 | state.go('registro');
22 | };
23 | return $q.reject(response);
24 | }
25 | return interceptor;
26 | }
27 |
28 | angular.module('controlCajaApp').config(configuradorInterceptores);
29 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/cajaCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var cajaCtrl = function (maestrosFactory, movimientosFactory) {
3 | var vm = this;
4 |
5 | vm.titulo = "Controla tu Cash Flow";
6 |
7 | vm.maestros = maestrosFactory.get();
8 |
9 | vm.nuevoMovimiento = new movimientosFactory.movimientos();
10 | vm.nuevoMovimiento.esIngreso = 1;
11 | vm.nuevoMovimiento.fecha = new Date();
12 |
13 | vm.movimientos = movimientosFactory.movimientos.query();
14 |
15 | vm.total = movimientosFactory.total.get();
16 |
17 | vm.guardarMovimiento = function () {
18 | vm.nuevoMovimiento.tipo = vm.tipo(vm.nuevoMovimiento);
19 | vm.nuevoMovimiento.$save()
20 | .then(function (postedData) {
21 | vm.movimientos = movimientosFactory.movimientos.query();
22 | vm.total = movimientosFactory.total.get();
23 | vm.nuevoMovimiento.importe = 0;
24 | });
25 | }
26 | vm.balance = function () {
27 | return vm.total.ingresos - vm.total.gastos
28 | }
29 | vm.tipo = function (movimiento) {
30 | return movimiento.esIngreso && 'Ingreso' || 'Gasto'
31 | }
32 | }
33 | angular.module('controlCajaApp').controller('CajaCtrl', cajaCtrl);
34 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/lista.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/21-organizacion/client/maestrosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var maestrosFactory = function ($resource) {
3 | return $resource("/api/pub/maestros/",{},{get: {cache: true}});
4 | };
5 |
6 | angular.module('controlCajaApp').factory('maestrosFactory', maestrosFactory);
7 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/menuCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var menuCtrl = function ($state) {
3 | this.isActive = function (estado) {
4 | return $state.is(estado);
5 | }
6 | }
7 | angular.module('controlCajaApp').controller('MenuCtrl',menuCtrl);
8 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/movimientoCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var movimientoCtrl = function ($stateParams, movimientosFactory) {
3 | var vm = this;
4 | var movId = $stateParams.id;
5 | vm.movimiento = movimientosFactory.movimientos.get({id:movId});
6 | }
7 | angular.module('controlCajaApp').controller('MovimientoCtrl', movimientoCtrl);
8 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/movimientosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var movimientosFactory = function ($resource) {
4 |
5 | var factory = {};
6 | factory.movimientos = $resource("/api/priv/movimientos/:id", {
7 | id: "@id"
8 | })
9 | factory.total = $resource("/api/priv/total/");
10 |
11 | return factory;
12 | };
13 |
14 | angular.module('controlCajaApp').factory('movimientosFactory', movimientosFactory);
15 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/not-found.html:
--------------------------------------------------------------------------------
1 |
2 | No se ha encontrado lo que buscabas
3 |
--------------------------------------------------------------------------------
/21-organizacion/client/registroCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var registroCtrl = function ($rootScope, $state, $http, $cookieStore) {
3 | var urlBase = "http://localhost:3000/api/";
4 | var vm = this;
5 | vm.usuario = {};
6 | vm.entrar = function () {
7 | $http.post(urlBase + 'sesiones/', vm.usuario)
8 | .success(function (data) {
9 | $rootScope.nombre = vm.usuario.email;
10 | $rootScope.mensaje = 'recién entrado';
11 | $cookieStore.put("sessionId", data);
12 | $state.go("total");
13 | });
14 | }
15 | vm.registrar = function () {
16 | $http.post(urlBase + 'usuarios/', vm.usuario)
17 | .success(function (data) {
18 | $rootScope.nombre = vm.usuario.email;
19 | $rootScope.mensaje = 'recién creado';
20 | $cookieStore.put("sessionId", data);
21 | $state.go("total");
22 | });
23 | }
24 | }
25 | angular.module('controlCajaApp').controller('RegistroCtrl', registroCtrl);
26 | }());
--------------------------------------------------------------------------------
/21-organizacion/client/total.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ caja.total.ingresos | number:2 }} €
9 |
10 |
11 | Total ingresos
12 | Acumulado
13 |
14 |
15 |
16 |
17 | {{ caja.total.gastos | number:2 }} €
18 |
19 |
20 | Total gastos
21 | Acumulado
22 |
23 |
24 |
25 |
26 | {{ caja.balance() | number:2 }} €
27 |
28 |
29 | Balance
30 | Ingresos-Gastos
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/21-organizacion/client/tpl-cabecera.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/21-organizacion/client/tpl-fila-movimiento.html:
--------------------------------------------------------------------------------
1 |
2 | {{movimientoplantilla.id }} |
3 | {{movimientoplantilla.fecha | date}} |
4 | {{movimientoplantilla.tipo}} |
5 | {{movimientoplantilla.categoria}} |
6 |
7 | {{movimientoplantilla.importe | number:2}} €
8 | |
9 | |
10 |
--------------------------------------------------------------------------------
/21-organizacion/client/tpl-valoracion.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 | *
10 |
11 |
12 |
--------------------------------------------------------------------------------
/21-organizacion/client/valoracion.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var valoracion = function () {
3 | return {
4 | restrict: 'AE',
5 | templateUrl: '/tpl-valoracion.html',
6 | scope: {
7 | valor: '=',
8 | max: '@',
9 | soloLectura: '@'
10 | },
11 | link: function (scope, elem, attrs) {
12 | function actualizar() {
13 | if(!scope.valor)scope.valor=1;
14 | scope.estrellas = [];
15 | for (var i = 0; i < scope.max; i++) {
16 | var estrella = {
17 | marcada: (i < scope.valor)
18 | };
19 | scope.estrellas.push(estrella);
20 | }
21 | };
22 |
23 | scope.marcar = function (indice) {
24 | if (scope.soloLectura && scope.soloLectura === 'true') {
25 | return;
26 | }
27 | scope.valor = indice + 1;
28 | actualizar();
29 | };
30 | actualizar();
31 | }
32 | }
33 | }
34 |
35 | angular.module('abDirectivas')
36 | .directive('abValoracion', valoracion);
37 |
38 | }());
--------------------------------------------------------------------------------
/21-organizacion/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "express": "~4.12.1",
13 | "body-parser": "~1.0.2"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/21-organizacion/recursos.md:
--------------------------------------------------------------------------------
1 | https://angular-ui.github.io/
2 | http://ngmodules.org/c
3 | http://angular-js.in/
4 | http://www.directiv.es/
5 |
6 | http://www.tamas.io/node-jsexpress-cors-implementation/
7 | http://stackoverflow.com/questions/23823010/how-to-enable-cors-in-angularjs
--------------------------------------------------------------------------------
/21b-organizacion/client/_comun/app.js:
--------------------------------------------------------------------------------
1 | angular.module('controlCajaApp', ['ui.router','ngCookies', 'ngResource', 'abFiltros','abDirectivas']);
2 |
3 | angular.module('controlCajaApp').config(function ($stateProvider,$locationProvider) {
4 | $stateProvider
5 | .state('total', {
6 | url: '/',
7 | controller: 'CajaCtrl as caja',
8 | templateUrl: 'controlcaja/total.html'
9 | })
10 | .state('nuevo', {
11 | url: '/nuevo',
12 | controller: 'CajaCtrl as caja',
13 | templateUrl: 'controlcaja/nuevo.html'
14 | })
15 | .state('lista', {
16 | url: '/lista',
17 | controller: 'CajaCtrl as caja',
18 | templateUrl: 'controlcaja/lista.html'
19 | })
20 | .state('movimiento', {
21 | url: '/movimiento/:id',
22 | controller: 'MovimientoCtrl as vm',
23 | templateUrl: 'movimiento/movimiento.html'
24 | })
25 | .state('registro', {
26 | url: '/registro',
27 | controller: 'RegistroCtrl as registro',
28 | templateUrl: 'registro/registro.html'
29 | })
30 | .state('not-found', {
31 | url: '*path',
32 | templateUrl: '_comun/not-found.html'
33 | });
34 | });
--------------------------------------------------------------------------------
/21b-organizacion/client/_comun/appHttpLog.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function configuradorInterceptores($httpProvider) {
4 | $httpProvider.interceptors.push(funcionInterceptoraLog);
5 | }
6 |
7 | function funcionInterceptoraLog($log) {
8 |
9 | var interceptor = {};
10 | interceptor.request = function (request) {
11 | $log.info('request:' + request.url);
12 | return request ;
13 | };
14 | interceptor.responseError = function (response) {
15 | $log.error("excepción: " + response.status + " de :" + response.config.url);
16 | }
17 | return interceptor;
18 | }
19 |
20 | angular.module('controlCajaApp').config(configuradorInterceptores);
21 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/_comun/appSecurity.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | function configuradorInterceptores($httpProvider) {
3 | $httpProvider.interceptors.push(funcionInterceptoraSeguridad);
4 | }
5 |
6 | function funcionInterceptoraSeguridad($q, $injector, $cookieStore, $rootScope) {
7 |
8 | var interceptor = {};
9 | interceptor.request = function (request) {
10 | request.headers["sessionId"] = $cookieStore.get("sessionId");
11 | return request || $q.when(request);
12 | };
13 | interceptor.responseError = function (response) {
14 | var state = $injector.get('$state');
15 | if (response.status === 401) {
16 | $rootScope.mensaje = "No hay derecho!!!";
17 | state.go('registro');
18 | } else if (response.status === 419) {
19 | $rootScope.mensaje = "Estoy caduco!!!";
20 | $cookieStore.remove("sessionId")
21 | state.go('registro');
22 | };
23 | return $q.reject(response);
24 | }
25 | return interceptor;
26 | }
27 |
28 | angular.module('controlCajaApp').config(configuradorInterceptores);
29 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/_comun/menuCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var menuCtrl = function ($state) {
3 | this.isActive = function (estado) {
4 | return $state.is(estado);
5 | }
6 | }
7 | angular.module('controlCajaApp').controller('MenuCtrl',menuCtrl);
8 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/_comun/not-found.html:
--------------------------------------------------------------------------------
1 |
2 | No se ha encontrado lo que buscabas
3 |
--------------------------------------------------------------------------------
/21b-organizacion/client/controlcaja/cajaCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var cajaCtrl = function (maestrosFactory, movimientosFactory) {
3 | var vm = this;
4 |
5 | vm.titulo = "Controla tu Cash Flow";
6 |
7 | vm.maestros = maestrosFactory.get();
8 |
9 | vm.nuevoMovimiento = new movimientosFactory.movimientos();
10 | vm.nuevoMovimiento.esIngreso = 1;
11 | vm.nuevoMovimiento.fecha = new Date();
12 |
13 | vm.movimientos = movimientosFactory.movimientos.query();
14 |
15 | vm.total = movimientosFactory.total.get();
16 |
17 | vm.guardarMovimiento = function () {
18 | vm.nuevoMovimiento.tipo = vm.tipo(vm.nuevoMovimiento);
19 | vm.nuevoMovimiento.$save()
20 | .then(function (postedData) {
21 | vm.movimientos = movimientosFactory.movimientos.query();
22 | vm.total = movimientosFactory.total.get();
23 | vm.nuevoMovimiento.importe = 0;
24 | });
25 | }
26 | vm.balance = function () {
27 | return vm.total.ingresos - vm.total.gastos
28 | }
29 | vm.tipo = function (movimiento) {
30 | return movimiento.esIngreso && 'Ingreso' || 'Gasto'
31 | }
32 | }
33 | angular.module('controlCajaApp').controller('CajaCtrl', cajaCtrl);
34 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/controlcaja/lista.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/21b-organizacion/client/controlcaja/total.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ caja.total.ingresos | number:2 }} €
9 |
10 |
11 | Total ingresos
12 | Acumulado
13 |
14 |
15 |
16 |
17 | {{ caja.total.gastos | number:2 }} €
18 |
19 |
20 | Total gastos
21 | Acumulado
22 |
23 |
24 |
25 |
26 | {{ caja.balance() | number:2 }} €
27 |
28 |
29 | Balance
30 | Ingresos-Gastos
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/21b-organizacion/client/data/maestrosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var maestrosFactory = function ($resource) {
3 | return $resource("/api/pub/maestros/",{},{get: {cache: true}});
4 | };
5 |
6 | angular.module('controlCajaApp').factory('maestrosFactory', maestrosFactory);
7 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/data/movimientosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var movimientosFactory = function ($resource) {
4 |
5 | var factory = {};
6 | factory.movimientos = $resource("/api/priv/movimientos/:id", {
7 | id: "@id"
8 | })
9 | factory.total = $resource("/api/priv/total/");
10 |
11 | return factory;
12 | };
13 |
14 | angular.module('controlCajaApp').factory('movimientosFactory', movimientosFactory);
15 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/directivas/tpl-cabecera.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/21b-organizacion/client/directivas/tpl-fila-movimiento.html:
--------------------------------------------------------------------------------
1 |
2 | {{movimientoplantilla.id }} |
3 | {{movimientoplantilla.fecha | date}} |
4 | {{movimientoplantilla.tipo}} |
5 | {{movimientoplantilla.categoria}} |
6 |
7 | {{movimientoplantilla.importe | number:2}} €
8 | |
9 | |
10 |
--------------------------------------------------------------------------------
/21b-organizacion/client/directivas/valoracion/tpl-valoracion.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 | *
10 |
11 |
12 |
--------------------------------------------------------------------------------
/21b-organizacion/client/directivas/valoracion/valoracion.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var valoracion = function () {
3 | return {
4 | restrict: 'AE',
5 | templateUrl: '/directivas/valoracion/tpl-valoracion.html',
6 | scope: {
7 | valor: '=',
8 | max: '@',
9 | soloLectura: '@'
10 | },
11 | link: function (scope, elem, attrs) {
12 | function actualizar() {
13 | if(!scope.valor)scope.valor=1;
14 | scope.estrellas = [];
15 | for (var i = 0; i < scope.max; i++) {
16 | var estrella = {
17 | marcada: (i < scope.valor)
18 | };
19 | scope.estrellas.push(estrella);
20 | }
21 | };
22 |
23 | scope.marcar = function (indice) {
24 | if (scope.soloLectura && scope.soloLectura === 'true') {
25 | return;
26 | }
27 | scope.valor = indice + 1;
28 | actualizar();
29 | };
30 | actualizar();
31 | }
32 | }
33 | }
34 |
35 | angular.module('abDirectivas')
36 | .directive('abValoracion', valoracion);
37 |
38 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/movimiento/movimientoCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var movimientoCtrl = function ($stateParams, movimientosFactory) {
3 | var vm = this;
4 | var movId = $stateParams.id;
5 | vm.movimiento = movimientosFactory.movimientos.get({id:movId});
6 | }
7 | angular.module('controlCajaApp').controller('MovimientoCtrl', movimientoCtrl);
8 | }());
--------------------------------------------------------------------------------
/21b-organizacion/client/registro/registroCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var registroCtrl = function ($rootScope, $state, $http, $cookieStore) {
3 | var urlBase = "http://localhost:3000/api/";
4 | var vm = this;
5 | vm.usuario = {};
6 | vm.entrar = function () {
7 | $http.post(urlBase + 'sesiones/', vm.usuario)
8 | .success(function (data) {
9 | $rootScope.nombre = vm.usuario.email;
10 | $rootScope.mensaje = 'recién entrado';
11 | $cookieStore.put("sessionId", data);
12 | $state.go("total");
13 | });
14 | }
15 | vm.registrar = function () {
16 | $http.post(urlBase + 'usuarios/', vm.usuario)
17 | .success(function (data) {
18 | $rootScope.nombre = vm.usuario.email;
19 | $rootScope.mensaje = 'recién creado';
20 | $cookieStore.put("sessionId", data);
21 | $state.go("total");
22 | });
23 | }
24 | }
25 | angular.module('controlCajaApp').controller('RegistroCtrl', registroCtrl);
26 | }());
--------------------------------------------------------------------------------
/21b-organizacion/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "express": "~4.12.1",
13 | "body-parser": "~1.0.2"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/21b-organizacion/server.js:
--------------------------------------------------------------------------------
1 | var app = require('./server/config.js').configApp();
2 | require('./server/seguridad.js').seguridad(app);
3 | console.log('ready');
4 |
5 | require('./server/maestros.js').routeMaestros(app);
6 | require('./server/movimientos.js').routeMovimientos(app);
7 | console.log('steady');
8 |
9 | app.listen(3000);
10 | console.log('go');
--------------------------------------------------------------------------------
/21b-organizacion/server/config.js:
--------------------------------------------------------------------------------
1 | module.exports.configApp = function () {
2 |
3 | var express = require('express');
4 | var bodyParser = require('body-parser');
5 |
6 | var app = express();
7 |
8 | app.use(bodyParser());
9 | app.use(express.static(__dirname + './../client'));
10 |
11 | app.use(function (peticion, respuesta, siguiente) {
12 | console.log("recibida petición: " + peticion.url);
13 | if (peticion.body && Object.keys(peticion.body).length > 0) {
14 | console.log("body: " + JSON.stringify(peticion.body));
15 | }
16 | siguiente();
17 | });
18 |
19 | return app;
20 |
21 | }
--------------------------------------------------------------------------------
/21b-organizacion/server/maestros.js:
--------------------------------------------------------------------------------
1 | module.exports.routeMaestros = function (app) {
2 | app.get('/api/pub/maestros', function (req, res, next) {
3 | var maestros = {
4 | categoriasIngresos: ['Nómina', 'Ventas', 'Intereses Depósitos'],
5 | categoriasGastos: ['Hipotéca', 'Compras', 'Impuestos']
6 | };
7 | res.json(maestros);
8 | });
9 | }
--------------------------------------------------------------------------------
/22-mongo-console/1-crear.js:
--------------------------------------------------------------------------------
1 | use control_caja
2 |
3 | db.movimientos.drop()
4 | db.createCollection('movimientos')
5 |
6 | //var movimiento = {
7 | // user: 'albertobasalo@agorabinaria.com',
8 | // tipo: 'Ingreso',
9 | // categoria: 'Nómina',
10 | // importe: 1200,
11 | // fecha: new Date(2015, 03, 06, 12, 00, 00, 000)
12 | //};
13 | //db.movimientos.insert(movimiento);
14 |
15 | var nomina_alberto = {
16 | user: 'albertobasalo@agorabinaria.com',
17 | tipo: 'Ingreso',
18 | categoria: 'Nómina',
19 | importe: 1200,
20 | fecha: new Date(2015, 03, 01, 12,00, 00, 000)
21 | };
22 | db.movimientos.insert(nomina_alberto);
23 | var hipoteca_alberto = {
24 | user: 'albertobasalo@agorabinaria.com',
25 | tipo: 'Gasto',
26 | categoria: 'Hipoteca',
27 | importe: 400,
28 | fecha: new Date(2015, 03, 06, 12, 0, 00, 000)
29 | };
30 | db.movimientos.insert(hipoteca_alberto);
31 | var nomina_reinaldo = {
32 | user: 'reinaldo.aguilera@gmail.com',
33 | tipo: 'Ingreso',
34 | categoria: 'Nómina',
35 | importe: 1100,
36 | fecha: new Date(2015, 03, 02, 12, 0, 00, 000)
37 | };
38 | db.movimientos.insert(nomina_reinaldo);
39 | var hipoteca_reinaldo = {
40 | user: 'reinaldo.aguilera@gmail.com',
41 | tipo: 'Gasto',
42 | categoria: 'Hipoteca',
43 | importe: 450,
44 | fecha: new Date(2015, 03, 04, 12, 0, 00, 000)
45 | };
46 | db.movimientos.insert(hipoteca_reinaldo);
47 |
48 | db.movimientos.find();
--------------------------------------------------------------------------------
/22-mongo-console/2-buscar.js:
--------------------------------------------------------------------------------
1 | use control_caja
2 |
3 | // busquedas
4 | var movimientos_alberto = db.movimientos.find({
5 | user: 'albertobasalo@agorabinaria.com'
6 | });
7 |
8 | var nomina_alberto = db.movimientos.find({
9 | user: 'albertobasalo@agorabinaria.com',
10 | categoria: 'Nómina'
11 | });
12 |
13 | var grandes_movimientos = db.movimientos.find({
14 | importe: {
15 | $gt: 1000
16 | }
17 | });
18 |
19 | var alberto_or_grandes_movimientos = db.movimientos.find({
20 | $or: [{
21 | importe: {
22 | $gt: 1000
23 | }
24 | }, {
25 | user: 'albertobasalo@agorabinaria.com'
26 | }
27 | ]
28 | });
29 |
30 | var movimientos_parecidos = db.movimientos.find({
31 | user: /agorabinaria/
32 | });
33 |
34 | var movimientos_parecidos = db.movimientos.find({
35 | user: /al/i
36 | });
37 |
38 | var movimientos_parecidos = db.movimientos.find({
39 | user: /^al/
40 | });
41 |
42 |
43 | var movimientos_ordenados = db.movimientos.find().sort({importe:1});
44 |
45 | // proyecciones
46 | var movimientos_importes = db.movimientos.find({},{importe:1})
47 | var movimientos_importes_sin_clave = db.movimientos.find({},{importe:1, _id:0})
48 |
49 | // limites y paginación
50 | db.movimientos.find().limit(2).skip(1)
51 | // cuenta
52 | db.movimientos.count()
53 | // distintos
54 | db.movimientos.distinct( "categoria" )
--------------------------------------------------------------------------------
/22-mongo-console/4-insertar.js:
--------------------------------------------------------------------------------
1 | use control_caja
2 |
3 | function azar(desde, hasta) {
4 | return Math.floor((Math.random() * hasta) + desde)
5 | }
6 |
7 | function tipo() {
8 | if (azar(0, 10) > 4) {
9 | return 'Ingreso';
10 | } else {
11 | return 'Gasto';
12 | }
13 | }
14 |
15 | function user() {
16 | if (azar(0, 10) > 4) {
17 | return 'albertobasalo@agorabinaria.com';
18 | } else {
19 | return 'reinaldo.aguilera@gmail.com';
20 | }
21 | }
22 |
23 | for (i = 0; i < 100; i++) {
24 | var movimiento = {
25 | user: user();
26 | tipo: tipo(),
27 | importe: azar(100, 2500),
28 | fecha: new Date(2015, azar(0, 11), azar(1, 30), 12, 0, 0)
29 | };
30 | db.movimientos.insert(movimiento);
31 | }
32 |
33 | db.movimientos.find();
--------------------------------------------------------------------------------
/22-mongo-console/mongodb.md:
--------------------------------------------------------------------------------
1 | #Schemma-less
2 |
3 | #Comparación
4 |
5 | ## Inconvenientes
6 | - No Joins
7 | - No Transactions
8 | - No Integrity
9 | - Sintaxis novedosa y a veces difícil
10 |
11 | ## Ventajas
12 | - Velocidad
13 | - Flexibilidad
14 | - Escalabilidad
15 |
16 | #Conceptos
17 |
18 | ## Física
19 | Server
20 |
21 | Réplica
22 |
23 | Shard
24 |
25 | Database
26 |
27 |
28 |
29 | ## Lógica
30 | Database
31 |
32 | Collection (Table)
33 |
34 | Document (Row)
35 |
36 | Property (Fiel)
37 |
38 | Schemma(-less)
39 |
40 |
41 | #Comandos
42 | mongod --dbpath
43 | mongo
44 |
45 | #GUI
46 | robomongo
47 |
48 |
49 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/_comun/app.js:
--------------------------------------------------------------------------------
1 | angular.module('controlCajaApp', ['ui.router','ngCookies', 'ngResource', 'abFiltros','abDirectivas']);
2 |
3 | angular.module('controlCajaApp').config(function ($stateProvider,$locationProvider) {
4 | $stateProvider
5 | .state('total', {
6 | url: '/',
7 | controller: 'CajaCtrl as caja',
8 | templateUrl: 'controlcaja/total.html'
9 | })
10 | .state('nuevo', {
11 | url: '/nuevo',
12 | controller: 'CajaCtrl as caja',
13 | templateUrl: 'controlcaja/nuevo.html'
14 | })
15 | .state('lista', {
16 | url: '/lista',
17 | controller: 'CajaCtrl as caja',
18 | templateUrl: 'controlcaja/lista.html'
19 | })
20 | .state('movimiento', {
21 | url: '/movimiento/:_id',
22 | controller: 'MovimientoCtrl as vm',
23 | templateUrl: 'movimiento/movimiento.html'
24 | })
25 | .state('registro', {
26 | url: '/registro',
27 | controller: 'RegistroCtrl as registro',
28 | templateUrl: 'registro/registro.html'
29 | })
30 | .state('not-found', {
31 | url: '*path',
32 | templateUrl: '_comun/not-found.html'
33 | });
34 | });
--------------------------------------------------------------------------------
/23-mongodb-client/client/_comun/appHttpLog.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function configuradorInterceptores($httpProvider) {
4 | $httpProvider.interceptors.push(funcionInterceptoraLog);
5 | }
6 |
7 | function funcionInterceptoraLog($log) {
8 |
9 | var interceptor = {};
10 | interceptor.request = function (request) {
11 | $log.info('request:' + request.url);
12 | return request ;
13 | };
14 | interceptor.responseError = function (response) {
15 | $log.error("excepción: " + response.status + " de :" + response.config.url);
16 | }
17 | return interceptor;
18 | }
19 |
20 | angular.module('controlCajaApp').config(configuradorInterceptores);
21 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/_comun/appSecurity.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | function configuradorInterceptores($httpProvider) {
3 | $httpProvider.interceptors.push(funcionInterceptoraSeguridad);
4 | }
5 |
6 | function funcionInterceptoraSeguridad($q, $injector, $cookieStore, $rootScope) {
7 |
8 | var interceptor = {};
9 | interceptor.request = function (request) {
10 | request.headers["sessionId"] = $cookieStore.get("sessionId");
11 | return request || $q.when(request);
12 | };
13 | interceptor.responseError = function (response) {
14 | var state = $injector.get('$state');
15 | if (response.status === 401) {
16 | $rootScope.mensaje = "No hay derecho!!!";
17 | state.go('registro');
18 | } else if (response.status === 419) {
19 | $rootScope.mensaje = "Estoy caduco!!!";
20 | $cookieStore.remove("sessionId")
21 | state.go('registro');
22 | };
23 | return $q.reject(response);
24 | }
25 | return interceptor;
26 | }
27 |
28 | angular.module('controlCajaApp').config(configuradorInterceptores);
29 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/_comun/menuCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var menuCtrl = function ($state) {
3 | this.isActive = function (estado) {
4 | return $state.is(estado);
5 | }
6 | }
7 | angular.module('controlCajaApp').controller('MenuCtrl',menuCtrl);
8 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/_comun/not-found.html:
--------------------------------------------------------------------------------
1 |
2 | No se ha encontrado lo que buscabas
3 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/controlcaja/cajaCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var cajaCtrl = function (maestrosFactory, movimientosFactory) {
3 | var vm = this;
4 |
5 | vm.titulo = "Controla tu Cash Flow";
6 |
7 | vm.maestros = maestrosFactory.get();
8 |
9 | vm.nuevoMovimiento = new movimientosFactory.movimientos();
10 | vm.nuevoMovimiento.esIngreso = 1;
11 | vm.nuevoMovimiento.fecha = new Date();
12 |
13 | vm.movimientos = movimientosFactory.movimientos.query();
14 |
15 | vm.total = movimientosFactory.total.get();
16 |
17 | vm.guardarMovimiento = function () {
18 | vm.nuevoMovimiento.tipo = vm.tipo(vm.nuevoMovimiento);
19 | vm.nuevoMovimiento.$save()
20 | .then(function (postedData) {
21 | vm.movimientos = movimientosFactory.movimientos.query();
22 | vm.total = movimientosFactory.total.get();
23 | vm.nuevoMovimiento.importe = 0;
24 | });
25 | }
26 | vm.balance = function () {
27 | return vm.total.ingresos - vm.total.gastos
28 | }
29 | vm.tipo = function (movimiento) {
30 | return movimiento.esIngreso && 'Ingreso' || 'Gasto'
31 | }
32 | }
33 | angular.module('controlCajaApp').controller('CajaCtrl', cajaCtrl);
34 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/controlcaja/lista.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/controlcaja/total.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ caja.total.ingresos | number:2 }} €
9 |
10 |
11 | Total ingresos
12 | Acumulado
13 |
14 |
15 |
16 |
17 | {{ caja.total.gastos | number:2 }} €
18 |
19 |
20 | Total gastos
21 | Acumulado
22 |
23 |
24 |
25 |
26 | {{ caja.balance() | number:2 }} €
27 |
28 |
29 | Balance
30 | Ingresos-Gastos
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/data/maestrosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var maestrosFactory = function ($resource) {
3 | return $resource("/api/pub/maestros/",{},{get: {cache: true}});
4 | };
5 |
6 | angular.module('controlCajaApp').factory('maestrosFactory', maestrosFactory);
7 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/data/movimientosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var movimientosFactory = function ($resource) {
4 |
5 | var factory = {};
6 | factory.movimientos = $resource("/api/priv/movimientos/:id", {
7 | id: "@id"
8 | })
9 | factory.total = $resource("/api/priv/total/");
10 |
11 | return factory;
12 | };
13 |
14 | angular.module('controlCajaApp').factory('movimientosFactory', movimientosFactory);
15 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/directivas/tpl-cabecera.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/directivas/tpl-fila-movimiento.html:
--------------------------------------------------------------------------------
1 |
2 | {{movimientoplantilla._id }} |
3 | {{movimientoplantilla.fecha | date}} |
4 | {{movimientoplantilla.tipo}} |
5 | {{movimientoplantilla.categoria}} |
6 |
7 | {{movimientoplantilla.importe | number:2}} €
8 | |
9 | |
10 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/directivas/valoracion/tpl-valoracion.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 | *
10 |
11 |
12 |
--------------------------------------------------------------------------------
/23-mongodb-client/client/directivas/valoracion/valoracion.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var valoracion = function () {
3 | return {
4 | restrict: 'AE',
5 | templateUrl: '/directivas/valoracion/tpl-valoracion.html',
6 | scope: {
7 | valor: '=',
8 | max: '@',
9 | soloLectura: '@'
10 | },
11 | link: function (scope, elem, attrs) {
12 | function actualizar() {
13 | if(!scope.valor)scope.valor=1;
14 | scope.estrellas = [];
15 | for (var i = 0; i < scope.max; i++) {
16 | var estrella = {
17 | marcada: (i < scope.valor)
18 | };
19 | scope.estrellas.push(estrella);
20 | }
21 | };
22 |
23 | scope.marcar = function (indice) {
24 | if (scope.soloLectura && scope.soloLectura === 'true') {
25 | return;
26 | }
27 | scope.valor = indice + 1;
28 | actualizar();
29 | };
30 | actualizar();
31 | }
32 | }
33 | }
34 |
35 | angular.module('abDirectivas')
36 | .directive('abValoracion', valoracion);
37 |
38 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/movimiento/movimientoCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var movimientoCtrl = function ($stateParams, movimientosFactory) {
3 | var vm = this;
4 | vm.movimiento = movimientosFactory.movimientos.get({id:$stateParams._id});
5 | }
6 | angular.module('controlCajaApp').controller('MovimientoCtrl', movimientoCtrl);
7 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/client/registro/registroCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var registroCtrl = function ($rootScope, $state, $http, $cookieStore) {
3 | var urlBase = "http://localhost:3000/api/";
4 | var vm = this;
5 | vm.usuario = {};
6 | vm.entrar = function () {
7 | $http.post(urlBase + 'sesiones/', vm.usuario)
8 | .success(function (data) {
9 | $rootScope.nombre = vm.usuario.email;
10 | $rootScope.mensaje = 'recién entrado';
11 | $cookieStore.put("sessionId", data);
12 | $state.go("total");
13 | });
14 | }
15 | vm.registrar = function () {
16 | $http.post(urlBase + 'usuarios/', vm.usuario)
17 | .success(function (data) {
18 | $rootScope.nombre = vm.usuario.email;
19 | $rootScope.mensaje = 'recién creado';
20 | $cookieStore.put("sessionId", data);
21 | $state.go("total");
22 | });
23 | }
24 | }
25 | angular.module('controlCajaApp').controller('RegistroCtrl', registroCtrl);
26 | }());
--------------------------------------------------------------------------------
/23-mongodb-client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "body-parser": "~1.0.2",
13 | "express": "~4.12.1",
14 | "mongodb": "^2.0.27",
15 | "q": "^1.2.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/23-mongodb-client/server.js:
--------------------------------------------------------------------------------
1 | var app = require('./server/config.js').configApp();
2 | require('./server/seguridad.js').seguridad(app);
3 | console.log('ready');
4 |
5 | require('./server/maestros.js').routeMaestros(app);
6 | require('./server/movimientos.js').routeMovimientos(app);
7 | console.log('steady');
8 |
9 | app.listen(3000);
10 | console.log('go');
--------------------------------------------------------------------------------
/23-mongodb-client/server/config.js:
--------------------------------------------------------------------------------
1 | module.exports.configApp = function () {
2 |
3 | var express = require('express');
4 | var bodyParser = require('body-parser');
5 |
6 | var app = express();
7 |
8 | app.use(bodyParser());
9 | app.use(express.static(__dirname + './../client'));
10 |
11 | app.use(function (peticion, respuesta, siguiente) {
12 | console.log("recibida petición: " + peticion.url);
13 | if (peticion.body && Object.keys(peticion.body).length > 0) {
14 | console.log("body: " + JSON.stringify(peticion.body));
15 | }
16 | siguiente();
17 | });
18 |
19 | return app;
20 |
21 | }
--------------------------------------------------------------------------------
/23-mongodb-client/server/data/mongodb.js:
--------------------------------------------------------------------------------
1 | var Q = require('q');
2 | var mongodb = require('mongodb');
3 | var MongoClient = mongodb.MongoClient;
4 | var mongoUrl = "mongodb://localhost:27017/control_caja";
5 |
6 | exports.connecting = function (mongoCol) {
7 | var deferred = Q.defer();
8 | MongoClient.connect(mongoUrl, function (err, db) {
9 | if (!err) {
10 | deferred.resolve(db.collection(mongoCol));
11 | } else {
12 | rejectOnError(deferred, err);
13 | }
14 | });
15 | return deferred.promise;
16 | }
17 |
18 | exports.ObjectId = mongodb.ObjectID;
19 |
20 | exports.rejectOnError = rejectOnError;
21 |
22 | function rejectOnError(deferred, err) {
23 | console.error(err);
24 | deferred.reject(err);
25 | }
--------------------------------------------------------------------------------
/23-mongodb-client/server/maestros.js:
--------------------------------------------------------------------------------
1 | module.exports.routeMaestros = function (app) {
2 | app.get('/api/pub/maestros', function (req, res, next) {
3 | var maestros = {
4 | categoriasIngresos: ['Nómina', 'Ventas', 'Intereses Depósitos'],
5 | categoriasGastos: ['Hipotéca', 'Compras', 'Impuestos']
6 | };
7 | res.json(maestros);
8 | });
9 | }
--------------------------------------------------------------------------------
/23-mongodb-client/server/movimientos.js:
--------------------------------------------------------------------------------
1 | var movimientosData = require('./data/movimientosData.js');
2 | var usuariosData = require('./data/usuariosData.js');
3 |
4 | module.exports.routeMovimientos = function (app) {
5 |
6 | app.route('/api/priv/movimientos')
7 | .get(function (req, res, next) {
8 | movimientosData.gettingByUsuario(req.usuario)
9 | .then(function (data) {
10 | res.json(data);
11 | })
12 | .fail(function (err) {
13 | res.status(500).send(err);
14 | });
15 | })
16 | .post(function (req, res, next) {
17 | var movimiento = req.body;
18 | movimiento.usuario = req.usuario;
19 | movimientosData.posting(movimiento)
20 | .then(function (data) {
21 | usuariosData.updatingTotal(movimiento)
22 | .then(function (data) {
23 | res.json(data);
24 | })
25 | .fail(function (err) {
26 | res.status(500).send(err);
27 | });
28 | })
29 | .fail(function (err) {
30 | res.status(500).send(err);
31 | });
32 | });
33 |
34 | app.get('/api/priv/movimientos/:id', function (req, res, next) {
35 | movimientosData.gettingByIdUsuario(req.params.id, req.usuario)
36 | .then(function (data) {
37 | res.json(data);
38 | })
39 | .fail(function (err) {
40 | res.status(500).send(err);
41 | });
42 | });
43 |
44 | app.get('/api/priv/total', function (req, res, next) {
45 | usuariosData.gettingByEmail(req.usuario)
46 | .then(function (data) {
47 | res.json(data.total);
48 | })
49 | .fail(function (err) {
50 | res.status(500).send(err);
51 | });
52 | });
53 | }
--------------------------------------------------------------------------------
/23b-mongodb-client/client/_comun/app.js:
--------------------------------------------------------------------------------
1 | angular.module('controlCajaApp', ['ui.router','ngCookies', 'ngResource', 'abFiltros','abDirectivas']);
2 |
3 | angular.module('controlCajaApp').config(function ($stateProvider,$locationProvider) {
4 | $stateProvider
5 | .state('total', {
6 | url: '/',
7 | controller: 'CajaCtrl as caja',
8 | templateUrl: 'controlcaja/total.html'
9 | })
10 | .state('nuevo', {
11 | url: '/nuevo',
12 | controller: 'CajaCtrl as caja',
13 | templateUrl: 'controlcaja/nuevo.html'
14 | })
15 | .state('lista', {
16 | url: '/lista',
17 | controller: 'CajaCtrl as caja',
18 | templateUrl: 'controlcaja/lista.html'
19 | })
20 | .state('movimiento', {
21 | url: '/movimiento/:_id',
22 | controller: 'MovimientoCtrl as vm',
23 | templateUrl: 'movimiento/movimiento.html'
24 | })
25 | .state('registro', {
26 | url: '/registro',
27 | controller: 'RegistroCtrl as registro',
28 | templateUrl: 'registro/registro.html'
29 | })
30 | .state('not-found', {
31 | url: '*path',
32 | templateUrl: '_comun/not-found.html'
33 | });
34 | });
--------------------------------------------------------------------------------
/23b-mongodb-client/client/_comun/appHttpLog.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function configuradorInterceptores($httpProvider) {
4 | $httpProvider.interceptors.push(funcionInterceptoraLog);
5 | }
6 |
7 | function funcionInterceptoraLog($log) {
8 |
9 | var interceptor = {};
10 | interceptor.request = function (request) {
11 | $log.info('request:' + request.url);
12 | return request ;
13 | };
14 | interceptor.responseError = function (response) {
15 | $log.error("excepción: " + response.status + " de :" + response.config.url);
16 | }
17 | return interceptor;
18 | }
19 |
20 | angular.module('controlCajaApp').config(configuradorInterceptores);
21 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/_comun/appSecurity.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | function configuradorInterceptores($httpProvider) {
3 | $httpProvider.interceptors.push(funcionInterceptoraSeguridad);
4 | }
5 |
6 | function funcionInterceptoraSeguridad($q, $injector, $cookieStore, $rootScope) {
7 |
8 | var interceptor = {};
9 | interceptor.request = function (request) {
10 | request.headers["sessionId"] = $cookieStore.get("sessionId");
11 | return request || $q.when(request);
12 | };
13 | interceptor.responseError = function (response) {
14 | var state = $injector.get('$state');
15 | if (response.status === 401) {
16 | $rootScope.mensaje = "No hay derecho!!!";
17 | state.go('registro');
18 | } else if (response.status === 419) {
19 | $rootScope.mensaje = "Estoy caduco!!!";
20 | $cookieStore.remove("sessionId")
21 | state.go('registro');
22 | };
23 | return $q.reject(response);
24 | }
25 | return interceptor;
26 | }
27 |
28 | angular.module('controlCajaApp').config(configuradorInterceptores);
29 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/_comun/menuCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var menuCtrl = function ($state) {
3 | this.isActive = function (estado) {
4 | return $state.is(estado);
5 | }
6 | }
7 | angular.module('controlCajaApp').controller('MenuCtrl',menuCtrl);
8 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/_comun/not-found.html:
--------------------------------------------------------------------------------
1 |
2 | No se ha encontrado lo que buscabas
3 |
--------------------------------------------------------------------------------
/23b-mongodb-client/client/controlcaja/cajaCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var cajaCtrl = function (maestrosFactory, movimientosFactory) {
3 | var vm = this;
4 |
5 | vm.titulo = "Controla tu Cash Flow";
6 |
7 | vm.maestros = maestrosFactory.get();
8 |
9 | vm.nuevoMovimiento = new movimientosFactory.movimientos();
10 | vm.nuevoMovimiento.esIngreso = 1;
11 | vm.nuevoMovimiento.fecha = new Date();
12 |
13 | vm.movimientos = movimientosFactory.movimientos.query();
14 |
15 | vm.total = movimientosFactory.total.get();
16 |
17 | vm.guardarMovimiento = function () {
18 | vm.nuevoMovimiento.tipo = vm.tipo(vm.nuevoMovimiento);
19 | vm.nuevoMovimiento.$save()
20 | .then(function (postedData) {
21 | vm.movimientos = movimientosFactory.movimientos.query();
22 | vm.total = movimientosFactory.total.get();
23 | vm.nuevoMovimiento.importe = 0;
24 | });
25 | }
26 | vm.balance = function () {
27 | return vm.total.ingresos - vm.total.gastos
28 | }
29 | vm.tipo = function (movimiento) {
30 | return movimiento.esIngreso && 'Ingreso' || 'Gasto'
31 | }
32 | }
33 | angular.module('controlCajaApp').controller('CajaCtrl', cajaCtrl);
34 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/controlcaja/lista.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/23b-mongodb-client/client/controlcaja/total.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ caja.total.ingresos | number:2 }} €
9 |
10 |
11 | Total ingresos
12 | Acumulado
13 |
14 |
15 |
16 |
17 | {{ caja.total.gastos | number:2 }} €
18 |
19 |
20 | Total gastos
21 | Acumulado
22 |
23 |
24 |
25 |
26 | {{ caja.balance() | number:2 }} €
27 |
28 |
29 | Balance
30 | Ingresos-Gastos
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/23b-mongodb-client/client/data/maestrosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var maestrosFactory = function ($resource) {
3 | return $resource("/api/pub/maestros/",{},{get: {cache: true}});
4 | };
5 |
6 | angular.module('controlCajaApp').factory('maestrosFactory', maestrosFactory);
7 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/data/movimientosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var movimientosFactory = function ($resource) {
4 |
5 | var factory = {};
6 | factory.movimientos = $resource("/api/priv/movimientos/:id", {
7 | id: "@id"
8 | })
9 | factory.total = $resource("/api/priv/total/");
10 |
11 | return factory;
12 | };
13 |
14 | angular.module('controlCajaApp').factory('movimientosFactory', movimientosFactory);
15 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/directivas/tpl-cabecera.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/23b-mongodb-client/client/directivas/tpl-fila-movimiento.html:
--------------------------------------------------------------------------------
1 |
2 | {{movimientoplantilla._id }} |
3 | {{movimientoplantilla.fecha | date}} |
4 | {{movimientoplantilla.tipo}} |
5 | {{movimientoplantilla.categoria}} |
6 |
7 | {{movimientoplantilla.importe | number:2}} €
8 | |
9 | |
10 |
--------------------------------------------------------------------------------
/23b-mongodb-client/client/directivas/valoracion/tpl-valoracion.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 | *
10 |
11 |
12 |
--------------------------------------------------------------------------------
/23b-mongodb-client/client/directivas/valoracion/valoracion.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var valoracion = function () {
3 | return {
4 | restrict: 'AE',
5 | templateUrl: '/directivas/valoracion/tpl-valoracion.html',
6 | scope: {
7 | valor: '=',
8 | max: '@',
9 | soloLectura: '@'
10 | },
11 | link: function (scope, elem, attrs) {
12 | function actualizar() {
13 | if(!scope.valor)scope.valor=1;
14 | scope.estrellas = [];
15 | for (var i = 0; i < scope.max; i++) {
16 | var estrella = {
17 | marcada: (i < scope.valor)
18 | };
19 | scope.estrellas.push(estrella);
20 | }
21 | };
22 |
23 | scope.marcar = function (indice) {
24 | if (scope.soloLectura && scope.soloLectura === 'true') {
25 | return;
26 | }
27 | scope.valor = indice + 1;
28 | actualizar();
29 | };
30 | actualizar();
31 | }
32 | }
33 | }
34 |
35 | angular.module('abDirectivas')
36 | .directive('abValoracion', valoracion);
37 |
38 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/movimiento/movimientoCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var movimientoCtrl = function ($stateParams, movimientosFactory) {
3 | var vm = this;
4 | vm.movimiento = movimientosFactory.movimientos.get({id:$stateParams._id});
5 | }
6 | angular.module('controlCajaApp').controller('MovimientoCtrl', movimientoCtrl);
7 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/client/registro/registroCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var registroCtrl = function ($rootScope, $state, $http, $cookieStore) {
3 | var urlBase = "http://localhost:3000/api/";
4 | var vm = this;
5 | vm.usuario = {};
6 | vm.entrar = function () {
7 | $http.post(urlBase + 'sesiones/', vm.usuario)
8 | .success(function (data) {
9 | $rootScope.nombre = vm.usuario.email;
10 | $rootScope.mensaje = 'recién entrado';
11 | $cookieStore.put("sessionId", data);
12 | $state.go("total");
13 | });
14 | }
15 | vm.registrar = function () {
16 | $http.post(urlBase + 'usuarios/', vm.usuario)
17 | .success(function (data) {
18 | $rootScope.nombre = vm.usuario.email;
19 | $rootScope.mensaje = 'recién creado';
20 | $cookieStore.put("sessionId", data);
21 | $state.go("total");
22 | });
23 | }
24 | }
25 | angular.module('controlCajaApp').controller('RegistroCtrl', registroCtrl);
26 | }());
--------------------------------------------------------------------------------
/23b-mongodb-client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "body-parser": "~1.0.2",
13 | "express": "~4.12.1",
14 | "mongodb": "^2.0.26",
15 | "q": "^1.2.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/23b-mongodb-client/server.js:
--------------------------------------------------------------------------------
1 | var app = require('./server/config.js').configApp();
2 | require('./server/seguridad.js').seguridad(app);
3 | console.log('ready');
4 |
5 | require('./server/maestros.js').routeMaestros(app);
6 | require('./server/movimientos.js').routeMovimientos(app);
7 | console.log('steady');
8 |
9 | app.listen(3000);
10 | console.log('go');
--------------------------------------------------------------------------------
/23b-mongodb-client/server/config.js:
--------------------------------------------------------------------------------
1 | module.exports.configApp = function () {
2 |
3 | var express = require('express');
4 | var bodyParser = require('body-parser');
5 |
6 | var app = express();
7 |
8 | app.use(bodyParser());
9 | app.use(express.static(__dirname + './../client'));
10 |
11 | app.use(function (peticion, respuesta, siguiente) {
12 | console.log("recibida petición: " + peticion.url);
13 | if (peticion.body && Object.keys(peticion.body).length > 0) {
14 | console.log("body: " + JSON.stringify(peticion.body));
15 | }
16 | siguiente();
17 | });
18 |
19 | return app;
20 |
21 | }
--------------------------------------------------------------------------------
/23b-mongodb-client/server/data/movimientosData.js:
--------------------------------------------------------------------------------
1 | var mongodb = require('./mongodb.js')
2 | var mongoCol = "movimientos"
3 |
4 | exports.findingByUsuario = function (usuario) {
5 | return mongodb.finding(mongoCol, {
6 | usuario: usuario
7 | });
8 | }
9 |
10 | exports.inserting = function (movimiento) {
11 | return mongodb.inserting(mongoCol, movimiento);
12 | }
13 |
14 | exports.findingByIdUsuario = function (_id, usuario) {
15 | return mongodb.finding(mongoCol, {
16 | _id: new mongodb.ObjectId(_id),
17 | usuario: usuario
18 | });
19 | }
--------------------------------------------------------------------------------
/23b-mongodb-client/server/data/usuariosData.js:
--------------------------------------------------------------------------------
1 | var mongodb = require('./mongodb.js')
2 | var mongoCol = "usuarios"
3 |
4 | exports.findingByEmail = function (email) {
5 | return mongodb.finding(mongoCol, {
6 | email: email
7 | });
8 | }
9 |
10 | exports.findingByEmailPassword = function (email, password) {
11 | return mongodb.finding(mongoCol, {
12 | email: email,
13 | password: password
14 | });
15 | }
16 |
17 | exports.inserting = function (usuario) {
18 | return mongodb.inserting(mongoCol, usuario);
19 | }
20 |
21 | exports.updating = function (usuario) {
22 | return mongodb.updating(mongoCol, {
23 | email: usuario.email
24 | },
25 | usuario);
26 | }
--------------------------------------------------------------------------------
/23b-mongodb-client/server/maestros.js:
--------------------------------------------------------------------------------
1 | module.exports.routeMaestros = function (app) {
2 | app.get('/api/pub/maestros', function (req, res, next) {
3 | var maestros = {
4 | categoriasIngresos: ['Nómina', 'Ventas', 'Intereses Depósitos'],
5 | categoriasGastos: ['Hipotéca', 'Compras', 'Impuestos']
6 | };
7 | res.json(maestros);
8 | });
9 | }
--------------------------------------------------------------------------------
/24-pretty-url/client/static/_comun/app.js:
--------------------------------------------------------------------------------
1 | angular.module('controlCajaApp', ['ui.router', 'ngCookies', 'ngResource', 'abFiltros', 'abDirectivas']);
2 |
3 | angular.module('controlCajaApp').config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
4 | // configuración para url amigables
5 | $locationProvider.html5Mode(true);
6 | // En caso de rutas no validas, vamos a la página raiz
7 | $urlRouterProvider.otherwise('/');
8 | $stateProvider
9 | .state('total', {
10 | url: '/',
11 | controller: 'CajaCtrl as caja',
12 | templateUrl: 'static/controlcaja/total.html'
13 | })
14 | .state('nuevo', {
15 | url: '/nuevo',
16 |
17 | controller: 'CajaCtrl as caja',
18 | templateUrl: 'static/controlcaja/nuevo.html'
19 | })
20 | .state('lista', {
21 | url: '/lista',
22 | controller: 'CajaCtrl as caja',
23 | templateUrl: 'static/controlcaja/lista.html'
24 | })
25 | .state('movimiento', {
26 | url: '/movimiento/:_id',
27 | controller: 'MovimientoCtrl as vm',
28 | templateUrl: 'static/movimiento/movimiento.html'
29 | })
30 | .state('registro', {
31 | url: '/registro',
32 | controller: 'RegistroCtrl as registro',
33 | templateUrl: 'static/registro/registro.html'
34 | });
35 | });
--------------------------------------------------------------------------------
/24-pretty-url/client/static/_comun/appHttpLog.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function configuradorInterceptores($httpProvider) {
4 | $httpProvider.interceptors.push(funcionInterceptoraLog);
5 | }
6 |
7 | function funcionInterceptoraLog($log) {
8 |
9 | var interceptor = {};
10 | interceptor.request = function (request) {
11 | $log.info('request:' + request.url);
12 | return request ;
13 | };
14 | interceptor.responseError = function (response) {
15 | $log.error("excepción: " + response.status + " de :" + response.config.url);
16 | }
17 | return interceptor;
18 | }
19 |
20 | angular.module('controlCajaApp').config(configuradorInterceptores);
21 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/_comun/appSecurity.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | function configuradorInterceptores($httpProvider) {
3 | $httpProvider.interceptors.push(funcionInterceptoraSeguridad);
4 | }
5 |
6 | function funcionInterceptoraSeguridad($q, $injector, $cookieStore, $rootScope) {
7 |
8 | var interceptor = {};
9 | interceptor.request = function (request) {
10 | request.headers["sessionId"] = $cookieStore.get("sessionId");
11 | return request || $q.when(request);
12 | };
13 | interceptor.responseError = function (response) {
14 | var state = $injector.get('$state');
15 | if (response.status === 401) {
16 | $rootScope.mensaje = "No hay derecho!!!";
17 | state.go('registro');
18 | } else if (response.status === 419) {
19 | $rootScope.mensaje = "Estoy caduco!!!";
20 | $cookieStore.remove("sessionId")
21 | state.go('registro');
22 | };
23 | return $q.reject(response);
24 | }
25 | return interceptor;
26 | }
27 |
28 | angular.module('controlCajaApp').config(configuradorInterceptores);
29 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/_comun/menuCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var menuCtrl = function ($state) {
3 | this.isActive = function (estado) {
4 | return $state.is(estado);
5 | }
6 | }
7 | angular.module('controlCajaApp').controller('MenuCtrl',menuCtrl);
8 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/_comun/not-found.html:
--------------------------------------------------------------------------------
1 |
2 | No se ha encontrado lo que buscabas
3 |
--------------------------------------------------------------------------------
/24-pretty-url/client/static/controlcaja/cajaCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var cajaCtrl = function (maestrosFactory, movimientosFactory) {
3 | var vm = this;
4 |
5 |
6 | vm.titulo = "Controla tu Cash Flow";
7 |
8 | vm.maestros = maestrosFactory.get();
9 |
10 | vm.nuevoMovimiento = new movimientosFactory.movimientos();
11 | vm.nuevoMovimiento.esIngreso = 1;
12 | vm.nuevoMovimiento.fecha = new Date();
13 |
14 | vm.movimientos = movimientosFactory.movimientos.query();
15 |
16 | vm.total = movimientosFactory.total.get();
17 |
18 | vm.guardarMovimiento = function () {
19 | vm.nuevoMovimiento.tipo = vm.tipo(vm.nuevoMovimiento);
20 | vm.nuevoMovimiento.$save()
21 | .then(function (postedData) {
22 | vm.movimientos = movimientosFactory.movimientos.query();
23 | vm.total = movimientosFactory.total.get();
24 | vm.nuevoMovimiento.importe = 0;
25 | });
26 | }
27 | vm.balance = function () {
28 | return vm.total.ingresos - vm.total.gastos
29 | }
30 | vm.tipo = function (movimiento) {
31 | return movimiento.esIngreso && 'Ingreso' || 'Gasto'
32 | }
33 | }
34 | angular.module('controlCajaApp').controller('CajaCtrl', cajaCtrl);
35 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/controlcaja/lista.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/24-pretty-url/client/static/controlcaja/total.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ caja.total.ingresos | number:2 }} €
9 |
10 |
11 | Total ingresos
12 | Acumulado
13 |
14 |
15 |
16 |
17 | {{ caja.total.gastos | number:2 }} €
18 |
19 |
20 | Total gastos
21 | Acumulado
22 |
23 |
24 |
25 |
26 | {{ caja.balance() | number:2 }} €
27 |
28 |
29 | Balance
30 | Ingresos-Gastos
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/24-pretty-url/client/static/data/maestrosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var maestrosFactory = function ($resource) {
3 | return $resource("/api/pub/maestros/",{},{get: {cache: true}});
4 | };
5 |
6 | angular.module('controlCajaApp').factory('maestrosFactory', maestrosFactory);
7 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/data/movimientosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var movimientosFactory = function ($resource) {
4 |
5 | var factory = {};
6 | factory.movimientos = $resource("/api/priv/movimientos/:id", {
7 | id: "@id"
8 | })
9 | factory.total = $resource("/api/priv/total/");
10 |
11 | return factory;
12 | };
13 |
14 | angular.module('controlCajaApp').factory('movimientosFactory', movimientosFactory);
15 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/directivas/tpl-cabecera.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/24-pretty-url/client/static/directivas/tpl-fila-movimiento.html:
--------------------------------------------------------------------------------
1 |
2 | {{movimientoplantilla._id }} |
3 | {{movimientoplantilla.fecha | date}} |
4 | {{movimientoplantilla.tipo}} |
5 | {{movimientoplantilla.categoria}} |
6 |
7 | {{movimientoplantilla.importe | number:2}} €
8 | |
9 | |
10 |
--------------------------------------------------------------------------------
/24-pretty-url/client/static/directivas/valoracion/tpl-valoracion.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 | *
10 |
11 |
12 |
--------------------------------------------------------------------------------
/24-pretty-url/client/static/directivas/valoracion/valoracion.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var valoracion = function () {
3 | return {
4 | restrict: 'AE',
5 | templateUrl: '/static/directivas/valoracion/tpl-valoracion.html',
6 | scope: {
7 | valor: '=',
8 | max: '@',
9 | soloLectura: '@'
10 | },
11 | link: function (scope, elem, attrs) {
12 | function actualizar() {
13 | if(!scope.valor)scope.valor=1;
14 | scope.estrellas = [];
15 | for (var i = 0; i < scope.max; i++) {
16 | var estrella = {
17 | marcada: (i < scope.valor)
18 | };
19 | scope.estrellas.push(estrella);
20 | }
21 | };
22 |
23 | scope.marcar = function (indice) {
24 | if (scope.soloLectura && scope.soloLectura === 'true') {
25 | return;
26 | }
27 | scope.valor = indice + 1;
28 | actualizar();
29 | };
30 | actualizar();
31 | }
32 | }
33 | }
34 |
35 | angular.module('abDirectivas')
36 | .directive('abValoracion', valoracion);
37 |
38 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/movimiento/movimientoCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var movimientoCtrl = function ($stateParams, movimientosFactory) {
3 | var vm = this;
4 | vm.movimiento = movimientosFactory.movimientos.get({id:$stateParams._id});
5 | }
6 | angular.module('controlCajaApp').controller('MovimientoCtrl', movimientoCtrl);
7 | }());
--------------------------------------------------------------------------------
/24-pretty-url/client/static/registro/registroCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var registroCtrl = function ($rootScope, $state, $http, $cookieStore) {
3 | var urlBase = "http://localhost:3000/api/";
4 | var vm = this;
5 | vm.usuario = {};
6 | vm.entrar = function () {
7 | $http.post(urlBase + 'sesiones/', vm.usuario)
8 | .success(function (data) {
9 | afterLogIn(data);
10 | });
11 | }
12 | vm.registrar = function () {
13 | $http.post(urlBase + 'usuarios/', vm.usuario)
14 | .success(function (data) {
15 | afterLogIn(data);
16 | });
17 | }
18 |
19 | function afterLogIn(data) {
20 | $rootScope.nombre = vm.usuario.email;
21 | $cookieStore.put("sessionId", data);
22 | $state.go("total");
23 | }
24 | }
25 | angular.module('controlCajaApp').controller('RegistroCtrl', registroCtrl);
26 | }());
--------------------------------------------------------------------------------
/24-pretty-url/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "server.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "body-parser": "~1.0.2",
13 | "express": "~4.12.1",
14 | "mongodb": "^2.0.26",
15 | "q": "^1.2.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/24-pretty-url/server.js:
--------------------------------------------------------------------------------
1 | var app = require('./server/config.js').configApp();
2 | require('./server/seguridad.js').seguridad(app);
3 | console.log('ready');
4 |
5 | require('./server/maestros.js').routeMaestros(app);
6 | require('./server/movimientos.js').routeMovimientos(app);
7 | console.log('steady');
8 |
9 |
10 |
11 | app.listen(3000);
12 | console.log('go');
--------------------------------------------------------------------------------
/24-pretty-url/server/config.js:
--------------------------------------------------------------------------------
1 | module.exports.configApp = function () {
2 | var path = require('path');
3 | var express = require('express');
4 | var bodyParser = require('body-parser');
5 |
6 | var app = express();
7 |
8 |
9 | app.use(function (peticion, respuesta, siguiente) {
10 | console.log("recibida petición: " + peticion.url);
11 | if (peticion.body && Object.keys(peticion.body).length > 0) {
12 | console.log("body: " + JSON.stringify(peticion.body));
13 | }
14 | siguiente();
15 | });
16 | app.use(bodyParser());
17 |
18 | // rewrites para que permita usar rutas sin #
19 | app.get('/*', function (req, res, next) {
20 | if ((req.url.indexOf("static/") >= 0) || (req.url.indexOf("api/") >= 0)) {
21 | next();
22 | } else {
23 | res.sendFile('./index.html', {
24 | root: path.join(__dirname, '../client')
25 | });
26 | }
27 | });
28 | app.use(express.static(__dirname + './../client'));
29 |
30 |
31 | return app;
32 |
33 | }
--------------------------------------------------------------------------------
/24-pretty-url/server/data/movimientosData.js:
--------------------------------------------------------------------------------
1 | var mongodb = require('./mongodb.js')
2 | var mongoCol = "movimientos"
3 |
4 | exports.findingByUsuario = function (usuario) {
5 | return mongodb.finding(mongoCol, {
6 | usuario: usuario
7 | });
8 | }
9 |
10 | exports.inserting = function (movimiento) {
11 | return mongodb.inserting(mongoCol, movimiento);
12 | }
13 |
14 | exports.findingByIdUsuario = function (_id, usuario) {
15 | return mongodb.finding(mongoCol, {
16 | _id: new mongodb.ObjectId(_id),
17 | usuario: usuario
18 | });
19 | }
--------------------------------------------------------------------------------
/24-pretty-url/server/data/usuariosData.js:
--------------------------------------------------------------------------------
1 | var mongodb = require('./mongodb.js')
2 | var mongoCol = "usuarios"
3 |
4 | exports.findingByEmail = function (email) {
5 | return mongodb.finding(mongoCol, {
6 | email: email
7 | });
8 | }
9 |
10 | exports.findingByEmailPassword = function (email, password) {
11 | return mongodb.finding(mongoCol, {
12 | email: email,
13 | password: password
14 | });
15 | }
16 |
17 | exports.inserting = function (usuario) {
18 | return mongodb.inserting(mongoCol, usuario);
19 | }
20 |
21 | exports.updating = function (usuario) {
22 | return mongodb.updating(mongoCol, {
23 | email: usuario.email
24 | },
25 | usuario);
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/24-pretty-url/server/maestros.js:
--------------------------------------------------------------------------------
1 | module.exports.routeMaestros = function (app) {
2 | app.get('/api/pub/maestros', function (req, res, next) {
3 | var maestros = {
4 | categoriasIngresos: ['Nómina', 'Ventas', 'Intereses Depósitos'],
5 | categoriasGastos: ['Hipotéca', 'Compras', 'Impuestos']
6 | };
7 | res.json(maestros);
8 | });
9 | }
--------------------------------------------------------------------------------
/25-socket-io/client/static/_comun/app.js:
--------------------------------------------------------------------------------
1 | angular.module('controlCajaApp', ['ui.router', 'ngCookies', 'ngResource', 'abFiltros', 'abDirectivas']);
2 |
3 | angular.module('controlCajaApp').config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
4 | $locationProvider.html5Mode(true);
5 |
6 | $urlRouterProvider.otherwise('/');
7 | $stateProvider
8 | .state('total', {
9 | url: '/',
10 | controller: 'CajaCtrl as caja',
11 | templateUrl: 'static/controlcaja/total.html'
12 | })
13 | .state('nuevo', {
14 | url: '/nuevo',
15 |
16 | controller: 'CajaCtrl as caja',
17 | templateUrl: 'static/controlcaja/nuevo.html'
18 | })
19 | .state('lista', {
20 | url: '/lista',
21 | controller: 'CajaCtrl as caja',
22 | templateUrl: 'static/controlcaja/lista.html'
23 | })
24 | .state('movimiento', {
25 | url: '/movimiento/:_id',
26 | controller: 'MovimientoCtrl as vm',
27 | templateUrl: 'static/movimiento/movimiento.html'
28 | })
29 | .state('registro', {
30 | url: '/registro',
31 | controller: 'RegistroCtrl as registro',
32 | templateUrl: 'static/registro/registro.html'
33 | }).state('dashboard', { // Nuevo estado para el dashboard
34 | url: '/dashboard',
35 | controller: 'DashboardCtrl as vm',
36 | templateUrl: 'static/dashboard/dashboard.html'
37 | });
38 |
39 | });
--------------------------------------------------------------------------------
/25-socket-io/client/static/_comun/appHttpLog.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | function configuradorInterceptores($httpProvider) {
4 | $httpProvider.interceptors.push(funcionInterceptoraLog);
5 | }
6 |
7 | function funcionInterceptoraLog($log) {
8 |
9 | var interceptor = {};
10 | interceptor.request = function (request) {
11 | $log.info('request:' + request.url);
12 | return request ;
13 | };
14 | interceptor.responseError = function (response) {
15 | $log.error("excepción: " + response.status + " de :" + response.config.url);
16 | }
17 | return interceptor;
18 | }
19 |
20 | angular.module('controlCajaApp').config(configuradorInterceptores);
21 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/_comun/appSecurity.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | function configuradorInterceptores($httpProvider) {
3 | $httpProvider.interceptors.push(funcionInterceptoraSeguridad);
4 | }
5 |
6 | function funcionInterceptoraSeguridad($q, $injector, $cookieStore, $rootScope) {
7 |
8 | var interceptor = {};
9 | interceptor.request = function (request) {
10 | request.headers["sessionId"] = $cookieStore.get("sessionId");
11 | return request || $q.when(request);
12 | };
13 | interceptor.responseError = function (response) {
14 | var state = $injector.get('$state');
15 | if (response.status === 401) {
16 | $rootScope.mensaje = "No hay derecho!!!";
17 | state.go('registro');
18 | } else if (response.status === 419) {
19 | $rootScope.mensaje = "Estoy caduco!!!";
20 | $cookieStore.remove("sessionId")
21 | state.go('registro');
22 | };
23 | return $q.reject(response);
24 | }
25 | return interceptor;
26 | }
27 |
28 | angular.module('controlCajaApp').config(configuradorInterceptores);
29 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/_comun/menuCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var menuCtrl = function ($state) {
3 | this.isActive = function (estado) {
4 | return $state.is(estado);
5 | }
6 | }
7 | angular.module('controlCajaApp').controller('MenuCtrl',menuCtrl);
8 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/_comun/not-found.html:
--------------------------------------------------------------------------------
1 |
2 | No se ha encontrado lo que buscabas
3 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/_comun/socketFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | angular.module('controlCajaApp').factory('socketFactory', function () {
3 | var socket;
4 | return {
5 | connect: function(){
6 | socket= io.connect();
7 | console.log("IO: connected" );
8 | },
9 | on: function (eventName, callback) {
10 | socket.on(eventName, function () {
11 | var args = arguments;
12 | console.log("IN: " + eventName + " : " + JSON.stringify(args));
13 | });
14 | },
15 | emit: function (eventName, data) {
16 | console.log("OUT: " + eventName + " : " + JSON.stringify(data));
17 | socket.emit(eventName, data);
18 | }
19 | }
20 | });
21 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/controlcaja/cajaCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var cajaCtrl = function (maestrosFactory, movimientosFactory) {
3 | var vm = this;
4 |
5 |
6 | vm.titulo = "Controla tu Cash Flow";
7 |
8 | vm.maestros = maestrosFactory.get();
9 |
10 | vm.nuevoMovimiento = new movimientosFactory.movimientos();
11 | vm.nuevoMovimiento.esIngreso = 1;
12 | vm.nuevoMovimiento.fecha = new Date();
13 |
14 | vm.movimientos = movimientosFactory.movimientos.query();
15 |
16 | vm.total = movimientosFactory.total.get();
17 |
18 | vm.guardarMovimiento = function () {
19 | vm.nuevoMovimiento.tipo = vm.tipo(vm.nuevoMovimiento);
20 | vm.nuevoMovimiento.$save()
21 | .then(function (postedData) {
22 | vm.movimientos = movimientosFactory.movimientos.query();
23 | vm.total = movimientosFactory.total.get();
24 | vm.nuevoMovimiento.importe = 0;
25 | });
26 | }
27 | vm.balance = function () {
28 | return vm.total.ingresos - vm.total.gastos
29 | }
30 | vm.tipo = function (movimiento) {
31 | return movimiento.esIngreso && 'Ingreso' || 'Gasto'
32 | }
33 | }
34 | angular.module('controlCajaApp').controller('CajaCtrl', cajaCtrl);
35 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/controlcaja/lista.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/controlcaja/total.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ caja.total.ingresos | number:2 }} €
9 |
10 |
11 | Total ingresos
12 | Acumulado
13 |
14 |
15 |
16 |
17 | {{ caja.total.gastos | number:2 }} €
18 |
19 |
20 | Total gastos
21 | Acumulado
22 |
23 |
24 |
25 |
26 | {{ caja.balance() | number:2 }} €
27 |
28 |
29 | Balance
30 | Ingresos-Gastos
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/dashboard/dashboard.html:
--------------------------------------------------------------------------------
1 |
2 | Comprueba de dónde viene y a dónde va tu dinero.
3 |
4 |
5 |
6 |
7 |
8 | {{ vm.total.usuarios | number:0 }}
9 |
10 |
11 | Usuarios
12 |
13 |
14 |
15 |
16 | {{ vm.total.ingresos | number:2 }} €
17 |
18 |
19 | Total ingresos
20 |
21 |
22 |
23 |
24 | {{ vm.total.gastos | number:2 }} €
25 |
26 |
27 | Total gastos
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/dashboard/dashboardCtrl.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | "use strict";
3 |
4 | angular
5 | .module("controlCajaApp")
6 | .controller("DashboardCtrl", function (socketFactory) {
7 | var vm = this;
8 | socketFactory.connect();
9 | socketFactory.on('total_updated', function (msgIn) {
10 | vm.total = msgIn[0];
11 | });
12 | });
13 |
14 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/data/maestrosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var maestrosFactory = function ($resource) {
3 | return $resource("/api/pub/maestros/",{},{get: {cache: true}});
4 | };
5 |
6 | angular.module('controlCajaApp').factory('maestrosFactory', maestrosFactory);
7 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/data/movimientosFactory.js:
--------------------------------------------------------------------------------
1 | (function () {
2 |
3 | var movimientosFactory = function ($resource) {
4 |
5 | var factory = {};
6 | factory.movimientos = $resource("/api/priv/movimientos/:id", {
7 | id: "@id"
8 | })
9 | factory.total = $resource("/api/priv/total/");
10 |
11 | return factory;
12 | };
13 |
14 | angular.module('controlCajaApp').factory('movimientosFactory', movimientosFactory);
15 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/directivas/tpl-cabecera.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/directivas/tpl-fila-movimiento.html:
--------------------------------------------------------------------------------
1 |
2 | {{movimientoplantilla._id }} |
3 | {{movimientoplantilla.fecha | date}} |
4 | {{movimientoplantilla.tipo}} |
5 | {{movimientoplantilla.categoria}} |
6 |
7 | {{movimientoplantilla.importe | number:2}} €
8 | |
9 | |
10 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/directivas/valoracion/tpl-valoracion.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 | *
10 |
11 |
12 |
--------------------------------------------------------------------------------
/25-socket-io/client/static/directivas/valoracion/valoracion.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var valoracion = function () {
3 | return {
4 | restrict: 'AE',
5 | templateUrl: '/static/directivas/valoracion/tpl-valoracion.html',
6 | scope: {
7 | valor: '=',
8 | max: '@',
9 | soloLectura: '@'
10 | },
11 | link: function (scope, elem, attrs) {
12 | function actualizar() {
13 | if(!scope.valor)scope.valor=1;
14 | scope.estrellas = [];
15 | for (var i = 0; i < scope.max; i++) {
16 | var estrella = {
17 | marcada: (i < scope.valor)
18 | };
19 | scope.estrellas.push(estrella);
20 | }
21 | };
22 |
23 | scope.marcar = function (indice) {
24 | if (scope.soloLectura && scope.soloLectura === 'true') {
25 | return;
26 | }
27 | scope.valor = indice + 1;
28 | actualizar();
29 | };
30 | actualizar();
31 | }
32 | }
33 | }
34 |
35 | angular.module('abDirectivas')
36 | .directive('abValoracion', valoracion);
37 |
38 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/movimiento/movimientoCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var movimientoCtrl = function ($stateParams, movimientosFactory) {
3 | var vm = this;
4 | vm.movimiento = movimientosFactory.movimientos.get({id:$stateParams._id});
5 | }
6 | angular.module('controlCajaApp').controller('MovimientoCtrl', movimientoCtrl);
7 | }());
--------------------------------------------------------------------------------
/25-socket-io/client/static/registro/registroCtrl.js:
--------------------------------------------------------------------------------
1 | (function () {
2 | var registroCtrl = function ($rootScope, $state, $http, $cookieStore, socketFactory) {
3 | var urlBase = "http://localhost:3000/api/";
4 | var vm = this;
5 | vm.usuario = {};
6 | vm.entrar = function () {
7 | $http.post(urlBase + 'sesiones/', vm.usuario)
8 | .success(function (data) {
9 | afterLogIn(data);
10 | });
11 | }
12 | vm.registrar = function () {
13 | $http.post(urlBase + 'usuarios/', vm.usuario)
14 | .success(function (data) {
15 | afterLogIn(data);
16 | });
17 | }
18 |
19 | function afterLogIn(data) {
20 | $rootScope.nombre = vm.usuario.email;
21 | $cookieStore.put("sessionId", data);
22 | socketFactory.connect();
23 | socketFactory.on('wellcome', function (msgIn) {
24 | console.log("Me he conectado: " + JSON.stringify(msgIn));
25 | socketFactory.emit("ackClient", "thanks");
26 | });
27 | socketFactory.on('ackServer', function (msgIn) {
28 | console.log("Han recibido mi mensaje: " + JSON.stringify(msgIn));
29 | });
30 | $state.go("total");
31 | }
32 | }
33 | angular.module('controlCajaApp').controller('RegistroCtrl', registroCtrl);
34 | }());
--------------------------------------------------------------------------------
/25-socket-io/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ControlCashFlow",
3 | "version": "0.0.0",
4 | "description": "Controla tu flujo de caja",
5 | "main": "server.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Alberto Basalo",
10 | "license": "BSD-2-Clause",
11 | "dependencies": {
12 | "body-parser": "~1.0.2",
13 | "express": "~4.12.1",
14 | "mongodb": "^2.0.26",
15 | "q": "^1.2.0",
16 | "socket.io": "^1.3.5"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/25-socket-io/server.js:
--------------------------------------------------------------------------------
1 | var app = require('./server/config.js').configApp();
2 | var socket = require('./server/socket.js').initIO(app);
3 | require('./server/seguridad.js').seguridad(app);
4 | console.log('ready');
5 |
6 | require('./server/maestros.js').routeMaestros(app);
7 | require('./server/movimientos.js').routeMovimientos(app, socket.emitter);
8 | console.log('steady');
9 |
10 |
11 | // El encargado de escuchar es el servicio http, en lugar de express
12 | // Esto se hace para soportar las llamadas desde socket.io
13 | socket.server.listen(3000);
14 | console.log('go');
--------------------------------------------------------------------------------
/25-socket-io/server/config.js:
--------------------------------------------------------------------------------
1 | module.exports.configApp = function () {
2 | var path = require('path');
3 | var express = require('express');
4 | var bodyParser = require('body-parser');
5 |
6 | var app = express();
7 |
8 |
9 | app.use(function (peticion, respuesta, siguiente) {
10 | console.log("recibida petición: " + peticion.url);
11 | if (peticion.body && Object.keys(peticion.body).length > 0) {
12 | console.log("body: " + JSON.stringify(peticion.body));
13 | }
14 | siguiente();
15 | });
16 | app.use(bodyParser());
17 |
18 | app.get('/*', function (req, res, next) {
19 | if ((req.url.indexOf("static/") >= 0) || (req.url.indexOf("api/") >= 0)) {
20 | next();
21 | } else {
22 | res.sendFile('./index.html', {
23 | root: path.join(__dirname, '../client')
24 | });
25 | }
26 | });
27 | app.use(express.static(__dirname + './../client'));
28 |
29 |
30 | return app;
31 |
32 | }
--------------------------------------------------------------------------------
/25-socket-io/server/data/movimientosData.js:
--------------------------------------------------------------------------------
1 | var mongodb = require('./mongodb.js')
2 | var mongoCol = "movimientos"
3 |
4 | exports.findingByUsuario = function (usuario) {
5 | return mongodb.finding(mongoCol, {
6 | usuario: usuario
7 | });
8 | }
9 |
10 | exports.inserting = function (movimiento) {
11 | return mongodb.inserting(mongoCol, movimiento);
12 | }
13 |
14 | exports.findingByIdUsuario = function (_id, usuario) {
15 | return mongodb.finding(mongoCol, {
16 | _id: new mongodb.ObjectId(_id),
17 | usuario: usuario
18 | });
19 | }
--------------------------------------------------------------------------------
/25-socket-io/server/data/usuariosData.js:
--------------------------------------------------------------------------------
1 | var mongodb = require('./mongodb.js')
2 | var mongoCol = "usuarios"
3 |
4 | exports.findingByEmail = function (email) {
5 | return mongodb.finding(mongoCol, {
6 | email: email
7 | });
8 | }
9 |
10 | exports.findingByEmailPassword = function (email, password) {
11 | return mongodb.finding(mongoCol, {
12 | email: email,
13 | password: password
14 | });
15 | }
16 |
17 | exports.inserting = function (usuario) {
18 | return mongodb.inserting(mongoCol, usuario);
19 | }
20 |
21 | exports.updating = function (usuario) {
22 | return mongodb.updating(mongoCol, {
23 | email: usuario.email
24 | },
25 | usuario);
26 | }
27 |
28 | exports.findingTotal = function () {
29 |
30 | return mongodb.aggregating(mongoCol, [{
31 | $group: {
32 | _id: null,
33 | usuarios: {
34 | $sum: 1
35 | },
36 | ingresos: {
37 | $sum: "$total.ingresos"
38 | },
39 | gastos: {
40 | $sum: "$total.gastos"
41 | }
42 | }
43 | }]);
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/25-socket-io/server/maestros.js:
--------------------------------------------------------------------------------
1 | module.exports.routeMaestros = function (app) {
2 | app.get('/api/pub/maestros', function (req, res, next) {
3 | var maestros = {
4 | categoriasIngresos: ['Nómina', 'Ventas', 'Intereses Depósitos'],
5 | categoriasGastos: ['Hipotéca', 'Compras', 'Impuestos']
6 | };
7 | res.json(maestros);
8 | });
9 | }
--------------------------------------------------------------------------------
/25-socket-io/server/socket.js:
--------------------------------------------------------------------------------
1 | var io;
2 | module.exports.initIO = function (app) {
3 |
4 | var server = require('http').Server(app);
5 | io = require('socket.io')(server);
6 |
7 | function conectar(socket) {
8 | console.log("IN: conectado!!!" + socket.client.conn.remoteAddress);
9 | var saludo = {
10 | serverPid: process.pid,
11 | date: new Date()
12 | };
13 | socket.emit('wellcome', saludo);
14 | socket.on('ackClient', function (data) {
15 | console.log("IN: mensaje: " + data);
16 | socket.emit('ackServer', data);
17 | });
18 | }
19 | io.on("connect", conectar);
20 |
21 |
22 | // Devolvemos el servidor http que hay bajo express y un puntero a una función para emitir mensajes
23 | return {
24 | server: server,
25 | emitter: emitirCanalMensaje
26 | };
27 | }
28 |
29 |
30 | function emitirCanalMensaje(canal, mensaje) {
31 | console.log("OUT: " + canal + ' : ' +JSON.stringify(mensaje));
32 | io.sockets.emit(canal, mensaje);
33 | }
--------------------------------------------------------------------------------
/26-pro/pro.md:
--------------------------------------------------------------------------------
1 | # AngularJS fullStack JavaScript
2 |
3 | ##Recursos extra para incorporar a una aplicación profesional
4 |
5 | ### Flujo de trabajo [gulp](http://gulpjs.com/)
6 | ### Concatenar y minificar [useref](https://www.npmjs.com/package/gulp-useref)
7 | ### Traducción [gettext](https://angular-gettext.rocketeer.be/)
8 | ### SEO [prerender.io](https://prerender.io/)
9 | ### Validación de esquema documento [mongoose](http://mongoosejs.com/)
10 | ### Carga dinámica [ocLazyLoad](https://github.com/ocombe/ocLazyLoad)
11 | ### Analíticas [angulartics](https://github.com/luisfarzati/angulartics)
12 | ### Animaciones [ngFx](https://github.com/Hendrixer/ngFx)
13 | ### Formularios complejos o dinámicos [formly](http://formly-js.github.io/angular-formly/#/)
14 | ### User Interface [angular-ui](https://angular-ui.github.io/)
15 | ### Gráficos [angular-chartist ](https://github.com/paradox41/angular-chartist.js)
16 | ### Tests [Karma](http://karma-runner.github.io)
17 | ### SiteMap [gulp-sitemap](https://www.npmjs.com/package/gulp-sitemap)
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Curso-angularjs-FS
2 | =======================
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------