JSFiddle - React, Tailwind, and code Playground

by Yuriy Bablyukh

HTML

<script src="http://build-master.jaspersoft.com:8580/jrs-pro-feature-dashboard-improvements-for-jasper-mobile/client/visualize.js"></script>

<button id="refreshAll">Refresh all dashboard</button>
<button id="cancelAll" style="display: none;">Cancel refreshing dashboard</button>
<button id="refreshComponent">Refresh "Country"</button>
<button id="cancelComponent" style="display: none;">Cancel refreshing "Sales Trend"</button>

<div id="container"></div>

CSS

html, body, #container {
    height: 100%;
    width: 100%;
    margin: 0;
}

JavaScript

visualize({
    auth: {
        name: "jasperadmin",
        password: "jasperadmin",
        organization: "organization_1"
    }
}, function (v) {

    var dashboard = v.dashboard({
        resource: "/public/Samples/Dashboards/3.1_Sales_Metrics",
        container: "#container",
        error: function(e) {
            alert(e);
        }, success: function(data) {
            console.log(data);
        }
    });

    $("#refreshAll").on("click", function() {
        $("#cancelAll").show();
        $("#refreshAll").hide();

        dashboard.refresh()
            .always(function() {
                $("#cancelAll").hide();
                $("#refreshAll").show();
            });
    });
    
    $("#cancelAll").on("click", function() {
        $("#cancelAll").hide();
        
        dashboard.cancel()
            .always(function() {
                $("#refreshAll").show();
            });
    });
    
    $("#refreshComponent").on("click", function() {
        $("#cancelComponent").show();
        $("#refreshComponent").hide();

        dashboard.refresh("Country").fail(function(e) {
            console.log(e);
                                                      })
            .always(function() {
                $("#cancelComponent").hide();
                $("#refreshComponent").show();
            });
    });
    
    $("#cancelComponent").on("click", function() {
        $("#cancelComponent").hide();
        
        dashboard.cancel("Sales_Trend")
            .always(function() {
                $("#refreshComponent").show();
            });
    });
});