From 991cf0bf5a744c641c04594a9be2bfaa1a717764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcell=20F=C3=BCl=C3=B6p?= Date: Sun, 19 Jun 2022 16:31:54 +0000 Subject: [PATCH] :adhesive_bandage: Move schema to Component.data + remove unnecessary null checks --- .../Widgets/NextcloudPhpOpcache.vue | 68 ++++++++-------- src/components/Widgets/NextcloudStats.vue | 71 +++++++++-------- src/components/Widgets/NextcloudSystem.vue | 77 +++++++++---------- src/mixins/NextcloudMixin.js | 10 +-- 4 files changed, 110 insertions(+), 116 deletions(-) diff --git a/src/components/Widgets/NextcloudPhpOpcache.vue b/src/components/Widgets/NextcloudPhpOpcache.vue index b64bdaf1..645cac07 100644 --- a/src/components/Widgets/NextcloudPhpOpcache.vue +++ b/src/components/Widgets/NextcloudPhpOpcache.vue @@ -55,39 +55,6 @@ import WidgetMixin from '@/mixins/WidgetMixin'; import NextcloudMixin from '@/mixins/NextcloudMixin'; -const NextcloudSystemSchema = { - opcache: { - opcache_enabled: null, - full: null, - opcache_statistics: { - num_cached_scripts: null, - num_cached_keys: null, - max_cached_keys: null, - hits: null, - start_time: null, - last_restart_time: null, - misses: null, - opcache_hit_rate: null, - }, - memory_usage: { - used_memory: null, - free_memory: null, - total_memory: null, - wasted_memory: null, - used_memory_percentage: null, - current_wasted_percentage: null, - }, - interned_strings_usage: { - buffer_size: null, - used_memory: null, - total_memory: null, - free_memory: null, - number_of_strings: null, - used_memory_percentage: null, - }, - }, -}; - /** * NextcloudPhpOpcache widget - Shows statistics about PHP opcache performance * Used endpoints @@ -97,7 +64,38 @@ export default { mixins: [WidgetMixin, NextcloudMixin], components: {}, data() { - return NextcloudSystemSchema; + return { + opcache: { + opcache_enabled: null, + full: null, + opcache_statistics: { + num_cached_scripts: null, + num_cached_keys: null, + max_cached_keys: null, + hits: null, + start_time: null, + last_restart_time: null, + misses: null, + opcache_hit_rate: null, + }, + memory_usage: { + used_memory: null, + free_memory: null, + total_memory: null, + wasted_memory: null, + used_memory_percentage: null, + current_wasted_percentage: null, + }, + interned_strings_usage: { + buffer_size: null, + used_memory: null, + total_memory: null, + free_memory: null, + number_of_strings: null, + used_memory_percentage: null, + }, + }, + }; }, computed: { didLoadData() { @@ -123,7 +121,7 @@ export default { }, processServerInfo(serverData) { const data = this.validateResponse(serverData); - this.opcache = data?.server?.php?.opcache; + this.opcache = data.server?.php?.opcache; if (!this.opcache) return; this.updateOpcacheMemory(); this.updateOpcacheInterned(); diff --git a/src/components/Widgets/NextcloudStats.vue b/src/components/Widgets/NextcloudStats.vue index f1c02fc0..8e2a5c72 100644 --- a/src/components/Widgets/NextcloudStats.vue +++ b/src/components/Widgets/NextcloudStats.vue @@ -64,45 +64,44 @@ import NextcloudMixin from '@/mixins/NextcloudMixin'; * Used endpoints * - serverinfo: requires Nextcloud admin user */ -const NextcloudStatsSchema = { - nextcloud: { - system: { - freespace: null, - apps: { - num_installed: null, - num_updates_available: 0, - app_updates: [], - }, - }, - storage: { - num_users: null, - num_files: null, - num_storages: null, - }, - shares: { - num_shares: null, - num_shares_user: null, - num_shares_groups: null, - num_shares_link: null, - num_shares_mail: null, - num_shares_room: null, - num_shares_link_no_password: null, - num_fed_shares_sent: null, - num_fed_shares_received: null, - }, - }, - activeUsers: { - last5minutes: null, - last1hour: null, - last24hours: null, - }, -}; export default { mixins: [WidgetMixin, NextcloudMixin], components: {}, data() { - return NextcloudStatsSchema; + return { + nextcloud: { + system: { + freespace: null, + apps: { + num_installed: null, + num_updates_available: 0, + app_updates: [], + }, + }, + storage: { + num_users: null, + num_files: null, + num_storages: null, + }, + shares: { + num_shares: null, + num_shares_user: null, + num_shares_groups: null, + num_shares_link: null, + num_shares_mail: null, + num_shares_room: null, + num_shares_link_no_password: null, + num_fed_shares_sent: null, + num_fed_shares_received: null, + }, + }, + activeUsers: { + last5minutes: null, + last1hour: null, + last24hours: null, + }, + }; }, computed: { didLoadData() { @@ -134,8 +133,8 @@ export default { }, processServerInfo(serverResponse) { const data = this.validateResponse(serverResponse); - this.nextcloud = data?.nextcloud; - this.activeUsers = data?.activeUsers; + this.nextcloud = data.nextcloud; + this.activeUsers = data.activeUsers; }, /* Tooltip generators */ activeUsersTooltip() { diff --git a/src/components/Widgets/NextcloudSystem.vue b/src/components/Widgets/NextcloudSystem.vue index 182b4e26..8df8be16 100644 --- a/src/components/Widgets/NextcloudSystem.vue +++ b/src/components/Widgets/NextcloudSystem.vue @@ -47,39 +47,6 @@ import NextcloudMixin from '@/mixins/NextcloudMixin'; import GaugeChart from '@/components/Charts/Gauge'; import ChartingMixin from '@/mixins/ChartingMixin'; -const NextcloudSystemSchema = { - server: { - server: { - database: { - type: null, - version: null, - size: null, - }, - webserver: null, - php: { - version: null, - }, - }, - nextcloud: { - system: { - version: null, - freespace: null, - cpuload: [], - mem_total: null, - mem_free: null, - mem_percent: null, - }, - }, - }, - memoryGauge: { - value: 0, - color: '#272f4d', - showMoreInfo: false, - moreInfo: null, - background: '#16161d', - }, -}; - /** * NextcloudSystem widget - Visualises CPU load and memory utilisation and shows server versions * Used endpoints @@ -89,14 +56,45 @@ export default { mixins: [WidgetMixin, NextcloudMixin, ChartingMixin], components: { GaugeChart }, data() { - return NextcloudSystemSchema; + return { + server: { + server: { + database: { + type: null, + version: null, + size: null, + }, + webserver: null, + php: { + version: null, + }, + }, + nextcloud: { + system: { + version: null, + freespace: null, + cpuload: [], + mem_total: null, + mem_free: null, + mem_percent: null, + }, + }, + }, + memoryGauge: { + value: 0, + color: '#272f4d', + showMoreInfo: false, + moreInfo: null, + background: '#16161d', + }, + }; }, computed: { cpuLoadChartId() { return `nextcloud-cpu-load-chart-${Math.random().toString().slice(-4)}`; }, didLoadData() { - return !!(this?.server?.nextcloud?.system?.version); + return !!(this.server?.nextcloud?.system?.version); }, }, methods: { @@ -112,11 +110,10 @@ export default { processServerInfo(serverData) { const data = this.validateResponse(serverData); if (!data || data.length === 0) return; - this.server.nextcloud.system = data?.nextcloud?.system; - this.$nextTick(); - this.server.server.php.version = data?.server?.php?.version; - this.server.server.database = data?.server?.database; - this.server.server.webserver = data?.server?.webserver; + this.server.nextcloud.system = data.nextcloud?.system; + this.server.server.php.version = data.server?.php?.version; + this.server.server.database = data.server?.database; + this.server.server.webserver = data.server?.webserver; }, updateMemoryGauge(sys) { this.memoryGauge.value = parseFloat( diff --git a/src/mixins/NextcloudMixin.js b/src/mixins/NextcloudMixin.js index fd89bb54..cb827a90 100644 --- a/src/mixins/NextcloudMixin.js +++ b/src/mixins/NextcloudMixin.js @@ -152,13 +152,13 @@ export default { /* Update the sate based on the capabilites response */ processCapabilities(capResponse) { const ocdata = this.validateResponse(capResponse); - const capNotif = ocdata?.capabilities?.notifications?.['ocs-endpoints']; - this.branding = ocdata?.capabilities?.theming; + const capNotif = ocdata.capabilities?.notifications?.['ocs-endpoints']; + this.branding = ocdata.capabilities?.theming; this.capabilities.notifications.enabled = !!(capNotif?.length); this.capabilities.notifications.features = capNotif || []; - this.capabilities.userStatus = !!(ocdata?.capabilities?.user_status?.enabled); - this.version.string = ocdata?.version?.string; - this.version.edition = ocdata?.version?.edition; + this.capabilities.userStatus = !!(ocdata.capabilities?.user_status?.enabled); + this.version.string = ocdata.version?.string; + this.version.edition = ocdata.version?.edition; this.capabilitiesLastUpdated = new Date().getTime(); }, /* Shared template helpers */