creada factoria q retorna los modulos disponibles para el usuario, ACL

This commit is contained in:
Dani Herrero 2017-05-30 09:54:35 +02:00
parent f57e9ecf6f
commit 49999b62f2
11 changed files with 60 additions and 35 deletions

View File

@ -1,6 +1,6 @@
{
"module": "client",
"name": "clients",
"name": "Clients",
"icon": "person",
"routes": [
{

View File

@ -1 +1 @@
<label>*[text]*</label>
<label translate="*[text]*"></label>

View File

@ -6,3 +6,4 @@ import './config';
import './run';
import './components';
import './styles/index';
import './modulesFactory';

View File

@ -1,4 +1,4 @@
<vn-vertical>
<vn-vertical ng-if="$ctrl.state.current.name === 'home'">
<vn-horizontal>
<h6 vn-one translate="Modules access"></h6>
</vn-horizontal>

View File

@ -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'),

View File

@ -27,7 +27,7 @@ vn-home {
margin: 0 auto;
}
&.clients{
&.Clients{
background-color: #ffa410;
color: #ffffff;
}

View File

@ -6,14 +6,16 @@
<vn-icon icon="account_circle" translate-attr="{title: 'Profile'}" style="font-size: 35px;"></vn-icon>
<ul class="mdl-menu mdl-js-menu mdl-menu--bottom-right" pad-medium for="apps">
<vn-horizontal>
<vn-vertical>
<a ui-sref="clients">
<button vn-one class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored popover-button">
<vn-icon vn-one icon="person" style="font-size:40px"></vn-icon>
</button>
</a>
<vn-label class="popover-label" text="Clientes"></vn-label>
</vn-vertical>
<div ng-repeat="mod in $ctrl.modules">
<vn-vertical>
<a ui-sref="{{::mod.route.state}}">
<button vn-one class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored popover-button">
<vn-icon vn-one icon="{{::mod.icon}}" style="font-size:40px"></vn-icon>
</button>
</a>
<vn-label class="popover-label" text="{{::mod.name}}"></vn-label>
</vn-vertical>
</div>
</vn-horizontal>
</ul>
</div>

View File

@ -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'),

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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);