<div ng-controller="SpringBatch.JobOverviewExecListController">


    <div class="row-fluid">
        <div class="span9">
            <div class="row-fluid">
                <div class="span2"><strong>Job Instance ID:</strong></div>
                <div class="span1"><span class="text-info">{{jobInstance.id}}</span></div>
                <div class="span3">
                    <span style="cursor: pointer" ng-click="fetchPrevJobInstance(jobInstance)"> <i class="icon-backward icon-2x"></i> </span>  &nbsp;
                    <span style="cursor: pointer" ng-click="refreshJobInstance(jobInstance)"> <i class="icon-refresh icon-2x"></i> </span>  &nbsp;
                    <span style="cursor: pointer" ng-click="fetchNextJobInstance(jobInstance)"> <i class="icon-forward icon-2x"></i> </span>  &nbsp;
                </div>
                <div class="span3">
                    <span id="jobExecutionStatus">
                        <span   class="btn-large {{(jobInstance.lastJobExecutionStatus == 'COMPLETED')?'btn-success':'btn-danger'}}">
                            {{jobInstance.lastJobExecutionStatus}}
                        </span>
                    </span>
                </div>
                <div class="span3">
                    <div class="dropdown">
                        <a class="dropdown-toggle btn btn-primary" data-toggle="dropdown" href="#">Actions <b class="caret"></b></a>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                            <li>
                                <a href="#/springbatch/jobs/{{jobName}}/{{jobInstance.id}}/history/executions" style="cursor: pointer">View History</a>
                            </li>
                            <li> <a ng-click="runJob(jobName,jobParams)" style="cursor: pointer">Run Job</a> </li>

                        </ul>
                    </div>
                </div>
            </div>

            <div class="row-fluid">
                <div>
                    <h3>Job Execution</h3>
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th></th>
                            <th> <a ng-click="executionPredicate='id';executionReverse=!executionReverse" style="cursor: pointer">ID</a> </th>
                            <th> <a ng-click="executionPredicate='startTime';executionReverse=!executionReverse" style="cursor: pointer">Date</a> </th>
                            <th> <a ng-click="executionPredicate='startTime';executionReverse=!executionReverse" style="cursor: pointer">Start</a> </th>
                            <th> <a ng-click="executionPredicate='duration';executionReverse=!executionReverse" style="cursor: pointer">Duration</a> </th>
                            <th> <a ng-click="executionPredicate='status';executionReverse=!executionReverse" style="cursor: pointer">Status</a> </th>
                            <th> <a ng-click="executionPredicate='status';executionReverse=!executionReverse" style="cursor: pointer">Exit Code</a> </th>
                            <th>Context</th>
                            <th>Export</th>

                        </tr>
                        </thead>
                        <tr ng-repeat="execution in jobExecutionList | orderBy:executionPredicate:executionReverse">
                            <td><input type="radio" name="fetchStepsForExecutionRadio" ng-click="fetchStepsForExecution(execution.id)"></td>
                            <td>{{execution.id}}</td>
                            <td>{{execution.startTime}}</td>
                            <td>{{execution.startTime}}</td>
                            <td>{{execution.duration}}</td>
                            <td>{{execution.status}}</td>
                            <td>{{execution.status}}</td>
                            <td data-title="Context">
                                <a ng-href="#/springbatch/jobs/{{jobInstance.id}}/executions/{{jobName}}/{{execution.id}}">fmt</a>
                            </td>
                            <td data-title="Export to CSV">
                                <div class="btn-group">
                                    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                                        Export
                                        <span class="caret"></span>
                                    </a>
                                    <ul class="dropdown-menu">
                                        <li>
                                            <a style="cursor: pointer;" ng-href="/hawtio/exportContext/?key=SOURCE_DATA&execId={{execution.id}}&server={{springBatchServer}}">
                                                SOURCE_DATA
                                            </a>
                                        </li>
                                        <li>
                                            <a style="cursor: pointer;" ng-href="/hawtio/exportContext/?key=TARGET_DATA&execId={{execution.id}}&server={{springBatchServer}}">
                                                TARGET_DATA
                                            </a>
                                        </li>
                                        <li>
                                            <a style="cursor: pointer;" ng-href="/hawtio/exportContext/?key=ERROR_MESSAGES&execId={{execution.id}}&server={{springBatchServer}}">
                                                ERROR_MESSAGES
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div>
                    <h3>Step Executions</h3>
                    <table class="table table-striped table-hover">
                        <thead>
                        <tr>
                            <th> <a ng-click="stepPredicate='name';stepReverse=!stepReverse" style="cursor: pointer">Name</a> </th>
                            <th> <a ng-click="stepPredicate='status';stepReverse=!stepReverse" style="cursor: pointer">Status</a> </th>
                            <th> <a ng-click="stepPredicate='readCount';stepReverse=!stepReverse" style="cursor: pointer">Reads</a> </th>
                            <th> <a ng-click="stepPredicate='writeCount';stepReverse=!stepReverse" style="cursor: pointer">Writes</a> </th>
                            <th> <a ng-click="stepPredicate='commitCount';stepReverse=!stepReverse" style="cursor: pointer">Commit</a> </th>
                            <th> <a ng-click="stepPredicate='rollbackCount';stepReverse=!stepReverse" style="cursor: pointer">Skip</a> </th>
                            <th> <a ng-click="stepPredicate='duration';stepReverse=!stepReverse" style="cursor: pointer">Duration</a> </th>
                            <th>Context</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr ng-repeat="stepExecution in stepExecutionList | orderBy:stepPredicate:stepReverse" >

                            <td data-title="'Id'">
                                {{stepExecution.name}}
                            </td>
                            <td data-title="Status">{{stepExecution.status}}</td>
                            <td data-title="Read Count">{{stepExecution.readCount}}</td>
                            <td data-title="Write Count">{{stepExecution.writeCount}}</td>
                            <td data-title="Commit Count">{{stepExecution.commitCount}}</td>
                            <td data-title="Skip Count">{{stepExecution.rollbackCount}}</td>
                            <td data-title="Duration">{{stepExecution.duration}}</td>
                            <td data-title="Context">
                                <a ng-href="#/springbatch/jobs/{{jobInstance.id}}/executions/{{jobName}}/{{executionId}}/steps/{{stepExecution.id}}">fmt</a>
                            </td>

                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <div class="span1">

            <table>
                <thead>
                <tr class="info">
                    <th>
                        <b class="pull-left">Params</b>
                    </th>
                    <th>
                        <span class="pull-left" ng-click="addParam(jobParams)" style="cursor: pointer"> <i class="icon-plus"></i> </span>
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr class="info" ng-repeat="param in jobParams">
                    <td>
                        <span class="pull-left">
                            <input type="text" ng-model="param.name">
                            <input type="text" ng-model="param.value">
                        </span>
                    </td>
                    <td>
                        <span class="pull-left" ng-click="removeParam(jobParams , $index)" style="cursor: pointer"> <i class="icon-trash"></i></span>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

</div>
