diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index a5b229d68..43c858543 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -30,6 +30,7 @@ use \Zend_Controller_Action_Exception as ActionException; use \Icinga\Web\Controller\ActionController; use \Icinga\Application\Icinga; +use \Icinga\Application\Logger; class StaticController extends ActionController { @@ -124,6 +125,9 @@ class StaticController extends ActionController } if (!file_exists($filePath)) { + Logger::error( + 'Non-existing frontend component "' . $module . '/' . $file + . '" was requested, which would resolve to the the path: ' . $filePath); echo '/** Module has no js files **/'; return; } diff --git a/public/js/icinga/componentLoader.js b/public/js/icinga/componentLoader.js index 0c9daa499..32bb9f08a 100644 --- a/public/js/icinga/componentLoader.js +++ b/public/js/icinga/componentLoader.js @@ -22,7 +22,7 @@ define(['jquery', 'logging', 'icinga/componentRegistry'], function ($, log, regi */ var loadComponent = function(cmpType, target, fin, err) { requirejs( - ['modules/'+cmpType], + ['modules/' + cmpType], function (Cmp) { var cmp; try { @@ -40,7 +40,7 @@ define(['jquery', 'logging', 'icinga/componentRegistry'], function ($, log, regi if (!ex) { return; } - log.emergency('Component "'+cmpType+'" could not be loaded.', ex); + log.emergency('Component "' + cmpType + '" could not be loaded.', ex); if (err) { err(ex); } diff --git a/public/js/icinga/componentRegistry.js b/public/js/icinga/componentRegistry.js index 49daadf36..c76ea7ac6 100644 --- a/public/js/icinga/componentRegistry.js +++ b/public/js/icinga/componentRegistry.js @@ -25,7 +25,7 @@ define(['jquery'], function($) { var createId = (function() { var id = 0; return function() { - return 'icinga-component-'+id++; + return 'icinga-component-' + id++; }; })(); diff --git a/test/js/test/icinga/componentTest.js b/test/js/test/icinga/componentTest.js index 6e2617ca0..13458ceeb 100644 --- a/test/js/test/icinga/componentTest.js +++ b/test/js/test/icinga/componentTest.js @@ -30,19 +30,19 @@ var setUp = function(registry) */ 'modules/app/component1': function(cmp) { cmp.test = 'changed-by-component-1'; - this.type = function(){ + this.type = function() { return "app/component1"; }; }, 'modules/app/component2': function(cmp) { cmp.test = 'changed-by-component-2'; - this.type = function(){ + this.type = function() { return "app/component2"; }; }, 'modules/module/component3': function(cmp) { cmp.test = 'changed-by-component-3-from-module'; - this.type = function(){ + this.type = function() { return "module/component3"; }; } @@ -60,21 +60,20 @@ var setUp = function(registry) * @param type {String} The type of the component in the form: "/" * @param id {String} The optional id of the component */ -var addComponent = function(type,id) { - var txt = '
test
'; +var addComponent = function(type, id) { + var txt = '
test
'; $('body').append(txt); }; -describe('Component loader',function(){ +describe('Component loader', function() { - it('Component loaded with automatic id',function(){ + it('Component loaded with automatic id', function() { setUp(); addComponent('app/component1'); - component.load(function(){ - // loading complete + component.load(function() { var cmpNode = $('#icinga-component-0'); cmpNode.length.should.equal(1); cmpNode[0].test.should.equal('changed-by-component-1'); @@ -82,12 +81,11 @@ describe('Component loader',function(){ }); }); - it('Component load with user-defined id',function(){ + it('Component load with user-defined id', function() { setUp(); addComponent('app/component2','some-id'); - component.load(function(){ - // loading complete + component.load(function() { var cmpNode = $('#some-id'); cmpNode.length.should.equal(1); cmpNode[0].test.should.equal('changed-by-component-2'); @@ -95,40 +93,39 @@ describe('Component loader',function(){ }); }); - it('Garbage collection removes deleted components',function(){ + it('Garbage collection removes deleted components', function() { setUp(); addComponent('app/component1'); addComponent('app/component2'); addComponent('app/component2'); addComponent('module/component3'); - component.load(function(){ - // loading complete + component.load(function() { var components = component.getComponents(); components.length.should.equal(4); $('body').empty(); - component.load(function(){ + component.load(function() { var components = component.getComponents(); components.length.should.equal(0); }); }); }); - it('Component queries are delegated to the registry correctly',function(){ + it('Component queries are delegated to the registry correctly', function() { var getByIdCalled = false; var getByTypeCalled = false; var getComponentsCalled = false; var registryMock = { - getById: function(id){ + getById: function(id) { getByIdCalled = true; id.should.equal('some-id'); }, - getByType: function(type){ + getByType: function(type) { getByTypeCalled = true; type.should.equal('some-type'); }, - getComponents: function(){ + getComponents: function() { getComponentsCalled = true; } }; diff --git a/test/js/test/icinga/registryTest.js b/test/js/test/icinga/registryTest.js index a49d468e5..14cb6cb93 100644 --- a/test/js/test/icinga/registryTest.js +++ b/test/js/test/icinga/registryTest.js @@ -19,48 +19,48 @@ var cleanTestDom = function() { }; -describe('Component registry',function(){ - it('Ids are created automatically in the form "icinga-component-"',function(){ +describe('Component registry',function() { + it('Ids are created automatically in the form "icinga-component-"', function() { setUp(); - registry.add({},null,null).should.equal('icinga-component-0'); - registry.add({},null,null).should.equal('icinga-component-1'); - registry.add({},null,null).should.equal('icinga-component-2'); + registry.add({}, null, null).should.equal('icinga-component-0'); + registry.add({}, null, null).should.equal('icinga-component-1'); + registry.add({}, null, null).should.equal('icinga-component-2'); cleanTestDom(); }); - it('Existing ids are preserved',function(){ + it('Existing ids are preserved', function() { setUp(); - registry.add({},'user-defined-id',null).should.equal('user-defined-id'); + registry.add({}, 'user-defined-id', null).should.equal('user-defined-id'); cleanTestDom(); }); - it('Components are correctly added to the library',function(){ + it('Components are correctly added to the library', function() { setUp(); var cmp1 = { component: "cmp1" }; - registry.add(cmp1,'user-defined-id',null); + registry.add(cmp1, 'user-defined-id', null); registry.getById('user-defined-id').should.equal(cmp1); var cmp2 = { component: "cmp2" }; - registry.add(cmp2,null,null); + registry.add(cmp2, null, null); registry.getById('icinga-component-0').should.equal(cmp2); cleanTestDom(); }); - it('getId(component) should return the components assigned id.',function(){ + it('getId(component) should return the components assigned id.', function() { setUp(); var cmp1 = { component: "cmp1" }; - registry.add(cmp1,'user-defined-id',null); + registry.add(cmp1, 'user-defined-id', null); registry.getId(cmp1).should.equal('user-defined-id'); var cmp2 = { component: "cmp2" }; - registry.add(cmp2,'user-defined-id-2',null); + registry.add(cmp2, 'user-defined-id-2',null); registry.getId(cmp2).should.equal('user-defined-id-2'); should.not.exist(registry.getId({})); @@ -68,17 +68,17 @@ describe('Component registry',function(){ cleanTestDom(); }); - it('getByType() should return all components of a certain type',function(){ + it('getByType() should return all components of a certain type', function() { setUp(); var cmp1 = { component: "some/type" }; - registry.add(cmp1,null,'some/type'); + registry.add(cmp1, null, 'some/type'); var cmp2 = { component: "some/type" }; - registry.add(cmp2,null,"some/type"); + registry.add(cmp2, null, "some/type"); var cmp3 = { component: "other/type" }; - registry.add(cmp3,null,"other/type"); + registry.add(cmp3, null, "other/type"); var cmps = registry.getByType('some/type'); cmps.length.should.equal(2); @@ -88,17 +88,17 @@ describe('Component registry',function(){ cleanTestDom(); }); - it('getComponents() should return all components',function(){ + it('getComponents() should return all components', function() { setUp(); var cmp1 = { component: "cmp1" }; - registry.add(cmp1,null,null); + registry.add(cmp1, null, null); var cmp2 = { component: "cmp2" }; - registry.add(cmp2,null,null); + registry.add(cmp2, null, null); var cmp3 = { component: "cmp3" }; - registry.add(cmp3,null,null); + registry.add(cmp3, null, null); var cmps = registry.getComponents(); cmps.length.should.equal(3);