tests and refactoring for AngularRouteBuilder
This commit is contained in:
parent
659417f7ef
commit
9248e4e8aa
7 changed files with 182 additions and 41 deletions
57
static/js/route-builder/route-builder.js
Normal file
57
static/js/route-builder/route-builder.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module("quay")
|
||||
.factory('RouteBuilder', factory);
|
||||
|
||||
factory.$inject = [
|
||||
|
||||
];
|
||||
|
||||
function factory() {
|
||||
function RouteBuilder(routeProvider, pages, profiles, currentProfile) {
|
||||
this.routeProvider = routeProvider;
|
||||
this.pages = pages;
|
||||
this.profiles = profiles;
|
||||
|
||||
for (var i = 0; i < profiles.length; ++i) {
|
||||
if (profiles[i].id == currentProfile) {
|
||||
this.profiles = this.profiles.slice(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RouteBuilder.prototype.otherwise = function(options) {
|
||||
this.routeProvider.otherwise(options);
|
||||
};
|
||||
|
||||
RouteBuilder.prototype.route = function(path, pagename) {
|
||||
// Lookup the page, matching our lists of profiles.
|
||||
var pair = this.pages.get(pagename, this.profiles);
|
||||
if (!pair) {
|
||||
throw Error('Unknown page: ' + pagename);
|
||||
}
|
||||
|
||||
// Create the route.
|
||||
var foundProfile = pair[0];
|
||||
var page = pair[1];
|
||||
var templateUrl = foundProfile.templatePath + page.templateName;
|
||||
|
||||
var options = jQuery.extend({}, page.flags || {});
|
||||
options['templateUrl'] = templateUrl;
|
||||
options['reloadOnSearch'] = false;
|
||||
options['controller'] = page.controller;
|
||||
|
||||
this.routeProvider.when(path, options);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
return function(routeProvider, pages, profiles, currentProfile) {
|
||||
return new RouteBuilder(routeProvider, pages, profiles, currentProfile);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
Reference in a new issue