<div class="bs-sidebar col-md-3 clearfix" data-ng-include data-src="'partials/realm-menu.html'"></div>
<div id="content-area" class="col-md-9" role="main">
    <kc-navigation-application></kc-navigation-application>
    <div id="content">
        <ol class="breadcrumb" data-ng-hide="create">
            <li><a href="#/realms/{{realm.realm}}/applications">Applications</a></li>
            <li><a href="#/realms/{{realm.realm}}/applications/{{application.id}}">{{application.name}}</a></li>
            <li class="active">Application Sessions</li>
        </ol>
        <h2><span>{{application.name}}</span> Active Sessions  <span tooltip-placement="right" tooltip="View active sessions for this application.  Allows you to see which users are active and when they logged in." class="fa fa-info-circle"></span></h2>
        <form class="form-horizontal" name="sessionStats">
            <fieldset class="border-top">
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="activeSessions">Active Sessions</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" id="activeSessions" name="activeSessions" data-ng-model="count" ng-disabled="true">
                    </div>
                    <span tooltip-placement="right" tooltip="Total number of active user sessions for this application." class="fa fa-info-circle"></span>
                </div>
            </fieldset>
        </form>
        <table class="table table-striped table-bordered" data-ng-show="count > 0">
            <thead>
            <tr>
                <th class="kc-table-actions" colspan="3">
                    <div class="pull-right">
                        <a class="btn btn-primary" ng-click="loadUsers()" tooltip-placement="left" tooltip="Warning, this is a potentially expensive operation depending on number of active sessions.">Show Sessions</a>
                    </div>
                </th>
            </tr>
            <tr data-ng-show="sessions">
                <th>User</th>
                <th>From IP</th>
                <th>Session Start</th>
            </tr>
            </thead>
            <tfoot data-ng-show="sessions && sessions.length > 5">
            <tr>
                <td colspan="7">
                    <div class="table-nav">
                        <button data-ng-click="firstPage()" class="first" ng-disabled="query.first == 0">First page</button>
                        <button data-ng-click="previousPage()" class="prev" ng-disabled="query.first == 0">Previous page</button>
                        <button data-ng-click="nextPage()" class="next" ng-disabled="sessions.length < query.max">Next page</button>
                    </div>
                </td>
            </tr>
            </tfoot>
            <tbody>
            <tr data-ng-repeat="session in sessions">
                <td><a href="#/realms/{{realm.realm}}/users/{{session.user}}">{{session.user}}</a></td>
                <td>{{session.ipAddress}}</td>
                <td>{{session.start | date:'medium'}}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>