/
SpeedLimitModal.vue
114 lines (113 loc) · 2.76 KB
/
SpeedLimitModal.vue
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
<template>
<v-dialog
v-model="dialog"
scrollable
max-width="500px"
:fullscreen="phoneLayout"
>
<v-card style="overflow: hidden !important">
<v-container :style="{ height: phoneLayout ? '100vh' : '' }">
<v-card-title class="pb-0 justify-center">
<h2 class="text-capitalize">
Limit {{ mode }}
</h2>
</v-card-title>
<v-card-text>
<div>
<v-container>
<v-row>
<v-col>
<v-text-field
v-model="limit"
label="Speed Limit"
:prepend-icon="mdiSpeedometer"
suffix="KB/s"
clearable
autofocus
@focus="$event.target.select()"
@keydown.enter="setLimit"
/>
</v-col>
</v-row>
</v-container>
</div>
</v-card-text>
<div>
<v-card-actions class="justify-center">
<v-btn color="success" @click="setLimit">
Save
</v-btn>
</v-card-actions>
</div>
</v-container>
<v-fab-transition v-if="phoneLayout">
<v-btn
color="red"
dark
absolute
bottom
right
@click="close"
>
<v-icon>{{ mdiClose }}</v-icon>
</v-btn>
</v-fab-transition>
</v-card>
</v-dialog>
</template>
<script>
import { mapGetters } from 'vuex'
import { mdiSpeedometer, mdiClose } from '@mdi/js'
import { Modal, FullScreenModal } from '@/mixins'
import qbit from '@/services/qbit'
export default {
name: 'SpeedLimitModal',
mixins: [Modal, FullScreenModal],
props: {
mode: String,
hash: String
},
data() {
return {
limit: '',
mdiSpeedometer, mdiClose
}
},
computed: {
...mapGetters(['getTorrent']),
torrent() {
return this.getTorrent(this.hash)
}
},
created() {
switch (this.mode) {
case 'download':
this.limit = this.torrent.dl_limit > 0 ? this.limit = this.torrent.dl_limit / 1024 : '∞'
break
case 'upload':
this.limit = this.torrent.up_limit > 0 ? this.torrent.up_limit / 1024 : '∞'
break
default:
break
}
},
methods: {
setLimit() {
switch (this.mode) {
case 'download':
qbit.setDownloadLimit([this.hash], this.limit > 0 ? this.limit * 1024 : NaN)
break
case 'upload':
qbit.setUploadLimit([this.hash], this.limit > 0 ? this.limit * 1024 : NaN)
break
default:
break
}
this.close()
},
close() {
this.$store.commit('DELETE_MODAL', this.guid)
}
}
}
</script>