<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 table-capitalize-header" id="tableauditlog">
            <thead>
            <tr>
                <th ng-show="audit_columns.includes('number')"><translate>number</translate></th>
                <th ng-show="audit_columns.includes('startdate')"
                    class="pifilter"><translate>startdate</translate>
                    <pi-filter ng-model="filter.startdate"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('date')"
                    class="pifilter"><translate>enddate</translate>
                    <pi-filter ng-model="filter.date"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('duration')"
                    class="pifilter"><translate>duration</translate>
                    <pi-filter ng-model="filter.duration"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('action')"
                    class="pifilter"><translate>action</translate>
                    <pi-filter ng-model="filter.action"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('success')"
                    class="pifilter"><translate>success</translate>
                    <pi-filter ng-model="filter.success"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('authentication')"
                    class="pifilter"><translate>authentication</translate>
                    <pi-filter ng-model="filter.authentication"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('action_detail')"
                    class="pifilter"><translate>action detail</translate>
                    <pi-filter ng-model="filter.action_detail"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('serial')"
                    class="pifilter"><translate>serial</translate>
                    <pi-filter ng-model="filter.serial"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return"></pi-filter>
                </th>
                <th ng-show="audit_columns.includes('token_type')"
                    class="pifilter"><translate>token type</translate>
                    <pi-filter ng-model="filter.type"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('container_serial')"
                    class="piFilter">
                    <translate> Container Serial </translate>
                    <pi-filter ng-model="filter.containerSerial"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('container_type')"
                    class="piFilter">
                    <translate> Container Type </translate>
                    <pi-filter ng-model="filter.containerType"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('administrator')"
                    class="pifilter"><translate>administrator</translate>
                    <pi-filter ng-model="filter.administrator"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('user')"
                    class="pifilter"><translate>user</translate>
                    <pi-filter ng-model="filter.user"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('realm')"
                    class="pifilter"><translate>realm</translate>
                    <pi-filter ng-model="filter.realm"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('resolver')"
                    class="pifilter"><translate>resolver</translate>
                    <pi-filter ng-model="filter.resolver"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('policies') && loggedInUser.role == 'admin'"
                    class="pifilter"><translate>policies</translate>
                    <pi-filter ng-model="filter.policies"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('client')"
                    class="pifilter"><translate>client</translate>
                    <pi-filter ng-model="filter.client"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('user_agent')"
                    class="pifilter"><translate>user agent</translate>
                    <pi-filter ng-model="filter.user_agent"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('user_agent_version')"
                    class="pifilter"><translate>user agent version</translate>
                    <pi-filter ng-model="filter.user_agent_version"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('info')"
                    class="pifilter"><translate>info</translate>
                    <pi-filter ng-model="filter.info"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
                <th ng-show="audit_columns.includes('sig_check')" translate>sig_check</th>
                <th ng-show="audit_columns.includes('missing_line')" translate>missing_line</th>
                <th ng-show="audit_columns.includes('thread_id')" translate>thread_id</th>
                <th ng-show="audit_columns.includes('clearance_level')" translate>clearance</th>
                <th ng-show="audit_columns.includes('log_level')" translate>log level</th>
                <th ng-show="audit_columns.includes('privacyidea_server')"
                    class="pifilter"><translate>privacyidea server</translate>
                    <pi-filter ng-model="filter.server"
                               ng-change="getAuditList('livesearch')"
                               ng-keypress="($event.which==13)?getAuditList():return">
                </th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="audit in auditdata.auditdata">
                <td ng-if="audit_columns.includes('number')">{{ audit.number }}</td>
                <td ng-if="audit_columns.includes('startdate')">{{ audit.startdate | date:dateFormat }}</td>
                <td ng-if="audit_columns.includes('date')">{{ audit.date | date:dateFormat }}</td>
                <td ng-if="audit_columns.includes('duration')">{{ audit.duration }}</td>
                <td ng-if="audit_columns.includes('action')">{{ audit.action }}</td>
                <td ng-if="audit_columns.includes('success')"><span status-class="{{ audit.success }}">{{ audit.success }}</span>
                <td ng-if="audit_columns.includes('authentication')"><span status-class="{{ audit.authentication }}">{{ audit.authentication }}</span></td>
                <td ng-if="audit_columns.includes('action_detail')">{{ 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 ng-if="audit_columns.includes('token_type')">{{ audit.token_type }}</td>
                <td ng-if="audit_columns.includes('container_serial')">
                    <a ui-sref="token.containerdetails({containerSerial:audit.container_serial})"
                        ng-click="$rootScope.returnTo=audit;">
                        {{ audit.container_serial }}
                       </a>
                </td>
                <td ng-if="audit_columns.includes('container_type')">{{ audit.container_type }}</td>
                <td ng-if="audit_columns.includes('administrator')">{{ audit.administrator }}</td>
                <td ng-if="audit_columns.includes('user')">
                    <a ui-sref="user.details({username:audit.user,realmname:audit.realm})">
                    {{ audit.user }}</a></td>
                <td ng-if="audit_columns.includes('realm')">
                    <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 ng-if="audit_columns.includes('resolver')">
                    <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="audit_columns.includes('policies') && 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 ng-if="audit_columns.includes('client')">{{ audit.client }}</td>
                <td ng-if="audit_columns.includes('user_agent')">{{ audit.user_agent }}</td>
                <td ng-if="audit_columns.includes('user_agent_version')">{{ audit.user_agent_version }}</td>
                <td ng-if="audit_columns.includes('info')">{{ audit.info }}</td>
                <td ng-if="audit_columns.includes('sig_check')"><span status-class="{{ audit.sig_check }}">
                {{ audit.sig_check }}
            </span></td>
                <td ng-if="audit_columns.includes('missing_line')"><span status-class="{{ audit.missing_line }}">
                {{ audit.missing_line }}</span></td>
                <td ng-if="audit_columns.includes('thread_id')">{{ audit.thread_id }}</td>
                <td ng-if="audit_columns.includes('clearance_level')">{{ audit.clearance_level }}</td>
                <td ng-if="audit_columns.includes('log_level')">{{ audit.log_level }}</td>
                <td ng-if="audit_columns.includes('privacyidea_server')">{{ audit.privacyidea_server }}</td>
            </tr>
            </tbody>
        </table>
    </div>

</div>
