<div class="well">
    <div uib-pagination ng-show="auditdata.count > 10"
         total-items="auditdata.count" ng-model="params.page"
         items-per-page="10"
         max-size="10"
         previous-text="{{ 'Previous'|translate }}"
         next-text="{{ 'Next'|translate }}"
         last-text="{{ 'Last'|translate }}"
         first-text="{{ 'First'|translate }}"
         boundary-links="true" ng-change="pageChanged()"></div>

    <div class="row-fluid">
        <csv-download url="{{ instanceUrl }}/audit/audit.csv"
                      filename="audit.csv"
                      ng-show="loggedInUser.role === 'admin' &&
                        checkRight('auditlog_download')">
        </csv-download>
        <translate>{{ auditdata.count }} entries found.</translate>
    </div>

    <div class="table-responsive">
        <table class="table table-bordered table-striped" id="tableauditlog">
            <thead>
            <tr>
                <th translate>number</th>
                <th class="pifilter"><translate>date</translate>
                    <pi-filter ng-model="dateFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>action</translate>
                    <pi-filter ng-model="actionFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>success</translate>
                    <pi-filter ng-model="successFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>action detail</translate>
                    <pi-filter ng-model="action_detailFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>serial</translate>
                    <pi-filter ng-model="serialFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return"></pi-filter>
                </th>
                <th class="pifilter"><translate>token type</translate>
                    <pi-filter ng-model="typeFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>administrator</translate>
                    <pi-filter ng-model="administratorFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>user</translate>
                    <pi-filter ng-model="userFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>realm</translate>
                    <pi-filter ng-model="realmFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>resolver</translate>
                    <pi-filter ng-model="resolverFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter" ng-if="loggedInUser.role == 'admin'"><translate>policies</translate>
                    <pi-filter ng-model="policiesFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>client</translate>
                    <pi-filter ng-model="clientFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th class="pifilter"><translate>info</translate>
                    <pi-filter ng-model="infoFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th translate>sig_check</th>
                <th translate>missing_line</th>
                <th translate>clearance</th>
                <th translate>log level</th>
                <th class="pifilter"><translate>privacyidea server</translate>
                    <pi-filter ng-model="serverFilter"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="audit in auditdata.auditdata">
                <td>{{ audit.number }}</td>
                <td>{{ audit.date | date:dateFormat }}</td>
                <td>{{ audit.action }}</td>
                <td><span status-class="{{ audit.success }}">
                {{ audit.success }}
            </span></td>
                <td>{{ audit.action_detail }}</td>
                <td>
                    <a ng-repeat="serial in audit.serial_list" ui-sref="token.details({tokenSerial:serial})"
                       ng-click="$rootScope.returnTo=audit;">
                    {{ serial }}</a>
                </td>
                <td>{{ audit.token_type }}</td>
                <td>{{ audit.administrator }}</td>
                <td><a ui-sref="user.details({username:audit.user,
                realmname:audit.realm})">
                    {{ audit.user }}</a></td>
                <td><a ng-if="loggedInUser.role == 'admin'" ui-sref="config.realms.list">{{ audit.realm }}</a>
                    <span ng-if="loggedInUser.role == 'user'">{{ audit.realm }}</span>
                </td>
                <td><a ng-if="loggedInUser.role == 'admin'" ui-sref="config.resolvers.list">{{ audit.resolver }}</a>
                    <span ng-if="loggedInUser.role == 'user'">{{ audit.resolver }}</span>
                </td>
                <td ng-if="loggedInUser.role == 'admin'">
                    <span ng-repeat="policy in audit.policies">
                        <span ng-if="policy.endsWith('+')">
                            {{ policy }}
                        </span>
                        <span ng-if="!policy.endsWith('+')">
                            <a ui-sref="config.policies.details({policyname:policy})"
                                ng-click="$rootScope.returnTo=audit;">{{ policy }}</a>
                        </span>
                    </span>
                </td>
                <td>{{ audit.client }}</td>
                <td>{{ audit.info }}</td>
                <td><span status-class="{{ audit.sig_check }}">
                {{ audit.sig_check }}
            </span></td>
                <td><span status-class="{{ audit.missing_line }}">
                {{ audit.missing_line }}</span></td>
                <td>{{ audit.clearance_level }}</td>
                <td>{{ audit.log_level }}</td>
                <td>{{ audit.privacyidea_server }}</td>
            </tr>
            </tbody>
        </table>
    </div>

</div>
