From b7893b61ebea23ec2241fa1c28d729c257d23a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sun, 11 Apr 2021 12:39:51 +0200 Subject: [PATCH] Fix home component --- web/frontend/src/components/Home.vue | 56 +++++++++++++++++++--------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/web/frontend/src/components/Home.vue b/web/frontend/src/components/Home.vue index 268fce2..0c763f6 100644 --- a/web/frontend/src/components/Home.vue +++ b/web/frontend/src/components/Home.vue @@ -55,40 +55,60 @@ interface TotalStatsResult { @Component export default class Home extends Vue { - totalLoginAttempts?: number; + totalLoginAttempts: number; - uniquePasswords?: number; + uniquePasswords: number; - uniqueUsernames?: number; + uniqueUsernames: number; - uniqueIPs?: number; + uniqueIPs: number; - uniqueCountries?: number; + uniqueCountries: number; ready = false; + constructor() { + super(); + this.totalLoginAttempts = 0; + this.uniquePasswords = 0; + this.uniqueUsernames = 0; + this.uniqueIPs = 0; + this.uniqueCountries = 0; + } + updateStats(): void { const url = `/api/stats?type=total`; axios .get(url) .then((resp) => { - this.totalLoginAttempts = resp.data.find( - (e) => e.name === 'TotalLoginAttempts', - )?.count; + const totals = resp.data.find((e) => e.name === 'TotalLoginAttempts') + ?.count; + if (totals) { + this.totalLoginAttempts = totals; + } - this.uniquePasswords = resp.data.find( - (e) => e.name === 'UniquePasswords', - )?.count; + const passwords = resp.data.find((e) => e.name === 'UniquePasswords') + ?.count; + if (passwords) { + this.uniquePasswords = passwords; + } - this.uniqueUsernames = resp.data.find( - (e) => e.name === 'UniqueUsernames', - )?.count; + const usernames = resp.data.find((e) => e.name === 'UniqueUsernames') + ?.count; + if (usernames) { + this.uniqueUsernames = usernames; + } - this.uniqueIPs = resp.data.find((e) => e.name === 'UniqueIPs')?.count; + const ips = resp.data.find((e) => e.name === 'UniqueIPs')?.count; + if (ips) { + this.uniqueIPs = ips; + } - this.uniqueCountries = resp.data.find( - (e) => e.name === 'UniqueCountries', - )?.count; + const countries = resp.data.find((e) => e.name === 'UniqueCountries') + ?.count; + if (countries) { + this.uniqueCountries = countries; + } this.ready = true; })