aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/components/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/services')
-rw-r--r--src/components/services/OpenWeather.vue135
-rw-r--r--src/components/services/PaperlessNG.vue1
-rw-r--r--src/components/services/PiHole.vue4
-rw-r--r--src/components/services/Ping.vue6
-rw-r--r--src/components/services/Radarr.vue10
-rw-r--r--src/components/services/Sonarr.vue10
6 files changed, 148 insertions, 18 deletions
diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue
new file mode 100644
index 0000000..09ff76a
--- /dev/null
+++ b/src/components/services/OpenWeather.vue
@@ -0,0 +1,135 @@
1<template>
2 <div>
3 <div class="card" :class="item.class">
4 <a
5 :href="`https://openweathermap.org/city/${id}`"
6 :target="item.target"
7 rel="noreferrer"
8 >
9 <div class="card-content">
10 <div class="media">
11 <div v-if="icon" class="media-left" :class="item.background">
12 <figure class="image is-48x48">
13 <img
14 :src="`https://openweathermap.org/img/wn/${icon}@2x.png`"
15 :alt="conditions"
16 :title="conditions"
17 />
18 </figure>
19 </div>
20 <div class="media-content">
21 <p v-if="error" class="error">Data could not be retrieved</p>
22 <div v-else>
23 <p class="title is-4">{{ name }}</p>
24 <p class="subtitle is-6">
25 {{ temp | tempSuffix(this.item.units) }}
26 </p>
27 </div>
28 </div>
29 </div>
30 <div class="tag" :class="item.tagstyle" v-if="item.tag">
31 <strong class="tag-text">#{{ item.tag }}</strong>
32 </div>
33 </div>
34 </a>
35 </div>
36 </div>
37</template>
38
39<script>
40export default {
41 name: "OpenWeather",
42 props: {
43 item: Object,
44 },
45 data: () => ({
46 id: null,
47 icon: null,
48 name: null,
49 temp: null,
50 conditions: null,
51 error: false,
52 }),
53 created() {
54 this.fetchWeather();
55 },
56 methods: {
57 fetchWeather: async function () {
58 let locationQuery;
59
60 // Use location ID if specified, otherwise retrieve value from location (name).
61 if (this.item.locationId) {
62 locationQuery = `id=${this.item.locationId}`;
63 } else {
64 locationQuery = `q=${this.item.location}`;
65 }
66
67 const url = `https://api.openweathermap.org/data/2.5/weather?${locationQuery}&appid=${this.item.apiKey}&units=${this.item.units}`;
68 fetch(url)
69 .then((response) => {
70 if (!response.ok) {
71 throw Error(response.statusText);
72 }
73 return response.json();
74 })
75 .then((weather) => {
76 this.id = weather.id;
77 this.name = weather.name;
78 this.temp = parseInt(weather.main.temp).toFixed(1);
79 this.icon = weather.weather[0].icon;
80 this.conditions = weather.weather[0].description;
81 })
82 .catch((e) => {
83 console.log(e);
84 this.error = true;
85 });
86 },
87 },
88 filters: {
89 tempSuffix: function (value, type) {
90 if (!value) return "";
91
92 let unit = "K";
93 if (type === "metric") {
94 unit = "°C";
95 } else if (type === "imperial") {
96 unit = "°F";
97 }
98 return `${value} ${unit}`;
99 },
100 },
101};
102</script>
103
104<style scoped lang="scss">
105// Add a border around the weather image.
106// Otherwise the image is not always distinguishable.
107.media-left {
108 &.circle,
109 &.square {
110 background-color: #e4e4e4;
111 }
112
113 &.circle {
114 border-radius: 90%;
115 }
116
117 img {
118 max-height: 100%;
119 }
120}
121
122.error {
123 color: #de0000;
124}
125
126// Change background color in dark mode.
127.is-dark {
128 .media-left {
129 &.circle,
130 &.square {
131 background-color: #909090;
132 }
133 }
134}
135</style>
diff --git a/src/components/services/PaperlessNG.vue b/src/components/services/PaperlessNG.vue
index 4fb31f8..af13317 100644
--- a/src/components/services/PaperlessNG.vue
+++ b/src/components/services/PaperlessNG.vue
@@ -59,6 +59,7 @@ export default {
59 } 59 }
60 const url = `${this.item.url}/api/documents/`; 60 const url = `${this.item.url}/api/documents/`;
61 this.api = await fetch(url, { 61 this.api = await fetch(url, {
62 credentials: "include",
62 headers: { 63 headers: {
63 Authorization: "Token " + this.item.apikey, 64 Authorization: "Token " + this.item.apikey,
64 }, 65 },
diff --git a/src/components/services/PiHole.vue b/src/components/services/PiHole.vue
index 7042a7b..87f7090 100644
--- a/src/components/services/PiHole.vue
+++ b/src/components/services/PiHole.vue
@@ -64,7 +64,9 @@ export default {
64 methods: { 64 methods: {
65 fetchStatus: async function () { 65 fetchStatus: async function () {
66 const url = `${this.item.url}/api.php`; 66 const url = `${this.item.url}/api.php`;
67 this.api = await fetch(url) 67 this.api = await fetch(url, {
68 credentials: "include",
69 })
68 .then((response) => response.json()) 70 .then((response) => response.json())
69 .catch((e) => console.log(e)); 71 .catch((e) => console.log(e));
70 }, 72 },
diff --git a/src/components/services/Ping.vue b/src/components/services/Ping.vue
index 8a9b7a4..e693af4 100644
--- a/src/components/services/Ping.vue
+++ b/src/components/services/Ping.vue
@@ -50,7 +50,11 @@ export default {
50 methods: { 50 methods: {
51 fetchStatus: async function () { 51 fetchStatus: async function () {
52 const url = `${this.item.url}`; 52 const url = `${this.item.url}`;
53 fetch(url, { method: "HEAD", cache: "no-cache" }) 53 fetch(url, {
54 method: "HEAD",
55 cache: "no-cache",
56 credentials: "include",
57 })
54 .then((response) => { 58 .then((response) => {
55 if (!response.ok) { 59 if (!response.ok) {
56 throw Error(response.statusText); 60 throw Error(response.statusText);
diff --git a/src/components/services/Radarr.vue b/src/components/services/Radarr.vue
index 93831a7..9d38292 100644
--- a/src/components/services/Radarr.vue
+++ b/src/components/services/Radarr.vue
@@ -70,10 +70,7 @@ export default {
70 }, 70 },
71 methods: { 71 methods: {
72 fetchConfig: function () { 72 fetchConfig: function () {
73 fetch(`${this.item.url}/api/health`, { 73 fetch(`${this.item.url}/api/health?apikey=${this.item.apikey}`)
74 credentials: "include",
75 headers: { "X-Api-Key": `${this.item.apikey}` },
76 })
77 .then((response) => { 74 .then((response) => {
78 if (response.status != 200) { 75 if (response.status != 200) {
79 throw new Error(response.statusText); 76 throw new Error(response.statusText);
@@ -95,10 +92,7 @@ export default {
95 console.error(e); 92 console.error(e);
96 this.serverError = true; 93 this.serverError = true;
97 }); 94 });
98 fetch(`${this.item.url}/api/queue`, { 95 fetch(`${this.item.url}/api/queue?apikey=${this.item.apikey}`)
99 credentials: "include",
100 headers: { "X-Api-Key": `${this.item.apikey}` },
101 })
102 .then((response) => { 96 .then((response) => {
103 if (response.status != 200) { 97 if (response.status != 200) {
104 throw new Error(response.statusText); 98 throw new Error(response.statusText);
diff --git a/src/components/services/Sonarr.vue b/src/components/services/Sonarr.vue
index 8cebac4..7851b6b 100644
--- a/src/components/services/Sonarr.vue
+++ b/src/components/services/Sonarr.vue
@@ -70,10 +70,7 @@ export default {
70 }, 70 },
71 methods: { 71 methods: {
72 fetchConfig: function () { 72 fetchConfig: function () {
73 fetch(`${this.item.url}/api/health`, { 73 fetch(`${this.item.url}/api/health?apikey=${this.item.apikey}`)
74 credentials: "include",
75 headers: { "X-Api-Key": `${this.item.apikey}` },
76 })
77 .then((response) => { 74 .then((response) => {
78 if (response.status != 200) { 75 if (response.status != 200) {
79 throw new Error(response.statusText); 76 throw new Error(response.statusText);
@@ -95,10 +92,7 @@ export default {
95 console.error(e); 92 console.error(e);
96 this.serverError = true; 93 this.serverError = true;
97 }); 94 });
98 fetch(`${this.item.url}/api/queue`, { 95 fetch(`${this.item.url}/api/queue?apikey=${this.item.apikey}`)
99 credentials: "include",
100 headers: { "X-Api-Key": `${this.item.apikey}` },
101 })
102 .then((response) => { 96 .then((response) => {
103 if (response.status != 200) { 97 if (response.status != 200) {
104 throw new Error(response.statusText); 98 throw new Error(response.statusText);