]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - src/components/services/Sonarr.vue
Radarr and Sonarr V3 api support optional
[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
8ede3041
DN
30const V3_API = "/api/v3";
31const LEGACY_API = "/api";
32
0211da26 33export default {
34 name: "Sonarr",
9c776516 35 mixins: [service],
0211da26 36 props: {
37 item: Object,
38 },
9c776516
BW
39 components: {
40 Generic,
41 },
8ede3041
DN
42 computed: {
43 apiPath() {
44 return this.item.legacyApi ? LEGACY_API : V3_API;
45 },
46 },
0211da26 47 data: () => {
48 return {
49 activity: null,
50 warnings: null,
51 errors: null,
52 serverError: false,
53 };
54 },
55 created: function () {
56 this.fetchConfig();
57 },
58 methods: {
59 fetchConfig: function () {
8ede3041 60 this.fetch(`${this.apiPath}/health?apikey=${this.item.apikey}`)
0211da26 61 .then((health) => {
62 this.warnings = 0;
63 this.errors = 0;
64 for (var i = 0; i < health.length; i++) {
65 if (health[i].type == "warning") {
66 this.warnings++;
67 } else if (health[i].type == "error") {
68 this.errors++;
69 }
70 }
71 })
72 .catch((e) => {
73 console.error(e);
74 this.serverError = true;
75 });
8ede3041 76 this.fetch(`${this.apiPath}/queue?apikey=${this.item.apikey}`)
0211da26 77 .then((queue) => {
78 this.activity = 0;
79 for (var i = 0; i < queue.length; i++) {
80 if (queue[i].series) {
81 this.activity++;
82 }
83 }
84 })
85 .catch((e) => {
86 console.error(e);
87 this.serverError = true;
88 });
89 },
90 },
91};
92</script>
93
94<style scoped lang="scss">
0211da26 95.notifs {
96 position: absolute;
97 color: white;
98 font-family: sans-serif;
99 top: 0.3em;
100 right: 0.5em;
0211da26 101
9c776516
BW
102 .notif {
103 display: inline-block;
104 padding: 0.2em 0.35em;
105 border-radius: 0.25em;
106 position: relative;
107 margin-left: 0.3em;
108 font-size: 0.8em;
109
110 &.activity {
111 background-color: #4fb5d6;
112 }
113
114 &.warnings {
115 background-color: #d08d2e;
116 }
0211da26 117
9c776516
BW
118 &.errors {
119 background-color: #e51111;
120 }
121 }
0211da26 122}
123</style>