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/constants/pages.constant.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

/**
* Manages the creation and retrieval of pages (route + controller)
* TODO: Convert to class/Angular service
*/
2017-01-19 22:54:00 +00:00
export default {
2017-02-01 08:29:56 +00:00
_pages: {},
2017-01-19 22:54:00 +00:00
/**
* Create a page.
* @param pageName The name of the page.
* @param templateName The file name of the template.
2017-02-01 08:29:56 +00:00
* @param controller Controller for the page.
* @param flags Additional flags passed to route provider.
* @param profiles Available profiles.
*/
2017-02-01 08:29:56 +00:00
create: function(pageName: string, templateName: string, controller?: Object, flags = {}, profiles = ['old-layout', 'layout']) {
2017-01-19 22:54:00 +00:00
for (var i = 0; i < profiles.length; ++i) {
this._pages[profiles[i] + ':' + pageName] = {
'name': pageName,
2017-02-01 08:29:56 +00:00
'controller': controller,
2017-01-19 22:54:00 +00:00
'templateName': templateName,
2017-02-01 08:29:56 +00:00
'flags': flags
2017-01-19 22:54:00 +00:00
};
}
},
/**
* Retrieve a registered page.
* @param pageName The name of the page.
* @param profiles Available profiles to search.
*/
2017-02-01 08:29:56 +00:00
get: function(pageName: string, profiles: any[]) {
2017-01-19 22:54:00 +00:00
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;
}
2017-02-01 08:29:56 +00:00
};