mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-23 21:55:30 +02:00
✅ Code style improvments, to pass SonarCloud review
This commit is contained in:
parent
fac3e8e456
commit
15eddb1565
@ -28,7 +28,7 @@ export default {
|
|||||||
/* Number of days worth of history to fetch and display */
|
/* Number of days worth of history to fetch and display */
|
||||||
numDays() {
|
numDays() {
|
||||||
const userChoice = this.options.numDays;
|
const userChoice = this.options.numDays;
|
||||||
if (!Number.isNaN(userChoice) && userChoice < 30 && userChoice > 0.15) {
|
if (typeof usersChoice === 'number' && userChoice < 30 && userChoice > 0.15) {
|
||||||
return userChoice;
|
return userChoice;
|
||||||
}
|
}
|
||||||
return 7;
|
return 7;
|
||||||
@ -42,7 +42,7 @@ export default {
|
|||||||
/* The number of data points to render on the chart */
|
/* The number of data points to render on the chart */
|
||||||
dataPoints() {
|
dataPoints() {
|
||||||
const userChoice = this.options.dataPoints;
|
const userChoice = this.options.dataPoints;
|
||||||
if (!Number.isNaN(userChoice) && userChoice < 100 && userChoice > 5) {
|
if (typeof usersChoice === 'number' && userChoice < 100 && userChoice > 5) {
|
||||||
return userChoice;
|
return userChoice;
|
||||||
}
|
}
|
||||||
return 30;
|
return 30;
|
||||||
|
@ -141,8 +141,8 @@ export default {
|
|||||||
return 'fg-grey';
|
return 'fg-grey';
|
||||||
},
|
},
|
||||||
makeScoreColor(inputScore) {
|
makeScoreColor(inputScore) {
|
||||||
if (!inputScore || Number.isNaN(parseFloat(inputScore, 10))) return 'bg-grey';
|
if (!inputScore || Number.isNaN(parseFloat(inputScore))) return 'bg-grey';
|
||||||
const score = parseFloat(inputScore, 10);
|
const score = parseFloat(inputScore);
|
||||||
if (score >= 9) return 'bg-red';
|
if (score >= 9) return 'bg-red';
|
||||||
if (score >= 7) return 'bg-orange';
|
if (score >= 7) return 'bg-orange';
|
||||||
if (score >= 4) return 'bg-yellow';
|
if (score >= 4) return 'bg-yellow';
|
||||||
|
@ -36,7 +36,7 @@ export default {
|
|||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.eventListener) {
|
if (this.eventListener) {
|
||||||
document.removeEventListener(this.eventListener);
|
window.removeEventListener(this.eventListener);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
|
@ -148,7 +148,6 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.repo-stats {}
|
|
||||||
&:not(:last-child) {
|
&:not(:last-child) {
|
||||||
border-bottom: 1px dashed var(--widget-text-color);
|
border-bottom: 1px dashed var(--widget-text-color);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ export default {
|
|||||||
},
|
},
|
||||||
count() {
|
count() {
|
||||||
const usersChoice = this.options.count;
|
const usersChoice = this.options.count;
|
||||||
if (usersChoice && !Number.isNaN(usersChoice)) return usersChoice;
|
if (usersChoice && typeof usersChoice === 'number') return usersChoice;
|
||||||
return 10;
|
return 10;
|
||||||
},
|
},
|
||||||
endpoint() {
|
endpoint() {
|
||||||
|
@ -80,8 +80,7 @@ export default {
|
|||||||
formatDate(timestamp) {
|
formatDate(timestamp) {
|
||||||
const localFormat = navigator.language;
|
const localFormat = navigator.language;
|
||||||
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
||||||
const date = new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
return new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||||
return date;
|
|
||||||
},
|
},
|
||||||
formatAuthor(author) {
|
formatAuthor(author) {
|
||||||
return author ? `by ${author}` : '';
|
return author ? `by ${author}` : '';
|
||||||
@ -162,7 +161,6 @@ export default {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
.post-title-wrap {}
|
|
||||||
p.post-title {
|
p.post-title {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
@ -40,7 +40,7 @@ export default {
|
|||||||
/* The number of data points to render on the chart */
|
/* The number of data points to render on the chart */
|
||||||
dataPoints() {
|
dataPoints() {
|
||||||
const userChoice = this.options.dataPoints;
|
const userChoice = this.options.dataPoints;
|
||||||
if (!Number.isNaN(userChoice) && userChoice < 100 && userChoice > 5) {
|
if (typeof usersChoice === 'number' && userChoice < 100 && userChoice > 5) {
|
||||||
return userChoice;
|
return userChoice;
|
||||||
}
|
}
|
||||||
return 30;
|
return 30;
|
||||||
@ -137,8 +137,7 @@ export default {
|
|||||||
formatDate(timestamp) {
|
formatDate(timestamp) {
|
||||||
const localFormat = navigator.language;
|
const localFormat = navigator.language;
|
||||||
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
||||||
const date = new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
return new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||||
return date;
|
|
||||||
},
|
},
|
||||||
/* Format the price, rounding to given number of decimal places */
|
/* Format the price, rounding to given number of decimal places */
|
||||||
formatPrice(priceStr) {
|
formatPrice(priceStr) {
|
||||||
|
@ -320,7 +320,7 @@ export default {
|
|||||||
/* Returns either `false` or a number in ms to continuously update widget data */
|
/* Returns either `false` or a number in ms to continuously update widget data */
|
||||||
updateInterval() {
|
updateInterval() {
|
||||||
const usersInterval = this.widget.updateInterval;
|
const usersInterval = this.widget.updateInterval;
|
||||||
if (!usersInterval) return false;
|
if (!usersInterval) return 0;
|
||||||
// If set to `true`, then default to 30 seconds
|
// If set to `true`, then default to 30 seconds
|
||||||
if (typeof usersInterval === 'boolean') return 30 * 1000;
|
if (typeof usersInterval === 'boolean') return 30 * 1000;
|
||||||
// If set to a number, and within valid range, return user choice
|
// If set to a number, and within valid range, return user choice
|
||||||
@ -329,7 +329,7 @@ export default {
|
|||||||
&& usersInterval < 7200) {
|
&& usersInterval < 7200) {
|
||||||
return usersInterval * 1000;
|
return usersInterval * 1000;
|
||||||
}
|
}
|
||||||
return false;
|
return 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="widget-error"></div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'WidgetError',
|
|
||||||
props: {
|
|
||||||
errorMessage: String,
|
|
||||||
},
|
|
||||||
computed: {},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped lang="scss">
|
|
||||||
.widget-error {}
|
|
||||||
</style>
|
|
@ -31,10 +31,8 @@ export default {
|
|||||||
return 'latest';
|
return 'latest';
|
||||||
} else if (usersChoice === 'random') {
|
} else if (usersChoice === 'random') {
|
||||||
return Math.abs(Math.floor(Math.random() * (1 - 2553)));
|
return Math.abs(Math.floor(Math.random() * (1 - 2553)));
|
||||||
} else if (usersChoice) {
|
|
||||||
return usersChoice;
|
|
||||||
}
|
}
|
||||||
return 'latest';
|
return usersChoice;
|
||||||
},
|
},
|
||||||
endpoint() {
|
endpoint() {
|
||||||
return `${widgetApiEndpoints.xkcdComic}?comic=${this.comicNumber}`;
|
return `${widgetApiEndpoints.xkcdComic}?comic=${this.comicNumber}`;
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* Mixin for helper functions, used for making chart widgets
|
* Mixin for helper functions, used for making chart widgets
|
||||||
*/
|
*/
|
||||||
// import ErrorHandler from '@/utils/ErrorHandler';
|
|
||||||
import { Chart } from 'frappe-charts/dist/frappe-charts.min.esm';
|
import { Chart } from 'frappe-charts/dist/frappe-charts.min.esm';
|
||||||
|
|
||||||
const WidgetMixin = {
|
const ChartingMixin = {
|
||||||
props: {},
|
props: {},
|
||||||
computed: {
|
computed: {
|
||||||
chartHeight() {
|
chartHeight() {
|
||||||
@ -29,15 +28,13 @@ const WidgetMixin = {
|
|||||||
formatDate(timestamp) {
|
formatDate(timestamp) {
|
||||||
const localFormat = navigator.language;
|
const localFormat = navigator.language;
|
||||||
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
const dateFormat = { weekday: 'short', day: 'numeric', month: 'short' };
|
||||||
const date = new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
return new Date(timestamp).toLocaleDateString(localFormat, dateFormat);
|
||||||
return date;
|
|
||||||
},
|
},
|
||||||
/* Format the time for a given time stamp */
|
/* Format the time for a given time stamp */
|
||||||
formatTime(timestamp) {
|
formatTime(timestamp) {
|
||||||
const localFormat = navigator.language;
|
const localFormat = navigator.language;
|
||||||
const timeFormat = { hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
const timeFormat = { hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
||||||
const time = Intl.DateTimeFormat(localFormat, timeFormat).format(timestamp);
|
return Intl.DateTimeFormat(localFormat, timeFormat).format(timestamp);
|
||||||
return time;
|
|
||||||
},
|
},
|
||||||
/* Given an array of numbers, returns the average of all */
|
/* Given an array of numbers, returns the average of all */
|
||||||
average(array) {
|
average(array) {
|
||||||
@ -46,4 +43,4 @@ const WidgetMixin = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default WidgetMixin;
|
export default ChartingMixin;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Mixin for all homepages (default home, minimal home, workspace, etc)
|
* Mixin for all homepages (default home, minimal home, workspace, etc)
|
||||||
*/
|
*/
|
||||||
// import ErrorHandler from '@/utils/ErrorHandler';
|
|
||||||
|
|
||||||
import Defaults, { localStorageKeys, iconCdns } from '@/utils/defaults';
|
import Defaults, { localStorageKeys, iconCdns } from '@/utils/defaults';
|
||||||
import { searchTiles } from '@/utils/Search';
|
import { searchTiles } from '@/utils/Search';
|
||||||
@ -48,16 +47,14 @@ const HomeMixin = {
|
|||||||
},
|
},
|
||||||
/* Checks if any sections or items use icons from a given CDN */
|
/* Checks if any sections or items use icons from a given CDN */
|
||||||
checkIfIconLibraryNeeded(prefix) {
|
checkIfIconLibraryNeeded(prefix) {
|
||||||
let isNeeded = false;
|
|
||||||
if (!this.sections) return false;
|
if (!this.sections) return false;
|
||||||
|
let isNeeded = false; // Will be set to true if prefix found in icon name
|
||||||
this.sections.forEach((section) => {
|
this.sections.forEach((section) => {
|
||||||
if (section) {
|
if (section && section.icon && section.icon.includes(prefix)) isNeeded = true;
|
||||||
if (section.icon && section.icon.includes(prefix)) isNeeded = true;
|
if (section && section.items) {
|
||||||
if (section.items) {
|
section.items.forEach((item) => {
|
||||||
section.items.forEach((item) => {
|
if (item.icon && item.icon.includes(prefix)) isNeeded = true;
|
||||||
if (item.icon && item.icon.includes(prefix)) isNeeded = true;
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return isNeeded;
|
return isNeeded;
|
||||||
|
@ -66,8 +66,7 @@ export const timestampToDate = (timestamp) => {
|
|||||||
export const timestampToTime = (timestamp) => {
|
export const timestampToTime = (timestamp) => {
|
||||||
const localFormat = navigator.language;
|
const localFormat = navigator.language;
|
||||||
const timeFormat = { hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
const timeFormat = { hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
||||||
const time = Intl.DateTimeFormat(localFormat, timeFormat).format(new Date(timestamp));
|
return Intl.DateTimeFormat(localFormat, timeFormat).format(new Date(timestamp));
|
||||||
return time;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Given a timestamp, returns both human Date and Time */
|
/* Given a timestamp, returns both human Date and Time */
|
||||||
@ -134,12 +133,13 @@ export const capitalize = (str) => {
|
|||||||
/* Round price to appropriate number of decimals */
|
/* Round price to appropriate number of decimals */
|
||||||
export const roundPrice = (price) => {
|
export const roundPrice = (price) => {
|
||||||
if (Number.isNaN(price)) return price;
|
if (Number.isNaN(price)) return price;
|
||||||
let decimals = 2;
|
let decimals;
|
||||||
if (price > 1000) decimals = 0;
|
if (price > 1000) decimals = 0;
|
||||||
else if (price > 1) decimals = 2;
|
else if (price > 1) decimals = 2;
|
||||||
else if (price > 0.1) decimals = 3;
|
else if (price > 0.1) decimals = 3;
|
||||||
else if (price > 0.01) decimals = 4;
|
else if (price > 0.01) decimals = 4;
|
||||||
else if (price <= 0.01) decimals = 5;
|
else if (price <= 0.01) decimals = 5;
|
||||||
|
else decimals = 2;
|
||||||
return price.toFixed(decimals);
|
return price.toFixed(decimals);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user