From af684be843d2efb9db2e9dd28f6c4cbaa88a08f2 Mon Sep 17 00:00:00 2001 From: Pablo Marco del Pont Date: Wed, 7 Nov 2018 12:57:17 -0300 Subject: [PATCH] Refactor para obtener los botones desde la base de datos. --- src/js/controller.js | 116 ++------------------------------------------------- src/js/route.js | 7 +++- src/js/service.js | 11 +++++ 3 files changed, 20 insertions(+), 114 deletions(-) create mode 100644 src/js/service.js diff --git a/src/js/controller.js b/src/js/controller.js index 6e149f7..87e3305 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,119 +1,9 @@ angular.module('focaBotoneraPrincipal') .controller('focaBotoneraPrincipalController', [ - '$scope', '$location', - function($scope, $location) { - // TODO: Tomar estos datos desde el servicio - $scope.botones = [ - { - texto: 'Abrir Turno', - clase: 'botonera-principal-abrir-turno', - accion: '/turno-apertura' - }, - { - texto: 'Cerrar Turno', - clase: 'botonera-principal-cerrar-turno', - accion: '/turno-cierre' - }, - { - texto: 'Nota Pedido', - clase: 'botonera-principal-nota-pedido', - accion: '/venta-nota-pedido/crear' - }, - { - texto: 'Seguimiento GPS', - clase: 'botonera-principal-seguimiento', - accion: '/admin-seguimiento' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - }, - { - texto: '', - clase: 'botonera-principal-vacio', - accion: '/' - } - ]; - + '$scope', '$location', 'botones', + function($scope, $location, botones) { $scope.paginas = []; - $scope.paginas.push($scope.botones.slice(0, 15)); - $scope.paginas.push($scope.botones.slice(15, 30)); + $scope.paginas.push(botones.data); $scope.irA = function(accion) { $location.path(accion); diff --git a/src/js/route.js b/src/js/route.js index 51fe99c..a7784ae 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -2,6 +2,11 @@ angular.module('focaBotoneraPrincipal') .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', { controller: 'focaBotoneraPrincipalController', - templateUrl: 'src/views/foca-botonera-principal.html' + templateUrl: 'src/views/foca-botonera-principal.html', + resolve: { + botones: ['focaBotoneraPrincipalService', function(focaBotoneraPrincipalService) { + return focaBotoneraPrincipalService.obtenerBotones(); + }] + } }); }]); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..a1839d5 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,11 @@ +angular.module('focaBotoneraPrincipal') + .service('focaBotoneraPrincipalService', [ + '$http', 'API_ENDPOINT', + function($http, API_ENDPOINT) { + return { + obtenerBotones: function() { + return $http.get(API_ENDPOINT.URL + '/boton'); + } + }; + } + ]); -- 1.9.1