-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathBotCard.vue
More file actions
186 lines (164 loc) · 5.52 KB
/
BotCard.vue
File metadata and controls
186 lines (164 loc) · 5.52 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<template>
<div class="bot" :class="[`status--${bot.status}`, { 'bot--big': selectedButtons.length > 2 }]">
<a v-if="bot.steamid !== '0'" target="_blank" :href="bot.profileURL">
<img class="bot__avatar" :src="bot.avatarURL" :alt="bot.name">
</a>
<router-link v-else :to="{ name: 'bot', params: { bot: bot.name } }" tag="img" class="bot__avatar" :src="bot.avatarURL"></router-link>
<router-link tag="div" :to="{ name: 'bot', params: { bot: bot.name } }" class="bot__status">
<span v-if="bot.nickname && nicknames" class="bot__status-property bot__status-property--name" :title="bot.name">{{ bot.nickname }}</span>
<span v-else class="bot__status-property bot__status-property--name">{{ bot.name }}</span>
<span class="bot__status-property bot__status-property--text">{{ bot.statusText }}</span>
</router-link>
<div class="bot__actions">
<router-link v-for="button in selectedButtons" v-if="button.name !== 'pause'" :key="button.name" :to="{ name: `bot-${button.name}`, params: { bot: bot.name } }">
<span class="bot__action"><font-awesome-icon :icon="button.icon"></font-awesome-icon></span>
</router-link>
<span v-if="bot.paused && bot.active && isPauseButtonSelected" class="bot__action" @click="resume"><font-awesome-icon icon="play"></font-awesome-icon></span>
<span v-if="!bot.paused && bot.active && isPauseButtonSelected" class="bot__action" @click="pause"><font-awesome-icon icon="pause"></font-awesome-icon></span>
<span v-if="!bot.active" class="bot__action" @click="start"><font-awesome-icon icon="power-off"></font-awesome-icon></span>
<span v-if="bot.active" class="bot__action" @click="stop"><font-awesome-icon icon="power-off"></font-awesome-icon></span>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex';
import getUserInputType from '../utils/getUserInputType';
const quickActionButtons = [
{ name: '2fa', icon: 'lock' },
{ name: 'bgr', icon: 'key' },
{ name: 'config', icon: 'wrench' },
{ name: 'pause', icon: 'none' },
];
export default {
name: 'bot-card',
props: {
bot: Object,
},
computed: {
...mapGetters({
nicknames: 'settings/nicknames',
favButtons: 'settings/favButtons',
headless: 'asf/headless',
}),
isPauseButtonSelected() {
return this.selectedButtons.filter(e => e.name === 'pause').length > 0;
},
selectedButtons() {
return Array.from(this.favButtons.toString(2))
.reverse()
.reduce((activeButtons, enabled, index) => {
if (enabled === '1') activeButtons.push(quickActionButtons[index]);
return activeButtons;
}, []);
},
},
methods: {
async pause() {
try {
await this.$http.botAction(this.bot.name, 'pause', { permanent: true, resumeInSeconds: 0 });
await this.$store.dispatch('bots/updateBot', { name: this.bot.name, paused: true });
} catch (err) {
this.$error(err.message);
}
},
async resume() {
try {
await this.$http.botAction(this.bot.name, 'resume');
await this.$store.dispatch('bots/updateBot', { name: this.bot.name, paused: false });
} catch (err) {
this.$error(err.message);
}
},
async start() {
try {
const inputType = getUserInputType(this.bot.requiredInput);
if (this.headless && inputType !== 'None') {
this.$router.push({ name: 'bot-input', params: { bot: this.bot.name, type: inputType } });
return;
}
await this.$http.botAction(this.bot.name, 'start');
await this.$store.dispatch('bots/updateBot', { name: this.bot.name, active: true });
} catch (err) {
this.$error(err.message);
}
},
async stop() {
try {
await this.$http.botAction(this.bot.name, 'stop');
await this.$store.dispatch('bots/updateBot', { name: this.bot.name, active: false });
} catch (err) {
this.$error(err.message);
}
},
},
};
</script>
<style lang="scss">
.bot {
background: var(--color-background-light);
border-radius: 0 0 4px 4px;
border-top: 3px solid var(--color-status);
display: grid;
grid-template-areas: 'avatar meta buttons';
grid-template-columns: min-content 1fr auto;
padding: 0.5em;
transition: border .3s;
&--big {
grid-template-areas: 'avatar meta' 'buttons buttons';
grid-template-columns: min-content 1fr;
grid-template-rows: auto min-content;
.bot__actions {
margin-top: 0.5rem;
}
.bot__action {
font-size: 1.25rem;
padding: 0 0.5rem;
}
}
}
.bot__avatar {
cursor: pointer;
display: block;
height: 2.25em; // (1em + 0.8em) * 1.25
padding-right: 0.5em;
width: 2.25em;
}
.bot__status {
cursor: pointer;
display: flex;
flex-direction: column;
overflow: hidden;
}
.bot__status-property {
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.bot__status-property--name {
font-weight: 600;
}
.bot__status-property--text {
font-size: 0.8em;
font-style: italic;
}
.bot__actions {
align-items: center;
display: flex;
grid-area: buttons;
justify-content: space-around;
}
.bot__action {
color: var(--color-text-disabled);
cursor: pointer;
display: block;
padding: 0.5em;
transition: color .3s;
&:hover {
color: var(--color-text-dark);
.app--dark-mode & {
color: var(--color-text);
}
}
}
</style>