aboutsummaryrefslogtreecommitdiff
path: root/extension/src/entries/options/components/AutoRules.vue
blob: 16fddd33ed4fb42e8f3ab9db0bca5715dc9905bf (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
    <div class="">
         <div class="flex flex-row justify-between mt-16">
            <div class="font-bold">
                Approval Rules
            </div>
            <div class="flex justify-center">
                <nav aria-label="Pagination">
                    <ul class="inline-flex items-center space-x-1 text-sm rounded-md">
                        <li>
                            <button @click="prev" class="page-btn">
                                <fa-icon icon="chevron-left" class="w-4" />
                            </button>
                        </li>
                        <li>
                            <span class="inline-flex items-center px-4 py-2 space-x-1 rounded-md">
                                Page 
                                <b class="mx-1">{{ currentPage }}</b> 
                                of 
                                <b class="ml-1">{{ pageCount }}</b>
                            </span>
                        </li>
                        <li>
                            <button @click="next" class="page-btn">
                                <fa-icon icon="chevron-right" class="w-4" />
                            </button>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
        <div class="">
            <table class="min-w-full text-sm 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">
                            Rule
                        </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="rule in currentRulePage" :key="rule.timestamp" class="">
                        <td class="p-2 t font-medium truncate max-w-[8rem] whitespace-nowrap ">
                            {{ rule.type }}
                        </td>
                        <td class="p-2 whitespace-nowrap">
                            {{ rule.origin }}
                        </td>
                        <td class="p-2 whitespace-nowrap">
                            {{ createShortDateAndTime(rule) }}
                        </td>
                        <td class="p-2 text-right whitespace-nowrap">
                            <div class="button-group">
                                <button class="rounded btn xs" @click="deleteRule(rule)">
                                    Revoke
                                </button>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { get, useOffsetPagination } from '@vueuse/core';
import { } from '@headlessui/vue'
import { useStore } from '../../store';
import { storeToRefs } from 'pinia';
import { slice } from 'lodash';
import { type AutoAllowRule } from '../../../features'

const store = useStore()
const { } = storeToRefs(store)

const rules = computed(() => store.permissions.rules)

const { next, prev, currentPage, currentPageSize, pageCount } = useOffsetPagination({
    pageSize: 10,
    total: computed(() => rules.value.length)
})

const currentRulePage = computed(() => {
    const start = (get(currentPage) - 1) * get(currentPageSize)
    const end = start + 10
    return slice(rules.value, start, end)
})

const deleteRule = (rule: AutoAllowRule) => {
    store.plugins.permission.deleteRule(rule)
}

const createShortDateAndTime = (request: { timestamp: number}) => {
    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}`
}


</script>

<style lang="scss">

</style>