mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Website components. Update chart component.
This commit is contained in:
parent
d81ee3932d
commit
bdcdcd9d13
9 changed files with 165 additions and 43 deletions
28
lib/date.js
28
lib/date.js
|
|
@ -1,5 +1,5 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { addMinutes } from 'date-fns';
|
||||
import { addMinutes, endOfDay, subDays, subHours } from 'date-fns';
|
||||
|
||||
export function getTimezone() {
|
||||
const tz = moment.tz.guess();
|
||||
|
|
@ -9,3 +9,29 @@ export function getTimezone() {
|
|||
export function getLocalTime(t) {
|
||||
return addMinutes(new Date(t), new Date().getTimezoneOffset());
|
||||
}
|
||||
|
||||
export function getDateRange(value) {
|
||||
const now = new Date();
|
||||
const endToday = endOfDay(now);
|
||||
|
||||
switch (value) {
|
||||
case '7d':
|
||||
return {
|
||||
startDate: subDays(endToday, 7),
|
||||
endDate: endToday,
|
||||
unit: 'day',
|
||||
};
|
||||
case '30d':
|
||||
return {
|
||||
startDate: subDays(endToday, 30),
|
||||
endDate: endToday,
|
||||
unit: 'day',
|
||||
};
|
||||
default:
|
||||
return {
|
||||
startDate: subHours(now, 24),
|
||||
endDate: now,
|
||||
unit: 'hour',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
18
lib/db.js
18
lib/db.js
|
|
@ -1,13 +1,27 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
export const prisma = new PrismaClient({
|
||||
const options = {
|
||||
log: [
|
||||
{
|
||||
emit: 'event',
|
||||
level: 'query',
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
let prisma;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient(options);
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient(options);
|
||||
}
|
||||
|
||||
prisma = global.prisma;
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
|
||||
prisma.on('query', e => {
|
||||
if (process.env.LOG_QUERY) {
|
||||
|
|
|
|||
23
lib/web.js
23
lib/web.js
|
|
@ -7,17 +7,20 @@ export const apiRequest = (method, url, body) =>
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
}).then(res => (res.ok ? res.json() : null));
|
||||
}).then(res => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
function parseQuery(url, params) {
|
||||
const query =
|
||||
params &&
|
||||
Object.keys(params).reduce((values, key) => {
|
||||
if (params[key] !== undefined) {
|
||||
return values.concat(`${key}=${encodeURIComponent(params[key])}`);
|
||||
}
|
||||
return values;
|
||||
}, []);
|
||||
function parseQuery(url, params = {}) {
|
||||
const query = Object.keys(params).reduce((values, key) => {
|
||||
if (params[key] !== undefined) {
|
||||
return values.concat(`${key}=${encodeURIComponent(params[key])}`);
|
||||
}
|
||||
return values;
|
||||
}, []);
|
||||
return query.length ? `${url}?${query.join('&')}` : url;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue