summaryrefslogtreecommitdiff
path: root/src/client/pages/instance/relays.vue
blob: eaf6c0b6828f7a145459b3a53664400d9c541444 (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
<template>
<div class="relaycxt">
	<portal to="icon"><fa :icon="faProjectDiagram"/></portal>
	<portal to="title">{{ $t('relays') }}</portal>

	<section class="_card _vMargin add">
		<div class="_title"><fa :icon="faPlus"/> {{ $t('addRelay') }}</div>
		<div class="_content">
			<mk-input v-model="inbox">
				<span>{{ $t('inboxUrl') }}</span>
			</mk-input>
			<mk-button @click="add(inbox)" primary><fa :icon="faPlus"/> {{ $t('add') }}</mk-button>
		</div>
	</section>

	<section class="_card _vMargin relays">
		<div class="_title"><fa :icon="faProjectDiagram"/> {{ $t('addedRelays') }}</div>
		<div class="_content relay" v-for="relay in relays" :key="relay.inbox">
			<div>{{ relay.inbox }}</div>
			<div>{{ $t(`_relayStatus.${relay.status}`) }}</div>
			<mk-button class="button" inline @click="remove(relay.inbox)"><fa :icon="faTrashAlt"/> {{ $t('remove') }}</mk-button>
		</div>
	</section>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import { faPlus, faProjectDiagram } from '@fortawesome/free-solid-svg-icons';
import { faSave, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
import MkButton from '../../components/ui/button.vue';
import MkInput from '../../components/ui/input.vue';

export default Vue.extend({
	metaInfo() {
		return {
			title: this.$t('relays') as string
		};
	},

	components: {
		MkButton,
		MkInput,
	},

	data() {
		return {
			relays: [],
			inbox: '',
			faPlus, faProjectDiagram, faSave, faTrashAlt
		}
	},

	created() {
		this.refresh();
	},

	methods: {
		add(inbox: string) {
			this.$root.api('admin/relays/add', {
				inbox
			}).then((relay: any) => {
				this.refresh();
			}).catch((e: any) => {
				this.$root.dialog({
					type: 'error',
					text: e.message || e
				});
			});
		},

		remove(inbox: string) {
			this.$root.api('admin/relays/remove', {
				inbox
			}).then(() => {
				this.refresh();
			}).catch((e: any) => {
				this.$root.dialog({
					type: 'error',
					text: e.message || e
				});
			});
		},

		refresh() {
			this.$root.api('admin/relays/list').then((relays: any) => {
				this.relays = relays;
			});
		}
	}
});
</script>

<style lang="scss" scoped>
._content.relay {
	div {
		margin: 0.5em 0;
	}
}
</style>