mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 09:14:08 +02:00
Add server-side logging when not existing components are required and fix code style issues
refs #4456
This commit is contained in:
parent
889abf55eb
commit
7353797147
@ -30,6 +30,7 @@
|
|||||||
use \Zend_Controller_Action_Exception as ActionException;
|
use \Zend_Controller_Action_Exception as ActionException;
|
||||||
use \Icinga\Web\Controller\ActionController;
|
use \Icinga\Web\Controller\ActionController;
|
||||||
use \Icinga\Application\Icinga;
|
use \Icinga\Application\Icinga;
|
||||||
|
use \Icinga\Application\Logger;
|
||||||
|
|
||||||
class StaticController extends ActionController
|
class StaticController extends ActionController
|
||||||
{
|
{
|
||||||
@ -124,6 +125,9 @@ class StaticController extends ActionController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($filePath)) {
|
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 **/';
|
echo '/** Module has no js files **/';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ define(['jquery', 'logging', 'icinga/componentRegistry'], function ($, log, regi
|
|||||||
*/
|
*/
|
||||||
var loadComponent = function(cmpType, target, fin, err) {
|
var loadComponent = function(cmpType, target, fin, err) {
|
||||||
requirejs(
|
requirejs(
|
||||||
['modules/'+cmpType],
|
['modules/' + cmpType],
|
||||||
function (Cmp) {
|
function (Cmp) {
|
||||||
var cmp;
|
var cmp;
|
||||||
try {
|
try {
|
||||||
@ -40,7 +40,7 @@ define(['jquery', 'logging', 'icinga/componentRegistry'], function ($, log, regi
|
|||||||
if (!ex) {
|
if (!ex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.emergency('Component "'+cmpType+'" could not be loaded.', ex);
|
log.emergency('Component "' + cmpType + '" could not be loaded.', ex);
|
||||||
if (err) {
|
if (err) {
|
||||||
err(ex);
|
err(ex);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ define(['jquery'], function($) {
|
|||||||
var createId = (function() {
|
var createId = (function() {
|
||||||
var id = 0;
|
var id = 0;
|
||||||
return function() {
|
return function() {
|
||||||
return 'icinga-component-'+id++;
|
return 'icinga-component-' + id++;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -30,19 +30,19 @@ var setUp = function(registry)
|
|||||||
*/
|
*/
|
||||||
'modules/app/component1': function(cmp) {
|
'modules/app/component1': function(cmp) {
|
||||||
cmp.test = 'changed-by-component-1';
|
cmp.test = 'changed-by-component-1';
|
||||||
this.type = function(){
|
this.type = function() {
|
||||||
return "app/component1";
|
return "app/component1";
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'modules/app/component2': function(cmp) {
|
'modules/app/component2': function(cmp) {
|
||||||
cmp.test = 'changed-by-component-2';
|
cmp.test = 'changed-by-component-2';
|
||||||
this.type = function(){
|
this.type = function() {
|
||||||
return "app/component2";
|
return "app/component2";
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
'modules/module/component3': function(cmp) {
|
'modules/module/component3': function(cmp) {
|
||||||
cmp.test = 'changed-by-component-3-from-module';
|
cmp.test = 'changed-by-component-3-from-module';
|
||||||
this.type = function(){
|
this.type = function() {
|
||||||
return "module/component3";
|
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 type {String} The type of the component in the form: "<module>/<type>"
|
||||||
* @param id {String} The optional id of the component
|
* @param id {String} The optional id of the component
|
||||||
*/
|
*/
|
||||||
var addComponent = function(type,id) {
|
var addComponent = function(type, id) {
|
||||||
var txt = '<div '+( id ? ( ' id= "'+id+'" ' ) : '' ) +
|
var txt = '<div ' + ( id ? ( ' id= "' + id + '" ' ) : '' ) +
|
||||||
' data-icinga-component="'+type+'" >test</div>';
|
' data-icinga-component="' + type + '" >test</div>';
|
||||||
|
|
||||||
$('body').append(txt);
|
$('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();
|
setUp();
|
||||||
addComponent('app/component1');
|
addComponent('app/component1');
|
||||||
|
|
||||||
component.load(function(){
|
component.load(function() {
|
||||||
// loading complete
|
|
||||||
var cmpNode = $('#icinga-component-0');
|
var cmpNode = $('#icinga-component-0');
|
||||||
cmpNode.length.should.equal(1);
|
cmpNode.length.should.equal(1);
|
||||||
cmpNode[0].test.should.equal('changed-by-component-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();
|
setUp();
|
||||||
addComponent('app/component2','some-id');
|
addComponent('app/component2','some-id');
|
||||||
|
|
||||||
component.load(function(){
|
component.load(function() {
|
||||||
// loading complete
|
|
||||||
var cmpNode = $('#some-id');
|
var cmpNode = $('#some-id');
|
||||||
cmpNode.length.should.equal(1);
|
cmpNode.length.should.equal(1);
|
||||||
cmpNode[0].test.should.equal('changed-by-component-2');
|
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();
|
setUp();
|
||||||
addComponent('app/component1');
|
addComponent('app/component1');
|
||||||
addComponent('app/component2');
|
addComponent('app/component2');
|
||||||
addComponent('app/component2');
|
addComponent('app/component2');
|
||||||
addComponent('module/component3');
|
addComponent('module/component3');
|
||||||
|
|
||||||
component.load(function(){
|
component.load(function() {
|
||||||
// loading complete
|
|
||||||
var components = component.getComponents();
|
var components = component.getComponents();
|
||||||
components.length.should.equal(4);
|
components.length.should.equal(4);
|
||||||
$('body').empty();
|
$('body').empty();
|
||||||
component.load(function(){
|
component.load(function() {
|
||||||
var components = component.getComponents();
|
var components = component.getComponents();
|
||||||
components.length.should.equal(0);
|
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 getByIdCalled = false;
|
||||||
var getByTypeCalled = false;
|
var getByTypeCalled = false;
|
||||||
var getComponentsCalled = false;
|
var getComponentsCalled = false;
|
||||||
|
|
||||||
var registryMock = {
|
var registryMock = {
|
||||||
getById: function(id){
|
getById: function(id) {
|
||||||
getByIdCalled = true;
|
getByIdCalled = true;
|
||||||
id.should.equal('some-id');
|
id.should.equal('some-id');
|
||||||
},
|
},
|
||||||
getByType: function(type){
|
getByType: function(type) {
|
||||||
getByTypeCalled = true;
|
getByTypeCalled = true;
|
||||||
type.should.equal('some-type');
|
type.should.equal('some-type');
|
||||||
},
|
},
|
||||||
getComponents: function(){
|
getComponents: function() {
|
||||||
getComponentsCalled = true;
|
getComponentsCalled = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,48 +19,48 @@ var cleanTestDom = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
describe('Component registry',function(){
|
describe('Component registry',function() {
|
||||||
it('Ids are created automatically in the form "icinga-component-<id>"',function(){
|
it('Ids are created automatically in the form "icinga-component-<id>"', function() {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
registry.add({},null,null).should.equal('icinga-component-0');
|
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-1');
|
||||||
registry.add({},null,null).should.equal('icinga-component-2');
|
registry.add({}, null, null).should.equal('icinga-component-2');
|
||||||
|
|
||||||
cleanTestDom();
|
cleanTestDom();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Existing ids are preserved',function(){
|
it('Existing ids are preserved', function() {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
registry.add({},'user-defined-id',null).should.equal('user-defined-id');
|
registry.add({}, 'user-defined-id', null).should.equal('user-defined-id');
|
||||||
|
|
||||||
cleanTestDom();
|
cleanTestDom();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Components are correctly added to the library',function(){
|
it('Components are correctly added to the library', function() {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
var cmp1 = { component: "cmp1" };
|
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);
|
registry.getById('user-defined-id').should.equal(cmp1);
|
||||||
|
|
||||||
var cmp2 = { component: "cmp2" };
|
var cmp2 = { component: "cmp2" };
|
||||||
registry.add(cmp2,null,null);
|
registry.add(cmp2, null, null);
|
||||||
registry.getById('icinga-component-0').should.equal(cmp2);
|
registry.getById('icinga-component-0').should.equal(cmp2);
|
||||||
|
|
||||||
cleanTestDom();
|
cleanTestDom();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getId(component) should return the components assigned id.',function(){
|
it('getId(component) should return the components assigned id.', function() {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
var cmp1 = { component: "cmp1" };
|
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');
|
registry.getId(cmp1).should.equal('user-defined-id');
|
||||||
|
|
||||||
var cmp2 = { component: "cmp2" };
|
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');
|
registry.getId(cmp2).should.equal('user-defined-id-2');
|
||||||
|
|
||||||
should.not.exist(registry.getId({}));
|
should.not.exist(registry.getId({}));
|
||||||
@ -68,17 +68,17 @@ describe('Component registry',function(){
|
|||||||
cleanTestDom();
|
cleanTestDom();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getByType() should return all components of a certain type',function(){
|
it('getByType() should return all components of a certain type', function() {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
var cmp1 = { component: "some/type" };
|
var cmp1 = { component: "some/type" };
|
||||||
registry.add(cmp1,null,'some/type');
|
registry.add(cmp1, null, 'some/type');
|
||||||
|
|
||||||
var cmp2 = { component: "some/type" };
|
var cmp2 = { component: "some/type" };
|
||||||
registry.add(cmp2,null,"some/type");
|
registry.add(cmp2, null, "some/type");
|
||||||
|
|
||||||
var cmp3 = { component: "other/type" };
|
var cmp3 = { component: "other/type" };
|
||||||
registry.add(cmp3,null,"other/type");
|
registry.add(cmp3, null, "other/type");
|
||||||
|
|
||||||
var cmps = registry.getByType('some/type');
|
var cmps = registry.getByType('some/type');
|
||||||
cmps.length.should.equal(2);
|
cmps.length.should.equal(2);
|
||||||
@ -88,17 +88,17 @@ describe('Component registry',function(){
|
|||||||
cleanTestDom();
|
cleanTestDom();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getComponents() should return all components',function(){
|
it('getComponents() should return all components', function() {
|
||||||
setUp();
|
setUp();
|
||||||
|
|
||||||
var cmp1 = { component: "cmp1" };
|
var cmp1 = { component: "cmp1" };
|
||||||
registry.add(cmp1,null,null);
|
registry.add(cmp1, null, null);
|
||||||
|
|
||||||
var cmp2 = { component: "cmp2" };
|
var cmp2 = { component: "cmp2" };
|
||||||
registry.add(cmp2,null,null);
|
registry.add(cmp2, null, null);
|
||||||
|
|
||||||
var cmp3 = { component: "cmp3" };
|
var cmp3 = { component: "cmp3" };
|
||||||
registry.add(cmp3,null,null);
|
registry.add(cmp3, null, null);
|
||||||
|
|
||||||
var cmps = registry.getComponents();
|
var cmps = registry.getComponents();
|
||||||
cmps.length.should.equal(3);
|
cmps.length.should.equal(3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user