Add server-side logging when not existing components are required and fix code style issues

refs #4456
This commit is contained in:
Matthias Jentsch 2013-08-20 19:31:29 +02:00 committed by Marius Hein
parent 889abf55eb
commit 7353797147
5 changed files with 46 additions and 45 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -25,7 +25,7 @@ define(['jquery'], function($) {
var createId = (function() {
var id = 0;
return function() {
return 'icinga-component-'+id++;
return 'icinga-component-' + id++;
};
})();

View File

@ -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: "<module>/<type>"
* @param id {String} The optional id of the component
*/
var addComponent = function(type,id) {
var txt = '<div '+( id ? ( ' id= "'+id+'" ' ) : '' ) +
' data-icinga-component="'+type+'" >test</div>';
var addComponent = function(type, id) {
var txt = '<div ' + ( id ? ( ' id= "' + id + '" ' ) : '' ) +
' data-icinga-component="' + type + '" >test</div>';
$('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;
}
};

View File

@ -19,48 +19,48 @@ var cleanTestDom = function() {
};
describe('Component registry',function(){
it('Ids are created automatically in the form "icinga-component-<id>"',function(){
describe('Component registry',function() {
it('Ids are created automatically in the form "icinga-component-<id>"', 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);