auditevents-list.vue 3.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--
  - Copyright 2014-2018 the original author or authors.
  -
  - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License.
  - You may obtain a copy of the License at
  -
  -     http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
  -->

<template>
18
  <table class="auditevents table is-hoverable is-fullwidth">
19 20 21 22 23 24 25 26 27
    <thead>
      <tr>
        <th>Timestamp</th>
        <th>Event</th>
        <th>Principal</th>
        <th>Remote address</th>
        <th>Session Id</th>
      </tr>
    </thead>
Johannes Edmeier committed
28
    <tbody>
29 30
      <template v-for="event in events">
        <tr class="is-selectable"
31
            :class="{ 'auditevents__event--is-detailed' : showDetails[event.key] }"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
            @click="showDetails[event.key] ? $delete(showDetails, event.key) : $set(showDetails, event.key, true)"
            :key="event.key">
          <td v-text="event.timestamp.format('L HH:mm:ss.SSS')"/>
          <td>
            <span v-text="event.type" class="tag"
                  :class="{ 'is-success' : event.isSuccess(), 'is-danger' : event.isFailure() }"/>
          </td>
          <td v-if="hasSessionEndpoint && event.principal">
            <router-link v-text="event.principal"
                         :to="{ name: 'instance/sessions', params: { 'instanceId' : instance.id }, query: { username : event.principal} }"/>
          </td>
          <td v-else v-text="event.principal"/>
          <td v-text="event.remoteAddress"/>
          <td v-if="hasSessionEndpoint && event.sessionId">
            <router-link v-text="event.sessionId"
                         :to="{ name: 'instance/sessions', params: { 'instanceId' : instance.id }, query: { sessionId : event.sessionId } }"/>
          </td>
          <td v-else v-text="event.sessionId"/>
        </tr>
51
        <tr :key="`${event.key}-detail`" v-if="showDetails[event.key]">
52
          <td colspan="5">
53
            <pre class="auditevents__event-detail" v-text="toJson(event.data)"/>
54 55 56 57 58
          </td>
        </tr>
      </template>
      <tr v-if="events.length === 0">
        <td class="is-muted" colspan="5">No auditevents found.</td>
59
      </tr>
Johannes Edmeier committed
60
    </tbody>
61
  </table>
62 63 64
</template>

<script>
65
  import Instance from '@/services/instance';
66 67 68
  import prettyBytes from 'pretty-bytes';

  export default {
69 70 71 72 73 74 75 76 77 78
    props: {
      events: {
        type: Array,
        default: () => []
      },
      instance: {
        type: Instance,
        required: true
      }
    },
79 80 81
    data: () => ({
      showDetails: {}
    }),
82 83
    computed: {
      hasSessionEndpoint() {
84
        return this.instance.hasEndpoint('sessions');
85 86
      }
    },
87 88 89 90 91 92 93 94 95 96
    methods: {
      prettyBytes,
      toJson(obj) {
        return JSON.stringify(obj, null, 4);
      }
    }
  }
</script>

<style lang="scss">
97 98
  .auditevents {
    table-layout: fixed;
99

100 101 102
    td {
      vertical-align: middle;
    }
103

104 105 106 107 108 109 110
    &__event--is-detailed td {
      border: none !important;
    }

    &__event-detail {
      overflow: auto;
    }
111 112
  }
</style>