Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Services.WebApp/3.3/WebApp/app.js @ 12428

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

#2394 added web app and status page to trunk

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