Visualize: render one report

Test plugins

by NesterOne

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(this.scope).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: []
        };

        var i = 0,
            j = 0;
        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;
                }
            }
        }

        return comparisonResult;
    };

    var scopeChecker = new ScopeChecker(window);
    var propertiesNames = scopeChecker.getPropertiesNames();
</script>
<!--<script type='text/javascript' src="http://build-master.jaspersoft.com:7580/jrs-pro-feature-amber-embedded-report/client/visualize.js"></script>-->
<script type='text/javascript'...

JavaScript

(function () {
    
    var uri = $("#selected_resource").val(),
        serverUrl = "http://localhost:8080/jrs";

    createReport(uri);

    $("#selected_resource").change(function () {
        $("#container").html("");
        createReport($("#selected_resource").val());
    });

    //create and render report to specific container
    function createReport(rep) {
        v("#container").report({
            server: serverUrl,
            resource: rep,
            success: function () {
                setTimeout(function () {
                    console.log("------------------Scope Check Results---------------------------");
                    console.log(scopeChecker.compareProperties(propertiesNames));
                    console.log("----------------------------------------------------------------");
                }, 5000);
            },
            error: function (err) {
                alert(err.message);
            }
        });
    }
})();