aboutsummaryrefslogtreecommitdiff
path: root/extension/src/entries/options/components/EvHistoryTable.vue
blob: 6ea6cacf642c5d1315ac1cdf598a59530aa20c4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
   <table class="min-w-full divide-y-2 divide-gray-200 dark:divide-dark-500">
        <thead class="text-left bg-gray-50 dark:bg-dark-700">
            <tr>
                <th class="p-2 font-medium whitespace-nowrap dark:text-white">
                    Type
                </th>
                <th class="p-2 font-medium whitespace-nowrap dark:text-white">
                    Origin
                </th>
                <th class="p-2 font-medium whitespace-nowrap dark:text-white">
                    Time
                </th>
                <th class="p-2"></th>
            </tr>
        </thead>

        <tbody class="divide-y divide-gray-200 dark:divide-dark-500">
            <tr v-for="req in requests" :key="req.uuid" class="">
                <td class="p-2 t font-medium truncate max-w-[8rem] whitespace-nowrap ">
                    {{ req.requestType }}
                </td>
                <td class="p-2 whitespace-nowrap">
                    {{ req.origin }}
                </td>
                <td class="p-2 whitespace-nowrap">
                    {{ createShortDateAndTime(req) }}
                </td>
                <td class="p-2 text-right whitespace-nowrap">
                    <div v-if="!readonly" class="button-group">
                        <button class="rounded btn xs" @click="approve(req)">
                            <fa-icon icon="check" class="inline" />
                        </button>
                        <button class="rounded btn red xs" @click="deny(req)">
                            <fa-icon icon="trash-can" class="inline" />
                        </button>
                    </div>
                    <div v-else class="text-sm font-bold">
                        {{ statusToString(req.status) }}
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { toRefs } from 'vue';
import { PermissionRequest, PrStatus } from '../../../features';

const emit = defineEmits(['deny', 'approve'])
const props = defineProps<{
    requests: PermissionRequest[],
    readonly: boolean
}>()

const { requests, readonly } = toRefs(props)

const createShortDateAndTime = (request: PermissionRequest) => {
    const date = new Date(request.timestamp)
    const hours = date.getHours()
    const minutes = date.getMinutes()
    const seconds = date.getSeconds()
    const day = date.getDate()
    const month = date.getMonth() + 1
    const year = date.getFullYear()
    return `${month}/${day}/${year} ${hours}:${minutes}:${seconds}`
}

const deny = (request: PermissionRequest) => emit('deny', request)
const approve = (request: PermissionRequest) => emit('approve', request)

const statusToString = (status: PrStatus) => {
    switch(status) {
        case PrStatus.Approved:
            return 'Approved'
        case PrStatus.Denied:
            return 'Denied'
        case PrStatus.Pending:
            return 'Pending'
    }
}

</script>