mirror of
https://github.com/nasa/openmct.git
synced 2025-02-21 09:52:04 +00:00
[Build] Add compatibility with text plugin
Allow templates to be loaded via the text plugin, which in turn will allow these to be built into the final JS artifact.
This commit is contained in:
parent
967f8c9151
commit
e0fbaa83b0
2
main.js
2
main.js
@ -30,7 +30,7 @@ requirejs.config({
|
|||||||
"moment": "bower_components/moment/moment",
|
"moment": "bower_components/moment/moment",
|
||||||
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
|
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
|
||||||
"screenfull": "bower_components/screenfull/dist/screenfull.min",
|
"screenfull": "bower_components/screenfull/dist/screenfull.min",
|
||||||
"text": "bower_components/text/text.js",
|
"text": "bower_components/text/text",
|
||||||
"uuid": "bower_components/node-uuid/uuid"
|
"uuid": "bower_components/node-uuid/uuid"
|
||||||
},
|
},
|
||||||
"shim": {
|
"shim": {
|
||||||
|
@ -22,11 +22,13 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define([
|
define([
|
||||||
|
"text!./res/templates/about-dialog.html",
|
||||||
"./src/LogoController",
|
"./src/LogoController",
|
||||||
"./src/AboutController",
|
"./src/AboutController",
|
||||||
"./src/LicenseController",
|
"./src/LicenseController",
|
||||||
'legacyRegistry'
|
'legacyRegistry'
|
||||||
], function (
|
], function (
|
||||||
|
aboutDialogTemplate,
|
||||||
LogoController,
|
LogoController,
|
||||||
AboutController,
|
AboutController,
|
||||||
LicenseController,
|
LicenseController,
|
||||||
@ -50,7 +52,7 @@ define([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "about-dialog",
|
"key": "about-dialog",
|
||||||
"templateUrl": "templates/about-dialog.html"
|
"template": aboutDialogTemplate
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "overlay-about",
|
"key": "overlay-about",
|
||||||
|
@ -74,7 +74,7 @@ define(
|
|||||||
var key = template.key;
|
var key = template.key;
|
||||||
// First found should win (priority ordering)
|
// First found should win (priority ordering)
|
||||||
templateMap[key] =
|
templateMap[key] =
|
||||||
templateMap[key] || templateLinker.getPath(template);
|
templateMap[key] || template;
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -69,11 +69,6 @@ define(
|
|||||||
representationMap[representation.key].push(representation);
|
representationMap[representation.key].push(representation);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get a path to a representation
|
|
||||||
function getPath(representation) {
|
|
||||||
return templateLinker.getPath(representation);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look up a matching representation for this domain object
|
// Look up a matching representation for this domain object
|
||||||
function lookup(key, domainObject) {
|
function lookup(key, domainObject) {
|
||||||
var candidates = representationMap[key] || [],
|
var candidates = representationMap[key] || [],
|
||||||
@ -175,9 +170,8 @@ define(
|
|||||||
function refresh() {
|
function refresh() {
|
||||||
var domainObject = $scope.domainObject,
|
var domainObject = $scope.domainObject,
|
||||||
representation = lookup($scope.key, domainObject),
|
representation = lookup($scope.key, domainObject),
|
||||||
path = representation && getPath(representation),
|
|
||||||
uses = ((representation || {}).uses || []),
|
uses = ((representation || {}).uses || []),
|
||||||
canRepresent = !!(path && domainObject),
|
canRepresent = !!(representation && domainObject),
|
||||||
canEdit = !!(domainObject && domainObject.hasCapability('editor')),
|
canEdit = !!(domainObject && domainObject.hasCapability('editor')),
|
||||||
idPath = getIdPath(domainObject),
|
idPath = getIdPath(domainObject),
|
||||||
key = $scope.key;
|
key = $scope.key;
|
||||||
@ -192,7 +186,7 @@ define(
|
|||||||
|
|
||||||
// Change templates (passing in undefined to clear
|
// Change templates (passing in undefined to clear
|
||||||
// if we don't have enough info to show a template.)
|
// if we don't have enough info to show a template.)
|
||||||
changeTemplate(canRepresent ? path : undefined);
|
changeTemplate(canRepresent ? representation : undefined);
|
||||||
|
|
||||||
// Any existing representers are no longer valid; release them.
|
// Any existing representers are no longer valid; release them.
|
||||||
destroyRepresenters();
|
destroyRepresenters();
|
||||||
|
@ -87,7 +87,7 @@ define(
|
|||||||
* @returns {Function} a function which can be called with a template
|
* @returns {Function} a function which can be called with a template
|
||||||
* URL to switch templates, or `undefined` to remove.
|
* URL to switch templates, or `undefined` to remove.
|
||||||
*/
|
*/
|
||||||
TemplateLinker.prototype.link = function (scope, element, templateUrl) {
|
TemplateLinker.prototype.link = function (scope, element, ext) {
|
||||||
var activeElement = element,
|
var activeElement = element,
|
||||||
activeTemplateUrl,
|
activeTemplateUrl,
|
||||||
comment = this.$compile('<!-- hidden mct element -->')(scope),
|
comment = this.$compile('<!-- hidden mct element -->')(scope),
|
||||||
@ -124,12 +124,18 @@ define(
|
|||||||
self.$compile(element.contents())(activeScope);
|
self.$compile(element.contents())(activeScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
function badTemplate(templateUrl) {
|
function showTemplate(template) {
|
||||||
|
addElement();
|
||||||
|
populateElement(template);
|
||||||
|
activeTemplateUrl = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function badTemplateUrl(templateUrl) {
|
||||||
self.$log.warn("Couldn't load template at " + templateUrl);
|
self.$log.warn("Couldn't load template at " + templateUrl);
|
||||||
removeElement();
|
removeElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeTemplate(templateUrl) {
|
function changeTemplateUrl(templateUrl) {
|
||||||
if (templateUrl) {
|
if (templateUrl) {
|
||||||
destroyScope();
|
destroyScope();
|
||||||
addElement();
|
addElement();
|
||||||
@ -139,7 +145,7 @@ define(
|
|||||||
populateElement(template);
|
populateElement(template);
|
||||||
}
|
}
|
||||||
}, function () {
|
}, function () {
|
||||||
badTemplate(templateUrl);
|
badTemplateUrl(templateUrl);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
removeElement();
|
removeElement();
|
||||||
@ -147,12 +153,19 @@ define(
|
|||||||
activeTemplateUrl = templateUrl;
|
activeTemplateUrl = templateUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templateUrl) {
|
function changeTemplate(ext) {
|
||||||
changeTemplate(templateUrl);
|
ext = ext || {};
|
||||||
} else {
|
if (ext.templateUrl) {
|
||||||
removeElement();
|
changeTemplateUrl(self.getPath(ext));
|
||||||
|
} else if (ext.template) {
|
||||||
|
showTemplate(ext.template);
|
||||||
|
} else {
|
||||||
|
removeElement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeTemplate(ext);
|
||||||
|
|
||||||
return changeTemplate;
|
return changeTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,11 +38,10 @@ define(
|
|||||||
.reduce(function (a, b) {
|
.reduce(function (a, b) {
|
||||||
return a.concat(b);
|
return a.concat(b);
|
||||||
}, [])
|
}, [])
|
||||||
.map(function (ext) {
|
.forEach(function (ext) {
|
||||||
return templateLinker.getPath(ext);
|
if (ext.templateUrl) {
|
||||||
})
|
templateLinker.load(templateLinker.getPath(ext));
|
||||||
.forEach(function (path) {
|
}
|
||||||
templateLinker.load(path);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user