Index.vue
4.32 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
<template>
<div>
<h1 class="mb-8 font-bold text-3xl">Tokens</h1>
<div class="mb-6 flex justify-between items-center">
<search-filter v-model="form.login" class="w-full max-w-md mr-4" @reset="reset">
<label class="block text-gray-700">Тип:</label>
<select v-model="form.type" class="mt-1 w-full form-select">
<option :value="null" />
<option v-for="type,key in types" :value="key">{{ type }}</option>
</select>
</search-filter>
<div class="flex flex-wrap">
<input :checked="cron_sync"
@change="cronSyncToggle(!cron_sync)"
type="checkbox"
class="mt-1"
id="cron-sync"
>
<label class="ml-1" for="cron-sync">Синхронизация</label>
</div>
<inertia-link class="btn-indigo" :href="route('token.get', {'api': 'yd'})">
<span>Добавить </span>
<span class="hidden md:inline">токен</span>
</inertia-link>
</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">Login</th>
<th class="px-6 pt-6 pb-4">АПИ</th>
<th class="px-6 pt-6 pb-4">Баллы</th>
<th class="px-6 pt-6 pb-4" colspan="2">Тип</th>
<th class="px-6 pt-6 pb-4">Ошибки</th>
</tr>
<tr v-for="token in tokens.data" :key="token.id" class="hover:bg-gray-100 focus-within:bg-gray-100">
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center focus:text-indigo-500" :href="route('token.edit', token.id)">
{{ token.login }}
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('token.edit', token.id)" tabindex="-1">
{{ token.api }}
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('token.edit', token.id)" tabindex="-1">
{{ token.limit }}
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('token.edit', token.id)" tabindex="-1">
{{ types[token.type] }}
</inertia-link>
</td>
<td class="border-t w-px">
<inertia-link class="px-4 flex items-center" :href="route('token.edit', token.id)" tabindex="-1">
<icon name="cheveron-right" class="block w-6 h-6 fill-gray-400" />
</inertia-link>
</td>
<td class="border-t">
<inertia-link class="px-6 py-4 flex items-center" :href="route('token.errors', token.id)" tabindex="-1">
{{ token.errors_count }} <icon name="cheveron-right" class="block w-6 h-6 fill-gray-400" />
</inertia-link>
</td>
</tr>
<tr v-if="tokens.data.length === 0">
<td class="border-t px-6 py-4" colspan="5">No tokens found.</td>
</tr>
</table>
</div>
<pagination class="mt-6" :links="tokens.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: 'Tokens' },
components: {
Icon,
Pagination,
SearchFilter,
},
layout: Layout,
props: {
cron_sync: Boolean,
tokens: Object,
filters: Object,
types: Object,
},
data() {
return {
form: {
login: this.filters.login,
type: this.filters.type,
},
}
},
watch: {
form: {
handler: throttle(function() {
let query = pickBy(this.form)
this.$inertia.replace(this.route('tokens', Object.keys(query).length ? query : { remember: 'forget' }))
}, 150),
deep: true,
},
},
methods: {
reset() {
this.form = mapValues(this.form, () => null)
},
cronSyncToggle(cron_sync) {
this.$inertia.post(this.route('cron_sync_update'), {
cron_sync_disable: !cron_sync ? 1 : 0,
})
},
},
}
</script>