From 49999b62f2b147c89beddd32d9a6fdf9db0dccc0 Mon Sep 17 00:00:00 2001 From: Dani Herrero Date: Tue, 30 May 2017 09:54:35 +0200 Subject: [PATCH] creada factoria q retorna los modulos disponibles para el usuario, ACL --- client/client/routes.json | 2 +- client/core/src/label/label.mdl.html | 2 +- client/salix/src/app.js | 1 + client/salix/src/components/home/home.html | 2 +- client/salix/src/components/home/home.js | 23 +++--------- client/salix/src/components/home/style.scss | 2 +- .../src/components/main-menu/main-menu.html | 18 +++++----- .../src/components/main-menu/main-menu.js | 5 +-- client/salix/src/locale/en.json | 2 +- client/salix/src/locale/es.json | 2 +- client/salix/src/modulesFactory.js | 36 +++++++++++++++++++ 11 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 client/salix/src/modulesFactory.js diff --git a/client/client/routes.json b/client/client/routes.json index f9fb09a06..bd49efb49 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -1,6 +1,6 @@ { "module": "client", - "name": "clients", + "name": "Clients", "icon": "person", "routes": [ { diff --git a/client/core/src/label/label.mdl.html b/client/core/src/label/label.mdl.html index 9f95f13b3..2f33b3a1a 100644 --- a/client/core/src/label/label.mdl.html +++ b/client/core/src/label/label.mdl.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/client/salix/src/app.js b/client/salix/src/app.js index 8ec2c5df7..92caaf50c 100644 --- a/client/salix/src/app.js +++ b/client/salix/src/app.js @@ -6,3 +6,4 @@ import './config'; import './run'; import './components'; import './styles/index'; +import './modulesFactory'; diff --git a/client/salix/src/components/home/home.html b/client/salix/src/components/home/home.html index 971654873..5f6db683a 100644 --- a/client/salix/src/components/home/home.html +++ b/client/salix/src/components/home/home.html @@ -1,4 +1,4 @@ - +
diff --git a/client/salix/src/components/home/home.js b/client/salix/src/components/home/home.js index e30e73bf9..66002ae9f 100644 --- a/client/salix/src/components/home/home.js +++ b/client/salix/src/components/home/home.js @@ -4,27 +4,12 @@ import './style.scss'; export const NAME = 'vnHome'; export default class vnHome { - constructor(aclService) { - this.modules = []; - this.aclService = aclService; - this.init(); - } - - init() { - for (let file in routes) { - let card = { - name: routes[file].name, - icon: routes[file].icon - }; - let fileRoutes = routes[file].routes; - if (fileRoutes.length && this.aclService.routeHasPermission(fileRoutes[0])) { - card.route = fileRoutes[0]; - this.modules.push(card); - } - } + constructor(modulesFactory, $state) { + this.modules = modulesFactory.getModules(); + this.state = $state; } } -vnHome.$inject = ['aclService']; +vnHome.$inject = ['modulesFactory', '$state']; export const COMPONENT = { template: require('./home.html'), diff --git a/client/salix/src/components/home/style.scss b/client/salix/src/components/home/style.scss index 6d35004f1..a5cc44446 100644 --- a/client/salix/src/components/home/style.scss +++ b/client/salix/src/components/home/style.scss @@ -27,7 +27,7 @@ vn-home { margin: 0 auto; } - &.clients{ + &.Clients{ background-color: #ffa410; color: #ffffff; } diff --git a/client/salix/src/components/main-menu/main-menu.html b/client/salix/src/components/main-menu/main-menu.html index 75100c1b2..da5047c63 100644 --- a/client/salix/src/components/main-menu/main-menu.html +++ b/client/salix/src/components/main-menu/main-menu.html @@ -6,14 +6,16 @@ diff --git a/client/salix/src/components/main-menu/main-menu.js b/client/salix/src/components/main-menu/main-menu.js index 4340c85e9..f2bc6e5d1 100644 --- a/client/salix/src/components/main-menu/main-menu.js +++ b/client/salix/src/components/main-menu/main-menu.js @@ -2,9 +2,10 @@ import ngModule from '../../module'; import './style.scss'; export default class Controller { - constructor($translate, $window) { + constructor($translate, $window, modulesFactory) { this.$translate = $translate; this.$window = $window; + this.modules = modulesFactory.getModules(); } onLogoutClick() { this.$window.location = 'salix/logout'; @@ -15,7 +16,7 @@ export default class Controller { console.log(`Locale changed: ${lang}`); } } -Controller.$inject = ['$translate', '$window']; +Controller.$inject = ['$translate', '$window', 'modulesFactory']; ngModule.component('vnMainMenu', { template: require('./main-menu.html'), diff --git a/client/salix/src/locale/en.json b/client/salix/src/locale/en.json index a3962d5d4..70dabcc3a 100644 --- a/client/salix/src/locale/en.json +++ b/client/salix/src/locale/en.json @@ -7,6 +7,6 @@ "Data saved!": "Data saved!", "Can't contact with server": "Can't contact with server", "Push on applications menu": "To open a module push on applications menu", - "clients": "clients", + "Clients": "Clients", "Modules access": "Modules access" } \ No newline at end of file diff --git a/client/salix/src/locale/es.json b/client/salix/src/locale/es.json index de6f9711a..5ff53c91d 100644 --- a/client/salix/src/locale/es.json +++ b/client/salix/src/locale/es.json @@ -7,6 +7,6 @@ "Data saved!": "¡Datos guardados!", "Can't contact with server": "No se pudo contactar con el servidor", "Push on applications menu": "Para abrir un módulo pulsa en el menú de aplicaciones", - "clients": "clientes", + "Clients": "Clientes", "Modules access" : "Acceso a módulos" } \ No newline at end of file diff --git a/client/salix/src/modulesFactory.js b/client/salix/src/modulesFactory.js new file mode 100644 index 000000000..a36b301ac --- /dev/null +++ b/client/salix/src/modulesFactory.js @@ -0,0 +1,36 @@ +import ngModule from './module'; + +function modulesFactory(aclService) { + function _getMainRoute(routeCollection) { + let cant = routeCollection.length; + for (let i = 0; i < cant; i++) { + if (!routeCollection[i].abstract) { + return routeCollection[i]; + } + } + return null; + } + + function getModules() { + let modules = []; + for (let file in window.routes) { + let card = { + name: routes[file].name || routes[file].module, + icon: routes[file].icon || '' + }; + let mainRoute = _getMainRoute(window.routes[file].routes); + if (mainRoute && aclService.routeHasPermission(mainRoute)) { + card.route = mainRoute; + modules.push(card); + } + } + return modules; + } + + return { + getModules: getModules + }; +} +modulesFactory.$inject = ['aclService']; + +ngModule.factory('modulesFactory', modulesFactory);