This commit is contained in:
Mike Cao 2022-09-05 10:44:28 -07:00
commit 912b63da82
29 changed files with 209 additions and 61 deletions

2
.gitignore vendored
View File

@ -36,5 +36,5 @@ yarn-error.log*
.env.test.local
.env.production.local
*.development.yml
*.dev.yml

View File

@ -18,6 +18,10 @@ export const filterOptions = [
),
value: '24hour',
},
{
label: <FormattedMessage id="label.yesterday" defaultMessage="Yesterday" />,
value: '-1day',
},
{
label: <FormattedMessage id="label.this-week" defaultMessage="This week" />,
value: '1week',

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { Formik, Form, Field } from 'formik';
import { Formik, Form, Field, useFormikContext } from 'formik';
import Button from 'components/common/Button';
import FormLayout, {
FormButtons,
@ -11,10 +11,14 @@ import FormLayout, {
import Checkbox from 'components/common/Checkbox';
import { DOMAIN_REGEX } from 'lib/constants';
import useApi from 'hooks/useApi';
import useFetch from 'hooks/useFetch';
import useUser from 'hooks/useUser';
import styles from './WebsiteEditForm.module.css';
const initialValues = {
name: '',
domain: '',
owner: '',
public: false,
};
@ -33,8 +37,45 @@ const validate = ({ name, domain }) => {
return errors;
};
const OwnerDropDown = ({ user, accounts }) => {
console.info(styles);
const { setFieldValue, values } = useFormikContext();
useEffect(() => {
if (values.user_id != null && values.owner === '') {
setFieldValue('owner', values.user_id.toString());
} else if (user?.user_id && values.owner === '') {
setFieldValue('owner', user.user_id.toString());
}
}, [accounts, setFieldValue, user, values]);
if (user?.is_admin) {
return (
<FormRow>
<label htmlFor="owner">
<FormattedMessage id="label.owner" defaultMessage="Owner" />
</label>
<div>
<Field as="select" name="owner" className={styles.dropdown}>
{accounts?.map(acc => (
<option key={acc.user_id} value={acc.user_id}>
{acc.username}
</option>
))}
</Field>
<FormError name="owner" />
</div>
</FormRow>
);
} else {
return null;
}
};
export default function WebsiteEditForm({ values, onSave, onClose }) {
const { post } = useApi();
const { data: accounts } = useFetch(`/accounts`);
const { user } = useUser();
const [message, setMessage] = useState();
const handleSubmit = async values => {
@ -72,10 +113,18 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
<FormattedMessage id="label.domain" defaultMessage="Domain" />
</label>
<div>
<Field name="domain" type="text" placeholder="example.com" />
<Field
name="domain"
type="text"
placeholder="example.com"
spellcheck="false"
autocapitalize="off"
autocorrect="off"
/>
<FormError name="domain" />
</div>
</FormRow>
<OwnerDropDown accounts={accounts} user={user} />
<FormRow>
<label />
<Field name="enable_share_url">

View File

@ -0,0 +1,5 @@
.dropdown {
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
}

View File

@ -24,7 +24,8 @@
flex: 1 1;
}
.row > div > input {
.row > div > input,
.row > div > select {
width: 100%;
min-width: 240px;
}

View File

@ -36,7 +36,7 @@ export default function DashboardEdit({ websites }) {
const [removed] = orderedWebsites.splice(source.index, 1);
orderedWebsites.splice(destination.index, 0, removed);
setOrder(orderedWebsites.map(({ website_id }) => website_id));
setOrder(orderedWebsites.map((website) => website?.website_id || 0));
}
function handleSave() {

View File

@ -8,7 +8,7 @@ datasource db {
}
model account {
user_id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
user_id Int @id @default(autoincrement()) @db.UnsignedInt
username String @unique() @db.VarChar(255)
password String @db.VarChar(60)
is_admin Boolean @default(false)
@ -18,9 +18,9 @@ model account {
}
model event {
event_id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
website_id BigInt @db.UnsignedBigInt
session_id BigInt @db.UnsignedBigInt
event_id Int @id @default(autoincrement()) @db.UnsignedInt
website_id Int @db.UnsignedInt
session_id Int @db.UnsignedInt
created_at DateTime? @default(now()) @db.Timestamp(0)
url String @db.VarChar(500)
event_name String @db.VarChar(50)
@ -34,16 +34,16 @@ model event {
}
model event_data {
event_data_id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
event_id BigInt @unique @db.UnsignedBigInt
event_data_id Int @id @default(autoincrement()) @db.UnsignedInt
event_id Int @unique @db.UnsignedInt
event_data Json
event event @relation(fields: [event_id], references: [event_id])
event event @relation(fields: [event_id], references: [event_id])
}
model pageview {
view_id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
website_id BigInt @db.UnsignedBigInt
session_id BigInt @db.UnsignedBigInt
view_id Int @id @default(autoincrement()) @db.UnsignedInt
website_id Int @db.UnsignedInt
session_id Int @db.UnsignedInt
created_at DateTime? @default(now()) @db.Timestamp(0)
url String @db.VarChar(500)
referrer String? @db.VarChar(500)
@ -58,9 +58,9 @@ model pageview {
}
model session {
session_id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
session_id Int @id @default(autoincrement()) @db.UnsignedInt
session_uuid String @unique() @db.VarChar(36)
website_id BigInt @db.UnsignedBigInt
website_id Int @db.UnsignedInt
created_at DateTime? @default(now()) @db.Timestamp(0)
hostname String? @db.VarChar(100)
browser String? @db.VarChar(20)
@ -78,9 +78,9 @@ model session {
}
model website {
website_id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
website_id Int @id @default(autoincrement()) @db.UnsignedInt
website_uuid String @unique() @db.VarChar(36)
user_id BigInt @db.UnsignedBigInt
user_id Int @db.UnsignedInt
name String @db.VarChar(100)
domain String? @db.VarChar(500)
share_id String? @unique() @db.VarChar(64)

View File

@ -62,6 +62,7 @@
"label.username": "Nom d'usuari",
"label.view-details": "Veure els detalls",
"label.websites": "Llocs web",
"label.yesterday": "Ahir",
"message.active-users": "{x} {x, plural, one {visitant actual} other {visitants actuals}}",
"message.confirm-delete": "Segur que vols esborrar {target}?",
"message.confirm-reset": "Segur que vols restablir les estadístiques de {target}?",

View File

@ -62,6 +62,7 @@
"label.username": "Benutzername",
"label.view-details": "Details anzeigen",
"label.websites": "Webseiten",
"label.yesterday": "Gestern",
"message.active-users": "{x} {x, plural, one {aktiver Besucher} other {aktive Besucher}}",
"message.confirm-delete": "Sind Sie sich sicher, {target} zu löschen?",
"message.confirm-reset": "Sind Sie sicher, dass Sie die Statistiken von {target} zurücksetzen wollen?",

View File

@ -62,6 +62,7 @@
"label.username": "Username",
"label.view-details": "View details",
"label.websites": "Websites",
"label.yesterday": "Yesterday",
"message.active-users": "{x} current {x, plural, one {visitor} other {visitors}}",
"message.confirm-delete": "Are you sure you want to delete {target}?",
"message.confirm-reset": "Are you sure you want to reset {target}'s statistics?",

View File

@ -62,6 +62,7 @@
"label.username": "Username",
"label.view-details": "View details",
"label.websites": "Websites",
"label.yesterday": "Yesterday",
"message.active-users": "{x} current {x, plural, one {visitor} other {visitors}}",
"message.confirm-delete": "Are you sure you want to delete {target}?",
"message.confirm-reset": "Are you sure you want to reset {target}'s statistics?",

View File

@ -62,6 +62,7 @@
"label.username": "Nombre de usuario",
"label.view-details": "Ver detalles",
"label.websites": "Sitios",
"label.yesterday": "Ayer",
"message.active-users": "{x} {x, plural, one {activo} other {activos}}",
"message.confirm-delete": "¿Estás seguro(a) de querer eliminar {target}?",
"message.confirm-reset": "¿Seguro que deseas restablecer las estadísticas de {target}?",

View File

@ -5,7 +5,7 @@
"label.administrator": "Administrateur",
"label.all": "Tout",
"label.all-time": "Toutes les données",
"label.all-websites": "Tous les sites web",
"label.all-websites": "Tous les sites",
"label.back": "Retour",
"label.cancel": "Annuler",
"label.change-password": "Changer le mot de passe",
@ -52,7 +52,7 @@
"label.share-url": "Partager l'URL",
"label.single-day": "Journée",
"label.theme": "Thème",
"label.this-month": "Ce mois ci",
"label.this-month": "Ce mois",
"label.this-week": "Cette semaine",
"label.this-year": "Cette année",
"label.timezone": "Fuseau horaire",
@ -62,12 +62,13 @@
"label.username": "Nom d'utilisateur",
"label.view-details": "Voir les details",
"label.websites": "Sites",
"label.yesterday": "Hier",
"message.active-users": "{x} {x, plural, one {visiteur} other {visiteurs}} actuellement",
"message.confirm-delete": "Êtes-vous sûr de vouloir supprimer {target} ?",
"message.confirm-reset": "Êtes-vous sûr de vouloir réinistialiser les statistiques de {target} ?",
"message.confirm-reset": "Êtes-vous sûr de vouloir réinitialiser les statistiques de {target} ?",
"message.copied": "Copié !",
"message.delete-warning": "Toutes les données associées seront également supprimées.",
"message.edit-dashboard": "Modifier l'ordre des sites",
"message.edit-dashboard": "Modifier le tableau de bord",
"message.failure": "Un problème est survenu.",
"message.get-share-url": "Obtenir l'URL de partage",
"message.get-tracking-code": "Obtenir le code de suivi",
@ -76,14 +77,14 @@
"message.log.visitor": "Visiteur de {country} utilisant {browser} sur {os} {device}",
"message.new-version-available": "Une nouvelle version de umami {version} est disponible !",
"message.no-data-available": "Pas de données disponibles.",
"message.no-websites-configured": "Vous n'avez configuré aucun site Web.",
"message.no-websites-configured": "Vous n'avez configuré aucun site.",
"message.page-not-found": "Page non trouvée.",
"message.powered-by": "Propulsé par {name}",
"message.reset-warning": "Toutes les statistiques pour ce site seront supprimés, mais votre code de suivi restera intact.",
"message.reset-warning": "Toutes les statistiques pour ce site seront supprimées, mais votre code de suivi restera intact.",
"message.save-success": "Enregistré avec succès.",
"message.share-url": "Ceci est l'URL partagée pour {target}.",
"message.toggle-charts": "Afficher/Masquer les graphiques",
"message.track-stats": "Pour suivre les statistiques de {target}, placez le code suivant dans la section {head} de votre site Web.",
"message.track-stats": "Pour suivre les statistiques de {target}, placez le code suivant dans la section {head} de votre site.",
"message.type-delete": "Tapez {delete} dans la case ci-dessous pour confirmer.",
"message.type-reset": "Tapez {reset} dans la case ci-dessous pour confirmer.",
"metrics.actions": "Actions",
@ -99,13 +100,13 @@
"metrics.events": "Événements",
"metrics.filter.combined": "Combiné",
"metrics.filter.raw": "Brut",
"metrics.languages": "Langages",
"metrics.languages": "Langues",
"metrics.operating-systems": "Systèmes d'exploitation",
"metrics.page-views": "Pages vues",
"metrics.pages": "Pages",
"metrics.query-parameters": "Query parameters",
"metrics.query-parameters": "Paramètres d'URL",
"metrics.referrers": "Sources",
"metrics.screens": "Tailles d'écran",
"metrics.screens": "Résolutions d'écran",
"metrics.unique-visitors": "Visiteurs uniques",
"metrics.views": "Vues",
"metrics.visitors": "Visiteurs"

View File

@ -62,6 +62,7 @@
"label.username": "Nome utente",
"label.view-details": "Vedi dettagli",
"label.websites": "Siti web",
"label.yesterday": "Ieri",
"message.active-users": "{x} {x, plural, one {visitatore} other {visitatori}} online",
"message.confirm-delete": "Sei sicuro di voler eliminare {target}?",
"message.confirm-reset": "Sei sicuro di voler azzerare le statistiche di {target}?",

View File

@ -7,6 +7,8 @@ import {
addYears,
subHours,
subDays,
subMonths,
subYears,
startOfMinute,
startOfHour,
startOfDay,
@ -39,7 +41,7 @@ export function getDateRange(value, locale = 'en-US') {
const now = new Date();
const dateLocale = getDateLocale(locale);
const match = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/);
const match = value.match(/^(?<num>[0-9-]+)(?<unit>hour|day|week|month|year)$/);
if (!match) return;
@ -78,6 +80,39 @@ export function getDateRange(value, locale = 'en-US') {
}
}
if (+num === -1) {
switch (unit) {
case 'day':
return {
startDate: subDays(startOfDay(now), 1),
endDate: subDays(endOfDay(now), 1),
unit: 'hour',
value,
};
case 'week':
return {
startDate: subDays(startOfWeek(now, { locale: dateLocale }), 7),
endDate: subDays(endOfWeek(now, { locale: dateLocale }), 1),
unit: 'day',
value,
};
case 'month':
return {
startDate: subMonths(startOfMonth(now), 1),
endDate: subMonths(endOfMonth(now), 1),
unit: 'day',
value,
};
case 'year':
return {
startDate: subYears(startOfYear(now), 1),
endDate: subYears(endOfYear(now), 1),
unit: 'month',
value,
};
}
}
switch (unit) {
case 'day':
return {

View File

@ -9,6 +9,10 @@ const INITIALIZED = 'redis:initialized';
export const DELETED = 'deleted';
function getClient() {
if (!process.env.REDIS_URL) {
return null;
}
const redis = new Redis(process.env.REDIS_URL);
if (process.env.NODE_ENV !== 'production') {

View File

@ -83,7 +83,7 @@
"isbot": "^3.4.5",
"kafkajs": "^2.1.0",
"maxmind": "^4.3.6",
"moment-timezone": "^0.5.33",
"moment-timezone": "^0.5.35",
"next": "^12.2.5",
"next-basics": "^0.6.0",
"node-fetch": "^3.2.8",

View File

@ -10,7 +10,8 @@ export default async (req, res) => {
const { website_id, enable_share_url } = req.body;
if (req.method === 'POST') {
const { name, domain } = req.body;
const { name, domain, owner } = req.body;
const website_owner = parseInt(owner);
if (website_id) {
const website = await getWebsiteById(website_id);
@ -27,13 +28,13 @@ export default async (req, res) => {
share_id = null;
}
await updateWebsite(website_id, { name, domain, share_id });
await updateWebsite(website_id, { name, domain, share_id, user_id: website_owner });
return ok(res);
} else {
const website_uuid = uuid();
const share_id = enable_share_url ? getRandomChars(8) : null;
const website = await createWebsite(user_id, { website_uuid, name, domain, share_id });
const website = await createWebsite(website_owner, { website_uuid, name, domain, share_id });
return ok(res, website);
}

View File

@ -397,6 +397,12 @@
"value": "Llocs web"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Ahir"
}
],
"message.active-users": [
{
"type": 1,

View File

@ -397,6 +397,12 @@
"value": "Webseiten"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Gestern"
}
],
"message.active-users": [
{
"type": 1,

View File

@ -397,6 +397,12 @@
"value": "Websites"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Yesterday"
}
],
"message.active-users": [
{
"type": 1,

View File

@ -397,6 +397,12 @@
"value": "Websites"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Yesterday"
}
],
"message.active-users": [
{
"type": 1,

View File

@ -397,6 +397,12 @@
"value": "Sitios"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Ayer"
}
],
"message.active-users": [
{
"type": 1,

View File

@ -38,7 +38,7 @@
"label.all-websites": [
{
"type": 0,
"value": "Tous les sites web"
"value": "Tous les sites"
}
],
"label.back": [
@ -332,7 +332,7 @@
"label.this-month": [
{
"type": 0,
"value": "Ce mois ci"
"value": "Ce mois"
}
],
"label.this-week": [
@ -389,6 +389,12 @@
"value": "Sites"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Hier"
}
],
"message.active-users": [
{
"type": 1,
@ -444,7 +450,7 @@
"message.confirm-reset": [
{
"type": 0,
"value": "Êtes-vous sûr de vouloir réinistialiser les statistiques de "
"value": "Êtes-vous sûr de vouloir réinitialiser les statistiques de "
},
{
"type": 1,
@ -470,7 +476,7 @@
"message.edit-dashboard": [
{
"type": 0,
"value": "Modifier l'ordre des sites"
"value": "Modifier le tableau de bord"
}
],
"message.failure": [
@ -560,7 +566,7 @@
"message.no-websites-configured": [
{
"type": 0,
"value": "Vous n'avez configuré aucun site Web."
"value": "Vous n'avez configuré aucun site."
}
],
"message.page-not-found": [
@ -582,7 +588,7 @@
"message.reset-warning": [
{
"type": 0,
"value": "Toutes les statistiques pour ce site seront supprimés, mais votre code de suivi restera intact."
"value": "Toutes les statistiques pour ce site seront supprimées, mais votre code de suivi restera intact."
}
],
"message.save-success": [
@ -630,7 +636,7 @@
},
{
"type": 0,
"value": " de votre site Web."
"value": " de votre site."
}
],
"message.type-delete": [
@ -742,7 +748,7 @@
"metrics.languages": [
{
"type": 0,
"value": "Langages"
"value": "Langues"
}
],
"metrics.operating-systems": [
@ -766,7 +772,7 @@
"metrics.query-parameters": [
{
"type": 0,
"value": "Query parameters"
"value": "Paramètres d'URL"
}
],
"metrics.referrers": [
@ -778,7 +784,7 @@
"metrics.screens": [
{
"type": 0,
"value": "Tailles d'écran"
"value": "Résolutions d'écran"
}
],
"metrics.unique-visitors": [

View File

@ -397,6 +397,12 @@
"value": "Siti web"
}
],
"label.yesterday": [
{
"type": 0,
"value": "Ieri"
}
],
"message.active-users": [
{
"type": 1,

View File

@ -4,12 +4,16 @@ import redis, { DELETED } from 'lib/redis';
export async function deleteAccount(user_id) {
const { client } = prisma;
const websiteUuids = await client.website
.findMany({
where: { user_id },
select: { website_uuid: true },
})
.map(a => a.website_uuid);
const websites = await client.website.findMany({
where: { user_id },
select: { website_uuid: true },
});
let websiteUuids = [];
if (websites.length > 0) {
websiteUuids = websites.map(a => a.website_uuid);
}
return client
.$transaction([

View File

@ -1,5 +1,4 @@
import prisma from 'lib/prisma';
import redis from 'lib/redis';
export async function resetWebsite(website_id) {
const { client, transaction } = prisma;
@ -17,9 +16,5 @@ export async function resetWebsite(website_id) {
client.session.deleteMany({
where: { website: { website_id } },
}),
]).then(async res => {
if (redis.client) {
await redis.del(`website:${res.website_uuid}`);
}
});
]);
}

View File

@ -84,6 +84,7 @@ a:visited {
input[type='text'],
input[type='password'],
select,
textarea {
color: var(--gray900);
background: var(--gray50);

View File

@ -4694,10 +4694,10 @@ mmdb-lib@2.0.2:
resolved "https://registry.npmjs.org/mmdb-lib/-/mmdb-lib-2.0.2.tgz"
integrity sha512-shi1I+fCPQonhTi7qyb6hr7hi87R7YS69FlfJiMFuJ12+grx0JyL56gLNzGTYXPU7EhAPkMLliGeyHer0K+AVA==
moment-timezone@^0.5.33:
version "0.5.37"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.37.tgz#adf97f719c4e458fdb12e2b4e87b8bec9f4eef1e"
integrity sha512-uEDzDNFhfaywRl+vwXxffjjq1q0Vzr+fcQpQ1bU0kbzorfS7zVtZnCnGc8mhWmF39d4g4YriF6kwA75mJKE/Zg==
moment-timezone@^0.5.35:
version "0.5.35"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.35.tgz#6fa2631bdbe8ff04f6b8753f7199516be6dc9839"
integrity sha512-cY/pBOEXepQvlgli06ttCTKcIf8cD1nmNwOKQQAdHBqYApQSpAqotBMX0RJZNgMp6i0PlZuf1mFtnlyEkwyvFw==
dependencies:
moment ">= 2.9.0"