]> git.immae.eu Git - github/bastienwirtz/homer.git/blame - src/components/services/Sonarr.vue
Added Tdarr service (#573)
[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;
f7f4ebdf
DN
79 if (this.item.legacyApi) {
80 for (var i = 0; i < queue.length; i++) {
81 if (queue[i].series) {
82 this.activity++;
83 }
84 }
85 } else {
c6ec28f1 86 this.activity = queue.totalRecords;
0211da26 87 }
88 })
89 .catch((e) => {
90 console.error(e);
91 this.serverError = true;
92 });
93 },
94 },
95};
96</script>
97
98<style scoped lang="scss">
0211da26 99.notifs {
100 position: absolute;
101 color: white;
102 font-family: sans-serif;
103 top: 0.3em;
104 right: 0.5em;
0211da26 105
9c776516
BW
106 .notif {
107 display: inline-block;
108 padding: 0.2em 0.35em;
109 border-radius: 0.25em;
110 position: relative;
111 margin-left: 0.3em;
112 font-size: 0.8em;
113
114 &.activity {
115 background-color: #4fb5d6;
116 }
117
118 &.warnings {
119 background-color: #d08d2e;
120 }
0211da26 121
9c776516
BW
122 &.errors {
123 background-color: #e51111;
124 }
125 }
0211da26 126}
127</style>