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