Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Services.WebApp/3.3/WebApp/app.js @ 18242

Last change on this file since 18242 was 12878, checked in by ascheibe, 9 years ago

#2388 merged hive statistics branch into trunk

File size: 4.9 KB
Line 
1// app configuration
2var appName = 'app';
3var appPath = 'WebApp';
4var defaultPageUpdateInterval = 60000;
5
6// route, plugin, menu, section and main app
7var Route = function (name, view, controller) {
8    this.name = name;
9    this.view = view;
10    this.controller = controller;
11};
12
13var Plugin = function (pluginName) {
14    this.name = pluginName;
15    this.parent = appName;
16    this.view = '';
17    this.controller = '';
18    this.dependencies = [];
19    this.routes = [];
20    this.files = [];
21
22    this.getPluginDirectory = function () {
23        return appPath + '/plugins/' + this.name + '/';
24    };
25
26    this.getFullPluginName = function() {
27        if (this.name.localeCompare(appName) == 0) {
28            return this.name;
29        }
30        return this.parent + '.' + this.name;
31    };
32
33    this.getRouteName = function() {
34        return '/' + this.name;
35    };
36
37    this.getAngularModule = function() {
38        return angular.module(this.getFullPluginName());
39    };
40
41    this.getFilePath = function (file) {
42        return this.getPluginDirectory() + file;
43    };
44
45    this.getViewUrl = function (view) {
46        return 'plugin=' + this.name + '&view=' + view;
47    };
48
49    // getFiles is used in the lazy loading provider
50    this.getFiles = function () {
51        var plugin = this;
52        var filesToLoad = [];
53        plugin.files.forEach(function (file) {
54            filesToLoad.push(plugin.getFilePath(file));
55        });
56        return filesToLoad;
57    };
58
59    this.configureRoutes = function ($stateProvider) {
60        var plugin = this;
61        this.routes.forEach(function (route) {
62            $stateProvider.state(plugin.name + route.name, {
63                url: '/' + plugin.name + '/' + route.name,
64                controller: route.controller,
65                templateUrl: plugin.getViewUrl(route.view),
66                cache: false,
67                resolve: {
68                    loadPlugin: ['$ocLazyLoad', 'cfpLoadingBar', function ($ocLazyLoad, cfpLoadingBar) {
69                        cfpLoadingBar.start();
70                        var retVal = plugin.load($ocLazyLoad);
71                        cfpLoadingBar.complete();
72                        return retVal;
73                    }]
74                }
75            });
76        });
77    };
78
79    this.load = function ($ocLazyLoad) {
80        var plugin = this;
81        var params = [];
82        var lazyLoadingFiles = [];
83        plugin.dependencies.forEach(function (dependency) {
84            params.push(dependency);
85        });
86        plugin.files.forEach(function (file) {
87            lazyLoadingFiles.push(plugin.getFilePath(file));
88        });
89        // load required files
90        var lazyLoaded = null;
91        if (!($ocLazyLoad === undefined || $ocLazyLoad === null)) {
92            lazyLoaded = $ocLazyLoad.load(plugin.getFullPluginName());
93        }
94        // load angular module
95        angular.module(this.getFullPluginName(), params);
96        return lazyLoaded;
97    };
98};
99
100var Section = function (name, index) {
101    this.name = name;
102    this.index = index;
103    this.entries = [];
104
105    this.addEntry = function (entry) {
106        this.entries.push(entry);
107    };
108};
109
110var Menu = function () {
111    this.sections = [];
112    this.nextIndex = 0;
113
114    this.getSection = function (name, index) {
115        var length = this.sections.length;
116        for (var i = 0; i < length; ++i) {
117            var section = this.sections[i];
118            if (section.name == name) {
119                return section;
120            }
121        }
122        if (index === undefined || index === null) {
123            this.nextIndex++;
124            index = this.nextIndex;
125        } else {
126            if (index > this.nextIndex) {
127                this.nextIndex = index;
128            }
129        }
130        var newSection = new Section(name, index);
131        this.sections.push(newSection);
132        return newSection;
133    };
134
135    this.getMenuEntries = function () {
136        var entries = [];
137        this.sections.sort(function (a, b) {
138            return parseFloat(a.index) - parseFloat(b.index);
139        });
140        this.sections.forEach(function (section) {
141            entries.push({ name: section.name, isCategory: true, route: '?' });
142            section.entries.sort(function(a, b) {
143                return parseFloat(a.index) - parseFloat(b.index);
144            });
145            section.entries.forEach(function (entry) {
146                entries.push(entry);
147            });
148        });
149        return entries;
150    };
151};
152
153// app that holds references to plugins and menu
154var app = new function () {
155    this.plugins = [];
156    this.registerPlugin = function (name) {
157        var plugin = new Plugin(name);
158        if (name.localeCompare(appName) != 0) {
159            this.plugins.push(plugin);
160        }
161        return plugin;
162    };
163
164    this.menu = new Menu();
165    this.getMenu = function () {
166        return this.menu;
167    };
168};
Note: See TracBrowser for help on using the repository browser.