This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/route-builder/route-builder.js
2017-01-07 04:24:26 -08:00

57 lines
No EOL
1.4 KiB
JavaScript

(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);
}
}
})();