Skip to content

Commit 2d6c499

Browse files
committed
✨ Optionally allow the widget to filter on StatPing Group and to display in a more compact view.
* Add widget option: `groupId`. StatPing services are filtered for the given group. * Add widget options: `showChart` and `showInfo`. Initially hide the chart and info summary. * Add buttons to show/hide chart and info sections. * Update widget documentation.
1 parent ee27dc8 commit 2d6c499

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

docs/widgets.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,9 @@ Displays the current and recent uptime of your running services, via a self-host
13501350
**Field** | **Type** | **Required** | **Description**
13511351
--- | --- | --- | ---
13521352
**`hostname`** | `string` | Required | The URL to your StatPing instance, without a trailing slash
1353+
**`groupId`** | `number` | Optional | If provided, only Services in the given group are displayed. Defaults to `0` in which case all services are displayed.
1354+
**`showChart`** | `boolean`| Optional | If provided and `false` then charts are not displayed. Defaults to `true`.
1355+
**`showInfo`** | `boolean`| Optional | If provided and `false` then information summaries are not displayed. Defaults to `true`.
13531356

13541357
##### Example
13551358

@@ -1358,6 +1361,18 @@ Displays the current and recent uptime of your running services, via a self-host
13581361
options:
13591362
hostname: http://192.168.130.1:8080
13601363
```
1364+
or
1365+
```yaml
1366+
- type: stat-ping
1367+
options:
1368+
hostname: http://192.168.130.1:8080
1369+
groupId: 3
1370+
showChart: false
1371+
showInfo: false
1372+
```
1373+
You can use multiple StatPing widgets with different `groupId`s.
1374+
1375+
Note, the Group Id is not directly visible in SttatPing UI, you can inspect the group select HTML element or the API response to find out.
13611376

13621377
##### Info
13631378
- **CORS**: 🟠 Proxied

src/components/Widgets/StatPing.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
<span v-else class="status-offline">
1616
{{ $t('widgets.stat-ping.down') }}
1717
</span>
18+
<Button v-on:click="service.infoHidden = !service.infoHidden"
19+
class="far fa-info"></Button>
20+
<Button v-on:click="service.chartHidden = !service.chartHidden"
21+
class="far fa-chart-line"></button>
1822
</p>
1923
<!-- Charts -->
20-
<div class="charts">
24+
<div v-if="!service.chartHidden" class="charts">
2125
<img
2226
class="uptime-pie-chart" alt="24 Hour Uptime Chart"
2327
:src="makeChartUrl(service.uptime24, '24 Hours')" />
2428
<img class="uptime-pie-chart" alt="7 Day Uptime Chart"
2529
:src="makeChartUrl(service.uptime7, '7 Days')" />
2630
</div>
2731
<!-- Info -->
28-
<div class="info">
32+
<div v-if="!service.infoHidden" class="info">
2933
<div class="info-row">
3034
<span class="lbl">Failed Pings</span>
3135
<span class="val">{{ service.totalFailure }}/{{ service.totalSuccess }}</span>
@@ -73,6 +77,15 @@ export default {
7377
endpoint() {
7478
return `${this.hostname}/api/services`;
7579
},
80+
groupId() {
81+
return this.options.groupId || 0;
82+
},
83+
showChart() {
84+
return typeof this.options.showChart !== 'boolean' ? true : this.options.showChart;
85+
},
86+
showInfo() {
87+
return typeof this.options.showInfo !== 'boolean' ? true : this.options.showInfo;
88+
},
7689
},
7790
methods: {
7891
fetchData() {
@@ -99,6 +112,7 @@ export default {
99112
processData(data) {
100113
let services = [];
101114
data.forEach((service) => {
115+
if (this.groupId && this.groupId !== service.group_id) return;
102116
services.push({
103117
name: service.name,
104118
online: service.online,
@@ -109,6 +123,8 @@ export default {
109123
totalFailure: showNumAsThousand(service.stats.failures),
110124
lastSuccess: getTimeAgo(service.last_success),
111125
lastFailure: getTimeAgo(service.last_error),
126+
chartHidden: this.showChart ? 0 : 1,
127+
infoHidden: this.showInfo ? 0 : 1,
112128
});
113129
});
114130
if (this.limit) services = services.slice(0, this.limit);
@@ -135,6 +151,18 @@ export default {
135151
&.status-offline { color: var(--danger); }
136152
}
137153
}
154+
button {
155+
float: right;
156+
color: var(--widget-text-color);
157+
top: 4px;
158+
background: none;
159+
border: none;
160+
position: relative;
161+
opacity: .4;
162+
}
163+
button:hover {
164+
opacity: .75;
165+
}
138166
.charts {
139167
display: flex;
140168
flex-direction: row;

0 commit comments

Comments
 (0)