/** * Manages the creation and retrieval of pages (route + controller) * TODO: Convert to class/Angular service */ export default { _pages: {}, /** * Create a page. * @param pageName The name of the page. * @param templateName The file name of the template. * @param controller Controller for the page. * @param flags Additional flags passed to route provider. * @param profiles Available profiles. */ create: function(pageName: string, templateName: string, controller?: Object, flags = {}, profiles = ['old-layout', 'layout']) { for (var i = 0; i < profiles.length; ++i) { this._pages[profiles[i] + ':' + pageName] = { 'name': pageName, 'controller': controller, 'templateName': templateName, 'flags': flags }; } }, /** * Retrieve a registered page. * @param pageName The name of the page. * @param profiles Available profiles to search. */ get: function(pageName: string, profiles: any[]) { for (var i = 0; i < profiles.length; ++i) { var current = profiles[i]; var key = current.id + ':' + pageName; var page = this._pages[key]; if (page) { return [current, page]; } } return null; } };