Merge pull request #642 from nasa/open460

[Build] Move to npm-based build
This commit is contained in:
Victor Woeltjen
2016-02-08 12:21:01 -08:00
55 changed files with 413 additions and 33687 deletions

View File

@@ -74,7 +74,7 @@ define(
var key = template.key;
// First found should win (priority ordering)
templateMap[key] =
templateMap[key] || templateLinker.getPath(template);
templateMap[key] || template;
});
return {

View File

@@ -69,11 +69,6 @@ define(
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
function lookup(key, domainObject) {
var candidates = representationMap[key] || [],
@@ -175,9 +170,8 @@ define(
function refresh() {
var domainObject = $scope.domainObject,
representation = lookup($scope.key, domainObject),
path = representation && getPath(representation),
uses = ((representation || {}).uses || []),
canRepresent = !!(path && domainObject),
canRepresent = !!(representation && domainObject),
canEdit = !!(domainObject && domainObject.hasCapability('editor')),
idPath = getIdPath(domainObject),
key = $scope.key;
@@ -192,7 +186,7 @@ define(
// Change templates (passing in undefined to clear
// 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.
destroyRepresenters();

View File

@@ -84,10 +84,13 @@ define(
* templates
* @param element the jqLite-wrapped element into which templates
* should be inserted
* @returns {Function} a function which can be called with a template
* URL to switch templates, or `undefined` to remove.
* @param {TemplateDefinition} extensionDefinition the definition
* of the template/representation/view to display initially
* @returns {Function} a function which can be called with a template's
* extension definition to switch templates, or `undefined`
* to remove.
*/
TemplateLinker.prototype.link = function (scope, element, templateUrl) {
TemplateLinker.prototype.link = function (scope, element, ext) {
var activeElement = element,
activeTemplateUrl,
comment = this.$compile('<!-- hidden mct element -->')(scope),
@@ -124,12 +127,18 @@ define(
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);
removeElement();
}
function changeTemplate(templateUrl) {
function changeTemplateUrl(templateUrl) {
if (templateUrl) {
destroyScope();
addElement();
@@ -139,7 +148,7 @@ define(
populateElement(template);
}
}, function () {
badTemplate(templateUrl);
badTemplateUrl(templateUrl);
});
} else {
removeElement();
@@ -147,12 +156,19 @@ define(
activeTemplateUrl = templateUrl;
}
if (templateUrl) {
changeTemplate(templateUrl);
} else {
removeElement();
function changeTemplate(ext) {
ext = ext || {};
if (ext.templateUrl) {
changeTemplateUrl(self.getPath(ext));
} else if (ext.template) {
showTemplate(ext.template);
} else {
removeElement();
}
}
changeTemplate(ext);
return changeTemplate;
};

View File

@@ -38,11 +38,10 @@ define(
.reduce(function (a, b) {
return a.concat(b);
}, [])
.map(function (ext) {
return templateLinker.getPath(ext);
})
.forEach(function (path) {
templateLinker.load(path);
.forEach(function (ext) {
if (ext.templateUrl) {
templateLinker.load(templateLinker.getPath(ext));
}
});
}

View File

@@ -91,12 +91,12 @@ define(
mockScope.key = 'abc';
fireWatch('key', mockScope.key);
expect(mockChangeTemplate)
.toHaveBeenCalledWith(testUrls.abc);
.toHaveBeenCalledWith(testTemplates[0]);
mockScope.key = 'xyz';
fireWatch('key', mockScope.key);
expect(mockChangeTemplate)
.toHaveBeenCalledWith(testUrls.xyz);
.toHaveBeenCalledWith(testTemplates[1]);
});
});

View File

@@ -174,7 +174,7 @@ define(
fireWatch('domainObject', mockDomainObject);
expect(mockChangeTemplate)
.toHaveBeenCalledWith(testUrls.abc);
.toHaveBeenCalledWith(testRepresentations[0]);
});
it("recognizes keys for views", function () {
@@ -186,7 +186,7 @@ define(
fireWatch('domainObject', mockDomainObject);
expect(mockChangeTemplate)
.toHaveBeenCalledWith(testUrls.xyz);
.toHaveBeenCalledWith(testViews[1]);
});
it("does not load templates until there is an object", function () {
@@ -196,13 +196,13 @@ define(
fireWatch('key', mockScope.key);
expect(mockChangeTemplate)
.not.toHaveBeenCalledWith(jasmine.any(String));
.not.toHaveBeenCalledWith(jasmine.any(Object));
mockScope.domainObject = mockDomainObject;
fireWatch('domainObject', mockDomainObject);
expect(mockChangeTemplate)
.toHaveBeenCalledWith(jasmine.any(String));
.toHaveBeenCalledWith(jasmine.any(Object));
});
it("loads declared capabilities", function () {

View File

@@ -44,6 +44,16 @@ define(
mockPromise,
linker;
function testExtension(path, res, templatePath) {
return {
bundle: {
path: path,
resources: res
},
templateUrl: templatePath
};
}
beforeEach(function () {
mockTemplateRequest = jasmine.createSpy('$templateRequest');
mockSce = jasmine.createSpyObj('$sce', ['trustAsResourceUrl']);
@@ -91,13 +101,8 @@ define(
});
it("resolves extension paths", function () {
expect(linker.getPath({
bundle: {
path: 'a',
resources: 'b'
},
templateUrl: 'c/d.html'
})).toEqual('a/b/c/d.html');
var testExt = testExtension('a', 'b', 'c/d.html');
expect(linker.getPath(testExt)).toEqual('a/b/c/d.html');
});
describe("when linking elements", function () {
@@ -132,13 +137,15 @@ define(
});
describe("and then changing templates", function () {
var testUrl,
var testExt,
testUrl,
testTemplate;
beforeEach(function () {
testUrl = "some/url/template.html";
testExt = testExtension('some', 'url', 'template.html');
testUrl = linker.getPath(testExt);
testTemplate = "<div>Some template!</div>";
changeTemplate(testUrl);
changeTemplate(testExt);
mockPromise.then.mostRecentCall
.args[0](testTemplate);
});
@@ -182,7 +189,9 @@ define(
describe("which cannot be found", function () {
beforeEach(function () {
changeTemplate("some/bad/url");
changeTemplate(
testExtension("some", "bad", "template.html")
);
// Reject the template promise
mockPromise.then.mostRecentCall.args[1]();
});
@@ -206,11 +215,13 @@ define(
});
describe("when an initial template URL is provided", function () {
var testUrl;
var testExt,
testUrl;
beforeEach(function () {
testUrl = "some/test/url.html";
linker.link(mockScope, mockElement, testUrl);
testExt = testExtension('some', 'test', 'template.html');
testUrl = linker.getPath(testExt);
linker.link(mockScope, mockElement, testExt);
});
it("does not remove the element initially", function () {