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