salix/front/salix/routes.js

101 lines
3.0 KiB
JavaScript

import ngModule from './module';
import getMainRoute from 'core/lib/get-main-route';
config.$inject = ['$stateProvider', '$urlRouterProvider'];
function config($stateProvider, $urlRouterProvider) {
$urlRouterProvider
.otherwise('/');
$stateProvider
.state('layout', {
abstract: true,
template: '<vn-layout></vn-layout>',
})
.state('outLayout', {
abstract: true,
template: '<vn-out-layout></vn-out-layout>',
})
.state('login', {
parent: 'outLayout',
url: '/login?continue',
description: 'Login',
template: '<vn-login></vn-login>'
})
.state('recover-password', {
parent: 'outLayout',
url: '/recover-password',
description: 'Recover password',
template: '<vn-recover-password></vn-recover-password>'
})
.state('reset-password', {
parent: 'outLayout',
url: '/reset-password',
description: 'Reset password',
template: '<vn-reset-password></vn-reset-password>'
})
.state('home', {
parent: 'layout',
url: '/',
description: 'Home',
template: '<vn-home></vn-home>'
});
for (let file in window.routes) {
let routeFile = window.routes[file];
let fileRoutes = routeFile.routes;
let moduleName = routeFile.module;
let validations = routeFile.validations || false;
let mainModule = getMainRoute(fileRoutes);
if (!mainModule) continue;
for (let route of fileRoutes) {
let configRoute = {
url: route.url,
template: `<${route.component} ${getParams(route)}></${route.component}>`,
description: route.description,
reloadOnSearch: false,
resolve: {
loader: loader(moduleName, validations)
},
data: {
moduleIndex: file,
acl: route.acl
}
};
if (route.abstract)
configRoute.abstract = true;
if (!route.state.includes('.'))
configRoute.parent = 'layout';
if (route.routeParams)
configRoute.params = route.routeParams;
$stateProvider.state(route.state, configRoute);
}
}
function getParams(route) {
let params = '';
let temporalParams = [];
if (!route.params)
return params;
Object.keys(route.params).forEach(key => {
temporalParams.push(`${key} = "${route.params[key]}"`);
});
return temporalParams.join(' ');
}
function loader(moduleName) {
load.$inject = ['vnModuleLoader'];
function load(moduleLoader) {
return moduleLoader.load(moduleName);
}
return load;
}
}
ngModule.config(config);