{"size": 3145, "ext": "js", "max_stars_repo_path": "html/js/app/ui/status_view.js", "max_stars_repo_name": "ClarkAtAmazon/aws-media-services-application-mapper", "max_stars_repo_stars_event_min_datetime": "2018-10-15T20:29:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-16T15:58:19.000Z", "max_issues_repo_path": "html/js/app/ui/status_view.js", "max_issues_repo_name": "ClarkAtAmazon/aws-media-services-application-mapper", "max_issues_repo_issues_event_min_datetime": "2018-10-11T23:50:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-09T18:13:57.000Z", "max_forks_repo_path": "html/js/app/ui/status_view.js", "max_forks_repo_name": "ClarkAtAmazon/aws-media-services-application-mapper", "max_forks_repo_forks_event_min_datetime": "2018-11-08T05:04:35.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-20T21:18:26.000Z"}
{"max_stars_count": 66, "max_issues_count": 214, "max_forks_count": 29, "avg_line_length": 43.0821917808, "max_line_length": 246, "alphanum_fraction": 0.5675675676}
/*! Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
       SPDX-License-Identifier: Apache-2.0 */

define(["jquery", "app/model", "app/statemachine"], function($, model, statemachine) {
    var current_tab = '';
    var progressTimer;

    var calculate_progress = function(fsm) {
        // get the total number of states for this FSM
        var states = Object.keys(fsm.states);
        // get our current position within the states
        var index = states.indexOf(fsm.state);
        // calculate the current state position as a percentage
        var percent = Number.parseInt(((index + 1) / states.length) * 100);
        return percent;
    };

    var show = function() {
        if (typeof progressTimer === "undefined") {
            progressTimer = setTimeout(update, 500);
        }
    };

    var update = function() {
        var id = "#nav-status";
        var tab = id + "-tab";
        if (current_tab !== tab) {
            $(tab).tab('show');
        }
        var configuration_percent = calculate_progress(statemachine.getConfigurationStateMachine());
        var model_data_percent = calculate_progress(statemachine.getModelDataStateMachine());
        var configuration_class = configuration_percent < 100 ? "progress-bar-striped progress-bar-animated bg-warning" : "bg-success";
        var model_data_class = model_data_percent < 100 ? "progress-bar-striped progress-bar-animated bg-warning" : "bg-success";
        var configuration_stats = configuration_percent < 100 ? configuration_percent + "%" : "Ready";
        var model_stats = `${model.nodes.length} Nodes, ${model.edges.length} Connections`;
        var html = `
        <table class="table table-sm borderless">
            <tbody>
                <tr>
                    <th scope="row">Configuration</th>
                    <td nowrap>
                        <div class="progress" style="width: 35%;">
                            <div class="progress-bar ${configuration_class}" role="progressbar" style="width: ${configuration_percent}%;" aria-valuenow="${configuration_percent}%" aria-valuemin="0" aria-valuemax="100">${configuration_stats}</div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th scope="row" style="width: 10%;">Model Contents</th>
                    <td nowrap>
                        <div class="progress" style="width: 35%;">
                            <div class="progress-bar ${model_data_class}" role="progressbar" style="width: ${model_data_percent}%;" aria-valuenow="${model_data_percent}%" aria-valuemin="0" aria-valuemax="100">${model_stats}</div>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>`;
        $(id).html(html);
        progressTimer = undefined;
    };

    model.nodes.on("add", function(event, properties, senderId) {
        show();
    });

    model.edges.on("add", function(event, properties, senderId) {
        show();
    });

    statemachine.getToolStateMachine().on("transition", function(data) {
        show();
    });

});