1 | var appName = 'app';
|
---|
2 | var appPath = 'WebApp';
|
---|
3 |
|
---|
4 | var Route = function (name, view, controller) {
|
---|
5 | this.name = name;
|
---|
6 | this.view = view;
|
---|
7 | this.controller = controller;
|
---|
8 | };
|
---|
9 |
|
---|
10 | var Module = function (moduleName) {
|
---|
11 | this.name = moduleName;
|
---|
12 | this.parent = 'app';
|
---|
13 | this.view = moduleName + '.cshtml';
|
---|
14 | this.controller = this.parent + "." + this.name + ".ctrl";
|
---|
15 | this.dependencies = [];
|
---|
16 | this.routes = [];
|
---|
17 | this.files = [];
|
---|
18 |
|
---|
19 | this.getModulePath = function() {
|
---|
20 | return appPath + '/plugins/' + this.name + '/';
|
---|
21 | };
|
---|
22 |
|
---|
23 | this.getFullModuleName = function () {
|
---|
24 | if (moduleName.localeCompare(appName) == 0) {
|
---|
25 | return this.name;
|
---|
26 | }
|
---|
27 | return this.parent + '.' + this.name;
|
---|
28 | };
|
---|
29 |
|
---|
30 | this.getRouteName = function() {
|
---|
31 | return '/' + this.name;
|
---|
32 | }
|
---|
33 |
|
---|
34 | this.getServiceName = function() {
|
---|
35 | return this.parent + "." + this.name + ".service";
|
---|
36 | };
|
---|
37 |
|
---|
38 | this.getControllerName = function() {
|
---|
39 | return this.parent + "." + this.name + ".ctrl";
|
---|
40 | }
|
---|
41 |
|
---|
42 | this.getAngularModule = function() {
|
---|
43 | return angular.module(this.getFullModuleName());
|
---|
44 | };
|
---|
45 |
|
---|
46 | this.getFilePath = function(file) {
|
---|
47 | return this.getModulePath() + file;
|
---|
48 | };
|
---|
49 |
|
---|
50 | this.getViewUrl = function(view) {
|
---|
51 | return 'plugin=' + this.name + '&view=' + view;
|
---|
52 | };
|
---|
53 |
|
---|
54 | this.getFiles = function() {
|
---|
55 | var module = this;
|
---|
56 | var filesToLoad = [];
|
---|
57 | module.files.forEach(function(file) {
|
---|
58 | filesToLoad.push(module.getFilePath(file));
|
---|
59 | });
|
---|
60 | return filesToLoad;
|
---|
61 | };
|
---|
62 |
|
---|
63 | this.getView = function() {
|
---|
64 | return this.view;
|
---|
65 | };
|
---|
66 |
|
---|
67 | this.getController = function() {
|
---|
68 | return this.controller;
|
---|
69 | };
|
---|
70 |
|
---|
71 | this.setView = function(view) {
|
---|
72 | this.view = view;
|
---|
73 | };
|
---|
74 |
|
---|
75 | this.setController = function(ctrl) {
|
---|
76 | this.controller = ctrl;
|
---|
77 | };
|
---|
78 |
|
---|
79 | this.configureFiles = function() {
|
---|
80 | var module = this.getAngularModule();
|
---|
81 | module.requires.push();
|
---|
82 | };
|
---|
83 |
|
---|
84 | this.configureRoutes = function ($stateProvider) {
|
---|
85 | var module = this;
|
---|
86 | this.routes.forEach(function(route) {
|
---|
87 | $stateProvider.state(module.name + route.name, {
|
---|
88 | url: '/' + module.name + '/' + route.name,
|
---|
89 | controller: route.controller,
|
---|
90 | templateUrl: module.getViewUrl(route.view),
|
---|
91 | cache: false,
|
---|
92 | resolve: {
|
---|
93 | loadModule: ['$ocLazyLoad', 'cfpLoadingBar', function ($ocLazyLoad, cfpLoadingBar) {
|
---|
94 | cfpLoadingBar.start();
|
---|
95 | var retVal = module.loadModule($ocLazyLoad);
|
---|
96 | cfpLoadingBar.complete();
|
---|
97 | return retVal;
|
---|
98 | }]
|
---|
99 | }
|
---|
100 | });
|
---|
101 | });
|
---|
102 | };
|
---|
103 |
|
---|
104 | this.loadModule = function ($ocLazyLoad) {
|
---|
105 | var module = this;
|
---|
106 | var params = [];
|
---|
107 | var lazyLoadingFiles = [];
|
---|
108 | module.dependencies.forEach(function (dependency) {
|
---|
109 | params.push(dependency);
|
---|
110 | });
|
---|
111 | module.files.forEach(function (file) {
|
---|
112 | lazyLoadingFiles.push(module.getFilePath(file));
|
---|
113 | });
|
---|
114 | // load required files
|
---|
115 | var lazyLoaded = null;
|
---|
116 | if (!($ocLazyLoad === undefined || $ocLazyLoad === null)) {
|
---|
117 | lazyLoaded = $ocLazyLoad.load(module.getFullModuleName());
|
---|
118 | }
|
---|
119 | // load angular module
|
---|
120 | angular.module(this.getFullModuleName(), params);
|
---|
121 | return lazyLoaded;
|
---|
122 | };
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 | var Menu = function () {
|
---|
127 | this.sections = [];
|
---|
128 | this.nextIndex = 0;
|
---|
129 |
|
---|
130 | this.getSection = function (name, index) {
|
---|
131 | var length = this.sections.length;
|
---|
132 | for (var i = 0; i < length; ++i) {
|
---|
133 | var section = this.sections[i];
|
---|
134 | if (section.name == name) {
|
---|
135 | return section;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | if (index === undefined || index === null) {
|
---|
139 | this.nextIndex++;
|
---|
140 | index = this.nextIndex;
|
---|
141 | } else {
|
---|
142 | if (index > this.nextIndex) {
|
---|
143 | this.nextIndex = index;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | var newSection = new Section(name, index);
|
---|
147 | this.sections.push(newSection);
|
---|
148 | return newSection;
|
---|
149 | };
|
---|
150 |
|
---|
151 | this.getMenuEntries = function () {
|
---|
152 | var entries = [];
|
---|
153 | this.sections.sort(function (a, b) {
|
---|
154 | return parseFloat(a.index) - parseFloat(b.index);
|
---|
155 | });
|
---|
156 | this.sections.forEach(function (section) {
|
---|
157 | entries.push({name: section.name, isCategory: true, route: '?'});
|
---|
158 | section.entries.forEach(function (entry) {
|
---|
159 | entries.push(entry);
|
---|
160 | });
|
---|
161 | });
|
---|
162 | return entries;
|
---|
163 | };
|
---|
164 | };
|
---|
165 |
|
---|
166 | var Section = function (name, index) {
|
---|
167 | this.name = name;
|
---|
168 | this.index = index;
|
---|
169 | this.entries = [];
|
---|
170 |
|
---|
171 | this.addEntry = function (entry) {
|
---|
172 | this.entries.push(entry);
|
---|
173 | };
|
---|
174 | };
|
---|
175 |
|
---|
176 | var app = new function () {
|
---|
177 | this.modules = [];
|
---|
178 | this.registerModule = function (moduleName) {
|
---|
179 | var module = new Module(moduleName);
|
---|
180 | if (moduleName.localeCompare(appName) != 0) {
|
---|
181 | this.modules.push(module);
|
---|
182 | }
|
---|
183 | return module;
|
---|
184 | };
|
---|
185 |
|
---|
186 | this.menu = new Menu();
|
---|
187 | this.getMenu = function () {
|
---|
188 | return this.menu;
|
---|
189 | };
|
---|
190 | }; |
---|