mirror of
https://github.com/nasa/openmct.git
synced 2025-06-01 07:00:49 +00:00
Merge remote-tracking branch 'origin/open1256' into open-1336
This commit is contained in:
commit
270cb48db0
@ -4,12 +4,12 @@
|
|||||||
{
|
{
|
||||||
"key": "mctInclude",
|
"key": "mctInclude",
|
||||||
"implementation": "MCTInclude.js",
|
"implementation": "MCTInclude.js",
|
||||||
"depends": [ "templates[]" ]
|
"depends": [ "templates[]", "$sce" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "mctRepresentation",
|
"key": "mctRepresentation",
|
||||||
"implementation": "MCTRepresentation.js",
|
"implementation": "MCTRepresentation.js",
|
||||||
"depends": [ "representations[]", "views[]", "representers[]", "$q", "$log" ]
|
"depends": [ "representations[]", "views[]", "representers[]", "$q", "$sce", "$log" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"gestures": [
|
"gestures": [
|
||||||
|
@ -53,17 +53,17 @@ define(
|
|||||||
* @param {TemplateDefinition[]} templates an array of
|
* @param {TemplateDefinition[]} templates an array of
|
||||||
* template extensions
|
* template extensions
|
||||||
*/
|
*/
|
||||||
function MCTInclude(templates) {
|
function MCTInclude(templates, $sce) {
|
||||||
var templateMap = {};
|
var templateMap = {};
|
||||||
|
|
||||||
// Prepopulate templateMap for easy look up by key
|
// Prepopulate templateMap for easy look up by key
|
||||||
templates.forEach(function (template) {
|
templates.forEach(function (template) {
|
||||||
var key = template.key,
|
var key = template.key,
|
||||||
path = [
|
path = $sce.trustAsResourceUrl([
|
||||||
template.bundle.path,
|
template.bundle.path,
|
||||||
template.bundle.resources,
|
template.bundle.resources,
|
||||||
template.templateUrl
|
template.templateUrl
|
||||||
].join("/");
|
].join("/"));
|
||||||
// First found should win (priority ordering)
|
// First found should win (priority ordering)
|
||||||
templateMap[key] = templateMap[key] || path;
|
templateMap[key] = templateMap[key] || path;
|
||||||
});
|
});
|
||||||
|
@ -52,7 +52,7 @@ define(
|
|||||||
* representation extensions
|
* representation extensions
|
||||||
* @param {ViewDefinition[]} views an array of view extensions
|
* @param {ViewDefinition[]} views an array of view extensions
|
||||||
*/
|
*/
|
||||||
function MCTRepresentation(representations, views, representers, $q, $log) {
|
function MCTRepresentation(representations, views, representers, $q, $sce, $log) {
|
||||||
var representationMap = {},
|
var representationMap = {},
|
||||||
gestureMap = {};
|
gestureMap = {};
|
||||||
|
|
||||||
@ -69,11 +69,11 @@ define(
|
|||||||
|
|
||||||
// Get a path to a representation
|
// Get a path to a representation
|
||||||
function getPath(representation) {
|
function getPath(representation) {
|
||||||
return [
|
return $sce.trustAsResourceUrl([
|
||||||
representation.bundle.path,
|
representation.bundle.path,
|
||||||
representation.bundle.resources,
|
representation.bundle.resources,
|
||||||
representation.templateUrl
|
representation.templateUrl
|
||||||
].join("/");
|
].join("/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look up a matching representation for this domain object
|
// Look up a matching representation for this domain object
|
||||||
|
@ -31,6 +31,7 @@ define(
|
|||||||
|
|
||||||
describe("The mct-include directive", function () {
|
describe("The mct-include directive", function () {
|
||||||
var testTemplates,
|
var testTemplates,
|
||||||
|
mockSce,
|
||||||
mctInclude;
|
mctInclude;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -46,7 +47,14 @@ define(
|
|||||||
templateUrl: "z/template.html"
|
templateUrl: "z/template.html"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
mctInclude = new MCTInclude(testTemplates);
|
mockSce = jasmine.createSpyObj(
|
||||||
|
'$sce',
|
||||||
|
['trustAsResourceUrl']
|
||||||
|
);
|
||||||
|
mockSce.trustAsResourceUrl.andCallFake(function (url) {
|
||||||
|
return url;
|
||||||
|
});
|
||||||
|
mctInclude = new MCTInclude(testTemplates, mockSce);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has a built-in template, with ng-include src=inclusion", function () {
|
it("has a built-in template, with ng-include src=inclusion", function () {
|
||||||
@ -69,6 +77,12 @@ define(
|
|||||||
expect(scope.inclusion).toEqual("x/y/z/template.html");
|
expect(scope.inclusion).toEqual("x/y/z/template.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("trusts template URLs", function () {
|
||||||
|
mctInclude.controller({ key: "xyz" });
|
||||||
|
expect(mockSce.trustAsResourceUrl)
|
||||||
|
.toHaveBeenCalledWith("x/y/z/template.html");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -38,6 +38,7 @@ define(
|
|||||||
testViews,
|
testViews,
|
||||||
mockRepresenters,
|
mockRepresenters,
|
||||||
mockQ,
|
mockQ,
|
||||||
|
mockSce,
|
||||||
mockLog,
|
mockLog,
|
||||||
mockScope,
|
mockScope,
|
||||||
mockElement,
|
mockElement,
|
||||||
@ -95,8 +96,16 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
mockQ = { when: mockPromise };
|
mockQ = { when: mockPromise };
|
||||||
|
mockSce = jasmine.createSpyObj(
|
||||||
|
'$sce',
|
||||||
|
['trustAsResourceUrl']
|
||||||
|
);
|
||||||
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
|
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
|
||||||
|
|
||||||
|
|
||||||
|
mockSce.trustAsResourceUrl.andCallFake(function (url) {
|
||||||
|
return url;
|
||||||
|
});
|
||||||
mockScope = jasmine.createSpyObj("scope", [ "$watch" ]);
|
mockScope = jasmine.createSpyObj("scope", [ "$watch" ]);
|
||||||
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
||||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||||
@ -108,6 +117,7 @@ define(
|
|||||||
testViews,
|
testViews,
|
||||||
mockRepresenters,
|
mockRepresenters,
|
||||||
mockQ,
|
mockQ,
|
||||||
|
mockSce,
|
||||||
mockLog
|
mockLog
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -125,9 +135,18 @@ define(
|
|||||||
|
|
||||||
it("watches scope when linked", function () {
|
it("watches scope when linked", function () {
|
||||||
mctRepresentation.link(mockScope, mockElement);
|
mctRepresentation.link(mockScope, mockElement);
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith("key", jasmine.any(Function));
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith("domainObject", jasmine.any(Function));
|
"key",
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith("domainObject.getModel().modified", jasmine.any(Function));
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
|
"domainObject",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
|
"domainObject.getModel().modified",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("recognizes keys for representations", function () {
|
it("recognizes keys for representations", function () {
|
||||||
@ -152,6 +171,18 @@ define(
|
|||||||
expect(mockScope.inclusion).toEqual("x/y/z/template.html");
|
expect(mockScope.inclusion).toEqual("x/y/z/template.html");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("trusts template URLs", function () {
|
||||||
|
mctRepresentation.link(mockScope, mockElement);
|
||||||
|
|
||||||
|
mockScope.key = "xyz";
|
||||||
|
|
||||||
|
// Trigger the watch
|
||||||
|
mockScope.$watch.calls[0].args[1]();
|
||||||
|
|
||||||
|
expect(mockSce.trustAsResourceUrl)
|
||||||
|
.toHaveBeenCalledWith("x/y/z/template.html");
|
||||||
|
});
|
||||||
|
|
||||||
it("loads declared capabilities", function () {
|
it("loads declared capabilities", function () {
|
||||||
mctRepresentation.link(mockScope, mockElement);
|
mctRepresentation.link(mockScope, mockElement);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user