]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - src/components/services/Sonarr.vue
Last batch of custom services refacto.
[github/bastienwirtz/homer.git] / src / components / services / Sonarr.vue
CommitLineData
0211da26 1<template>
9c776516
BW
2 <Generic :item="item">
3 <template #indicator>
4 <div class="notifs">
5 <strong v-if="activity > 0" class="notif activity" title="Activity">
6 {{ activity }}
7 </strong>
8 <strong v-if="warnings > 0" class="notif warnings" title="Warning">
9 {{ warnings }}
10 </strong>
11 <strong v-if="errors > 0" class="notif errors" title="Error">
12 {{ errors }}
13 </strong>
14 <strong
15 v-if="serverError"
16 class="notif errors"
17 title="Connection error to Sonarr API, check url and apikey in config.yml"
18 >
19 ?
20 </strong>
21 </div>
22 </template>
23 </Generic>
0211da26 24</template>
25
26<script>
9c776516
BW
27import service from "@/mixins/service.js";
28import Generic from "./Generic.vue";
29
0211da26 30export default {
31 name: "Sonarr",
9c776516 32 mixins: [service],
0211da26 33 props: {
34 item: Object,
35 },
9c776516
BW
36 components: {
37 Generic,
38 },
0211da26 39 data: () => {
40 return {
41 activity: null,
42 warnings: null,
43 errors: null,
44 serverError: false,
45 };
46 },
47 created: function () {
48 this.fetchConfig();
49 },
50 methods: {
51 fetchConfig: function () {
9c776516 52 this.fetch(`/api/health?apikey=${this.item.apikey}`)
0211da26 53 .then((health) => {
54 this.warnings = 0;
55 this.errors = 0;
56 for (var i = 0; i < health.length; i++) {
57 if (health[i].type == "warning") {
58 this.warnings++;
59 } else if (health[i].type == "error") {
60 this.errors++;
61 }
62 }
63 })
64 .catch((e) => {
65 console.error(e);
66 this.serverError = true;
67 });
9c776516 68 this.fetch(`/api/queue?apikey=${this.item.apikey}`)
0211da26 69 .then((queue) => {
70 this.activity = 0;
71 for (var i = 0; i < queue.length; i++) {
72 if (queue[i].series) {
73 this.activity++;
74 }
75 }
76 })
77 .catch((e) => {
78 console.error(e);
79 this.serverError = true;
80 });
81 },
82 },
83};
84</script>
85
86<style scoped lang="scss">
0211da26 87.notifs {
88 position: absolute;
89 color: white;
90 font-family: sans-serif;
91 top: 0.3em;
92 right: 0.5em;
0211da26 93
9c776516
BW
94 .notif {
95 display: inline-block;
96 padding: 0.2em 0.35em;
97 border-radius: 0.25em;
98 position: relative;
99 margin-left: 0.3em;
100 font-size: 0.8em;
101
102 &.activity {
103 background-color: #4fb5d6;
104 }
105
106 &.warnings {
107 background-color: #d08d2e;
108 }
0211da26 109
9c776516
BW
110 &.errors {
111 background-color: #e51111;
112 }
113 }
0211da26 114}
115</style>