mirror of
https://github.com/nasa/openmct.git
synced 2025-04-29 23:40:11 +00:00
[Framework] Add comments, logging
Add additional comments and logging to components of the framework layer. WTD-518.
This commit is contained in:
parent
3ed3ee19d7
commit
dbd5b148e2
@ -22,6 +22,8 @@ define(
|
|||||||
function ApplicationBootstrapper(angular, document, $log) {
|
function ApplicationBootstrapper(angular, document, $log) {
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
|
* Bootstrap the application.
|
||||||
|
*
|
||||||
* @method
|
* @method
|
||||||
* @memberof ApplicationBootstrapper#
|
* @memberof ApplicationBootstrapper#
|
||||||
* @param {angular.Module} app the Angular application to
|
* @param {angular.Module} app the Angular application to
|
||||||
|
@ -58,9 +58,9 @@ define(
|
|||||||
logName += ")";
|
logName += ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
return (self = {
|
self = {
|
||||||
/**
|
/**
|
||||||
*
|
* Get the path to this bundle.
|
||||||
* @memberof Bundle#
|
* @memberof Bundle#
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
@ -112,6 +112,8 @@ define(
|
|||||||
return logName;
|
return logName;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
* Get all extensions exposed by this bundle of a given
|
||||||
|
* category.
|
||||||
*
|
*
|
||||||
* @param category
|
* @param category
|
||||||
* @memberof Bundle#
|
* @memberof Bundle#
|
||||||
@ -125,6 +127,9 @@ define(
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
* Get a list of all categories of extension exposed by
|
||||||
|
* this bundle.
|
||||||
|
*
|
||||||
* @memberof Bundle#
|
* @memberof Bundle#
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
@ -132,6 +137,8 @@ define(
|
|||||||
return Object.keys(definition.extensions);
|
return Object.keys(definition.extensions);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
* Get the plain definition of this bundle, as read from
|
||||||
|
* its JSON declaration.
|
||||||
*
|
*
|
||||||
* @memberof Bundle#
|
* @memberof Bundle#
|
||||||
* @returns {BundleDefinition} the raw definition of this bundle
|
* @returns {BundleDefinition} the raw definition of this bundle
|
||||||
@ -139,7 +146,9 @@ define(
|
|||||||
getDefinition: function () {
|
getDefinition: function () {
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Bundle;
|
return Bundle;
|
||||||
|
@ -14,6 +14,9 @@ define(
|
|||||||
LOAD_ERROR_PREFIX = "Failed to load bundle ";
|
LOAD_ERROR_PREFIX = "Failed to load bundle ";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Loads bundle definitions and wraps them in interfaces which are
|
||||||
|
* useful to the framework. This provides the base information which
|
||||||
|
* will be used by later phases of framework layer initialization.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {object} $http Angular's HTTP requester
|
* @param {object} $http Angular's HTTP requester
|
||||||
@ -53,12 +56,16 @@ define(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load an individual bundle, as a Bundle object.
|
||||||
|
// Returns undefined if the definition could not be loaded.
|
||||||
function loadBundle(bundlePath) {
|
function loadBundle(bundlePath) {
|
||||||
return loadBundleDefinition(bundlePath).then(function (definition) {
|
return loadBundleDefinition(bundlePath).then(function (definition) {
|
||||||
return definition && (new Bundle(bundlePath, definition));
|
return definition && (new Bundle(bundlePath, definition));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load all named bundles from the array, returned as an array
|
||||||
|
// of Bundle objects.
|
||||||
function loadBundlesFromArray(bundleArray) {
|
function loadBundlesFromArray(bundleArray) {
|
||||||
var bundlePromises = bundleArray.map(loadBundle);
|
var bundlePromises = bundleArray.map(loadBundle);
|
||||||
|
|
||||||
@ -66,10 +73,16 @@ define(
|
|||||||
.then(filterBundles);
|
.then(filterBundles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load all bundles named in the referenced file. The file is
|
||||||
|
// presumed to be a JSON file
|
||||||
function loadBundlesFromFile(listFile) {
|
function loadBundlesFromFile(listFile) {
|
||||||
return getJSON(listFile).then(loadBundlesFromArray);
|
return getJSON(listFile).then(loadBundlesFromArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load all indicated bundles. If the argument is an array,
|
||||||
|
// this is taken to be a list of all bundles to load; if it
|
||||||
|
// is a string, then it is treated as the name of a JSON
|
||||||
|
// file containing the list of bundles to load.
|
||||||
function loadBundles(bundles) {
|
function loadBundles(bundles) {
|
||||||
return Array.isArray(bundles) ? loadBundlesFromArray(bundles) :
|
return Array.isArray(bundles) ? loadBundlesFromArray(bundles) :
|
||||||
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
|
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
|
||||||
@ -78,6 +91,15 @@ define(
|
|||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Load a group of bundles, to be used to constitute the
|
||||||
|
* application by later framework initialization phases.
|
||||||
|
*
|
||||||
|
* @memberof BundleLoader#
|
||||||
|
* @param {string|string[]} an array of bundle names to load, or
|
||||||
|
* the name of a JSON file containing that array
|
||||||
|
* @returns {Promise.<Bundle[]>}
|
||||||
|
*/
|
||||||
loadBundles: loadBundles
|
loadBundles: loadBundles
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,20 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Responsible for the extension resolution phase of framework
|
||||||
|
* initialization. During this phase, any scripts implementing
|
||||||
|
* extensions provided by bundles are loaded.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function BundleResolver(extensionResolver) {
|
function BundleResolver(extensionResolver, $log) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Merge resolved bundles (where each is expressed as an
|
||||||
|
* object containing key-value pairs, where keys are extension
|
||||||
|
* categories and values are arrays of resolved extensions)
|
||||||
|
* into one large object containing resolved extensions from
|
||||||
|
* all bundles (in the same form.)
|
||||||
*
|
*
|
||||||
* @param {Object.<string, object[]>[]} resolvedBundles
|
* @param {Object.<string, object[]>[]} resolvedBundles
|
||||||
* @returns {Object.<string, object[]>}
|
* @returns {Object.<string, object[]>}
|
||||||
@ -31,6 +39,9 @@ define(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve a bundle; resolve all extensions, and return
|
||||||
|
// the resolved extensions in an object in the format described
|
||||||
|
// for mergeResolvedBundles above
|
||||||
function resolveBundle(bundle) {
|
function resolveBundle(bundle) {
|
||||||
var categories = bundle.getExtensionCategories(),
|
var categories = bundle.getExtensionCategories(),
|
||||||
result = {};
|
result = {};
|
||||||
@ -56,11 +67,25 @@ define(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the large-scale task
|
||||||
|
$log.info(
|
||||||
|
"Resolving extensions for bundle " + bundle.getLogName()
|
||||||
|
);
|
||||||
|
|
||||||
return Promise.all(categories.map(resolveCategory))
|
return Promise.all(categories.map(resolveCategory))
|
||||||
.then(giveResult);
|
.then(giveResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Resolve all extensions exposed by these bundles.
|
||||||
|
*
|
||||||
|
* @param {Bundle[]} bundles the bundles to resolve
|
||||||
|
* @returns {Object.<string, object[]>} an object containing
|
||||||
|
* key-value pairs, where keys are extension
|
||||||
|
* categories and values are arrays of resolved
|
||||||
|
* extensions belonging to those categories
|
||||||
|
*/
|
||||||
resolveBundles: function (bundles) {
|
resolveBundles: function (bundles) {
|
||||||
return Promise.all(bundles.map(resolveBundle))
|
return Promise.all(bundles.map(resolveBundle))
|
||||||
.then(mergeResolvedBundles);
|
.then(mergeResolvedBundles);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants used by the framework.
|
* Constants used by the framework layer.
|
||||||
*/
|
*/
|
||||||
define({
|
define({
|
||||||
MODULE_NAME: "OpenMCTWeb",
|
MODULE_NAME: "OpenMCTWeb",
|
||||||
|
@ -15,6 +15,10 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function CustomRegistrars(app, $log) {
|
function CustomRegistrars(app, $log) {
|
||||||
|
|
||||||
|
// Used to create custom registration functions which map to
|
||||||
|
// named methods on Angular modules, which follow the normal
|
||||||
|
// app.method(key, [ deps..., function ]) pattern.
|
||||||
function CustomRegistrar(angularFunction) {
|
function CustomRegistrar(angularFunction) {
|
||||||
return function (extension, index) {
|
return function (extension, index) {
|
||||||
var key = extension.key,
|
var key = extension.key,
|
||||||
@ -45,7 +49,8 @@ define(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerRoute(extension, index) {
|
// Custom registration function for extensions of category "route"
|
||||||
|
function registerRoute(extension) {
|
||||||
var route = Object.create(extension);
|
var route = Object.create(extension);
|
||||||
|
|
||||||
// Adjust path for bundle
|
// Adjust path for bundle
|
||||||
@ -57,6 +62,9 @@ define(
|
|||||||
].join(Constants.SEPARATOR);
|
].join(Constants.SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the registration
|
||||||
|
$log.info("Registering route: " + (route.key || route.when));
|
||||||
|
|
||||||
// Register the route with Angular
|
// Register the route with Angular
|
||||||
app.config(['$routeProvider', function ($routeProvider) {
|
app.config(['$routeProvider', function ($routeProvider) {
|
||||||
if (route.when) {
|
if (route.when) {
|
||||||
@ -67,6 +75,9 @@ define(
|
|||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// More like key-value pairs than methods; key is the
|
||||||
|
// name of the extension category to be handled, and the value
|
||||||
|
// is the function which handles it.
|
||||||
return {
|
return {
|
||||||
routes: registerRoute,
|
routes: registerRoute,
|
||||||
directives: new CustomRegistrar("directive"),
|
directives: new CustomRegistrar("directive"),
|
||||||
|
@ -57,12 +57,16 @@ define(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
|
* Get the machine-readable identifier for this extension.
|
||||||
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getKey: function () {
|
getKey: function () {
|
||||||
return definition.key || "undefined";
|
return definition.key || "undefined";
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
* Get the bundle which declared this extension.
|
||||||
|
*
|
||||||
* @memberof Extension#
|
* @memberof Extension#
|
||||||
* @returns {Bundle}
|
* @returns {Bundle}
|
||||||
*/
|
*/
|
||||||
@ -70,6 +74,9 @@ define(
|
|||||||
return bundle;
|
return bundle;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
* Get the category into which this extension falls.
|
||||||
|
* (e.g. "directives")
|
||||||
|
*
|
||||||
* @memberof Extension#
|
* @memberof Extension#
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
@ -77,8 +84,12 @@ define(
|
|||||||
return category;
|
return category;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Check whether or not this
|
* Check whether or not this extension should have an
|
||||||
* @returns {boolean}
|
* associated implementation module which may need to
|
||||||
|
* be loaded.
|
||||||
|
*
|
||||||
|
* @returns {boolean} true if an implementation separate
|
||||||
|
* from this definition should also be loaded
|
||||||
*/
|
*/
|
||||||
hasImplementation: function () {
|
hasImplementation: function () {
|
||||||
return definition.implementation !== undefined;
|
return definition.implementation !== undefined;
|
||||||
@ -107,8 +118,16 @@ define(
|
|||||||
return logName;
|
return logName;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
* Get the plain definition of the extension.
|
||||||
|
*
|
||||||
|
* Note that this definition will have an additional "bundle"
|
||||||
|
* field which points back to the bundle which defined the
|
||||||
|
* extension, as a convenience.
|
||||||
|
*
|
||||||
* @memberof Extension#
|
* @memberof Extension#
|
||||||
* @returns {ExtensionDefinition}
|
* @returns {ExtensionDefinition} the plain definition of
|
||||||
|
* this extension, as read from the bundle
|
||||||
|
* declaration.
|
||||||
*/
|
*/
|
||||||
getDefinition: function () {
|
getDefinition: function () {
|
||||||
return extensionDefinition;
|
return extensionDefinition;
|
||||||
|
@ -9,8 +9,15 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Responsible for registering extensions with Angular.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @param {angular.Module} the Angular application with which
|
||||||
|
* extensions should be registered
|
||||||
|
* @param {Object.<string,function>} customRegistrars an object
|
||||||
|
* containing custom registration functions, primarily for
|
||||||
|
* Angular built-ins.
|
||||||
|
* @param {*} $log Angular's logging service
|
||||||
*/
|
*/
|
||||||
function ExtensionRegistrar(app, customRegistrars, $log) {
|
function ExtensionRegistrar(app, customRegistrars, $log) {
|
||||||
// Track which extension categories have already been registered.
|
// Track which extension categories have already been registered.
|
||||||
@ -18,6 +25,8 @@ define(
|
|||||||
// registered twice.
|
// registered twice.
|
||||||
var registeredCategories = {};
|
var registeredCategories = {};
|
||||||
|
|
||||||
|
// Used to build unique identifiers for individual extensions,
|
||||||
|
// so that these can be registered separately with Angular
|
||||||
function identify(category, extension, index) {
|
function identify(category, extension, index) {
|
||||||
var name = extension.key ?
|
var name = extension.key ?
|
||||||
(extension.key + "-" + index) :
|
(extension.key + "-" + index) :
|
||||||
@ -25,10 +34,14 @@ define(
|
|||||||
return category + "[" + name + "]";
|
return category + "[" + name + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Echo arguments; used to represent groups of non-built-in
|
||||||
|
// extensions as a single dependency.
|
||||||
function echo() {
|
function echo() {
|
||||||
return arguments.slice;
|
return arguments.slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always return a static value; used to represent plain
|
||||||
|
// metadata as a single dependency in Angular.
|
||||||
function staticFunction(value) {
|
function staticFunction(value) {
|
||||||
return function () { return value; };
|
return function () { return value; };
|
||||||
}
|
}
|
||||||
@ -45,6 +58,8 @@ define(
|
|||||||
return dependencies.concat([factory]);
|
return dependencies.concat([factory]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register extension arrays with Angular under an appropriately
|
||||||
|
// suffixed name, e.g. "types[]"
|
||||||
function registerExtensionArraysForCategory(category, names) {
|
function registerExtensionArraysForCategory(category, names) {
|
||||||
var name = category + Constants.EXTENSION_SUFFIX;
|
var name = category + Constants.EXTENSION_SUFFIX;
|
||||||
app.factory(name, names.concat([echo]));
|
app.factory(name, names.concat([echo]));
|
||||||
@ -102,6 +117,21 @@ define(
|
|||||||
customRegistrars = customRegistrars || {};
|
customRegistrars = customRegistrars || {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Register a group of resolved extensions with the Angular
|
||||||
|
* module managed by this registrar.
|
||||||
|
*
|
||||||
|
* For convenient chaining (particularly from the framework
|
||||||
|
* initializer's perspective), this returns the Angular
|
||||||
|
* module with which extensions were registered.
|
||||||
|
*
|
||||||
|
* @param {Object.<string, object[]>} extensionGroup an object
|
||||||
|
* containing key-value pairs, where keys are extension
|
||||||
|
* categories and values are arrays of resolved
|
||||||
|
* extensions
|
||||||
|
* @returns {angular.Module} the application module with
|
||||||
|
* which extensions were registered
|
||||||
|
*/
|
||||||
registerExtensions: registerExtensionGroup
|
registerExtensions: registerExtensionGroup
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,13 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Responsible for managing the four stages of framework
|
||||||
|
* initialization:
|
||||||
|
*
|
||||||
|
* * Loading bundle metadata (JSON files)
|
||||||
|
* * Resolving extension implementations with Require
|
||||||
|
* * Registering extensions with Angular
|
||||||
|
* * Bootstrapping the Angular application.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {BundleLoader} loader
|
* @param {BundleLoader} loader
|
||||||
@ -18,35 +25,12 @@ define(
|
|||||||
*/
|
*/
|
||||||
function FrameworkInitializer(loader, resolver, registrar, bootstrapper) {
|
function FrameworkInitializer(loader, resolver, registrar, bootstrapper) {
|
||||||
|
|
||||||
function registerExtensions(resolvedExtensions) {
|
|
||||||
Object.keys(resolvedExtensions).forEach(function (category) {
|
|
||||||
registrar.registerExtensions(
|
|
||||||
category,
|
|
||||||
resolvedExtensions[category]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {Bundle[]} bundles
|
|
||||||
* @returns {Object.<string, object[]>} an object mapping
|
|
||||||
*/
|
|
||||||
function resolveExtensions(bundles) {
|
|
||||||
return resolver.resolveBundles(bundles);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadBundles(bundleList) {
|
|
||||||
return loader.loadBundles(bundleList);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
runApplication: function (bundleList) {
|
runApplication: function (bundleList) {
|
||||||
return loader.loadBundles(bundleList)
|
return loader.loadBundles(bundleList)
|
||||||
.then(resolver.resolveBundles)
|
.then(resolver.resolveBundles)
|
||||||
.then(registrar.registerExtensions)
|
.then(registrar.registerExtensions)
|
||||||
.then(bootstrapper.bootstrap);
|
.then(bootstrapper.bootstrap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -58,7 +58,7 @@ define(
|
|||||||
resolver = new BundleResolver(new ExtensionResolver(
|
resolver = new BundleResolver(new ExtensionResolver(
|
||||||
new ImplementationLoader(require),
|
new ImplementationLoader(require),
|
||||||
$log
|
$log
|
||||||
)),
|
), $log),
|
||||||
registrar = new ExtensionRegistrar(
|
registrar = new ExtensionRegistrar(
|
||||||
app,
|
app,
|
||||||
new CustomRegistrars(app, $log),
|
new CustomRegistrars(app, $log),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user