Visualize: render one report
Test plugins
by Yuriy Bablyukh
HTML
<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<!--Provide URL to visualize.js-->
<script>
function ScopeChecker(scope) {
this.scope = scope;
}
ScopeChecker.prototype.getPropertiesCount = function() {
return this.getPropertiesNames().length;
};
ScopeChecker.prototype.getPropertiesNames = function() {
return Object.keys(this.scope);
};
ScopeChecker.prototype.compareProperties = function(scope1PropertiesNames, scope2PropertiesNames) {
if (!scope1PropertiesNames) {
throw "Properties for scope 1 not specified";
}
if (!scope2PropertiesNames) {
scope2PropertiesNames = this.getPropertiesNames();
}
var comparisonResult = {
added: [],
removed: [],
madeUndefined: [],
pollution: []
};
var i, j;
for (i = 0; i < scope1PropertiesNames.length; i++) {
comparisonResult.removed.push(scope1PropertiesNames[i]);
for (j = 0; j < scope2PropertiesNames.length; j++) {
if (scope1PropertiesNames[i] === scope2PropertiesNames[j]) {
comparisonResult.removed.pop();
break;
}
}
}
for (i = 0; i < scope2PropertiesNames.length; i++) {
comparisonResult.added.push(scope2PropertiesNames[i]);
for (j = 0; j < scope1PropertiesNames.length; j++) {
if (scope2PropertiesNames[i] === scope1PropertiesNames[j]) {
comparisonResult.added.pop();
break;
}
}
}
for (i = 0; i < comparisonResult.added.length; i++) {
if (this.scope[comparisonResult.added[i]] === undefined) {
comparisonResult.madeUndefined.push(comparisonResult.added[i]);
} else {
comparisonResult.pollution.push(comparisonResult.added[i]);
...
JavaScript
visualize({
auth: {
name: "jasperadmin",
password: "jasperadmin",
organization: "organization_1"
}
}, function (v) {
createReport();
$("#selected_resource").change(function () {
//clean container
$("#container").html("");
createReport();
});
//enable report chooser
$(':disabled').prop('disabled', false);
function createReport(){
//render report from another resource
v("#container").report({
resource: $("#selected_resource").val(),
success: function(){
setTimeout(function () {
console.log("------------------Scope Check Results---------------------------");
console.log(scopeChecker.compareProperties(propertiesNames));
console.log("----------------------------------------------------------------");
}, 5000);
},
error:handleError
});
}
//show error
function handleError(err){
alert(err.message);
}
});