🩹 Move schema to Component.data + remove unnecessary null checks

This commit is contained in:
Marcell Fülöp 2022-06-19 16:31:54 +00:00
parent db0fc0454d
commit 991cf0bf5a
4 changed files with 110 additions and 116 deletions

View File

@ -55,7 +55,16 @@
import WidgetMixin from '@/mixins/WidgetMixin'; import WidgetMixin from '@/mixins/WidgetMixin';
import NextcloudMixin from '@/mixins/NextcloudMixin'; import NextcloudMixin from '@/mixins/NextcloudMixin';
const NextcloudSystemSchema = { /**
* NextcloudPhpOpcache widget - Shows statistics about PHP opcache performance
* Used endpoints
* - serverinfo: requires Nextcloud admin user
*/
export default {
mixins: [WidgetMixin, NextcloudMixin],
components: {},
data() {
return {
opcache: { opcache: {
opcache_enabled: null, opcache_enabled: null,
full: null, full: null,
@ -87,17 +96,6 @@ const NextcloudSystemSchema = {
}, },
}, },
}; };
/**
* NextcloudPhpOpcache widget - Shows statistics about PHP opcache performance
* Used endpoints
* - serverinfo: requires Nextcloud admin user
*/
export default {
mixins: [WidgetMixin, NextcloudMixin],
components: {},
data() {
return NextcloudSystemSchema;
}, },
computed: { computed: {
didLoadData() { didLoadData() {
@ -123,7 +121,7 @@ export default {
}, },
processServerInfo(serverData) { processServerInfo(serverData) {
const data = this.validateResponse(serverData); const data = this.validateResponse(serverData);
this.opcache = data?.server?.php?.opcache; this.opcache = data.server?.php?.opcache;
if (!this.opcache) return; if (!this.opcache) return;
this.updateOpcacheMemory(); this.updateOpcacheMemory();
this.updateOpcacheInterned(); this.updateOpcacheInterned();

View File

@ -64,7 +64,12 @@ import NextcloudMixin from '@/mixins/NextcloudMixin';
* Used endpoints * Used endpoints
* - serverinfo: requires Nextcloud admin user * - serverinfo: requires Nextcloud admin user
*/ */
const NextcloudStatsSchema = {
export default {
mixins: [WidgetMixin, NextcloudMixin],
components: {},
data() {
return {
nextcloud: { nextcloud: {
system: { system: {
freespace: null, freespace: null,
@ -97,12 +102,6 @@ const NextcloudStatsSchema = {
last24hours: null, last24hours: null,
}, },
}; };
export default {
mixins: [WidgetMixin, NextcloudMixin],
components: {},
data() {
return NextcloudStatsSchema;
}, },
computed: { computed: {
didLoadData() { didLoadData() {
@ -134,8 +133,8 @@ export default {
}, },
processServerInfo(serverResponse) { processServerInfo(serverResponse) {
const data = this.validateResponse(serverResponse); const data = this.validateResponse(serverResponse);
this.nextcloud = data?.nextcloud; this.nextcloud = data.nextcloud;
this.activeUsers = data?.activeUsers; this.activeUsers = data.activeUsers;
}, },
/* Tooltip generators */ /* Tooltip generators */
activeUsersTooltip() { activeUsersTooltip() {

View File

@ -47,7 +47,16 @@ import NextcloudMixin from '@/mixins/NextcloudMixin';
import GaugeChart from '@/components/Charts/Gauge'; import GaugeChart from '@/components/Charts/Gauge';
import ChartingMixin from '@/mixins/ChartingMixin'; import ChartingMixin from '@/mixins/ChartingMixin';
const NextcloudSystemSchema = { /**
* NextcloudSystem widget - Visualises CPU load and memory utilisation and shows server versions
* Used endpoints
* - serverinfo: requires Nextcloud admin user
*/
export default {
mixins: [WidgetMixin, NextcloudMixin, ChartingMixin],
components: { GaugeChart },
data() {
return {
server: { server: {
server: { server: {
database: { database: {
@ -79,24 +88,13 @@ const NextcloudSystemSchema = {
background: '#16161d', background: '#16161d',
}, },
}; };
/**
* NextcloudSystem widget - Visualises CPU load and memory utilisation and shows server versions
* Used endpoints
* - serverinfo: requires Nextcloud admin user
*/
export default {
mixins: [WidgetMixin, NextcloudMixin, ChartingMixin],
components: { GaugeChart },
data() {
return NextcloudSystemSchema;
}, },
computed: { computed: {
cpuLoadChartId() { cpuLoadChartId() {
return `nextcloud-cpu-load-chart-${Math.random().toString().slice(-4)}`; return `nextcloud-cpu-load-chart-${Math.random().toString().slice(-4)}`;
}, },
didLoadData() { didLoadData() {
return !!(this?.server?.nextcloud?.system?.version); return !!(this.server?.nextcloud?.system?.version);
}, },
}, },
methods: { methods: {
@ -112,11 +110,10 @@ export default {
processServerInfo(serverData) { processServerInfo(serverData) {
const data = this.validateResponse(serverData); const data = this.validateResponse(serverData);
if (!data || data.length === 0) return; if (!data || data.length === 0) return;
this.server.nextcloud.system = data?.nextcloud?.system; this.server.nextcloud.system = data.nextcloud?.system;
this.$nextTick(); this.server.server.php.version = data.server?.php?.version;
this.server.server.php.version = data?.server?.php?.version; this.server.server.database = data.server?.database;
this.server.server.database = data?.server?.database; this.server.server.webserver = data.server?.webserver;
this.server.server.webserver = data?.server?.webserver;
}, },
updateMemoryGauge(sys) { updateMemoryGauge(sys) {
this.memoryGauge.value = parseFloat( this.memoryGauge.value = parseFloat(

View File

@ -152,13 +152,13 @@ export default {
/* Update the sate based on the capabilites response */ /* Update the sate based on the capabilites response */
processCapabilities(capResponse) { processCapabilities(capResponse) {
const ocdata = this.validateResponse(capResponse); const ocdata = this.validateResponse(capResponse);
const capNotif = ocdata?.capabilities?.notifications?.['ocs-endpoints']; const capNotif = ocdata.capabilities?.notifications?.['ocs-endpoints'];
this.branding = ocdata?.capabilities?.theming; this.branding = ocdata.capabilities?.theming;
this.capabilities.notifications.enabled = !!(capNotif?.length); this.capabilities.notifications.enabled = !!(capNotif?.length);
this.capabilities.notifications.features = capNotif || []; this.capabilities.notifications.features = capNotif || [];
this.capabilities.userStatus = !!(ocdata?.capabilities?.user_status?.enabled); this.capabilities.userStatus = !!(ocdata.capabilities?.user_status?.enabled);
this.version.string = ocdata?.version?.string; this.version.string = ocdata.version?.string;
this.version.edition = ocdata?.version?.edition; this.version.edition = ocdata.version?.edition;
this.capabilitiesLastUpdated = new Date().getTime(); this.capabilitiesLastUpdated = new Date().getTime();
}, },
/* Shared template helpers */ /* Shared template helpers */