mirror of https://github.com/statping/statping
removed linting from mixin
parent
49a4ff1714
commit
bd0683d5ae
|
@ -1,264 +1,264 @@
|
||||||
import Vue from 'vue';
|
import Vue from "vue";
|
||||||
const { startOfDay, startOfHour, startOfWeek, endOfMonth, endOfHour, startOfToday, startOfTomorrow, startOfYesterday, endOfYesterday, endOfTomorrow, endOfToday, endOfDay, startOfMonth, lastDayOfMonth, subSeconds, getUnixTime, fromUnixTime, differenceInSeconds, formatDistance, addMonths, addSeconds, isWithinInterval } = require('date-fns');
|
const { startOfDay, startOfHour, startOfWeek, endOfMonth, endOfHour, startOfToday, startOfTomorrow, startOfYesterday, endOfYesterday, endOfTomorrow, endOfToday, endOfDay, startOfMonth, lastDayOfMonth, subSeconds, getUnixTime, fromUnixTime, differenceInSeconds, formatDistance, addMonths, addSeconds, isWithinInterval } = require('date-fns')
|
||||||
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
|
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
|
||||||
import format from 'date-fns/format';
|
import format from 'date-fns/format'
|
||||||
import parseISO from 'date-fns/parseISO';
|
import parseISO from 'date-fns/parseISO'
|
||||||
import isBefore from 'date-fns/isBefore';
|
import isBefore from 'date-fns/isBefore'
|
||||||
import isAfter from 'date-fns/isAfter';
|
import isAfter from 'date-fns/isAfter'
|
||||||
import { roundToNearestMinutes } from 'date-fns';
|
import { roundToNearestMinutes } from 'date-fns'
|
||||||
|
|
||||||
export default Vue.mixin({
|
export default Vue.mixin({
|
||||||
methods: {
|
methods: {
|
||||||
now () {
|
now() {
|
||||||
return new Date();
|
return new Date()
|
||||||
},
|
},
|
||||||
isNumeric: function (n) {
|
isNumeric: function (n) {
|
||||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||||
},
|
},
|
||||||
current () {
|
current() {
|
||||||
return parseISO(new Date());
|
return parseISO(new Date())
|
||||||
},
|
},
|
||||||
startToday () {
|
startToday() {
|
||||||
return startOfToday();
|
return startOfToday()
|
||||||
},
|
},
|
||||||
secondsHumanize (val) {
|
secondsHumanize(val) {
|
||||||
return `${val} ${this.$t('second', val)}`;
|
return `${val} ${this.$t('second', val)}`
|
||||||
},
|
},
|
||||||
utc (val) {
|
utc(val) {
|
||||||
return new Date.UTC(val);
|
return new Date.UTC(val)
|
||||||
},
|
},
|
||||||
ago (t1) {
|
ago(t1) {
|
||||||
return formatDistanceToNow(parseISO(t1));
|
return formatDistanceToNow(parseISO(t1))
|
||||||
},
|
},
|
||||||
daysInMonth (t1) {
|
daysInMonth(t1) {
|
||||||
return lastDayOfMonth(t1);
|
return lastDayOfMonth(t1)
|
||||||
},
|
},
|
||||||
nowSubtract (seconds) {
|
nowSubtract(seconds) {
|
||||||
return subSeconds(this.now(), seconds);
|
return subSeconds(this.now(), seconds)
|
||||||
},
|
},
|
||||||
isAfter (date, compare) {
|
isAfter(date, compare) {
|
||||||
return isAfter(date, parseISO(compare));
|
return isAfter(date, parseISO(compare))
|
||||||
},
|
},
|
||||||
isBefore (date, compare) {
|
isBefore(date, compare) {
|
||||||
return isBefore(date, parseISO(compare));
|
return isBefore(date, parseISO(compare))
|
||||||
},
|
},
|
||||||
dur (t1, t2) {
|
dur(t1, t2) {
|
||||||
return formatDistance(t1, t2);
|
return formatDistance(t1, t2)
|
||||||
},
|
},
|
||||||
format (val, type = 'EEE, MMM do h:mma') {
|
format(val, type = "EEEE, MMM do h:mma") {
|
||||||
return format(val, type);
|
return format(val, type)
|
||||||
},
|
},
|
||||||
niceDate (val) {
|
niceDate(val) {
|
||||||
return format(parseISO(val), 'EEE, MMM do h:mma');
|
return format(parseISO(val), "EEEE, MMM do h:mma")
|
||||||
},
|
},
|
||||||
niceDateWithYear (val) {
|
parseISO(v) {
|
||||||
return format(parseISO(val), 'EEE, do MMM yyyy \'at\' h:mma');
|
return parseISO(v)
|
||||||
},
|
},
|
||||||
parseISO (v) {
|
round(minutes) {
|
||||||
return parseISO(v);
|
return roundToNearestMinutes(minutes)
|
||||||
},
|
},
|
||||||
round (minutes) {
|
endOf(method, val) {
|
||||||
return roundToNearestMinutes(minutes);
|
|
||||||
},
|
|
||||||
endOf (method, val) {
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'hour':
|
case "hour":
|
||||||
return endOfHour(val);
|
return endOfHour(val)
|
||||||
case 'day':
|
case "day":
|
||||||
return endOfDay(val);
|
return endOfDay(val)
|
||||||
case 'today':
|
case "today":
|
||||||
return endOfToday();
|
return endOfToday()
|
||||||
case 'tomorrow':
|
case "tomorrow":
|
||||||
return endOfTomorrow();
|
return endOfTomorrow()
|
||||||
case 'yesterday':
|
case "yesterday":
|
||||||
return endOfYesterday();
|
return endOfYesterday()
|
||||||
case 'month':
|
case "month":
|
||||||
return endOfMonth(val);
|
return endOfMonth(val)
|
||||||
}
|
}
|
||||||
return val;
|
return val
|
||||||
},
|
},
|
||||||
startEndParams (start, end, group) {
|
startEndParams(start, end, group) {
|
||||||
start = this.beginningOf('hour', start);
|
start = this.beginningOf("hour", start)
|
||||||
end = this.endOf('hour', end);
|
end = this.endOf("hour", end)
|
||||||
return { start: this.toUnix(start), end: this.toUnix(end), group: group };
|
return {start: this.toUnix(start), end: this.toUnix(end), group: group}
|
||||||
},
|
},
|
||||||
beginningOf (method, val) {
|
beginningOf(method, val) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'hour':
|
case "hour":
|
||||||
return startOfHour(val);
|
return startOfHour(val)
|
||||||
case 'day':
|
case "day":
|
||||||
return startOfDay(val);
|
return startOfDay(val)
|
||||||
case 'today':
|
case "today":
|
||||||
return startOfToday();
|
return startOfToday()
|
||||||
case 'tomorrow':
|
case "tomorrow":
|
||||||
return startOfTomorrow();
|
return startOfTomorrow()
|
||||||
case 'yesterday':
|
case "yesterday":
|
||||||
return startOfYesterday();
|
return startOfYesterday()
|
||||||
case 'week':
|
case "week":
|
||||||
return startOfWeek(val);
|
return startOfWeek(val)
|
||||||
case 'month':
|
case "month":
|
||||||
return startOfMonth(val);
|
return startOfMonth(val)
|
||||||
}
|
}
|
||||||
return val;
|
return val
|
||||||
},
|
},
|
||||||
isZero (val) {
|
isZero(val) {
|
||||||
return getUnixTime(parseISO(val)) <= 0;
|
return getUnixTime(parseISO(val)) <= 0
|
||||||
},
|
},
|
||||||
smallText (s) {
|
smallText(s) {
|
||||||
if (s.online) {
|
if (s.online) {
|
||||||
return `${this.$t('service_online_check')} ${this.ago(s.last_success)} ago`;
|
return `${this.$t('service_online_check')} ${this.ago(s.last_success)} ago`
|
||||||
} else {
|
} else {
|
||||||
const last = s.last_failure;
|
const last = s.last_failure
|
||||||
if (last) {
|
if (last) {
|
||||||
return `Offline, last error: ${last} ${this.ago(last.created_at)}`;
|
return `Offline, last error: ${last} ${this.ago(last.created_at)}`
|
||||||
}
|
}
|
||||||
if (this.isZero(s.last_success)) {
|
if (this.isZero(s.last_success)) {
|
||||||
return this.$t('service_never_online');
|
return this.$t('service_never_online')
|
||||||
}
|
}
|
||||||
return `${this.$t('service_offline_time')} ${this.ago(s.last_success)}`;
|
return `${this.$t('service_offline_time')} ${this.ago(s.last_success)}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
round_time (frame, val) {
|
round_time(frame, val) {
|
||||||
switch (frame) {
|
switch(frame) {
|
||||||
case '15m':
|
case "15m":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 60 * 15 });
|
return roundToNearestMinutes(val, {nearestTo: 60 * 15})
|
||||||
case '30m':
|
case "30m":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 60 * 30 });
|
return roundToNearestMinutes(val, {nearestTo: 60 * 30})
|
||||||
case '1h':
|
case "1h":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 3600 });
|
return roundToNearestMinutes(val, {nearestTo: 3600})
|
||||||
case '3h':
|
case "3h":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 3600 * 3 });
|
return roundToNearestMinutes(val, {nearestTo: 3600 * 3})
|
||||||
case '6h':
|
case "6h":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 3600 * 6 });
|
return roundToNearestMinutes(val, {nearestTo: 3600 * 6})
|
||||||
case '12h':
|
case "12h":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 3600 * 12 });
|
return roundToNearestMinutes(val, {nearestTo: 3600 * 12})
|
||||||
case '24h':
|
case "24h":
|
||||||
return roundToNearestMinutes(val, { nearestTo: 3600 * 24 });
|
return roundToNearestMinutes(val, {nearestTo: 3600 * 24})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toUnix (val) {
|
toUnix(val) {
|
||||||
return getUnixTime(val);
|
return getUnixTime(val)
|
||||||
},
|
},
|
||||||
fromUnix (val) {
|
fromUnix(val) {
|
||||||
return fromUnixTime(val);
|
return fromUnixTime(val)
|
||||||
},
|
},
|
||||||
isBetween (t, start, end) {
|
isBetween(t, start, end) {
|
||||||
return isWithinInterval(t, { start: parseISO(start), end: parseISO(end) });
|
return isWithinInterval(t, {start: parseISO(start), end: parseISO(end)})
|
||||||
},
|
},
|
||||||
hour () {
|
hour() {
|
||||||
return 3600;
|
return 3600
|
||||||
},
|
},
|
||||||
day () {
|
day() {
|
||||||
return 3600 * 24;
|
return 3600 * 24
|
||||||
},
|
},
|
||||||
maxDate () {
|
maxDate() {
|
||||||
return new Date(8640000000000000);
|
return new Date(8640000000000000)
|
||||||
},
|
},
|
||||||
copy (txt) {
|
copy(txt) {
|
||||||
this.$copyText(txt).then((e) => {
|
this.$copyText(txt).then(function (e) {
|
||||||
alert('Copied: \n' + txt);
|
alert('Copied: \n' + txt)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
serviceLink (service) {
|
serviceLink(service) {
|
||||||
if (service.permalink) {
|
if (service.permalink) {
|
||||||
service = this.$store.getters.serviceById(service.permalink);
|
service = this.$store.getters.serviceById(service.permalink)
|
||||||
}
|
}
|
||||||
if (service === undefined || this.isEmptyObject(service)) {
|
if (service === undefined || this.isEmptyObject(service)) {
|
||||||
return `/service/0`;
|
return `/service/0`
|
||||||
}
|
}
|
||||||
const link = service.permalink ? service.permalink : service.id;
|
let link = service.permalink ? service.permalink : service.id
|
||||||
return `/service/${link}`;
|
return `/service/${link}`
|
||||||
},
|
},
|
||||||
isEmptyObject (obj) {
|
isEmptyObject(obj) {
|
||||||
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
return Object.keys(obj).length === 0 && obj.constructor === Object
|
||||||
},
|
},
|
||||||
isInt (n) {
|
isInt(n) {
|
||||||
return n % 1 === 0;
|
return n % 1 === 0;
|
||||||
},
|
},
|
||||||
isAdmin () {
|
isAdmin() {
|
||||||
return this.$store.state.admin;
|
return this.$store.state.admin
|
||||||
},
|
},
|
||||||
iconName (name) {
|
iconName(name) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'fas fa-terminal':
|
case "fas fa-terminal":
|
||||||
return 'terminal';
|
return "terminal"
|
||||||
case 'fab fa-discord':
|
case "fab fa-discord":
|
||||||
return [ 'fab', 'discord' ];
|
return ["fab", "discord"]
|
||||||
case 'far fa-envelope':
|
case "far fa-envelope":
|
||||||
return 'envelope';
|
return "envelope"
|
||||||
case 'far fa-bell':
|
case "far fa-bell":
|
||||||
return 'bell';
|
return "bell"
|
||||||
case 'fas fa-mobile-alt':
|
case "fas fa-mobile-alt":
|
||||||
return 'mobile';
|
return "mobile"
|
||||||
case 'fa dot-circle':
|
case "fa dot-circle":
|
||||||
return [ 'fa', 'dot-circle' ];
|
return ["fa", "dot-circle"]
|
||||||
case 'fas envelope-square':
|
case "fas envelope-square":
|
||||||
return [ 'fas', 'envelope-square' ];
|
return ["fas", "envelope-square"]
|
||||||
case 'fab fa-slack':
|
case "fab fa-slack":
|
||||||
return [ 'fab', 'slack-hash' ];
|
return ["fab", "slack-hash"]
|
||||||
case 'fab fa-telegram-plane':
|
case "fab fa-telegram-plane":
|
||||||
return [ 'fab', 'telegram-plane' ];
|
return ["fab", "telegram-plane"]
|
||||||
case 'far fa-comment-alt':
|
case "far fa-comment-alt":
|
||||||
return 'comment';
|
return "comment"
|
||||||
case 'fas fa-code-branch':
|
case "fas fa-code-branch":
|
||||||
return 'code-branch';
|
return "code-branch"
|
||||||
case 'csv':
|
case "csv":
|
||||||
return 'file';
|
return "file"
|
||||||
case 'docker':
|
case "docker":
|
||||||
return [ 'fab', 'docker' ];
|
return ["fab", "docker"]
|
||||||
case 'traefik':
|
case "traefik":
|
||||||
return 'server';
|
return "server"
|
||||||
default:
|
default:
|
||||||
return 'bars';
|
return "bars"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toBarData (data = []) {
|
toBarData(data = []) {
|
||||||
const newSet = [];
|
let newSet = [];
|
||||||
data.forEach((f) => {
|
data.forEach((f) => {
|
||||||
newSet.push([ this.toUnix(this.parseISO(f.timeframe)), f.amount ]);
|
newSet.push([this.toUnix(this.parseISO(f.timeframe)), f.amount])
|
||||||
});
|
})
|
||||||
return newSet;
|
return newSet
|
||||||
},
|
},
|
||||||
convertToChartData (data = [], multiplier = 1, asInt = false) {
|
convertToChartData(data = [], multiplier = 1, asInt = false) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return { data: [] };
|
return {data: []}
|
||||||
}
|
}
|
||||||
const newSet = [];
|
let newSet = [];
|
||||||
data.forEach((f) => {
|
data.forEach((f) => {
|
||||||
let amount = f.amount * multiplier;
|
let amount = f.amount * multiplier;
|
||||||
if (asInt) {
|
if (asInt) {
|
||||||
amount = amount.toFixed(0);
|
amount = amount.toFixed(0)
|
||||||
}
|
}
|
||||||
newSet.push({
|
newSet.push({
|
||||||
x: f.timeframe,
|
x: f.timeframe,
|
||||||
y: amount
|
y: amount
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
return { data: newSet };
|
return {data: newSet}
|
||||||
},
|
},
|
||||||
humanTime (val) {
|
humanTime(val) {
|
||||||
if (val >= 1000) {
|
if (val >= 1000) {
|
||||||
return Math.round(val / 1000) + ' ms';
|
return Math.round(val / 1000) + " ms"
|
||||||
}
|
}
|
||||||
return val + ' μs';
|
return val + " μs"
|
||||||
},
|
},
|
||||||
humanTimeNum (val) {
|
humanTimeNum(val) {
|
||||||
if (val >= 1000) {
|
if (val >= 1000) {
|
||||||
return Math.round(val / 1000);
|
return Math.round(val / 1000)
|
||||||
}
|
}
|
||||||
return val;
|
return val
|
||||||
},
|
},
|
||||||
firstDayOfMonth (date) {
|
firstDayOfMonth(date) {
|
||||||
return startOfMonth(date);
|
return startOfMonth(date)
|
||||||
},
|
},
|
||||||
lastDayOfMonth (month) {
|
lastDayOfMonth(month) {
|
||||||
return lastDayOfMonth(month);
|
return lastDayOfMonth(month)
|
||||||
},
|
},
|
||||||
addMonths (date, amount) {
|
addMonths(date, amount) {
|
||||||
return addMonths(date, amount);
|
return addMonths(date, amount)
|
||||||
},
|
},
|
||||||
addSeconds (date, amount) {
|
addSeconds(date, amount) {
|
||||||
return addSeconds(date, amount);
|
return addSeconds(date, amount)
|
||||||
}
|
},
|
||||||
}
|
niceDateWithYear (val) {
|
||||||
|
return format(parseISO(val), 'EEE, do MMM yyyy \'at\' h:mma');
|
||||||
|
},
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue