-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (72 loc) · 2.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var lnCms = angular.module('lnCms', [
require('angular-ui-router')
])
.config(['$stateProvider', '$urlRouterProvider', '$urlMatcherFactoryProvider',
function ($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvider) {
lnCms.stateProvider = $stateProvider;
//allow trailing slashes on routes
$urlMatcherFactoryProvider.strictMode(false);
//prevent $urlRouter from automatically intercepting URL changes
$urlRouterProvider.deferIntercept();
$urlRouterProvider.otherwise('/not-found');
}
])
.run(['lnCmsClientService', '$urlRouter', '$state', '$q',
function(lnCmsClientService, $urlRouter, $state, $q) {
//add error state
lnCms.stateProvider.state({
name: '503',
templateUrl: 'templates/error/template.html'
});
//add states defined in the routes endpoint
lnCmsClientService.getRoutes()
.then(function success(response) {
var routes = response.data;
angular.forEach(routes, function(route, key) {
var state = {
name: route.state,
url: route.url,
templateUrl: 'templates/' + route.template + '/template.html',
controller: 'LnViewController as vm',
resolve: {
staticData: ['lnCmsClientService', function(lnCmsClientService){
return lnCmsClientService.getStatic();
}],
viewData: ['lnCmsClientService', '$stateParams', function(lnCmsClientService, $stateParams){
var endpoint = route.endpoint || 'post';
var params = route.params || {};
angular.merge(params, $stateParams);
return lnCmsClientService.getData(endpoint, params);
}],
},
request: 'request' in route ? route.request : true,
};
if (route.url == '/') {
// //define default state for the empty url
var defState = {};
angular.copy(state, defState);
defState.name = 'default';
defState.url = '';
lnCms.stateProvider.state(defState);
} else if ( ! state.request || route.state === '404' ) {
state.resolve.viewData = function _resolve() {
return $q.when({});
}
}
//add state for the route
lnCms.stateProvider.state(state);
});
//enable $urlRouter listener again
$urlRouter.listen();
$urlRouter.sync();
}, function error() {
$state.go('503');
});
}
]);
require('./lib/cms.config.provider');
require('./lib/cms.client.service');
require('./lib/cms.controller');
require('./lib/cms-ln-view.controller');
require('./lib/cms.meta.directive');
require('./lib/cms.view.directive');