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 0cfa52a624
commit 87c38a0d89
11 changed files with 60 additions and 35 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -4,27 +4,12 @@ import './style.scss';
export const NAME = 'vnHome'; export const NAME = 'vnHome';
export default class vnHome { export default class vnHome {
constructor(aclService) { constructor(modulesFactory, $state) {
this.modules = []; this.modules = modulesFactory.getModules();
this.aclService = aclService; this.state = $state;
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);
}
}
} }
} }
vnHome.$inject = ['aclService']; vnHome.$inject = ['modulesFactory', '$state'];
export const COMPONENT = { export const COMPONENT = {
template: require('./home.html'), template: require('./home.html'),

View File

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

View File

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

View File

@ -2,9 +2,10 @@ import ngModule from '../../module';
import './style.scss'; import './style.scss';
export default class Controller { export default class Controller {
constructor($translate, $window) { constructor($translate, $window, modulesFactory) {
this.$translate = $translate; this.$translate = $translate;
this.$window = $window; this.$window = $window;
this.modules = modulesFactory.getModules();
} }
onLogoutClick() { onLogoutClick() {
this.$window.location = 'salix/logout'; this.$window.location = 'salix/logout';
@ -15,7 +16,7 @@ export default class Controller {
console.log(`Locale changed: ${lang}`); console.log(`Locale changed: ${lang}`);
} }
} }
Controller.$inject = ['$translate', '$window']; Controller.$inject = ['$translate', '$window', 'modulesFactory'];
ngModule.component('vnMainMenu', { ngModule.component('vnMainMenu', {
template: require('./main-menu.html'), template: require('./main-menu.html'),

View File

@ -7,6 +7,6 @@
"Data saved!": "Data saved!", "Data saved!": "Data saved!",
"Can't contact with server": "Can't contact with server", "Can't contact with server": "Can't contact with server",
"Push on applications menu": "To open a module push on applications menu", "Push on applications menu": "To open a module push on applications menu",
"clients": "clients", "Clients": "Clients",
"Modules access": "Modules access" "Modules access": "Modules access"
} }

View File

@ -7,6 +7,6 @@
"Data saved!": "¡Datos guardados!", "Data saved!": "¡Datos guardados!",
"Can't contact with server": "No se pudo contactar con el servidor", "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", "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" "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);