1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<template>
<div>
<div class="my-4">
<label for="keepDataPeriodDays" class="form-label">
{{
$t("clearDataOlderThan", [
settings.keepDataPeriodDays,
])
}}
{{ $t("infiniteRetention") }}
</label>
<input
id="keepDataPeriodDays"
v-model="settings.keepDataPeriodDays"
type="number"
class="form-control"
required
min="0"
step="1"
/>
<div v-if="settings.keepDataPeriodDays < 0" class="form-text">
{{ $t("dataRetentionTimeError") }}
</div>
</div>
<div class="my-4">
<button class="btn btn-primary" type="button" @click="saveSettings()">
{{ $t("Save") }}
</button>
</div>
<div class="my-4">
<div v-if="$root.info.dbType === 'sqlite'" class="my-3">
<button class="btn btn-outline-info me-2" @click="shrinkDatabase">
{{ $t("Shrink Database") }} ({{ databaseSizeDisplay }})
</button>
<i18n-t tag="div" keypath="shrinkDatabaseDescriptionSqlite" class="form-text mt-2 mb-4 ms-2">
<template #vacuum>
<code>VACUUM</code>
</template>
<template #auto_vacuum>
<code>AUTO_VACUUM</code>
</template>
</i18n-t>
</div>
<button
id="clearAllStats-btn"
class="btn btn-outline-danger me-2 mb-2"
@click="confirmClearStatistics"
>
{{ $t("Clear all statistics") }}
</button>
</div>
<Confirm
ref="confirmClearStatistics"
btn-style="btn-danger"
:yes-text="$t('Yes')"
:no-text="$t('No')"
@yes="clearStatistics"
>
{{ $t("confirmClearStatisticsMsg") }}
</Confirm>
</div>
</template>
<script>
import Confirm from "../../components/Confirm.vue";
import { log } from "../../util.ts";
export default {
components: {
Confirm,
},
data() {
return {
databaseSize: 0,
};
},
computed: {
settings() {
return this.$parent.$parent.$parent.settings;
},
saveSettings() {
return this.$parent.$parent.$parent.saveSettings;
},
settingsLoaded() {
return this.$parent.$parent.$parent.settingsLoaded;
},
databaseSizeDisplay() {
return (
Math.round((this.databaseSize / 1024 / 1024) * 10) / 10 + " MB"
);
},
},
mounted() {
this.loadDatabaseSize();
},
methods: {
/**
* Get the current size of the database
* @returns {void}
*/
loadDatabaseSize() {
log.debug("monitorhistory", "load database size");
this.$root.getSocket().emit("getDatabaseSize", (res) => {
if (res.ok) {
this.databaseSize = res.size;
log.debug("monitorhistory", "database size: " + res.size);
} else {
log.debug("monitorhistory", res);
}
});
},
/**
* Request that the database is shrunk
* @returns {void}
*/
shrinkDatabase() {
this.$root.getSocket().emit("shrinkDatabase", (res) => {
if (res.ok) {
this.loadDatabaseSize();
this.$root.toastSuccess("Done");
} else {
log.debug("monitorhistory", res);
}
});
},
/**
* Show the dialog to confirm clearing stats
* @returns {void}
*/
confirmClearStatistics() {
this.$refs.confirmClearStatistics.show();
},
/**
* Send the request to clear stats
* @returns {void}
*/
clearStatistics() {
this.$root.clearStatistics((res) => {
if (res.ok) {
this.$router.go();
} else {
this.$root.toastError(res.msg);
}
});
},
},
};
</script>
|