Errors.vue 3.87 KB
<template>
  <div>
    <h1 class="mb-8 font-bold text-3xl">
      <inertia-link class="text-indigo-400 hover:text-indigo-600" :href="route('tokens')">Tokens</inertia-link>
      <span class="text-indigo-400 font-medium">/</span>
      <inertia-link class="text-indigo-400 hover:text-indigo-600" :href="route('token.edit', token.id)">{{token.login}}</inertia-link>
      <span class="text-indigo-400 font-medium">/</span>
      Errors
    </h1>
    <div class="mb-6 flex justify-between items-center">

      <search-filter class="w-full max-w-md mr-4" @reset="reset">
        <label class="block text-gray-700">Service:</label>
        <select v-model="form.service" class="mt-1 w-full form-select">
          <option hidden :value="null" />
          <option v-for="service in services" :value="service">{{ service }}</option>
        </select>
        <label class="block text-gray-700 mt-2">Method:</label>
        <select v-model="form.method" class="mt-1 w-full form-select">
          <option hidden :value="null" />
          <option v-for="method in methods" :value="method">{{ method }}</option>
        </select>
      </search-filter>

      <button class="text-red-600 hover:underline mb-4"
              tabindex="-1"
              type="button"
              @click="errorsDestroy"
      >
        Delete errors
      </button>

    </div>
    <div class="bg-white rounded-md shadow overflow-x-auto">
      <table class="w-full whitespace-nowrap">
        <tr class="text-left font-bold">
          <th class="px-6 pt-6 pb-4">Create</th>
          <th class="px-6 pt-6 pb-4">Service</th>
          <th class="px-6 pt-6 pb-4">Method</th>
          <th class="px-6 pt-6 pb-4">Errors</th>
          <th class="px-6 pt-6 pb-4">Params</th>
        </tr>
        <tr v-for="error in rows.data" :key="error.id" class="">
          <td class="border-t px-6 pt-6 pb-4">
            {{ error.created_at }}
          </td>
          <td class="border-t px-6 pt-6 pb-4">
            {{ error.service }}
          </td>
          <td class="border-t px-6 pt-6 pb-4">
            {{ error.method }}
          </td>
          <td class="border-t px-6 pt-6 pb-4">
              <pre v-html="objectFormatting(error.errors)"/>
          </td>
          <td class="border-t px-6 pt-6 pb-4">
            <details>
              <summary>Params</summary>
              <pre v-html="objectFormatting(error.params)"/>
            </details>
          </td>
        </tr>
        <tr v-if="rows.data.length === 0">
          <td class="border-t px-6 py-4" colspan="6">No errors found.</td>
        </tr>
      </table>
    </div>
    <pagination class="mt-6" :links="rows.links" />
  </div>
</template>

<script>
import Icon from '@/Shared/Icon'
import pickBy from 'lodash/pickBy'
import Layout from '@/Shared/Layout'
import throttle from 'lodash/throttle'
import mapValues from 'lodash/mapValues'
import Pagination from '@/Shared/Pagination'
import SearchFilter from '@/Shared/SearchFilter'

export default {
  metaInfo: { title: 'Token' },
  components: {
    Icon,
    Pagination,
    SearchFilter,
  },
  layout: Layout,
  props: {
    token: Object,
    rows: Object,
    filters: Object,
    services: Object,
    methods: Object,
  },
  data() {
    return {
      form: {
        service: this.filters.service,
        method: this.filters.method,
      },
    }
  },
  watch: {
    form: {
      handler: throttle(function() {
        this.$inertia.get(this.route('token.errors', this.token.id), pickBy(this.form))
      }, 150),
      deep: true,
    },
  },
  methods: {
    objectFormatting(object) {
      return JSON.stringify(object, null, '&nbsp;').replace(/\n/gi,'<br/>')
    },
    errorsDestroy() {
      if (confirm('Are you sure you want to delete this errors?')) {
       this.$inertia.delete(this.route('token.errors.destroy', this.token.id))
      }
    },
    reset() {
      this.form = mapValues(this.form, () => null)
    },
  },
}
</script>