Compare commits
7 Commits
a9f2e11fe6
...
main
Author | SHA1 | Date | |
---|---|---|---|
fdc8525abe | |||
8075d1fe1f | |||
8709989fbe | |||
![]() |
b0d6bb5512 | ||
![]() |
690b7f4034 | ||
![]() |
fdf56a4c0b | ||
![]() |
a908db4f38 |
7
.editorconfig
Normal file
@@ -0,0 +1,7 @@
|
||||
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}]
|
||||
charset = utf-8
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
120
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,120 @@
|
||||
name: Build Quasar SPA and Go Backend for memberApp
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
build-spa:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Install Quasar CLI
|
||||
run: |
|
||||
npm cache clean --force
|
||||
npm install -g @quasar/cli --force
|
||||
|
||||
- name: Build Quasar SPA
|
||||
run: quasar build
|
||||
|
||||
- name: Upload SPA artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: quasar-dist
|
||||
path: ./dist/spa
|
||||
|
||||
build-backend:
|
||||
needs: build-spa
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- goos: windows
|
||||
arch: amd64
|
||||
ext: .exe
|
||||
- goos: linux
|
||||
arch: amd64
|
||||
ext: ""
|
||||
- goos: linux
|
||||
arch: arm64
|
||||
ext: ""
|
||||
- goos: linux
|
||||
arch: arm
|
||||
arm_version: 6
|
||||
ext: ""
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download SPA artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: quasar-dist
|
||||
path: ./dist/spa
|
||||
|
||||
- name: Ensure latest Go is installed in /data/go
|
||||
run: |
|
||||
export GOROOT=/data/go/go
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
export GOCACHE=/data/gocache
|
||||
export GOMODCACHE=/data/gomodcache
|
||||
mkdir -p $GOCACHE $GOMODCACHE
|
||||
|
||||
if [ ! -x "$GOROOT/bin/go" ]; then
|
||||
echo "Go not found in $GOROOT, downloading latest stable..."
|
||||
GO_VERSION=$(curl -s https://go.dev/VERSION?m=text | head -n1)
|
||||
echo "Latest version is $GO_VERSION"
|
||||
mkdir -p /data/go
|
||||
curl -sSL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tar.gz
|
||||
tar -C /data/go -xzf /tmp/go.tar.gz
|
||||
else
|
||||
echo "Using cached Go from $GOROOT"
|
||||
fi
|
||||
|
||||
go version
|
||||
|
||||
- name: Go Mod Tidy & Download
|
||||
working-directory: ./backend
|
||||
run: |
|
||||
export GOROOT=/data/go/go
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
export GOCACHE=/data/gocache
|
||||
export GOMODCACHE=/data/gomodcache
|
||||
mkdir -p $GOCACHE $GOMODCACHE
|
||||
go mod tidy -v
|
||||
go mod download
|
||||
|
||||
- name: Build Go backend binary
|
||||
working-directory: ./backend
|
||||
run: |
|
||||
export GOROOT=/data/go/go
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
export GOCACHE=/data/gocache
|
||||
export GOMODCACHE=/data/gomodcache
|
||||
mkdir -p $GOCACHE $GOMODCACHE
|
||||
|
||||
OUTPUT="../memberApp-${{ matrix.goos }}-${{ matrix.arch }}${{ matrix.ext }}"
|
||||
if [ "${{ matrix.arch }}" = "arm" ]; then
|
||||
GOARM=${{ matrix.arm_version }}
|
||||
fi
|
||||
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT" main.go
|
||||
|
||||
- name: Upload combined package
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: memberApp-${{ matrix.goos }}-${{ matrix.arch }}
|
||||
path: |
|
||||
./dist/spa
|
||||
memberApp-${{ matrix.goos }}-${{ matrix.arch }}${{ matrix.ext }}
|
45
.gitignore
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
.DS_Store
|
||||
.thumbs.db
|
||||
node_modules
|
||||
|
||||
# Quasar core related directories
|
||||
.quasar
|
||||
/dist
|
||||
/quasar.config.*.temporary.compiled*
|
||||
|
||||
# Cordova related directories and files
|
||||
/src-cordova/node_modules
|
||||
/src-cordova/platforms
|
||||
/src-cordova/plugins
|
||||
/src-cordova/www
|
||||
|
||||
# Capacitor related directories and files
|
||||
/src-capacitor
|
||||
/src-capacitor/www
|
||||
/src-capacitor/node_modules
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.scene
|
||||
|
||||
# local .env files
|
||||
.env.local*
|
||||
|
||||
# local .db files
|
||||
*.db
|
||||
|
||||
# local .log files
|
||||
*.log
|
||||
|
||||
# golang quasar websever executable
|
||||
backend/server-linux-arm64
|
||||
backend/cert
|
5
.npmrc
Normal file
@@ -0,0 +1,5 @@
|
||||
# pnpm-related options
|
||||
shamefully-hoist=true
|
||||
strict-peer-dependencies=false
|
||||
# to get the latest compatible packages when creating the project https://github.com/pnpm/pnpm/issues/6463
|
||||
resolution-mode=highest
|
5
.prettierrc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/prettierrc",
|
||||
"singleQuote": true,
|
||||
"printWidth": 100
|
||||
}
|
15
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint",
|
||||
"esbenp.prettier-vscode",
|
||||
"editorconfig.editorconfig",
|
||||
"vue.volar",
|
||||
"wayou.vscode-todo-highlight"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"octref.vetur",
|
||||
"hookyqr.beautify",
|
||||
"dbaeumer.jshint",
|
||||
"ms-vscode.vscode-typescript-tslint-plugin"
|
||||
]
|
||||
}
|
16
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"editor.bracketPairColorization.enabled": true,
|
||||
"editor.guides.bracketPairs": true,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.codeActionsOnSave": [
|
||||
"source.fixAll.eslint"
|
||||
],
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"vue"
|
||||
],
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
BIN
backend/bin/memberApp.exe
Normal file
BIN
backend/bin/server-arm64
Normal file
45
backend/dbRequest/dbRequest.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package dbRequest
|
||||
|
||||
import (
|
||||
"backend/models"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var CreateUserTable string = `CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
settings TEXT NOT NULL
|
||||
);`
|
||||
|
||||
var CreateRoleTable string = `CREATE TABLE IF NOT EXISTS roles (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
role TEXT NOT NULL,
|
||||
rights TEXT NOT NULL
|
||||
);`
|
||||
|
||||
var NewUser string = `INSERT INTO users (username, email, role, password, settings) VALUES (?, ?, ?, ?, ?)`
|
||||
var NewRole = `INSERT INTO roles (role, rights) VALUES (?, ?)`
|
||||
var DBQueryPassword string = `SELECT id, role, password, settings FROM users WHERE username = ?`
|
||||
var DBUserLookup string = `SELECT EXISTS(SELECT 1 FROM users WHERE username = ?)`
|
||||
var DBRoleLookup string = `SELECT EXISTS(SELECT 1 FROM roles WHERE role = ?)`
|
||||
var DBRemoveUser string = `DELETE FROM users WHERE username = $1`
|
||||
var DBUpdateSettings string = `UPDATE users SET settings = ? WHERE username = ?`
|
||||
var DBUpdateRole string = `UPDATE roles SET rights = ? WHERE role = ?`
|
||||
|
||||
func CheckDBError(c *gin.Context, username string, err error) bool {
|
||||
if err != nil {
|
||||
if err.Error() == "sql: no rows in result set" {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse(fmt.Sprintf("no user '%s' found", username)))
|
||||
return true
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
59
backend/go.mod
Normal file
@@ -0,0 +1,59 @@
|
||||
module backend
|
||||
|
||||
go 1.24.5
|
||||
|
||||
require (
|
||||
gitea.tecamino.com/paadi/memberDB v1.0.1
|
||||
gitea.tecamino.com/paadi/tecamino-dbm v0.1.1
|
||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
|
||||
github.com/gin-contrib/cors v1.7.6
|
||||
github.com/gin-gonic/gin v1.11.0
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2
|
||||
golang.org/x/crypto v0.40.0
|
||||
modernc.org/sqlite v1.39.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.14.0 // indirect
|
||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.27.0 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/goccy/go-yaml v1.18.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/quic-go/qpack v0.5.1 // indirect
|
||||
github.com/quic-go/quic-go v0.54.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||
go.uber.org/mock v0.5.0 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.20.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
|
||||
golang.org/x/mod v0.25.0 // indirect
|
||||
golang.org/x/net v0.42.0 // indirect
|
||||
golang.org/x/sync v0.16.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.27.0 // indirect
|
||||
golang.org/x/tools v0.34.0 // indirect
|
||||
google.golang.org/protobuf v1.36.9 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
modernc.org/libc v1.66.3 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
)
|
147
backend/go.sum
Normal file
@@ -0,0 +1,147 @@
|
||||
gitea.tecamino.com/paadi/memberDB v1.0.1 h1:hNnnoCeFRBEOQ+QmizF9nzvrQ8bNed8YrDln5jeRy2Y=
|
||||
gitea.tecamino.com/paadi/memberDB v1.0.1/go.mod h1:4tgbjrSZ2FZeJL68R2TFHPH34+aGxx5wtZxRmu6nZv4=
|
||||
gitea.tecamino.com/paadi/tecamino-dbm v0.1.1 h1:vAq7mwUxlxJuLzCQSDMrZCwo8ky5usWi9Qz+UP+WnkI=
|
||||
gitea.tecamino.com/paadi/tecamino-dbm v0.1.1/go.mod h1:+tmf1rjPaKEoNeUcr1vdtoFIFweNG3aUGevDAl3NMBk=
|
||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1 h1:sQTBKYPdzn9mmWX2JXZBtGBvNQH7cuXIwsl4TD0aMgE=
|
||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
|
||||
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
||||
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
|
||||
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
|
||||
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
||||
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
||||
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
||||
github.com/gin-contrib/cors v1.7.6 h1:3gQ8GMzs1Ylpf70y8bMw4fVpycXIeX1ZemuSQIsnQQY=
|
||||
github.com/gin-contrib/cors v1.7.6/go.mod h1:Ulcl+xN4jel9t1Ry8vqph23a60FwH9xVLd+3ykmTjOk=
|
||||
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
||||
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
|
||||
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
|
||||
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
|
||||
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
|
||||
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
||||
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
|
||||
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA=
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
||||
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
|
||||
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
|
||||
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
|
||||
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
|
||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
|
||||
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
|
||||
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
|
||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
|
||||
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
|
||||
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
|
||||
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
|
||||
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
||||
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.26.2 h1:991HMkLjJzYBIfha6ECZdjrIYz2/1ayr+FL8GN+CNzM=
|
||||
modernc.org/cc/v4 v4.26.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||
modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU=
|
||||
modernc.org/ccgo/v4 v4.28.0/go.mod h1:JygV3+9AV6SmPhDasu4JgquwU81XAKLd3OKTUDNOiKE=
|
||||
modernc.org/fileutil v1.3.8 h1:qtzNm7ED75pd1C7WgAGcK4edm4fvhtBsEiI/0NQ54YM=
|
||||
modernc.org/fileutil v1.3.8/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.66.3 h1:cfCbjTUcdsKyyZZfEUKfoHcP3S0Wkvz3jgSzByEWVCQ=
|
||||
modernc.org/libc v1.66.3/go.mod h1:XD9zO8kt59cANKvHPXpx7yS2ELPheAey0vjIuZOhOU8=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
|
||||
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.39.0 h1:6bwu9Ooim0yVYA7IZn9demiQk/Ejp0BtTjBWFLymSeY=
|
||||
modernc.org/sqlite v1.39.0/go.mod h1:cPTJYSlgg3Sfg046yBShXENNtPrWrDX8bsbAQBzgQ5E=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
185
backend/main.go
Normal file
@@ -0,0 +1,185 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"backend/models"
|
||||
"backend/server"
|
||||
"backend/user"
|
||||
"backend/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.tecamino.com/paadi/tecamino-dbm/cert"
|
||||
|
||||
dbApi "gitea.tecamino.com/paadi/memberDB/api"
|
||||
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var allowOrigins models.StringSlice
|
||||
|
||||
flag.Var(&allowOrigins, "allowOrigin", "Allowed origin (can repeat this flag)")
|
||||
|
||||
spa := flag.String("spa", "./dist/spa", "quasar spa files")
|
||||
workingDir := flag.String("workingDirectory", ".", "quasar spa files")
|
||||
ip := flag.String("ip", "0.0.0.0", "server listening ip")
|
||||
organization := flag.String("organization", "", "self signed ciertificate organization")
|
||||
port := flag.Uint("port", 9500, "server listening port")
|
||||
https := flag.Bool("https", false, "serves as https needs flag -cert and -chain")
|
||||
sslKey := flag.String("privkey", "", "ssl private key path")
|
||||
sslFullchain := flag.String("fullchain", "", "ssl fullchain path")
|
||||
debug := flag.Bool("debug", false, "log debug")
|
||||
flag.Parse()
|
||||
|
||||
//change working directory only if value is given
|
||||
if *workingDir != "." && *workingDir != "" {
|
||||
os.Chdir(*workingDir)
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Could not get working directory: %v", err)
|
||||
}
|
||||
|
||||
folderName := filepath.Base(wd)
|
||||
logFileName := folderName + ".log"
|
||||
|
||||
logger, err := logging.NewLogger(logFileName, &logging.Config{
|
||||
MaxSize: 1,
|
||||
MaxBackup: 3,
|
||||
MaxAge: 28,
|
||||
Debug: *debug,
|
||||
TerminalOut: true,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("main new logger", err.Error())
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//new login manager
|
||||
userManager, err := user.NewUserManager(".")
|
||||
if err != nil {
|
||||
logger.Error("main login manager", err.Error())
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// new server
|
||||
s := server.NewServer()
|
||||
|
||||
// initiate Database handler
|
||||
dbHandler := dbApi.NewAPIHandler()
|
||||
|
||||
//get local ip
|
||||
httpString := "http://"
|
||||
if *https {
|
||||
httpString = "https://"
|
||||
|
||||
}
|
||||
allowOrigins = append(allowOrigins, httpString+"localhost:9000", httpString+"localhost:9500", httpString+"127.0.0.1:9500")
|
||||
|
||||
localIP, err := utils.GetLocalIP()
|
||||
if err != nil {
|
||||
logger.Error("main", fmt.Sprintf("get local ip : %s", err.Error()))
|
||||
} else {
|
||||
allowOrigins = append(allowOrigins, fmt.Sprintf("%s%s:9000", httpString, localIP), fmt.Sprintf("%s%s:9500", httpString, localIP))
|
||||
}
|
||||
|
||||
s.Routes.Use(cors.New(cors.Config{
|
||||
AllowOrigins: allowOrigins,
|
||||
AllowMethods: []string{"POST", "GET", "DELETE", "OPTIONS"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
MaxAge: 12 * time.Hour,
|
||||
}))
|
||||
|
||||
api := s.Routes.Group("/api")
|
||||
//set routes
|
||||
|
||||
//public
|
||||
api.GET("/logout", userManager.Logout)
|
||||
api.GET("/login/me", userManager.Me)
|
||||
|
||||
api.POST("/login", userManager.Login)
|
||||
|
||||
//private
|
||||
auth := api.Group("/secure", user.AuthMiddleware())
|
||||
|
||||
auth.GET("/users", userManager.GetUserById)
|
||||
auth.GET("/members", dbHandler.GetMemberById)
|
||||
auth.GET("/roles", userManager.GetRoleById)
|
||||
|
||||
auth.POST("database/open", dbHandler.OpenDatabase)
|
||||
auth.POST("/members/add", dbHandler.AddNewMember)
|
||||
auth.POST("/members/edit", dbHandler.EditMember)
|
||||
auth.POST("/members/delete", dbHandler.DeleteMember)
|
||||
auth.POST("/members/import/csv", dbHandler.ImportCSV)
|
||||
|
||||
auth.POST("/settings/update", userManager.UpdateSettings)
|
||||
|
||||
auth.POST("/roles/add", userManager.AddRole)
|
||||
auth.POST("/roles/update", userManager.UpdateRole)
|
||||
auth.POST("/roles/delete", userManager.DeleteRole)
|
||||
|
||||
auth.POST("/users/add", userManager.AddUser)
|
||||
auth.POST("/users/delete", userManager.DeleteUser)
|
||||
|
||||
auth.POST("/login/refresh", userManager.Refresh)
|
||||
|
||||
// Serve static files
|
||||
s.Routes.StaticFS("/assets", gin.Dir(filepath.Join(*spa, "assets"), true))
|
||||
s.Routes.NoRoute(func(c *gin.Context) {
|
||||
// Disallow fallback for /api paths
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/api") {
|
||||
c.JSON(http.StatusNotFound, models.NewJsonErrorMessageResponse("API endpoint not found"))
|
||||
return
|
||||
}
|
||||
// Try to serve file from SPA directory
|
||||
filePath := filepath.Join(*spa, c.Request.URL.Path)
|
||||
if _, err := os.Stat(filePath); err == nil {
|
||||
c.File(filePath)
|
||||
return
|
||||
}
|
||||
// Fallback to index.html for SPA routing
|
||||
c.File(filepath.Join(*spa, "index.html"))
|
||||
|
||||
})
|
||||
|
||||
go func() {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
if err := utils.OpenBrowser(fmt.Sprintf("%slocalhost:%d", httpString, *port), logger); err != nil {
|
||||
logger.Error("main", fmt.Sprintf("starting browser error : %s", err.Error()))
|
||||
}
|
||||
}()
|
||||
|
||||
if *https {
|
||||
if *sslCert == "" {
|
||||
logger.Error("ssl certificate", "-cert flag not given for https server")
|
||||
log.Fatal("-cert flag not given for https server")
|
||||
}
|
||||
if *sslChain == "" {
|
||||
logger.Error("ssl key", "-chain flag not given for https server")
|
||||
log.Fatal("-chain flag not given for https server")
|
||||
}
|
||||
|
||||
// start https server
|
||||
logger.Info("main", fmt.Sprintf("https listen on ip: %s port: %d", *ip, *port))
|
||||
if err := s.ServeHttps(*ip, *port, cert.Cert{Organization: *organization, CertFile: *sslFullchain, KeyFile: *sslKey}); err != nil {
|
||||
logger.Error("main", "error https server "+err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// start http server
|
||||
logger.Info("main", fmt.Sprintf("http listen on ip: %s port: %d", *ip, *port))
|
||||
if err := s.ServeHttp(*ip, *port); err != nil {
|
||||
logger.Error("main", "error http server "+err.Error())
|
||||
}
|
||||
}
|
BIN
backend/members.dba
Normal file
20
backend/models/jsonResponse.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
type JsonResponse struct {
|
||||
Error bool `json:"error,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
func NewJsonErrorMessageResponse(msg string) JsonResponse {
|
||||
return JsonResponse{
|
||||
Error: true,
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
|
||||
func NewJsonErrorResponse(err error) JsonResponse {
|
||||
return JsonResponse{
|
||||
Error: true,
|
||||
Message: err.Error(),
|
||||
}
|
||||
}
|
8
backend/models/rights.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package models
|
||||
|
||||
type Rights struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Read bool `json:"read,omitempty"`
|
||||
Write bool `json:"write,omitempty"`
|
||||
Delete bool `json:"delete,omitempty"`
|
||||
}
|
11
backend/models/role.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package models
|
||||
|
||||
type Role struct {
|
||||
Id int `json:"id"`
|
||||
Role string `json:"role"`
|
||||
Rights []Rights `json:"rights"`
|
||||
}
|
||||
|
||||
func (r *Role) IsValid() bool {
|
||||
return r.Role != ""
|
||||
}
|
9
backend/models/settings.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package models
|
||||
|
||||
type Settings struct {
|
||||
PrimaryColor string `json:"primaryColor,omitempty"`
|
||||
SecondaryColor string `json:"secondaryColor,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
DatabaseName string `json:"databaseName,omitempty"`
|
||||
DatabaseToken string `json:"databaseToken,omitempty"`
|
||||
}
|
14
backend/models/stringSlice.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
import "strings"
|
||||
|
||||
type StringSlice []string
|
||||
|
||||
func (s *StringSlice) String() string {
|
||||
return strings.Join(*s, ",")
|
||||
}
|
||||
|
||||
func (s *StringSlice) Set(value string) error {
|
||||
*s = append(*s, value)
|
||||
return nil
|
||||
}
|
14
backend/models/user.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package models
|
||||
|
||||
type User struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"user"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Settings Settings `json:"settings"`
|
||||
}
|
||||
|
||||
func (u *User) IsValid() bool {
|
||||
return u.Name != ""
|
||||
}
|
38
backend/server/server.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"gitea.tecamino.com/paadi/tecamino-dbm/cert"
|
||||
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// server model for database manager websocket
|
||||
type Server struct {
|
||||
Routes *gin.Engine
|
||||
sync.RWMutex
|
||||
Logger *logging.Logger
|
||||
}
|
||||
|
||||
// initalizes new dbm server
|
||||
func NewServer() *Server {
|
||||
return &Server{
|
||||
Routes: gin.Default(),
|
||||
}
|
||||
}
|
||||
|
||||
// serve dbm as http
|
||||
func (s *Server) ServeHttp(ip string, port uint) error {
|
||||
return s.Routes.Run(fmt.Sprintf("%s:%d", ip, port))
|
||||
}
|
||||
|
||||
// serve dbm as http
|
||||
func (s *Server) ServeHttps(url string, port uint, cert cert.Cert) error {
|
||||
// generate self signed tls certificate
|
||||
if err := cert.GenerateSelfSignedCert(); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.Routes.RunTLS(fmt.Sprintf("%s:%d", url, port), cert.CertFile, cert.KeyFile)
|
||||
}
|
41
backend/user/Middleware.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
func AuthMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// Read access token from cookie
|
||||
cookie, err := c.Cookie("access_token")
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"message": "not logged in"})
|
||||
return
|
||||
}
|
||||
|
||||
token, err := jwt.Parse(cookie, func(t *jwt.Token) (any, error) {
|
||||
return JWT_SECRET, nil
|
||||
})
|
||||
if err != nil || !token.Valid {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"message": "invalid token"})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func AuthorizeRole(roles ...string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
userRole := c.GetString("role")
|
||||
for _, role := range roles {
|
||||
if userRole == role {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"message": "Forbidden"})
|
||||
}
|
||||
}
|
||||
}
|
181
backend/user/login.go
Normal file
@@ -0,0 +1,181 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"backend/dbRequest"
|
||||
"backend/models"
|
||||
"backend/utils"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
var JWT_SECRET = []byte("4h5Jza1Fn_zuzu&417%8nH*UH100+55-")
|
||||
var DOMAIN = "localhost"
|
||||
var ACCESS_TOKEN_TIME = 15 * time.Minute
|
||||
var REFRESH_TOKEN_TIME = 72 * time.Hour
|
||||
|
||||
func (um *UserManager) Login(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
user := models.User{}
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsValid() {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("user empty"))
|
||||
return
|
||||
}
|
||||
|
||||
var storedPassword, settingsJsonString string
|
||||
if err := um.database.QueryRow(dbRequest.DBQueryPassword, user.Name).Scan(&user.Id, &user.Role, &storedPassword, &settingsJsonString); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(settingsJsonString), &user.Settings)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.CheckPassword(user.Password, storedPassword) {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("wrong password"))
|
||||
return
|
||||
}
|
||||
|
||||
// ---- Create JWT tokens ----
|
||||
accessTokenExp := time.Now().Add(ACCESS_TOKEN_TIME)
|
||||
refreshTokenExp := time.Now().Add(REFRESH_TOKEN_TIME)
|
||||
|
||||
// Create token
|
||||
accessToken := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"id": user.Id,
|
||||
"username": user.Name,
|
||||
"role": user.Role,
|
||||
"type": "access",
|
||||
"exp": accessTokenExp.Unix(),
|
||||
})
|
||||
|
||||
refreshToken := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"id": user.Id,
|
||||
"username": user.Name,
|
||||
"role": user.Role,
|
||||
"type": "refresh",
|
||||
"exp": refreshTokenExp.Unix(),
|
||||
})
|
||||
|
||||
accessString, err := accessToken.SignedString(JWT_SECRET)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.NewJsonErrorMessageResponse("could not create access token"))
|
||||
return
|
||||
}
|
||||
|
||||
refreshString, err := refreshToken.SignedString(JWT_SECRET)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.NewJsonErrorMessageResponse("could not create refresh token"))
|
||||
return
|
||||
}
|
||||
|
||||
// ---- Set secure cookies ----
|
||||
secure := gin.Mode() == gin.ReleaseMode
|
||||
c.SetCookie("access_token", accessString, int(time.Until(accessTokenExp).Seconds()),
|
||||
"/", "", secure, true) // Path=/, Secure=true (only HTTPS), HttpOnly=true
|
||||
c.SetCookie("refresh_token", refreshString, int(time.Until(refreshTokenExp).Seconds()),
|
||||
"/", "", secure, true)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "login successful",
|
||||
"id": user.Id,
|
||||
"user": user.Name,
|
||||
"role": user.Role,
|
||||
"settings": user.Settings,
|
||||
})
|
||||
}
|
||||
|
||||
func (um *UserManager) Refresh(c *gin.Context) {
|
||||
refreshCookie, err := c.Cookie("refresh_token")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "no refresh token"})
|
||||
return
|
||||
}
|
||||
|
||||
token, err := jwt.Parse(refreshCookie, func(token *jwt.Token) (any, error) {
|
||||
return JWT_SECRET, nil
|
||||
})
|
||||
if err != nil || !token.Valid {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "invalid refresh token"})
|
||||
return
|
||||
}
|
||||
|
||||
claims, ok := token.Claims.(jwt.MapClaims)
|
||||
if !ok || claims["type"] != "refresh" {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "invalid token type"})
|
||||
return
|
||||
}
|
||||
|
||||
username := claims["username"].(string)
|
||||
id := claims["id"].(float64)
|
||||
role := claims["role"].(string)
|
||||
|
||||
// new access token
|
||||
accessExp := time.Now().Add(ACCESS_TOKEN_TIME)
|
||||
newAccess := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"id": id,
|
||||
"username": username,
|
||||
"role": role,
|
||||
"exp": accessExp.Unix(),
|
||||
})
|
||||
accessString, _ := newAccess.SignedString(JWT_SECRET)
|
||||
|
||||
c.SetCookie("access_token", accessString, int(time.Until(accessExp).Seconds()), "/", DOMAIN, gin.Mode() == gin.ReleaseMode, true)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "token refreshed"})
|
||||
}
|
||||
|
||||
func (um *UserManager) Me(c *gin.Context) {
|
||||
// Read access token from cookie
|
||||
cookie, err := c.Cookie("access_token")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "not logged in"})
|
||||
return
|
||||
}
|
||||
|
||||
// Verify token
|
||||
token, err := jwt.Parse(cookie, func(t *jwt.Token) (any, error) {
|
||||
return JWT_SECRET, nil
|
||||
})
|
||||
if err != nil || !token.Valid {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"message": "invalid token"})
|
||||
return
|
||||
}
|
||||
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"id": claims["id"],
|
||||
"user": claims["username"],
|
||||
"role": claims["role"],
|
||||
})
|
||||
}
|
||||
|
||||
func (um *UserManager) Logout(c *gin.Context) {
|
||||
secure := gin.Mode() == gin.ReleaseMode
|
||||
|
||||
c.SetCookie("access_token", "", -1, "/", DOMAIN, secure, true)
|
||||
c.SetCookie("refresh_token", "", -1, "/", DOMAIN, secure, true)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "logged out"})
|
||||
}
|
261
backend/user/manager.go
Normal file
@@ -0,0 +1,261 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"backend/dbRequest"
|
||||
"backend/models"
|
||||
"backend/utils"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UserManager struct {
|
||||
database *sql.DB
|
||||
}
|
||||
|
||||
func NewUserManager(dir string) (*UserManager, error) {
|
||||
if dir == "" {
|
||||
dir = "."
|
||||
}
|
||||
|
||||
var err error
|
||||
var um UserManager
|
||||
file := fmt.Sprintf("%s/user.db", dir)
|
||||
|
||||
um.database, err = sql.Open("sqlite", file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(file); err != nil {
|
||||
_, err = um.database.Exec(dbRequest.CreateUserTable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hash, err := utils.HashPassword("tecamino@2025")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = um.database.Exec(dbRequest.NewUser, "admin", "", "admin", hash, `{"databaseName":"members.dba","primaryColor":"#1976d2", "secondaryColor":"#26a69a"}`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &um, nil
|
||||
}
|
||||
|
||||
func (um *UserManager) databaseOpened(c *gin.Context) bool {
|
||||
if um.database == nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "no database opened",
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (um *UserManager) AddUser(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
user := models.User{}
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsValid() {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("user empty"))
|
||||
return
|
||||
}
|
||||
|
||||
var exists bool
|
||||
|
||||
if err := um.database.QueryRow(dbRequest.DBUserLookup, user.Name).Scan(&exists); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
return
|
||||
}
|
||||
|
||||
if exists {
|
||||
c.JSON(http.StatusOK, models.NewJsonErrorMessageResponse(fmt.Sprintf("user '%s' exists already", user.Name)))
|
||||
return
|
||||
}
|
||||
|
||||
hash, err := utils.HashPassword(user.Password)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.IsValidEmail(user.Email) {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(errors.New("not valid email address")))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := um.database.Exec(dbRequest.NewUser, user.Name, user.Email, user.Role, hash, "{}"); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("user '%s' successfully added", user.Name),
|
||||
})
|
||||
}
|
||||
|
||||
func (um *UserManager) GetUserById(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
var i int
|
||||
var err error
|
||||
|
||||
id := c.Query("id")
|
||||
if id != "" {
|
||||
i, err = strconv.Atoi(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
query := `SELECT id, username, email, role, settings FROM users`
|
||||
var args any
|
||||
if i > 0 {
|
||||
query = `
|
||||
SELECT id, username, email, role, settings FROM users
|
||||
WHERE id = ?
|
||||
`
|
||||
args = i
|
||||
}
|
||||
|
||||
rows, err := um.database.Query(query, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var users []models.User
|
||||
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var name, email, role, settingsString string
|
||||
if err = rows.Scan(&id, &name, &email, &role, &settingsString); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var settings models.Settings
|
||||
err := json.Unmarshal([]byte(settingsString), &settings)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
users = append(users, models.User{
|
||||
Id: id,
|
||||
Name: name,
|
||||
Email: email,
|
||||
Role: role,
|
||||
Settings: settings,
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
||||
func (um *UserManager) DeleteUser(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
queryId := c.Query("id")
|
||||
|
||||
if queryId == "" || queryId == "null" || queryId == "undefined" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "id query missing or wrong value: " + queryId,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var request struct {
|
||||
Ids []int `json:"ids"`
|
||||
}
|
||||
|
||||
err := c.BindJSON(&request)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if len(request.Ids) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "no ids given to be deleted",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var ownId string
|
||||
placeholders := make([]string, len(request.Ids))
|
||||
args := make([]any, len(request.Ids))
|
||||
for i, id := range request.Ids {
|
||||
if queryId == fmt.Sprint(id) {
|
||||
ownId = queryId
|
||||
continue
|
||||
}
|
||||
|
||||
placeholders[i] = "?"
|
||||
args[i] = id
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("DELETE FROM users WHERE id IN (%s)", strings.Join(placeholders, ","))
|
||||
|
||||
_, err = um.database.Exec(query, args...)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if ownId != "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "can not delete logged in member id: " + queryId,
|
||||
"id": queryId,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "member(s) deleted",
|
||||
})
|
||||
}
|
245
backend/user/roles.go
Normal file
@@ -0,0 +1,245 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"backend/dbRequest"
|
||||
"backend/models"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (um *UserManager) AddRole(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
role := models.Role{}
|
||||
err = json.Unmarshal(body, &role)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !role.IsValid() {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("user empty"))
|
||||
return
|
||||
}
|
||||
|
||||
var exists bool
|
||||
|
||||
if err := um.database.QueryRow(dbRequest.DBRoleLookup, role.Role).Scan(&exists); dbRequest.CheckDBError(c, role.Role, err) {
|
||||
return
|
||||
}
|
||||
|
||||
if exists {
|
||||
c.JSON(http.StatusOK, models.NewJsonErrorMessageResponse(fmt.Sprintf("role '%s' exists already", role.Role)))
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(role.Rights)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, models.NewJsonErrorMessageResponse(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := um.database.Exec(dbRequest.NewRole, role.Role, string(jsonBytes)); dbRequest.CheckDBError(c, role.Role, err) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("role '%s' successfully added", role.Role),
|
||||
})
|
||||
}
|
||||
|
||||
func (um *UserManager) GetRoleById(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := um.database.Exec(dbRequest.CreateRoleTable); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
var i int
|
||||
var err error
|
||||
|
||||
id := c.Query("id")
|
||||
if id != "" {
|
||||
i, err = strconv.Atoi(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
query := `SELECT id, role, rights FROM roles`
|
||||
var args any
|
||||
if i > 0 {
|
||||
query = `
|
||||
SELECT id, role, rights FROM users
|
||||
WHERE id = ?
|
||||
`
|
||||
args = i
|
||||
}
|
||||
|
||||
rows, err := um.database.Query(query, args)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var roles []models.Role
|
||||
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var role, rightsString string
|
||||
if err = rows.Scan(&id, &role, &rightsString); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var data struct {
|
||||
Rights []models.Rights `json:"rights"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(rightsString), &data)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
roles = append(roles, models.Role{
|
||||
Id: id,
|
||||
Role: role,
|
||||
Rights: data.Rights,
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, roles)
|
||||
}
|
||||
|
||||
func (um *UserManager) UpdateRole(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
role := models.Role{}
|
||||
err = json.Unmarshal(body, &role)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(role)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, models.NewJsonErrorMessageResponse(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := um.database.Exec(dbRequest.DBUpdateRole, string(jsonBytes), role.Role); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("role rights '%s' successfully updated", role.Role),
|
||||
})
|
||||
}
|
||||
|
||||
func (um *UserManager) DeleteRole(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
queryRole := c.Query("role")
|
||||
|
||||
if queryRole == "" || queryRole == "null" || queryRole == "undefined" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "role query missing or wrong value: " + queryRole,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var request struct {
|
||||
Roles []string `json:"roles"`
|
||||
}
|
||||
|
||||
err := c.BindJSON(&request)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if len(request.Roles) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "no roles given to be deleted",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var ownRole string
|
||||
placeholders := make([]string, len(request.Roles))
|
||||
args := make([]any, len(request.Roles))
|
||||
for i, role := range request.Roles {
|
||||
if ownRole == role {
|
||||
ownRole = queryRole
|
||||
continue
|
||||
}
|
||||
|
||||
placeholders[i] = "?"
|
||||
args[i] = role
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("DELETE FROM roles WHERE role IN (%s)", strings.Join(placeholders, ","))
|
||||
|
||||
_, err = um.database.Exec(query, args...)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if ownRole != "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "can not delete logged in role id: " + ownRole,
|
||||
"role": ownRole,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "role(s) deleted",
|
||||
})
|
||||
}
|
46
backend/user/settings.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"backend/dbRequest"
|
||||
"backend/models"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (um *UserManager) UpdateSettings(c *gin.Context) {
|
||||
if !um.databaseOpened(c) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
user := models.User{}
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(user.Settings)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, models.NewJsonErrorMessageResponse(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := um.database.Exec(dbRequest.DBUpdateSettings, string(jsonBytes), user.Name); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("user settings '%s' successfully updated", user.Name),
|
||||
})
|
||||
}
|
14
backend/utils/hash.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import "golang.org/x/crypto/bcrypt"
|
||||
|
||||
// Hash password
|
||||
func HashPassword(password string) (string, error) {
|
||||
b, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// Check password
|
||||
func CheckPassword(password, hash string) bool {
|
||||
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
|
||||
}
|
22
backend/utils/ip.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
func GetLocalIP() (string, error) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
|
||||
if ipNet.IP.To4() != nil {
|
||||
return ipNet.IP.String(), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no local IP address found")
|
||||
}
|
14
backend/utils/secret.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
func GenerateJWTSecret(length int) ([]byte, error) {
|
||||
bytes := make([]byte, length)
|
||||
_, err := rand.Read(bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes, nil
|
||||
}
|
71
backend/utils/utils.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||
)
|
||||
|
||||
func OpenBrowser(url string, logger *logging.Logger) error {
|
||||
var commands [][]string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
// Try with Chrome in kiosk mode
|
||||
commands = [][]string{
|
||||
{`C:\Program Files\Google\Chrome\Application\chrome.exe`, "--kiosk", url},
|
||||
{"rundll32", "url.dll,FileProtocolHandler", url}, // fallback
|
||||
}
|
||||
case "darwin":
|
||||
// macOS: open with Chrome in kiosk
|
||||
commands = [][]string{
|
||||
{"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--kiosk", url},
|
||||
{"open", url}, // fallback
|
||||
}
|
||||
default: // Linux
|
||||
if os.Getenv("DISPLAY") == "" && os.Getenv("WAYLAND_DISPLAY") == "" && os.Getenv("XDG_SESSION_TYPE") != "wayland" {
|
||||
|
||||
return fmt.Errorf("os is running i headless mode do not start browser")
|
||||
}
|
||||
commands = [][]string{
|
||||
{"chromium-browser", "--kiosk", url},
|
||||
{"google-chrome", "--kiosk", url},
|
||||
{"firefox", "--kiosk", url},
|
||||
{"xdg-open", url}, // fallback
|
||||
}
|
||||
}
|
||||
|
||||
for _, cmd := range commands {
|
||||
execCmd := exec.Command(cmd[0], cmd[1:]...)
|
||||
if err := execCmd.Start(); err == nil {
|
||||
return nil
|
||||
} else {
|
||||
logger.Error("utils.OpenBrowser", err)
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("could not open browser")
|
||||
}
|
||||
|
||||
func FindAllFiles(rootDir, fileExtention string) (files []string, err error) {
|
||||
err = filepath.WalkDir(rootDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
} else if filepath.Ext(d.Name()) == fileExtention {
|
||||
files = append(files, path)
|
||||
}
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func IsValidEmail(email string) bool {
|
||||
re := regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
|
||||
return re.MatchString(email)
|
||||
}
|
83
eslint.config.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import js from '@eslint/js';
|
||||
import globals from 'globals';
|
||||
import pluginVue from 'eslint-plugin-vue';
|
||||
import pluginQuasar from '@quasar/app-vite/eslint';
|
||||
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript';
|
||||
import prettierSkipFormatting from '@vue/eslint-config-prettier/skip-formatting';
|
||||
|
||||
export default defineConfigWithVueTs(
|
||||
{
|
||||
/**
|
||||
* Ignore the following files.
|
||||
* Please note that pluginQuasar.configs.recommended() already ignores
|
||||
* the "node_modules" folder for you (and all other Quasar project
|
||||
* relevant folders and files).
|
||||
*
|
||||
* ESLint requires "ignores" key to be the only one in this object
|
||||
*/
|
||||
// ignores: []
|
||||
},
|
||||
|
||||
pluginQuasar.configs.recommended(),
|
||||
js.configs.recommended,
|
||||
|
||||
/**
|
||||
* https://eslint.vuejs.org
|
||||
*
|
||||
* pluginVue.configs.base
|
||||
* -> Settings and rules to enable correct ESLint parsing.
|
||||
* pluginVue.configs[ 'flat/essential']
|
||||
* -> base, plus rules to prevent errors or unintended behavior.
|
||||
* pluginVue.configs["flat/strongly-recommended"]
|
||||
* -> Above, plus rules to considerably improve code readability and/or dev experience.
|
||||
* pluginVue.configs["flat/recommended"]
|
||||
* -> Above, plus rules to enforce subjective community defaults to ensure consistency.
|
||||
*/
|
||||
pluginVue.configs['flat/essential'],
|
||||
|
||||
{
|
||||
files: ['**/*.ts', '**/*.d.ts', '**/*.vue'],
|
||||
rules: {
|
||||
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
||||
},
|
||||
},
|
||||
// https://github.com/vuejs/eslint-config-typescript
|
||||
vueTsConfigs.recommendedTypeChecked,
|
||||
|
||||
{
|
||||
languageOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.node, // SSR, Electron, config files
|
||||
process: 'readonly', // process.env.*
|
||||
ga: 'readonly', // Google Analytics
|
||||
cordova: 'readonly',
|
||||
Capacitor: 'readonly',
|
||||
chrome: 'readonly', // BEX related
|
||||
browser: 'readonly', // BEX related
|
||||
},
|
||||
},
|
||||
|
||||
// add your custom rules here
|
||||
rules: {
|
||||
'prefer-promise-reject-errors': 'off',
|
||||
|
||||
// allow debugger during development only
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
files: ['src-pwa/custom-service-worker.ts'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.serviceworker,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
prettierSkipFormatting,
|
||||
);
|
21
index.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= productName %></title>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="description" content="<%= productDescription %>">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="msapplication-tap-highlight" content="no">
|
||||
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width<% if (ctx.mode.cordova || ctx.mode.capacitor) { %>, viewport-fit=cover<% } %>">
|
||||
|
||||
<link rel="icon" type="image/png" sizes="128x128" href="icons/favicon-128x128.png">
|
||||
<link rel="icon" type="image/png" sizes="96x96" href="icons/favicon-96x96.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="icons/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png">
|
||||
<link rel="icon" type="image/ico" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<!-- quasar:entry-point -->
|
||||
</body>
|
||||
</html>
|
8420
package-lock.json
generated
Normal file
50
package.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "lightcontrol",
|
||||
"version": "1.0.1",
|
||||
"description": "A Tecamino App",
|
||||
"productName": "Member Database",
|
||||
"author": "A. Zuercher",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint -c ./eslint.config.js \"./src*/**/*.{ts,js,cjs,mjs,vue}\"",
|
||||
"format": "prettier --write \"**/*.{js,ts,vue,scss,html,md,json}\" --ignore-path .gitignore",
|
||||
"test": "echo \"No test specified\" && exit 0",
|
||||
"dev": "quasar dev",
|
||||
"build": "quasar build",
|
||||
"postinstall": "quasar prepare"
|
||||
},
|
||||
"dependencies": {
|
||||
"@capacitor-community/sqlite": "^7.0.1",
|
||||
"@quasar/extras": "^1.16.4",
|
||||
"axios": "^1.10.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"pinia": "^3.0.3",
|
||||
"quasar": "^2.16.0",
|
||||
"vue": "^3.4.18",
|
||||
"vue-i18n": "^11.1.12",
|
||||
"vue-router": "^4.0.12",
|
||||
"vuedraggable": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.14.0",
|
||||
"@quasar/app-vite": "^2.1.0",
|
||||
"@types/node": "^20.5.9",
|
||||
"@vue/eslint-config-prettier": "^10.1.0",
|
||||
"@vue/eslint-config-typescript": "^14.4.0",
|
||||
"autoprefixer": "^10.4.2",
|
||||
"eslint": "^9.14.0",
|
||||
"eslint-plugin-vue": "^9.30.0",
|
||||
"globals": "^15.12.0",
|
||||
"prettier": "^3.3.3",
|
||||
"typescript": "~5.5.3",
|
||||
"vite-plugin-checker": "^0.9.0",
|
||||
"vue-tsc": "^2.0.29"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^28 || ^26 || ^24 || ^22 || ^20 || ^18",
|
||||
"npm": ">= 6.13.4",
|
||||
"yarn": ">= 1.21.1"
|
||||
}
|
||||
}
|
29
postcss.config.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// https://github.com/michael-ciniawsky/postcss-load-config
|
||||
|
||||
import autoprefixer from 'autoprefixer'
|
||||
// import rtlcss from 'postcss-rtlcss'
|
||||
|
||||
export default {
|
||||
plugins: [
|
||||
// https://github.com/postcss/autoprefixer
|
||||
autoprefixer({
|
||||
overrideBrowserslist: [
|
||||
'last 4 Chrome versions',
|
||||
'last 4 Firefox versions',
|
||||
'last 4 Edge versions',
|
||||
'last 4 Safari versions',
|
||||
'last 4 Android versions',
|
||||
'last 4 ChromeAndroid versions',
|
||||
'last 4 FirefoxAndroid versions',
|
||||
'last 4 iOS versions'
|
||||
]
|
||||
}),
|
||||
|
||||
// https://github.com/elchininet/postcss-rtlcss
|
||||
// If you want to support RTL css, then
|
||||
// 1. yarn/pnpm/bun/npm install postcss-rtlcss
|
||||
// 2. optionally set quasar.config.js > framework > lang to an RTL language
|
||||
// 3. uncomment the following line (and its import statement above):
|
||||
// rtlcss()
|
||||
]
|
||||
}
|
31
public/LOGO_CF-ICON_color.svg
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Adobe Illustrator 24.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Ebene_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="246px" height="246px" viewBox="0 0 246 246" style="enable-background:new 0 0 246 246;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#113A68;}
|
||||
.st1{fill:#9E2D29;}
|
||||
.st2{fill:#9B1515;}
|
||||
.st3{fill:#FFFFFF;}
|
||||
</style>
|
||||
<g>
|
||||
<path class="st0" d="M166.6,210.9c-11.6,5-24.4,7.8-37.8,7.8c-52.8,0-95.6-42.8-95.6-95.6c0-2.3,0.1-4.6,0.2-6.8
|
||||
c2.4-1.8,10.8-5.2,31.7-5.2s46.4,3.4,71.6,9.4c-13,22.2-15.9,44.7-7.8,62.2C133.6,192.6,143.9,205.2,166.6,210.9"/>
|
||||
<path class="st0" d="M146.9,103.8C102.4,90.7,61.4,88.5,39.7,88.4c0-0.1,0.1-0.2,0.1-0.2c2.5-1.4,8.9-3.3,22.1-3.3
|
||||
c23.7,0,55.7,5.9,86.9,15.8C148.2,101.7,147.5,102.7,146.9,103.8"/>
|
||||
<path class="st0" d="M168.4,49.9c0.7,7.9-2.7,18.9-10.6,34.4C117.3,69.2,78.9,63.7,55.4,61.7c17.5-21,43.9-34.3,73.4-34.3
|
||||
c7.8,0,15.5,0.9,22.8,2.7l3.8,2.5C164.2,38.3,167.8,43.1,168.4,49.9"/>
|
||||
<path class="st0" d="M209.6,71.8c8.7,13.7,14,29.8,14.7,47c-3.9-2.6-8.2-5.3-13.1-8.3C214,95.5,212.6,82.5,209.6,71.8"/>
|
||||
<path class="st0" d="M206.8,144.8c4.5,2.1,9,4.5,13.2,6.7c-2.2,6.9-5.1,13.5-8.7,19.6c-0.6-4-2.2-7.4-3.5-10.3
|
||||
c-2.5-5.6-4.2-9.3-1.2-15.7C206.8,145,206.8,144.9,206.8,144.8"/>
|
||||
<path class="st0" d="M207.2,125.1c5.4,2.9,11.3,6.2,16.6,9.2c-0.1,1.2-0.3,2.4-0.5,3.7c-5.7-3.5-11.8-7-17.2-9.9
|
||||
C206.4,127.1,206.8,126.1,207.2,125.1"/>
|
||||
<path class="st1" d="M185.2,205.6c41.5-36.8,4.9-39.5,15.9-63.1c-14,12.6-44,47.2-18,64.1C164.7,168.9,207.4,157.8,185.2,205.6"/>
|
||||
<path class="st2" d="M198.1,130.8c9.6,5,24.5,13.5,33.5,20c-9.4-5.4-24.7-13-34.9-17.4c-2,3.9-4.3,7.8-7,11.8
|
||||
c-10.3,15-36.7,44.6-12.5,61.4c-51.2-7.1-57.1-49.2-33.1-86.7c0.8-1.2,1.5-2.4,2.3-3.6c-62.2-16.2-119.6-14.7-119.8,0.3
|
||||
c-14.3-6.8-26.2-20.1-2.1-21.8c9.6-0.7,65.2-2.4,125.1,16.2c3-4.9,5.8-9.6,8.2-13.9c-63.3-21.6-124.4-24-125.5-8.6
|
||||
C18.4,81,7.4,67,31.6,66.7c9.9-0.1,68.5,1.5,129.1,25.3c21.2-39.5,16.4-52.7-2-64.6c21.6,1.5,57.2,37,45.6,86.1
|
||||
c8.8,5.4,22.8,14.1,31,20.7c-8.4-5.5-22.6-13.3-31.7-17.9C202.2,121.1,200.4,125.9,198.1,130.8"/>
|
||||
<path class="st2" d="M185.2,205.6c41.5-36.8,4.9-39.5,15.9-63.1c-14,12.6-44,47.2-18,64.1C164.7,168.9,207.4,157.8,185.2,205.6"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
BIN
public/favicon.ico
Normal file
After Width: | Height: | Size: 63 KiB |
BIN
public/icons/favicon-128x128.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
public/icons/favicon-16x16.png
Normal file
After Width: | Height: | Size: 859 B |
BIN
public/icons/favicon-32x32.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
public/icons/favicon-96x96.png
Normal file
After Width: | Height: | Size: 9.4 KiB |
231
quasar.config.ts
Normal file
@@ -0,0 +1,231 @@
|
||||
// Configuration for your app
|
||||
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file
|
||||
|
||||
import { defineConfig } from '#q-app/wrappers';
|
||||
|
||||
export default defineConfig((/* ctx */) => {
|
||||
return {
|
||||
// https://v2.quasar.dev/quasar-cli-vite/prefetch-feature
|
||||
// preFetch: true,
|
||||
|
||||
// app boot file (/src/boot)
|
||||
// --> boot files are part of "main.js"
|
||||
// https://v2.quasar.dev/quasar-cli-vite/boot-files
|
||||
boot: ['auth', 'axios', 'lang', 'quasar-global'],
|
||||
|
||||
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#css
|
||||
css: ['app.scss'],
|
||||
|
||||
// https://github.com/quasarframework/quasar/tree/dev/extras
|
||||
extras: [
|
||||
// 'ionicons-v4',
|
||||
// 'mdi-v7',
|
||||
// 'fontawesome-v6',
|
||||
// 'eva-icons',
|
||||
// 'themify',
|
||||
// 'line-awesome',
|
||||
// 'roboto-font-latin-ext', // this or either 'roboto-font', NEVER both!
|
||||
|
||||
'roboto-font', // optional, you are not bound to it
|
||||
'material-icons', // optional, you are not bound to it
|
||||
],
|
||||
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#build
|
||||
build: {
|
||||
target: {
|
||||
browser: ['es2022', 'firefox115', 'chrome115', 'safari14'],
|
||||
node: 'node20',
|
||||
publicPath: '/',
|
||||
},
|
||||
|
||||
typescript: {
|
||||
strict: true,
|
||||
vueShim: true,
|
||||
// extendTsConfig (tsConfig) {}
|
||||
},
|
||||
|
||||
vueRouterMode: 'hash', // available values: 'hash', 'history'
|
||||
// vueRouterBase,
|
||||
// vueDevtools,
|
||||
// vueOptionsAPI: false,
|
||||
|
||||
// rebuildCache: true, // rebuilds Vite/linter/etc cache on startup
|
||||
|
||||
// publicPath: '/',
|
||||
// analyze: true,
|
||||
// env: {},
|
||||
// rawDefine: {}
|
||||
// ignorePublicFolder: true,
|
||||
// minify: false,
|
||||
// polyfillModulePreload: true,
|
||||
// distDir
|
||||
|
||||
// extendViteConf (viteConf) {},
|
||||
// viteVuePluginOptions: {},
|
||||
|
||||
vitePlugins: [
|
||||
[
|
||||
'vite-plugin-checker',
|
||||
{
|
||||
vueTsc: true,
|
||||
eslint: {
|
||||
lintCommand: 'eslint -c ./eslint.config.js "./src*/**/*.{ts,js,mjs,cjs,vue}"',
|
||||
useFlatConfig: true,
|
||||
},
|
||||
},
|
||||
{ server: false },
|
||||
],
|
||||
],
|
||||
},
|
||||
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#devserver
|
||||
devServer: {
|
||||
open: true, // opens browser window automatically
|
||||
https: true, // or true if you want HTTPS
|
||||
port: 9000, // your custom port
|
||||
// host: '0.0.0.0', // allows external access (not just localhost)
|
||||
// allowedHosts: ['members.tecamino.com'],
|
||||
// headers: {
|
||||
// 'Access-Control-Allow-Origin': '*',
|
||||
// },
|
||||
// proxy: {
|
||||
// '/v1': {
|
||||
// target: 'http://0.0.0.0:4040/',
|
||||
// changeOrigin: true,
|
||||
// secure: false,
|
||||
// },
|
||||
// },
|
||||
},
|
||||
|
||||
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#framework
|
||||
framework: {
|
||||
config: {},
|
||||
|
||||
// iconSet: 'material-icons', // Quasar icon set
|
||||
// lang: 'en-US', // Quasar language pack
|
||||
|
||||
// For special cases outside of where the auto-import strategy can have an impact
|
||||
// (like functional components as one of the examples),
|
||||
// you can manually specify Quasar components/directives to be available everywhere:
|
||||
//
|
||||
// components: [],
|
||||
// directives: [],
|
||||
|
||||
// Quasar plugins
|
||||
plugins: ['Notify', 'Dialog'],
|
||||
},
|
||||
|
||||
// animations: 'all', // --- includes all animations
|
||||
// https://v2.quasar.dev/options/animations
|
||||
animations: [],
|
||||
|
||||
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#sourcefiles
|
||||
// sourceFiles: {
|
||||
// rootComponent: 'src/App.vue',
|
||||
// router: 'src/router/index',
|
||||
// store: 'src/store/index',
|
||||
// pwaRegisterServiceWorker: 'src-pwa/register-service-worker',
|
||||
// pwaServiceWorker: 'src-pwa/custom-service-worker',
|
||||
// pwaManifestFile: 'src-pwa/manifest.json',
|
||||
// electronMain: 'src-electron/electron-main',
|
||||
// electronPreload: 'src-electron/electron-preload'
|
||||
// bexManifestFile: 'src-bex/manifest.json
|
||||
// },
|
||||
|
||||
// https://v2.quasar.dev/quasar-cli-vite/developing-ssr/configuring-ssr
|
||||
ssr: {
|
||||
prodPort: 3000, // The default port that the production server should use
|
||||
// (gets superseded if process.env.PORT is specified at runtime)
|
||||
|
||||
middlewares: [
|
||||
'render', // keep this as last one
|
||||
],
|
||||
|
||||
// extendPackageJson (json) {},
|
||||
// extendSSRWebserverConf (esbuildConf) {},
|
||||
|
||||
// manualStoreSerialization: true,
|
||||
// manualStoreSsrContextInjection: true,
|
||||
// manualStoreHydration: true,
|
||||
// manualPostHydrationTrigger: true,
|
||||
|
||||
pwa: false,
|
||||
// pwaOfflineHtmlFilename: 'offline.html', // do NOT use index.html as name!
|
||||
|
||||
// pwaExtendGenerateSWOptions (cfg) {},
|
||||
// pwaExtendInjectManifestOptions (cfg) {}
|
||||
},
|
||||
|
||||
// https://v2.quasar.dev/quasar-cli-vite/developing-pwa/configuring-pwa
|
||||
pwa: {
|
||||
workboxMode: 'GenerateSW', // 'GenerateSW' or 'InjectManifest'
|
||||
// swFilename: 'sw.js',
|
||||
// manifestFilename: 'manifest.json',
|
||||
// extendManifestJson (json) {},
|
||||
// useCredentialsForManifestTag: true,
|
||||
// injectPwaMetaTags: false,
|
||||
// extendPWACustomSWConf (esbuildConf) {},
|
||||
// extendGenerateSWOptions (cfg) {},
|
||||
// extendInjectManifestOptions (cfg) {}
|
||||
},
|
||||
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/developing-cordova-apps/configuring-cordova
|
||||
cordova: {
|
||||
// noIosLegacyBuildFlag: true, // uncomment only if you know what you are doing
|
||||
},
|
||||
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/developing-capacitor-apps/configuring-capacitor
|
||||
capacitor: {
|
||||
hideSplashscreen: true,
|
||||
},
|
||||
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/developing-electron-apps/configuring-electron
|
||||
electron: {
|
||||
// extendElectronMainConf (esbuildConf) {},
|
||||
// extendElectronPreloadConf (esbuildConf) {},
|
||||
|
||||
// extendPackageJson (json) {},
|
||||
|
||||
// Electron preload scripts (if any) from /src-electron, WITHOUT file extension
|
||||
preloadScripts: ['electron-preload'],
|
||||
|
||||
// specify the debugging port to use for the Electron app when running in development mode
|
||||
inspectPort: 5858,
|
||||
|
||||
bundler: 'packager', // 'packager' or 'builder'
|
||||
|
||||
packager: {
|
||||
// https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#options
|
||||
// OS X / Mac App Store
|
||||
// appBundleId: '',
|
||||
// appCategoryType: '',
|
||||
// osxSign: '',
|
||||
// protocol: 'myapp://path',
|
||||
// Windows only
|
||||
// win32metadata: { ... }
|
||||
},
|
||||
|
||||
builder: {
|
||||
// https://www.electron.build/configuration/configuration
|
||||
|
||||
appId: 'lightcontrol',
|
||||
},
|
||||
},
|
||||
|
||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/developing-browser-extensions/configuring-bex
|
||||
bex: {
|
||||
// extendBexScriptsConf (esbuildConf) {},
|
||||
// extendBexManifestJson (json) {},
|
||||
|
||||
/**
|
||||
* The list of extra scripts (js/ts) not in your bex manifest that you want to
|
||||
* compile and use in your browser extension. Maybe dynamic use them?
|
||||
*
|
||||
* Each entry in the list should be a relative filename to /src-bex/
|
||||
*
|
||||
* @example [ 'my-script.ts', 'sub-folder/my-other-script.js' ]
|
||||
*/
|
||||
extraScripts: [],
|
||||
},
|
||||
};
|
||||
});
|
7
src/App.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
//
|
||||
</script>
|
1
src/assets/LOGO_CF-BERN_high_color.svg
Normal file
After Width: | Height: | Size: 7.1 KiB |
31
src/assets/LOGO_CF-ICON_color.svg
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Adobe Illustrator 24.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Ebene_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="246px" height="246px" viewBox="0 0 246 246" style="enable-background:new 0 0 246 246;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#113A68;}
|
||||
.st1{fill:#9E2D29;}
|
||||
.st2{fill:#9B1515;}
|
||||
.st3{fill:#FFFFFF;}
|
||||
</style>
|
||||
<g>
|
||||
<path class="st0" d="M166.6,210.9c-11.6,5-24.4,7.8-37.8,7.8c-52.8,0-95.6-42.8-95.6-95.6c0-2.3,0.1-4.6,0.2-6.8
|
||||
c2.4-1.8,10.8-5.2,31.7-5.2s46.4,3.4,71.6,9.4c-13,22.2-15.9,44.7-7.8,62.2C133.6,192.6,143.9,205.2,166.6,210.9"/>
|
||||
<path class="st0" d="M146.9,103.8C102.4,90.7,61.4,88.5,39.7,88.4c0-0.1,0.1-0.2,0.1-0.2c2.5-1.4,8.9-3.3,22.1-3.3
|
||||
c23.7,0,55.7,5.9,86.9,15.8C148.2,101.7,147.5,102.7,146.9,103.8"/>
|
||||
<path class="st0" d="M168.4,49.9c0.7,7.9-2.7,18.9-10.6,34.4C117.3,69.2,78.9,63.7,55.4,61.7c17.5-21,43.9-34.3,73.4-34.3
|
||||
c7.8,0,15.5,0.9,22.8,2.7l3.8,2.5C164.2,38.3,167.8,43.1,168.4,49.9"/>
|
||||
<path class="st0" d="M209.6,71.8c8.7,13.7,14,29.8,14.7,47c-3.9-2.6-8.2-5.3-13.1-8.3C214,95.5,212.6,82.5,209.6,71.8"/>
|
||||
<path class="st0" d="M206.8,144.8c4.5,2.1,9,4.5,13.2,6.7c-2.2,6.9-5.1,13.5-8.7,19.6c-0.6-4-2.2-7.4-3.5-10.3
|
||||
c-2.5-5.6-4.2-9.3-1.2-15.7C206.8,145,206.8,144.9,206.8,144.8"/>
|
||||
<path class="st0" d="M207.2,125.1c5.4,2.9,11.3,6.2,16.6,9.2c-0.1,1.2-0.3,2.4-0.5,3.7c-5.7-3.5-11.8-7-17.2-9.9
|
||||
C206.4,127.1,206.8,126.1,207.2,125.1"/>
|
||||
<path class="st1" d="M185.2,205.6c41.5-36.8,4.9-39.5,15.9-63.1c-14,12.6-44,47.2-18,64.1C164.7,168.9,207.4,157.8,185.2,205.6"/>
|
||||
<path class="st2" d="M198.1,130.8c9.6,5,24.5,13.5,33.5,20c-9.4-5.4-24.7-13-34.9-17.4c-2,3.9-4.3,7.8-7,11.8
|
||||
c-10.3,15-36.7,44.6-12.5,61.4c-51.2-7.1-57.1-49.2-33.1-86.7c0.8-1.2,1.5-2.4,2.3-3.6c-62.2-16.2-119.6-14.7-119.8,0.3
|
||||
c-14.3-6.8-26.2-20.1-2.1-21.8c9.6-0.7,65.2-2.4,125.1,16.2c3-4.9,5.8-9.6,8.2-13.9c-63.3-21.6-124.4-24-125.5-8.6
|
||||
C18.4,81,7.4,67,31.6,66.7c9.9-0.1,68.5,1.5,129.1,25.3c21.2-39.5,16.4-52.7-2-64.6c21.6,1.5,57.2,37,45.6,86.1
|
||||
c8.8,5.4,22.8,14.1,31,20.7c-8.4-5.5-22.6-13.3-31.7-17.9C202.2,121.1,200.4,125.9,198.1,130.8"/>
|
||||
<path class="st2" d="M185.2,205.6c41.5-36.8,4.9-39.5,15.9-63.1c-14,12.6-44,47.2-18,64.1C164.7,168.9,207.4,157.8,185.2,205.6"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
62
src/assets/lang/de-CH.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
language: Sprach
|
||||
prename: Vorname
|
||||
lastName: Nachname
|
||||
birthday: Geburtstag
|
||||
email: Email
|
||||
group: Gruppe
|
||||
age: Auter
|
||||
address: Adresse
|
||||
town: Ort
|
||||
zipCode: Postleitzau
|
||||
phone: Telefon
|
||||
responsible: Verantwortlech
|
||||
firstVisit: Erste Bsuech
|
||||
lastVisit: Letscht Bsuech
|
||||
search: Suechi
|
||||
noDataAvailable: Keni Date
|
||||
importCSV: importier CSV
|
||||
selectMemberOptions: Wähle Mitglieder Optione
|
||||
addNewMember: Neues Mitglied
|
||||
csvOptions: CSV Optionen
|
||||
delete: Lösche
|
||||
edit: Editiere
|
||||
confirm: Bestätige
|
||||
cancel: Abbreche
|
||||
doYouWantToDelete: Wosch dä Iitrag lösche
|
||||
close: Zu tue
|
||||
loading: lade
|
||||
recordsPerPage: 'Iiträg pro Site:'
|
||||
recordSelected: Iiträg usgwäut
|
||||
selected: Usgwäut
|
||||
settings: Iistellige
|
||||
databaseName: Datebank Name
|
||||
token: Schlüssu
|
||||
login: Amäude
|
||||
user: Benutzer
|
||||
password: Passwort
|
||||
isRequired: isch erforderlich
|
||||
colors: Farbe
|
||||
primaryColor: Primär Farb
|
||||
secondaryColor: Sekondär Farb
|
||||
database: Datebank
|
||||
general: Augemein
|
||||
setColors: Setz Farbe
|
||||
icon: Ikon
|
||||
resetColors: Farbe zrügsetze
|
||||
save: Spichere
|
||||
users: Benutzer
|
||||
roles: Rollen
|
||||
name: Name
|
||||
role: Rolle
|
||||
addNewUser: Füeg neue Benutzer hinzue
|
||||
expires: Ablouf
|
||||
selectUserOptions: Wähle Benutzer Optione
|
||||
prenameIsRequired: Vorname ist erforderlich
|
||||
lastNameIsRequired: Nachname ist erforderlich
|
||||
birthdayIsRequired: Geburtstag ist erforderlich
|
||||
userIsRequired: Benutzer ist erforderlich
|
||||
emailIsRequired: Email ist erforderlich
|
||||
roleIsRequired: Rolle ist erforderlich
|
||||
rights: Recht
|
||||
selectRoleOptions: Wähle Roue Optione
|
||||
addNewRole: Füeg neui Roue hinzue
|
62
src/assets/lang/de-DE.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
language: Sprache
|
||||
prename: Vorname
|
||||
lastName: Nachname
|
||||
birthday: Geburtstag
|
||||
email: Email
|
||||
group: Gruppe
|
||||
age: Alter
|
||||
address: Adresse
|
||||
town: Ort
|
||||
zipCode: Postleitzahl
|
||||
phone: Telefon
|
||||
responsible: Verantwortlich
|
||||
firstVisit: Erster Besuch
|
||||
lastVisit: Letzter Besuch
|
||||
search: Suche
|
||||
noDataAvailable: Keine Daten
|
||||
importCSV: importiere CSV
|
||||
selectMemberOptions: Wähle Mitglieder Optionen
|
||||
addNewMember: Neues Mitglied
|
||||
csvOptions: CSV Optionen
|
||||
delete: Löschen
|
||||
edit: Editieren
|
||||
confirm: Bestätigen
|
||||
cancel: Abbrechen
|
||||
doYouWantToDelete: Willst du folgenden Eintrag löschen
|
||||
close: Schliessen
|
||||
loading: laden
|
||||
recordsPerPage: 'Einträge pro Seite:'
|
||||
recordSelected: Eintrag ausgewählt
|
||||
selected: Ausgewählt
|
||||
settings: Einstellungen
|
||||
databaseName: Datenbank Name
|
||||
token: Schlüssel
|
||||
login: Anmelden
|
||||
user: Benutzer
|
||||
password: Passwort
|
||||
isRequired: ist erforderlich
|
||||
colors: Farben
|
||||
primaryColor: Primär Farbe
|
||||
secondaryColor: Sekondär Farbe
|
||||
database: Datenbank
|
||||
general: Allgemein
|
||||
setColors: Setze Farben
|
||||
icon: Ikon
|
||||
resetColors: Farben zurücksetzen
|
||||
save: Speichern
|
||||
users: Benutzer
|
||||
roles: Rollen
|
||||
name: Name
|
||||
role: Rolle
|
||||
addNewUser: Füge neuen Benutzer hinzu
|
||||
expires: Ablauf
|
||||
selectUserOptions: Wähle Benutzer Optionen
|
||||
prenameIsRequired: Vorname ist erforderlich
|
||||
lastNameIsRequired: Nachname ist erforderlich
|
||||
birthdayIsRequired: Geburtstag ist erforderlich
|
||||
userIsRequired: Benutzer ist erforderlich
|
||||
emailIsRequired: Email ist erforderlich
|
||||
roleIsRequired: Rolle ist erforderlich
|
||||
rights: Rechte
|
||||
selectRoleOptions: Wähle Rollen Option
|
||||
addNewRole: Füge neue Rolle hinzu
|
62
src/assets/lang/en-US.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
language: Language
|
||||
prename: Prename
|
||||
lastName: Name
|
||||
birthday: Birthday
|
||||
email: Email
|
||||
group: Group
|
||||
age: Age
|
||||
address: Address
|
||||
town: Town
|
||||
zipCode: Zip Code
|
||||
phone: Phone
|
||||
responsible: Responsible
|
||||
firstVisit: First Visit
|
||||
lastVisit: Last Visit
|
||||
search: search
|
||||
noDataAvailable: No data available
|
||||
importCSV: Import CSV
|
||||
selectMemberOptions: Select Member Options
|
||||
addNewMember: Add new Member
|
||||
csvOptions: CSV Options
|
||||
delete: Delete
|
||||
edit: Edit
|
||||
confirm: Confirm
|
||||
cancel: Cancel
|
||||
doYouWantToDelete: Do you want to delete
|
||||
close: Close
|
||||
loading: loading
|
||||
recordsPerPage: 'Records per page:'
|
||||
recordSelected: record selected
|
||||
selected: Selected
|
||||
settings: Settings
|
||||
databaseName: Database Name
|
||||
token: Token
|
||||
login: Login
|
||||
user: User
|
||||
password: Password
|
||||
isRequired: is required
|
||||
colors: Colors
|
||||
primaryColor: Primary Color
|
||||
secondaryColor: Secondary Color
|
||||
database: Database
|
||||
general: General
|
||||
setColors: Set Colors
|
||||
icon: Icon
|
||||
resetColors: Reset Colors
|
||||
save: Save
|
||||
users: Users
|
||||
roles: Roles
|
||||
name: Name
|
||||
role: Role
|
||||
addNewUser: Add new User
|
||||
expires: Expires
|
||||
selectUserOptions: Select User Options
|
||||
prenameIsRequired: Fist Name is required
|
||||
lastNameIsRequired: Last Name is required
|
||||
birthdayIsRequired: Birthday is required
|
||||
userIsRequired: User is required
|
||||
emailIsRequired: Email is required
|
||||
roleIsRequired: Role is required
|
||||
rights: Rights
|
||||
selectRoleOptions: Select Role Options
|
||||
addNewRole: Add new Role
|
3
src/assets/lang/es-ES.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
hello: hola
|
||||
goodbye: adios
|
||||
language: Lengua
|
1
src/assets/pottershouse.svg
Normal file
After Width: | Height: | Size: 233 KiB |
15
src/assets/quasar-logo-vertical.svg
Normal file
@@ -0,0 +1,15 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 356 360">
|
||||
<path
|
||||
d="M43.4 303.4c0 3.8-2.3 6.3-7.1 6.3h-15v-22h14.4c4.3 0 6.2 2.2 6.2 5.2 0 2.6-1.5 4.4-3.4 5 2.8.4 4.9 2.5 4.9 5.5zm-8-13H24.1v6.9H35c2.1 0 4-1.3 4-3.8 0-2.2-1.3-3.1-3.7-3.1zm5.1 12.6c0-2.3-1.8-3.7-4-3.7H24.2v7.7h11.7c3.4 0 4.6-1.8 4.6-4zm36.3 4v2.7H56v-22h20.6v2.7H58.9v6.8h14.6v2.3H58.9v7.5h17.9zm23-5.8v8.5H97v-8.5l-11-13.4h3.4l8.9 11 8.8-11h3.4l-10.8 13.4zm19.1-1.8V298c0-7.9 5.2-10.7 12.7-10.7 7.5 0 13 2.8 13 10.7v1.4c0 7.9-5.5 10.8-13 10.8s-12.7-3-12.7-10.8zm22.7 0V298c0-5.7-3.9-8-10-8-6 0-9.8 2.3-9.8 8v1.4c0 5.8 3.8 8.1 9.8 8.1 6 0 10-2.3 10-8.1zm37.2-11.6v21.9h-2.9l-15.8-17.9v17.9h-2.8v-22h3l15.6 18v-18h2.9zm37.9 10.2v1.3c0 7.8-5.2 10.4-12.4 10.4H193v-22h11.2c7.2 0 12.4 2.8 12.4 10.3zm-3 0c0-5.3-3.3-7.6-9.4-7.6h-8.4V307h8.4c6 0 9.5-2 9.5-7.7V298zm50.8-7.6h-9.7v19.3h-3v-19.3h-9.7v-2.6h22.4v2.6zm34.4-2.6v21.9h-3v-10.1h-16.8v10h-2.8v-21.8h2.8v9.2H296v-9.2h2.9zm34.9 19.2v2.7h-20.7v-22h20.6v2.7H316v6.8h14.5v2.3H316v7.5h17.8zM24 340.2v7.3h13.9v2.4h-14v9.6H21v-22h20v2.7H24zm41.5 11.4h-9.8v7.9H53v-22h13.3c5.1 0 8 1.9 8 6.8 0 3.7-2 6.3-5.6 7l6 8.2h-3.3l-5.8-8zm-9.8-2.6H66c3.1 0 5.3-1.5 5.3-4.7 0-3.3-2.2-4.1-5.3-4.1H55.7v8.8zm47.9 6.2H89l-2 4.3h-3.2l10.7-22.2H98l10.7 22.2h-3.2l-2-4.3zm-1-2.3l-6.3-13-6 13h12.2zm46.3-15.3v21.9H146v-17.2L135.7 358h-2.1l-10.2-15.6v17h-2.8v-21.8h3l11 16.9 11.3-17h3zm35 19.3v2.6h-20.7v-22h20.6v2.7H166v6.8h14.5v2.3H166v7.6h17.8zm47-19.3l-8.3 22h-3l-7.1-18.6-7 18.6h-3l-8.2-22h3.3L204 356l6.8-18.5h3.4L221 356l6.6-18.5h3.3zm10 11.6v-1.4c0-7.8 5.2-10.7 12.7-10.7 7.6 0 13 2.9 13 10.7v1.4c0 7.9-5.4 10.8-13 10.8-7.5 0-12.7-3-12.7-10.8zm22.8 0v-1.4c0-5.7-4-8-10-8s-9.9 2.3-9.9 8v1.4c0 5.8 3.8 8.2 9.8 8.2 6.1 0 10-2.4 10-8.2zm28.3 2.4h-9.8v7.9h-2.8v-22h13.2c5.2 0 8 1.9 8 6.8 0 3.7-2 6.3-5.6 7l6 8.2h-3.3l-5.8-8zm-9.8-2.6h10.2c3 0 5.2-1.5 5.2-4.7 0-3.3-2.1-4.1-5.2-4.1h-10.2v8.8zm40.3-1.5l-6.8 5.6v6.4h-2.9v-22h2.9v12.3l15.2-12.2h3.7l-9.9 8.1 10.3 13.8h-3.6l-8.9-12z" />
|
||||
<path fill="#050A14"
|
||||
d="M188.4 71.7a10.4 10.4 0 01-20.8 0 10.4 10.4 0 1120.8 0zM224.2 45c-2.2-3.9-5-7.5-8.2-10.7l-12 7c-3.7-3.2-8-5.7-12.6-7.3a49.4 49.4 0 00-9.7 13.9 59 59 0 0140.1 14l7.6-4.4a57 57 0 00-5.2-12.5zM178 125.1c4.5 0 9-.6 13.4-1.7v-14a40 40 0 0012.5-7.2 47.7 47.7 0 00-7.1-15.3 59 59 0 01-32.2 27.7v8.7c4.4 1.2 8.9 1.8 13.4 1.8zM131.8 45c-2.3 4-4 8.1-5.2 12.5l12 7a40 40 0 000 14.4c5.7 1.5 11.3 2 16.9 1.5a59 59 0 01-8-41.7l-7.5-4.3c-3.2 3.2-6 6.7-8.2 10.6z" />
|
||||
<path fill="#00B4FF"
|
||||
d="M224.2 98.4c2.3-3.9 4-8 5.2-12.4l-12-7a40 40 0 000-14.5c-5.7-1.5-11.3-2-16.9-1.5a59 59 0 018 41.7l7.5 4.4c3.2-3.2 6-6.8 8.2-10.7zm-92.4 0c2.2 4 5 7.5 8.2 10.7l12-7a40 40 0 0012.6 7.3c4-4.1 7.3-8.8 9.7-13.8a59 59 0 01-40-14l-7.7 4.4c1.2 4.3 3 8.5 5.2 12.4zm46.2-80c-4.5 0-9 .5-13.4 1.7V34a40 40 0 00-12.5 7.2c1.5 5.7 4 10.8 7.1 15.4a59 59 0 0132.2-27.7V20a53.3 53.3 0 00-13.4-1.8z" />
|
||||
<path fill="#00B4FF"
|
||||
d="M178 9.2a62.6 62.6 0 11-.1 125.2A62.6 62.6 0 01178 9.2m0-9.2a71.7 71.7 0 100 143.5A71.7 71.7 0 00178 0z" />
|
||||
<path fill="#050A14"
|
||||
d="M96.6 212v4.3c-9.2-.8-15.4-5.8-15.4-17.8V180h4.6v18.4c0 8.6 4 12.6 10.8 13.5zm16-31.9v18.4c0 8.9-4.3 12.8-10.9 13.5v4.4c9.2-.7 15.5-5.6 15.5-18v-18.3h-4.7zM62.2 199v-2.2c0-12.7-8.8-17.4-21-17.4-12.1 0-20.7 4.7-20.7 17.4v2.2c0 12.8 8.6 17.6 20.7 17.6 1.5 0 3-.1 4.4-.3l11.8 6.2 2-3.3-8.2-4-6.4-3.1a32 32 0 01-3.6.2c-9.8 0-16-3.9-16-13.3v-2.2c0-9.3 6.2-13.1 16-13.1 9.9 0 16.3 3.8 16.3 13.1v2.2c0 5.3-2.1 8.7-5.6 10.8l4.8 2.4c3.4-2.8 5.5-7 5.5-13.2zM168 215.6h5.1L156 179.7h-4.8l17 36zM143 205l7.4-15.7-2.4-5-15.1 31.4h5.1l3.3-7h18.3l-1.8-3.7H143zm133.7 10.7h5.2l-17.3-35.9h-4.8l17 36zm-25-10.7l7.4-15.7-2.4-5-15.1 31.4h5.1l3.3-7h18.3l-1.7-3.7h-14.8zm73.8-2.5c6-1.2 9-5.4 9-11.4 0-8-4.5-10.9-12.9-10.9h-21.4v35.5h4.6v-31.3h16.5c5 0 8.5 1.4 8.5 6.7 0 5.2-3.5 7.7-8.5 7.7h-11.4v4.1h10.7l9.3 12.8h5.5l-9.9-13.2zm-117.4 9.9c-9.7 0-14.7-2.5-18.6-6.3l-2.2 3.8c5.1 5 11 6.7 21 6.7 1.6 0 3.1-.1 4.6-.3l-1.9-4h-3zm18.4-7c0-6.4-4.7-8.6-13.8-9.4l-10.1-1c-6.7-.7-9.3-2.2-9.3-5.6 0-2.5 1.4-4 4.6-5l-1.8-3.8c-4.7 1.4-7.5 4.2-7.5 8.9 0 5.2 3.4 8.7 13 9.6l11.3 1.2c6.4.6 8.9 2 8.9 5.4 0 2.7-2.1 4.7-6 5.8l1.8 3.9c5.3-1.6 8.9-4.7 8.9-10zm-20.3-21.9c7.9 0 13.3 1.8 18.1 5.7l1.8-3.9a30 30 0 00-19.6-5.9c-2 0-4 .1-5.7.3l1.9 4 3.5-.2z" />
|
||||
<path fill="#00B4FF"
|
||||
d="M.5 251.9c29.6-.5 59.2-.8 88.8-1l88.7-.3 88.7.3 44.4.4 44.4.6-44.4.6-44.4.4-88.7.3-88.7-.3a7981 7981 0 01-88.8-1z" />
|
||||
<path fill="none" d="M-565.2 324H-252v15.8h-313.2z" />
|
||||
</svg>
|
After Width: | Height: | Size: 4.4 KiB |
0
src/boot/.gitkeep
Normal file
23
src/boot/auth.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { boot } from 'quasar/wrappers';
|
||||
import { appApi } from './axios';
|
||||
import { createPinia } from 'pinia';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
|
||||
const pinia = createPinia();
|
||||
|
||||
export default boot(async ({ app }) => {
|
||||
app.use(pinia);
|
||||
const useStore = useUserStore();
|
||||
const login = useLogin();
|
||||
|
||||
await appApi
|
||||
.get('/login/me')
|
||||
.then((resp) => {
|
||||
useStore.setUser({ id: resp.data.id, username: resp.data.username, role: resp.data.role });
|
||||
login.refresh().catch((err) => console.error(err));
|
||||
})
|
||||
.catch(() => {
|
||||
login.logout().catch((err) => console.error(err));
|
||||
});
|
||||
});
|
125
src/boot/axios.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { boot } from 'quasar/wrappers';
|
||||
import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
|
||||
const host = window.location.hostname;
|
||||
export const portApp = 9500;
|
||||
|
||||
// Create axios instance
|
||||
export const appApi: AxiosInstance = axios.create({
|
||||
baseURL: `https://${host}:${portApp}/api`,
|
||||
timeout: 10000,
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
interface RetryRequestConfig extends AxiosRequestConfig {
|
||||
_retry?: boolean;
|
||||
}
|
||||
|
||||
const noRefreshEndpoints = ['/login', '/secure/login/refresh', '/logout'];
|
||||
|
||||
// ========= Refresh Queue Handling ========= //
|
||||
let isRefreshing = false;
|
||||
|
||||
interface FailedRequest {
|
||||
resolve: (value?: unknown) => void;
|
||||
reject: (reason?: Error) => void;
|
||||
}
|
||||
|
||||
let failedQueue: FailedRequest[] = [];
|
||||
|
||||
const processQueue = (error: Error | null): void => {
|
||||
failedQueue.forEach((prom) => {
|
||||
if (error) prom.reject(error);
|
||||
else prom.resolve();
|
||||
});
|
||||
failedQueue = [];
|
||||
};
|
||||
// ========================================= //
|
||||
|
||||
appApi.interceptors.response.use(
|
||||
(response: AxiosResponse) => response,
|
||||
|
||||
async (error: AxiosError<unknown, RetryRequestConfig>): Promise<AxiosResponse> => {
|
||||
const { refresh, logout } = useLogin();
|
||||
const originalRequest = error.config as RetryRequestConfig | undefined;
|
||||
|
||||
// Skip refresh for login/logout endpoints
|
||||
if (
|
||||
!originalRequest ||
|
||||
noRefreshEndpoints.some((url) => originalRequest.url?.includes(url ?? ''))
|
||||
) {
|
||||
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
// Handle unauthorized responses
|
||||
if (error.response?.status === 401 && !originalRequest._retry) {
|
||||
if (isRefreshing) {
|
||||
// Wait until refresh completes
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
failedQueue.push({
|
||||
resolve: () => {
|
||||
void appApi(originalRequest).then(resolve).catch(reject);
|
||||
},
|
||||
reject,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
originalRequest._retry = true;
|
||||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
const refreshed = await refresh().catch(() => false);
|
||||
processQueue(null);
|
||||
|
||||
if (refreshed) {
|
||||
// Token refreshed successfully → retry request
|
||||
return appApi(originalRequest);
|
||||
}
|
||||
|
||||
// Refresh returned false → logout
|
||||
console.warn('[Axios] Refresh returned false, logging out');
|
||||
await logout();
|
||||
throw new Error('Token refresh failed');
|
||||
} catch (err) {
|
||||
const e = err instanceof Error ? err : new Error(String(err));
|
||||
console.error('[Axios] Token refresh failed:', e.message);
|
||||
|
||||
// Always logout, even if refresh throws
|
||||
try {
|
||||
await logout();
|
||||
} catch (logoutErr) {
|
||||
console.error('[Axios] Logout failed after token refresh error:', logoutErr);
|
||||
}
|
||||
|
||||
processQueue(e);
|
||||
throw e;
|
||||
} finally {
|
||||
isRefreshing = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Not a 401 — rethrow as Error
|
||||
|
||||
let msg = '';
|
||||
if (error && (error as AxiosError).isAxiosError) {
|
||||
const axiosError = error as AxiosError<{ message?: string }>;
|
||||
msg = axiosError.response?.data?.message ?? axiosError.message;
|
||||
} else {
|
||||
msg = error instanceof Error ? error.message : JSON.stringify(error);
|
||||
}
|
||||
|
||||
throw new Error(msg);
|
||||
},
|
||||
);
|
||||
|
||||
// ======== Boot registration for Quasar ======== //
|
||||
export default boot(({ app }) => {
|
||||
app.config.globalProperties.$axios = axios;
|
||||
app.config.globalProperties.$appApi = appApi;
|
||||
});
|
||||
|
||||
export { axios };
|
38
src/boot/lang.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export const lang = [];
|
||||
|
||||
const systemLocale = navigator.language || 'en-US';
|
||||
const savedLang = localStorage.getItem('lang');
|
||||
|
||||
const messages = {};
|
||||
const modules = import.meta.glob('src/assets/lang/*.yaml', {
|
||||
eager: true,
|
||||
import: 'default',
|
||||
query: '?raw',
|
||||
});
|
||||
|
||||
for (const path in modules) {
|
||||
const raw = modules[path];
|
||||
const parsed = yaml.load(raw);
|
||||
|
||||
// Extract the file name (e.g., "en.yaml" → "en")
|
||||
const locale = path.split('/').pop().replace('.yaml', '');
|
||||
|
||||
lang.push(locale);
|
||||
messages[locale] = parsed;
|
||||
}
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false, // Composition API mode
|
||||
locale: savedLang || systemLocale,
|
||||
fallbackLocale: systemLocale,
|
||||
messages,
|
||||
});
|
||||
|
||||
export default ({ app }) => {
|
||||
app.use(i18n);
|
||||
};
|
||||
|
||||
export { i18n };
|
25
src/boot/quasar-global.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { boot } from 'quasar/wrappers';
|
||||
import { setQuasarInstance } from 'src/utils/globalQ';
|
||||
import { setRouterInstance } from 'src/utils/globalRouter';
|
||||
import { databaseName } from 'src/vueLib/tables/members/MembersTable';
|
||||
import { Logo } from 'src/vueLib/models/logo';
|
||||
|
||||
export default boot(({ app, router }) => {
|
||||
setRouterInstance(router); // store router for global access
|
||||
const $q = app.config.globalProperties.$q;
|
||||
setQuasarInstance($q);
|
||||
|
||||
Logo.value = localStorage.getItem('icon') ?? Logo.value;
|
||||
databaseName.value = localStorage.getItem('databaseName') ?? databaseName.value;
|
||||
let primaryColor = localStorage.getItem('primaryColor');
|
||||
if (primaryColor == null || primaryColor === 'undefined' || primaryColor.trim() === '') {
|
||||
primaryColor = null;
|
||||
}
|
||||
let secondaryColor = localStorage.getItem('secondaryColor');
|
||||
if (secondaryColor == null || secondaryColor === 'undefined' || secondaryColor.trim() === '') {
|
||||
secondaryColor = null;
|
||||
}
|
||||
|
||||
document.documentElement.style.setProperty('--q-primary', primaryColor ?? '#1976d2');
|
||||
document.documentElement.style.setProperty('--q-secondary', secondaryColor ?? '#26a69a');
|
||||
});
|
68
src/components/EditOneDialog.vue
Normal file
@@ -0,0 +1,68 @@
|
||||
<template>
|
||||
<DialogFrame ref="dialog" :header-title="'Edit ' + localTitle">
|
||||
<div class="row justify-center">
|
||||
<q-input
|
||||
autofocus
|
||||
class="q-ml-md col-6"
|
||||
:label="localTitle"
|
||||
filled
|
||||
v-model="value"
|
||||
@keyup.enter="save"
|
||||
></q-input>
|
||||
</div>
|
||||
<div class="row justify-center">
|
||||
<q-btn class="q-ma-md" color="primary" no-caps @click="save">Save</q-btn>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import type { Member } from 'src/vueLib/models/member';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
|
||||
const dialog = ref();
|
||||
const localMember = ref();
|
||||
const localTitle = ref('');
|
||||
const localField = ref('');
|
||||
const value = ref('');
|
||||
|
||||
const emit = defineEmits(['update']);
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
function open(label: string, field: string, member: Member) {
|
||||
localTitle.value = label;
|
||||
localField.value = field;
|
||||
localMember.value = member;
|
||||
|
||||
value.value = localMember.value[field];
|
||||
dialog.value?.open();
|
||||
}
|
||||
|
||||
function save() {
|
||||
const query = 'secure/members/edit?id=' + localMember.value.id;
|
||||
let payload = {};
|
||||
|
||||
if (value.value === localMember.value[localField.value]) {
|
||||
dialog.value.close();
|
||||
return;
|
||||
}
|
||||
payload = {
|
||||
[localField.value]: value.value,
|
||||
};
|
||||
|
||||
appApi
|
||||
.post(query, payload)
|
||||
.then(() => {
|
||||
emit('update', '');
|
||||
dialog.value.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
186
src/components/MemberEditAllDialog.vue
Normal file
@@ -0,0 +1,186 @@
|
||||
<template>
|
||||
<DialogFrame
|
||||
ref="dialog"
|
||||
:header-title="
|
||||
newMember ? $t('addNewMember') : 'Edit ' + localMember.firstName + ' ' + localMember.lastName
|
||||
"
|
||||
:height="600"
|
||||
:width="500"
|
||||
>
|
||||
<q-form ref="form">
|
||||
<div class="row justify-center q-gutter-md">
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('prename')"
|
||||
filled
|
||||
:rules="[(val) => !!val || $t('prenameIsRequired')]"
|
||||
v-model="localMember.firstName"
|
||||
autofocus
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('lastName')"
|
||||
filled
|
||||
:rules="[(val) => !!val || $t('lastNameIsRequired')]"
|
||||
v-model="localMember.lastName"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('birthday')"
|
||||
:rules="[(val) => !!val || $t('birthdayIsRequired')]"
|
||||
filled
|
||||
v-model="localMember.birthday"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('address')"
|
||||
filled
|
||||
v-model="localMember.address"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('town')"
|
||||
filled
|
||||
v-model="localMember.town"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('zipCode')"
|
||||
filled
|
||||
v-model="localMember.zip"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('phone')"
|
||||
filled
|
||||
v-model="localMember.phone"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('email')"
|
||||
filled
|
||||
v-model="localMember.email"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('group')"
|
||||
filled
|
||||
v-model="localMember.group"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('responsible')"
|
||||
filled
|
||||
v-model="localMember.responsiblePerson"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="!newMember"
|
||||
class="q-ml-md col-11"
|
||||
:label="$t('firstVisit')"
|
||||
filled
|
||||
v-model="localMember.firstVisit"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="!newMember"
|
||||
class="q-ml-md col-11"
|
||||
:label="$t('lastVisit')"
|
||||
filled
|
||||
v-model="localMember.lastVisit"
|
||||
></q-input>
|
||||
</div>
|
||||
</q-form>
|
||||
<div class="row justify-center">
|
||||
<q-btn class="q-ma-md" color="primary" no-caps @click="save">Save</q-btn>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import type { Member } from 'src/vueLib/models/member';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const dialog = ref();
|
||||
const form = ref();
|
||||
const newMember = ref(false);
|
||||
const localMember = ref<Member>({
|
||||
id: 0,
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
birthday: '',
|
||||
age: '',
|
||||
address: '',
|
||||
town: '',
|
||||
zip: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
group: '',
|
||||
responsiblePerson: '',
|
||||
firstVisit: '',
|
||||
lastVisit: '',
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update-member']);
|
||||
|
||||
function open(member: Member | null) {
|
||||
if (member === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (member !== null) {
|
||||
localMember.value = member;
|
||||
newMember.value = false;
|
||||
} else {
|
||||
localMember.value = {
|
||||
id: 0,
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
birthday: '',
|
||||
age: '',
|
||||
address: '',
|
||||
town: '',
|
||||
zip: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
group: '',
|
||||
responsiblePerson: '',
|
||||
firstVisit: '',
|
||||
lastVisit: '',
|
||||
};
|
||||
newMember.value = true;
|
||||
}
|
||||
|
||||
dialog.value?.open();
|
||||
}
|
||||
|
||||
async function save() {
|
||||
const valid = await form.value.validate();
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
let query = 'secure/members/edit?id=' + localMember.value.id;
|
||||
if (newMember.value) {
|
||||
query = 'secure/members/add';
|
||||
}
|
||||
|
||||
appApi
|
||||
.post(query, JSON.stringify(localMember.value))
|
||||
.then(() => {
|
||||
emit('update-member');
|
||||
dialog.value.close();
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.required .q-field__label::after {
|
||||
content: ' *';
|
||||
color: red;
|
||||
}
|
||||
</style>
|
83
src/components/RoleEditAllDialog.vue
Normal file
@@ -0,0 +1,83 @@
|
||||
<template>
|
||||
<DialogFrame
|
||||
ref="dialog"
|
||||
:header-title="newRole ? $t('addNewRole') : 'Edit ' + localRole.role"
|
||||
:height="600"
|
||||
:width="500"
|
||||
>
|
||||
<div class="row justify-center q-gutter-md">
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('role')"
|
||||
filled
|
||||
:rules="[(val) => !!val || $t('roleIsRequired')]"
|
||||
v-model="localRole.role"
|
||||
autofocus
|
||||
></q-input>
|
||||
</div>
|
||||
<div class="row justify-center">
|
||||
<q-btn class="q-ma-md" color="primary" no-caps @click="save">Save</q-btn>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import type { Role } from 'src/vueLib/models/roles';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const dialog = ref();
|
||||
const newRole = ref(false);
|
||||
const localRole = ref<Role>({
|
||||
role: '',
|
||||
rights: null,
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update-role']);
|
||||
|
||||
function open(role: Role | null) {
|
||||
if (role === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (role !== null) {
|
||||
localRole.value = role;
|
||||
newRole.value = false;
|
||||
} else {
|
||||
localRole.value = {
|
||||
role: '',
|
||||
rights: null,
|
||||
};
|
||||
newRole.value = true;
|
||||
}
|
||||
|
||||
dialog.value?.open();
|
||||
}
|
||||
|
||||
function save() {
|
||||
let query = 'secure/roles/edit?id=' + localRole.value.id;
|
||||
if (newRole.value) {
|
||||
query = 'secure/roles/add';
|
||||
}
|
||||
|
||||
appApi
|
||||
.post(query, JSON.stringify(localRole.value))
|
||||
.then(() => {
|
||||
emit('update-role');
|
||||
dialog.value.close();
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.required .q-field__label::after {
|
||||
content: ' *';
|
||||
color: red;
|
||||
}
|
||||
</style>
|
218
src/components/UploadDialog.vue
Normal file
@@ -0,0 +1,218 @@
|
||||
<template>
|
||||
<DialogFrame ref="dialog" header-title="Import CSV" :height="dialogHeight" :width="dialogWidth">
|
||||
<div class="column q-gutter-xs">
|
||||
<div class="row">
|
||||
<q-uploader
|
||||
style="max-width: 300px"
|
||||
:url="/api/members/import/csv"
|
||||
label="Import CSV"
|
||||
multiple
|
||||
accept=".csv"
|
||||
field-name="file"
|
||||
method="POST"
|
||||
:form-fields="metaData"
|
||||
v-on:failed="onImportFail"
|
||||
:headers="[{ name: 'Accept', value: 'application/json' }]"
|
||||
@uploaded="onUploaded"
|
||||
/>
|
||||
</div>
|
||||
<q-card :flat="!showOptions">
|
||||
<div class="row q-ma-sm">
|
||||
<div class="text-bold q-ma-sm">
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
size="sm"
|
||||
:icon="showOptions ? 'remove' : 'add'"
|
||||
@click="showOptions = !showOptions"
|
||||
></q-btn>
|
||||
CSV options
|
||||
</div>
|
||||
<div class="row justify-center q-gutter-md">
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-4"
|
||||
label="Row Index of Column titles"
|
||||
dense
|
||||
borderless
|
||||
type="number"
|
||||
v-model.number="data.rowIndex"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-4"
|
||||
label="Seperator"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.seperator"
|
||||
></q-input>
|
||||
<q-space class="col-1"></q-space>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="First Name"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.firstName"
|
||||
autofocus
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="Last Name"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.lastName"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="Birthday"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.birthday"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="Address"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.address"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="Town"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.town"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="Zip Code"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.zip"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="Phone"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.phone"
|
||||
></q-input>
|
||||
<q-input
|
||||
v-if="showOptions"
|
||||
class="col-2"
|
||||
label="E-Mail"
|
||||
dense
|
||||
borderless
|
||||
v-model="data.email"
|
||||
></q-input>
|
||||
</div>
|
||||
</div>
|
||||
</q-card>
|
||||
<div class="row justify-end q-ma-sm">
|
||||
<q-btn no-caps color="primary" class="col-3" v-close-popup>{{ $t('close') }}</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref, watch } from 'vue';
|
||||
import type { MetaData } from 'src/vueLib/models/metaData';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { portApp } from 'src/boot/axios';
|
||||
|
||||
const dialogHeight = ref(300);
|
||||
const dialogWidth = ref(500);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const emit = defineEmits(['update-upload']);
|
||||
|
||||
const dialog = ref();
|
||||
const showOptions = ref(true);
|
||||
const data = ref<MetaData>({
|
||||
rowIndex: 0,
|
||||
seperator: ';',
|
||||
firstName: 'firstName',
|
||||
lastName: 'lastName',
|
||||
birthday: 'birthday',
|
||||
address: 'address',
|
||||
town: 'town',
|
||||
zip: 'zip',
|
||||
phone: 'phone',
|
||||
email: 'email',
|
||||
});
|
||||
|
||||
const metaData = ref([
|
||||
{ name: 'rowIndex', value: String(data.value.rowIndex) },
|
||||
{ name: 'seperator', value: data.value.seperator },
|
||||
{ name: 'firstName', value: data.value.firstName },
|
||||
{ name: 'lastName', value: data.value.lastName },
|
||||
{ name: 'birthday', value: data.value.birthday },
|
||||
{ name: 'address', value: data.value.address },
|
||||
{ name: 'town', value: data.value.town },
|
||||
{ name: 'zip', value: data.value.zip },
|
||||
{ name: 'phone', value: data.value.phone },
|
||||
{ name: 'email', value: data.value.email },
|
||||
]);
|
||||
|
||||
function open() {
|
||||
showOptions.value = false;
|
||||
dialog.value?.open();
|
||||
}
|
||||
|
||||
watch(showOptions, () => {
|
||||
if (dialogWidth.value === 500) {
|
||||
dialogWidth.value = 325;
|
||||
dialogHeight.value = 325;
|
||||
return;
|
||||
}
|
||||
dialogHeight.value = 500;
|
||||
dialogWidth.value = 500;
|
||||
});
|
||||
|
||||
watch(
|
||||
data,
|
||||
() => {
|
||||
metaData.value = [
|
||||
{ name: 'rowIndex', value: String(data.value.rowIndex) },
|
||||
{ name: 'seperator', value: data.value.seperator },
|
||||
{ name: 'firstName', value: data.value.firstName },
|
||||
{ name: 'lastName', value: data.value.lastName },
|
||||
{ name: 'birthday', value: data.value.birthday },
|
||||
{ name: 'address', value: data.value.address },
|
||||
{ name: 'town', value: data.value.town },
|
||||
{ name: 'zip', value: data.value.zip },
|
||||
{ name: 'phone', value: data.value.phone },
|
||||
{ name: 'email', value: data.value.email },
|
||||
];
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
function onImportFail(info: { files: readonly File[]; xhr: XMLHttpRequest }) {
|
||||
const response = JSON.parse(info.xhr.responseText);
|
||||
if (response.message) {
|
||||
NotifyResponse(response.message, 'error', 15000);
|
||||
}
|
||||
emit('update-upload');
|
||||
}
|
||||
|
||||
function onUploaded(info: { files: readonly File[]; xhr: XMLHttpRequest }) {
|
||||
const response = JSON.parse(info.xhr.responseText);
|
||||
if (response.message) {
|
||||
NotifyResponse(response.message);
|
||||
}
|
||||
emit('update-upload');
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
107
src/components/UserEditAllDialog.vue
Normal file
@@ -0,0 +1,107 @@
|
||||
<template>
|
||||
<DialogFrame
|
||||
ref="dialog"
|
||||
:header-title="newUser ? $t('addNewUser') : 'Edit ' + localUser.user"
|
||||
:height="600"
|
||||
:width="500"
|
||||
>
|
||||
<div class="row justify-center q-gutter-md">
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('user')"
|
||||
filled
|
||||
:rules="[(val) => !!val || $t('userIsRequired')]"
|
||||
v-model="localUser.user"
|
||||
autofocus
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('email')"
|
||||
filled
|
||||
:rules="[(val) => !!val || $t('emailIsRequired')]"
|
||||
v-model="localUser.email"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5 required"
|
||||
:label="$t('role')"
|
||||
filled
|
||||
:rules="[(val) => !!val || $t('roleIsRequired')]"
|
||||
v-model="localUser.role"
|
||||
></q-input>
|
||||
<q-input
|
||||
class="q-ml-md col-5"
|
||||
:label="$t('expires')"
|
||||
filled
|
||||
v-model="localUser.expires"
|
||||
></q-input>
|
||||
</div>
|
||||
<div class="row justify-center">
|
||||
<q-btn class="q-ma-md" color="primary" no-caps @click="save">Save</q-btn>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import type { User } from 'src/vueLib/models/users';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const dialog = ref();
|
||||
const newUser = ref(false);
|
||||
const localUser = ref<User>({
|
||||
user: '',
|
||||
email: '',
|
||||
role: '',
|
||||
expires: '',
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update-user']);
|
||||
|
||||
function open(user: User | null) {
|
||||
if (user === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user !== null) {
|
||||
localUser.value = user;
|
||||
newUser.value = false;
|
||||
} else {
|
||||
localUser.value = {
|
||||
user: '',
|
||||
email: '',
|
||||
role: '',
|
||||
expires: '',
|
||||
};
|
||||
newUser.value = true;
|
||||
}
|
||||
|
||||
dialog.value?.open();
|
||||
}
|
||||
|
||||
function save() {
|
||||
let query = 'secure/users/edit?id=' + localUser.value.id;
|
||||
if (newUser.value) {
|
||||
query = 'secure/users/add';
|
||||
}
|
||||
|
||||
appApi
|
||||
.post(query, JSON.stringify(localUser.value))
|
||||
.then(() => {
|
||||
emit('update-user');
|
||||
dialog.value.close();
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.required .q-field__label::after {
|
||||
content: ' *';
|
||||
color: red;
|
||||
}
|
||||
</style>
|
92
src/components/dialog/OkDialog.vue
Normal file
@@ -0,0 +1,92 @@
|
||||
<template>
|
||||
<q-dialog ref="dialog">
|
||||
<q-card :style="'width:' + props.width">
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel"
|
||||
class="text-h6 text-center"
|
||||
:class="'text-' + props.labelColor"
|
||||
>{{ props.dialogLabel }}</q-card-section
|
||||
>
|
||||
<q-card-section v-if="props.text" class="text-center" style="white-space: pre-line">{{
|
||||
props.text
|
||||
}}</q-card-section>
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn
|
||||
v-if="props.buttonCancelLabel"
|
||||
:flat="props.buttonCancelFlat"
|
||||
:label="props.buttonCancelLabel"
|
||||
v-close-popup
|
||||
>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="props.buttonOkLabel"
|
||||
:flat="props.buttonOkFlat"
|
||||
:label="props.buttonOkLabel"
|
||||
:color="props.buttonOkColor"
|
||||
v-close-popup
|
||||
@click="confirm"
|
||||
>
|
||||
</q-btn>
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
buttonOkLabel: {
|
||||
type: String,
|
||||
default: 'OK',
|
||||
},
|
||||
buttonOkColor: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
buttonOkFlat: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
labelColor: {
|
||||
type: String,
|
||||
default: 'primary',
|
||||
},
|
||||
dialogLabel: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
text: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
buttonCancelLabel: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
buttonCancelFlat: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update-confirm']);
|
||||
|
||||
const dialog = ref();
|
||||
const localInput = ref();
|
||||
|
||||
const open = (input?: unknown) => {
|
||||
localInput.value = input;
|
||||
dialog.value?.show();
|
||||
};
|
||||
|
||||
const confirm = () => {
|
||||
emit('update-confirm', localInput.value);
|
||||
};
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
1
src/css/app.scss
Normal file
@@ -0,0 +1 @@
|
||||
// app global css in SCSS form
|
25
src/css/quasar.variables.scss
Normal file
@@ -0,0 +1,25 @@
|
||||
// Quasar SCSS (& Sass) Variables
|
||||
// --------------------------------------------------
|
||||
// To customize the look and feel of this app, you can override
|
||||
// the Sass/SCSS variables found in Quasar's source Sass/SCSS files.
|
||||
|
||||
// Check documentation for full list of Quasar variables
|
||||
|
||||
// Your own variables (that are declared here) and Quasar's own
|
||||
// ones will be available out of the box in your .vue/.scss/.sass files
|
||||
|
||||
// It's highly recommended to change the default colors
|
||||
// to match your app's branding.
|
||||
// Tip: Use the "Theme Builder" on Quasar's documentation website.
|
||||
|
||||
$primary: #1976d2;
|
||||
$secondary: #26a69a;
|
||||
$accent: #9c27b0;
|
||||
|
||||
$dark: #1d1d1d;
|
||||
$dark-page: #121212;
|
||||
|
||||
$positive: #21ba45;
|
||||
$negative: #c10015;
|
||||
$info: #31ccec;
|
||||
$warning: #f2c037;
|
7
src/env.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
declare namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
NODE_ENV: string;
|
||||
VUE_ROUTER_MODE: 'hash' | 'history' | 'abstract' | undefined;
|
||||
VUE_ROUTER_BASE: string | undefined;
|
||||
}
|
||||
}
|
61
src/layouts/MainLayout.vue
Normal file
@@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<q-layout view="lHh Lpr lFf">
|
||||
<q-header elevated>
|
||||
<q-toolbar>
|
||||
<q-img
|
||||
:src="localLogo"
|
||||
alt="Logo"
|
||||
style="width: 40px; height: 40px; background-color: var(--q-primary)"
|
||||
class="q-mr-sm"
|
||||
/>
|
||||
<q-btn flat dense round icon="menu" aria-label="Menu" @click="toggleLeftDrawer" />
|
||||
|
||||
<q-toolbar-title> {{ productName }} </q-toolbar-title>
|
||||
|
||||
<div>Version {{ version }}</div>
|
||||
<q-btn dense icon="refresh" square class="q-px-md q-ml-md" @click="refresh" />
|
||||
<LoginMenu />
|
||||
</q-toolbar>
|
||||
</q-header>
|
||||
|
||||
<q-drawer v-model="leftDrawerOpen" bordered>
|
||||
<q-list>
|
||||
<q-item v-if="!autorized" to="/login" exact clickable v-ripple @click="closeDrawer">
|
||||
<q-item-section>{{ $t('login') }}</q-item-section>
|
||||
</q-item>
|
||||
<q-item v-if="autorized" to="/members" exact clickable v-ripple @click="closeDrawer">
|
||||
<q-item-section>Members</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-drawer>
|
||||
<q-page-container>
|
||||
<router-view />
|
||||
</q-page-container>
|
||||
</q-layout>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { version, productName } from '../../package.json';
|
||||
import LoginMenu from 'src/vueLib/login/LoginMenu.vue';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { Logo } from 'src/vueLib/models/logo';
|
||||
|
||||
const localLogo = ref(Logo);
|
||||
|
||||
const leftDrawerOpen = ref(false);
|
||||
const user = useUserStore();
|
||||
const autorized = computed(() => !!user.isAuthorizedAs(['admin']));
|
||||
|
||||
function toggleLeftDrawer() {
|
||||
leftDrawerOpen.value = !leftDrawerOpen.value;
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
leftDrawerOpen.value = false;
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
window.location.reload();
|
||||
}
|
||||
</script>
|
27
src/pages/ErrorNotFound.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<template>
|
||||
<div class="fullscreen bg-blue text-white text-center q-pa-md flex flex-center">
|
||||
<div>
|
||||
<div style="font-size: 30vh">
|
||||
404
|
||||
</div>
|
||||
|
||||
<div class="text-h2" style="opacity:.4">
|
||||
Oops. Nothing here...
|
||||
</div>
|
||||
|
||||
<q-btn
|
||||
class="q-mt-xl"
|
||||
color="white"
|
||||
text-color="blue"
|
||||
unelevated
|
||||
to="/"
|
||||
label="Go Home"
|
||||
no-caps
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
//
|
||||
</script>
|
24
src/pages/LoginPage.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<div class="flex flex-center">
|
||||
<LoginForm v-on:update-close="forwardToPage" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import LoginForm from 'src/vueLib/login/LoginForm.vue';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
|
||||
onMounted(() => {
|
||||
const user = userStore.getUser();
|
||||
if (user?.username !== '' && user?.role !== '') {
|
||||
forwardToPage().catch((err) => console.error(err));
|
||||
}
|
||||
});
|
||||
|
||||
const forwardToPage = () => router.push('/members');
|
||||
</script>
|
34
src/pages/MembersTable.vue
Normal file
@@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<q-page>
|
||||
<MembersTable />
|
||||
<DialogFrame ref="dialog" header-title="Test Frame">
|
||||
<MembersTable ref="memberDialog" />
|
||||
<q-btn @click="getSelection">Get Selected</q-btn>
|
||||
</DialogFrame>
|
||||
<DialogFrame ref="uploadDialog" header-title="Test Frame">
|
||||
<MembersTable ref="memberDialog" />
|
||||
<q-btn @click="getSelection">Get Selected</q-btn>
|
||||
</DialogFrame>
|
||||
<div class="row">
|
||||
<q-btn @click="open">Click Me</q-btn>
|
||||
</div>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import MembersTable from 'src/vueLib/tables/members/MembersTable.vue';
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref } from 'vue';
|
||||
import type { MemberDialog } from 'src/vueLib/tables/members/MembersTable.vue';
|
||||
|
||||
const dialog = ref();
|
||||
const memberDialog = ref<MemberDialog>();
|
||||
|
||||
const open = () => dialog.value?.open();
|
||||
|
||||
function getSelection() {
|
||||
const selected = memberDialog.value?.getSelected();
|
||||
if (selected === undefined) return;
|
||||
console.log(65, selected[0]?.id);
|
||||
}
|
||||
</script>
|
121
src/pages/SettingsPage.vue
Normal file
@@ -0,0 +1,121 @@
|
||||
<template>
|
||||
<div class="text-h2 flex flex-center">
|
||||
<q-card class="q-gutter-md">
|
||||
<p class="text-center text-bold text-h3 text-primary q-pt-md">{{ $t('settings') }}</p>
|
||||
|
||||
<div>
|
||||
<q-card class="q-ma-lg">
|
||||
<p class="text-bold text-h6 text-primary q-pa-md">{{ $t('general') }}</p>
|
||||
<div class="row">
|
||||
<q-input
|
||||
:class="[
|
||||
colorGroup ? 'col-md-4' : 'col-md-3',
|
||||
colorGroup ? 'col-md-6' : 'col-md-6',
|
||||
colorGroup ? 'col-md-4' : 'col-md-12',
|
||||
'q-pa-md',
|
||||
]"
|
||||
filled
|
||||
:label="$t('icon')"
|
||||
v-model="settings.icon"
|
||||
></q-input>
|
||||
</div>
|
||||
</q-card>
|
||||
<q-card class="q-ma-lg">
|
||||
<p class="text-bold text-h6 text-primary q-pa-md">{{ $t('database') }}</p>
|
||||
<div class="row">
|
||||
<q-input
|
||||
:class="[
|
||||
colorGroup ? 'col-md-4' : 'col-md-3',
|
||||
colorGroup ? 'col-md-6' : 'col-md-6',
|
||||
colorGroup ? 'col-md-4' : 'col-md-12',
|
||||
'q-pa-md',
|
||||
]"
|
||||
filled
|
||||
:label="$t('databaseName')"
|
||||
v-model="settings.databaseName"
|
||||
></q-input>
|
||||
</div>
|
||||
</q-card>
|
||||
<q-card class="q-ma-lg">
|
||||
<q-btn
|
||||
class="q-pa-md"
|
||||
:icon="colorGroup ? 'remove' : 'add'"
|
||||
size="md"
|
||||
dense
|
||||
no-caps
|
||||
color="primary"
|
||||
flat
|
||||
@click="colorGroup = !colorGroup"
|
||||
>{{ $t('colors') }}</q-btn
|
||||
>
|
||||
<div v-if="colorGroup" class="colum">
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-6 col-md-3 q-px-md">
|
||||
<p class="text-center text-bold text-h6 text-primary">{{ $t('primaryColor') }}</p>
|
||||
<q-color bordered class="q-mx-md" v-model="settings.primaryColor"></q-color>
|
||||
</div>
|
||||
<div class="col-12 col-sm-6 col-md-3 q-px-md">
|
||||
<p class="text-center text-bold text-h6 text-secondary">
|
||||
{{ $t('secondaryColor') }}
|
||||
</p>
|
||||
<q-color class="q-mx-md" v-model="settings.secondaryColor"></q-color>
|
||||
</div>
|
||||
</div>
|
||||
<q-btn class="q-my-md q-mx-md" color="secondary" dense no-caps @click="resetColors">{{
|
||||
$t('resetColors')
|
||||
}}</q-btn>
|
||||
</div>
|
||||
</q-card>
|
||||
<div class="row justify-end">
|
||||
<div class="q-my-lg q-mr-xl">
|
||||
<q-btn no-caps color="primary" @click="save">{{ $t('save') }}</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</q-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { databaseName } from 'src/vueLib/tables/members/MembersTable';
|
||||
import { Logo } from 'src/vueLib/models/logo';
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { type Settings } from 'src/vueLib/models/settings';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const colorGroup = ref(false);
|
||||
|
||||
const settings = reactive<Settings>({
|
||||
icon: Logo.value,
|
||||
databaseName: databaseName.value,
|
||||
primaryColor: document.documentElement.style.getPropertyValue('--q-primary'),
|
||||
secondaryColor: document.documentElement.style.getPropertyValue('--q-secondary'),
|
||||
});
|
||||
|
||||
watch(settings, (newSettings) => {
|
||||
Logo.value = newSettings.icon;
|
||||
databaseName.value = newSettings.databaseName;
|
||||
});
|
||||
|
||||
function resetColors() {
|
||||
document.documentElement.style.setProperty('--q-primary', '#1976d2');
|
||||
document.documentElement.style.setProperty('--q-secondary', '#26a69a');
|
||||
}
|
||||
|
||||
function save() {
|
||||
document.documentElement.style.setProperty('--q-primary', settings.primaryColor);
|
||||
document.documentElement.style.setProperty('--q-secondary', settings.secondaryColor);
|
||||
Logo.value = settings.icon;
|
||||
localStorage.setItem('icon', settings.icon);
|
||||
localStorage.setItem('databaseName', settings.databaseName);
|
||||
localStorage.setItem('primaryColor', settings.primaryColor);
|
||||
localStorage.setItem('secondaryColor', settings.secondaryColor);
|
||||
|
||||
appApi
|
||||
.post('secure/settings/update', { user: 'admin', settings })
|
||||
.then((resp) => NotifyResponse(resp.data.message))
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
</script>
|
38
src/pages/UserSettings.vue
Normal file
@@ -0,0 +1,38 @@
|
||||
<template>
|
||||
<div class="q-pa-md">
|
||||
<div class="q-gutter-y-md">
|
||||
<q-card>
|
||||
<q-tabs
|
||||
v-model="tab"
|
||||
dense
|
||||
class="taxt-grey"
|
||||
active-color="primary"
|
||||
indicator-color="primary"
|
||||
align="justify"
|
||||
narrow-indicator
|
||||
>
|
||||
<q-tab name="users" no-caps :label="$t('users')" />
|
||||
<q-tab name="roles" no-caps :label="$t('roles')" />
|
||||
</q-tabs>
|
||||
<q-separator />
|
||||
|
||||
<q-tab-panels v-model="tab" animated>
|
||||
<q-tab-panel name="users">
|
||||
<UserTable />
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="roles">
|
||||
<RoleTable />
|
||||
</q-tab-panel>
|
||||
</q-tab-panels>
|
||||
</q-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import UserTable from 'src/vueLib/tables/users/UserTable.vue';
|
||||
import RoleTable from 'src/vueLib/tables/roles/RoleTable.vue';
|
||||
|
||||
const tab = ref('users');
|
||||
</script>
|
53
src/router/index.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { defineRouter } from '#q-app/wrappers';
|
||||
import {
|
||||
createMemoryHistory,
|
||||
createRouter,
|
||||
createWebHashHistory,
|
||||
createWebHistory,
|
||||
} from 'vue-router';
|
||||
import routes from './routes';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
|
||||
/*
|
||||
* If not building with SSR mode, you can
|
||||
* directly export the Router instantiation;
|
||||
*
|
||||
* The function below can be async too; either use
|
||||
* async/await or return a Promise which resolves
|
||||
* with the Router instance.
|
||||
*/
|
||||
|
||||
export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
const createHistory = process.env.SERVER
|
||||
? createMemoryHistory
|
||||
: process.env.VUE_ROUTER_MODE === 'history'
|
||||
? createWebHistory
|
||||
: createWebHashHistory;
|
||||
|
||||
const Router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
routes,
|
||||
|
||||
// Leave this as is and make changes in quasar.conf.js instead!
|
||||
// quasar.conf.js -> build -> vueRouterMode
|
||||
// quasar.conf.js -> build -> publicPath
|
||||
history: createHistory(process.env.VUE_ROUTER_BASE),
|
||||
});
|
||||
|
||||
Router.beforeEach((to, from, next) => {
|
||||
const userStore = useUserStore();
|
||||
|
||||
const isLoggedIn = userStore.isAuthenticated;
|
||||
const isAdmin = userStore.user?.role === 'admin';
|
||||
|
||||
if (to.meta.requiresAuth && !isLoggedIn) {
|
||||
next('/login');
|
||||
} else if (to.meta.requiresAdmin && !isAdmin) {
|
||||
next('/');
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
return Router;
|
||||
});
|
42
src/router/routes.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('layouts/MainLayout.vue'),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: () => import('pages/LoginPage.vue'),
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
component: () => import('pages/LoginPage.vue'),
|
||||
},
|
||||
{
|
||||
path: '/members',
|
||||
component: () => import('pages/MembersTable.vue'),
|
||||
meta: { requiresAuth: true, requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
component: () => import('pages/SettingsPage.vue'),
|
||||
meta: { requiresAuth: true, requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/usersSettings',
|
||||
component: () => import('pages/UserSettings.vue'),
|
||||
meta: { requiresAuth: true, requiresAdmin: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// Always leave this as last one,
|
||||
// but you can also remove it
|
||||
{
|
||||
path: '/:catchAll(.*)*',
|
||||
component: () => import('pages/ErrorNotFound.vue'),
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
11
src/utils/globalQ.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { QVueGlobals } from 'quasar';
|
||||
|
||||
let qInstance: QVueGlobals | null = null;
|
||||
|
||||
export function setQuasarInstance($q: QVueGlobals) {
|
||||
qInstance = $q;
|
||||
}
|
||||
|
||||
export function useGlobalQ(): QVueGlobals | null {
|
||||
return qInstance;
|
||||
}
|
12
src/utils/globalRouter.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { Router } from 'vue-router';
|
||||
|
||||
let globalRouter: Router | null = null;
|
||||
|
||||
export function setRouterInstance(router: Router) {
|
||||
globalRouter = router;
|
||||
}
|
||||
|
||||
export function useGlobalRouter(): Router {
|
||||
if (!globalRouter) throw new Error('Router not initialized yet!');
|
||||
return globalRouter;
|
||||
}
|
50
src/utils/number-helpers.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
export function separate16BitUint(value: number): { highByte: number; lowByte: number } {
|
||||
// Ensure the value is treated as a 16-bit unsigned integer
|
||||
// (optional, but good for clarity and safety if 'value' might be outside 0-65535)
|
||||
const normalizedValue = value & 0xffff; // Mask to ensure it's within 16 bits
|
||||
|
||||
// Extract the low byte (least significant 8 bits)
|
||||
// This is simply the value modulo 256, or bitwise AND with 0xFF
|
||||
const lowByte = normalizedValue & 0xff;
|
||||
|
||||
// Extract the high byte (most significant 8 bits)
|
||||
// Right shift by 8 bits to move the high byte into the low byte's position,
|
||||
// then mask with 0xFF to get just those 8 bits.
|
||||
const highByte = (normalizedValue >> 8) & 0xff;
|
||||
|
||||
return { highByte, lowByte };
|
||||
}
|
||||
|
||||
export function combineBytesTo16BitUint(highByte: number, lowByte: number): number {
|
||||
// Ensure both bytes are within the 0-255 range for safety
|
||||
const safeHighByte = highByte & 0xff;
|
||||
const safeLowByte = lowByte & 0xff;
|
||||
|
||||
// Shift the high byte 8 bits to the left to place it in the higher position.
|
||||
// Example: if highByte is 0xA4 (10100100), after shifting it becomes 0xA400 (1010010000000000).
|
||||
const shiftedHighByte = safeHighByte << 8;
|
||||
|
||||
// Combine the shifted high byte with the low byte using a bitwise OR.
|
||||
// Example: if shiftedHighByte is 0xA400 and lowByte is 0x78 (01111000),
|
||||
// the result is 0xA478 (1010010001111000).
|
||||
const combinedValue = shiftedHighByte | safeLowByte;
|
||||
|
||||
// Optional: Mask the result to ensure it's strictly within the 16-bit unsigned range (0 to 65535).
|
||||
// This is good practice as JavaScript numbers are 64-bit floats, and this ensures
|
||||
// the value wraps correctly if intermediate operations somehow exceeded 16 bits.
|
||||
return combinedValue & 0xffff;
|
||||
}
|
||||
|
||||
export function addOne(val: Ref<number>, limit: number) {
|
||||
if (val.value < limit) {
|
||||
val.value++;
|
||||
}
|
||||
}
|
||||
|
||||
export function substractOne(val: Ref<number>, limit: number) {
|
||||
if (val.value > limit) {
|
||||
val.value--;
|
||||
}
|
||||
}
|
49
src/vueLib/db/db.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';
|
||||
import type { Settings } from '../models/settings';
|
||||
|
||||
const sqlite = new SQLiteConnection(CapacitorSQLite);
|
||||
|
||||
export async function initDB() {
|
||||
const db = await sqlite.createConnection('membersDB', true, 'secreto_passwordo', 1, false);
|
||||
await db.open();
|
||||
await db.execute(`CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
settings TEXT NOT NULL
|
||||
);`);
|
||||
|
||||
const result = await db.query(`SELECT * FROM users WHERE username = ?`, ['admin']);
|
||||
if (result.values?.length === 0) {
|
||||
await db.run(`INSERT INTO users (username, role, password, settings) VALUES (?, ?, ?, ?)`, [
|
||||
'admin',
|
||||
'admin',
|
||||
'tecamino@2023',
|
||||
{},
|
||||
]);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
export async function addUser(user: string, role: string, password: string, settings: Settings) {
|
||||
const db = await initDB();
|
||||
await db.run(`INSERT INTO users (username, role, password, settings) VALUES (?, ?, ?, ?)`, [
|
||||
user,
|
||||
role,
|
||||
password,
|
||||
settings,
|
||||
]);
|
||||
}
|
||||
|
||||
export async function getUsers() {
|
||||
const db = await initDB();
|
||||
const resp = await db.query(`SELECT * FROM users`);
|
||||
return resp.values;
|
||||
}
|
||||
|
||||
export async function getUser(user: string) {
|
||||
const db = await initDB();
|
||||
const resp = await db.query(`SELECT EXISTS(SELECT 1 FROM users WHERE username = ?)`, [user]);
|
||||
return resp.values;
|
||||
}
|
172
src/vueLib/dialog/DialogFrame.vue
Normal file
@@ -0,0 +1,172 @@
|
||||
<template>
|
||||
<q-dialog
|
||||
ref="dialogRef"
|
||||
:maximized="minMaxState"
|
||||
:full-width="minMaxState"
|
||||
:no-focus="!minMaxState"
|
||||
:no-refocus="!minMaxState"
|
||||
:seamless="!minMaxState"
|
||||
>
|
||||
<q-card class="layout" :style="cardStyle">
|
||||
<!-- Draggable Header -->
|
||||
<div
|
||||
class="dialog-header row items-center justify-between bg-grey-1"
|
||||
v-touch-pan.mouse.prevent.stop="handlePan"
|
||||
>
|
||||
<div v-if="headerTitle" class="text-left text-bold text-caption q-mx-sm">
|
||||
{{ headerTitle }}
|
||||
</div>
|
||||
<div class="row justify-end q-mx-sm">
|
||||
<q-btn dense flat :icon="minMaxIcon" size="md" @click="minMax" />
|
||||
<q-btn dense flat icon="close" size="md" v-close-popup />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<q-separator color="black" />
|
||||
|
||||
<!-- Content Slot -->
|
||||
<div class="scrollArea">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
<!-- Resize Handle -->
|
||||
<div v-if="!minMaxState" class="resize-handle" @mousedown.prevent="startResizing" />
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import type { TouchPanValue } from 'quasar';
|
||||
|
||||
const dialogRef = ref();
|
||||
const open = () => dialogRef.value?.show();
|
||||
const close = () => dialogRef.value?.hide();
|
||||
defineExpose({ open, close });
|
||||
|
||||
const props = defineProps({
|
||||
headerTitle: { type: String, default: '' },
|
||||
width: { type: Number, default: 400 },
|
||||
height: { type: Number, default: 250 },
|
||||
});
|
||||
|
||||
// Fullscreen toggle
|
||||
const minMaxIcon = ref('fullscreen');
|
||||
const minMaxState = ref(false);
|
||||
function minMax() {
|
||||
minMaxState.value = !minMaxState.value;
|
||||
minMaxIcon.value = minMaxState.value ? 'fullscreen_exit' : 'fullscreen';
|
||||
}
|
||||
|
||||
// Position and Size
|
||||
const position = ref({ x: 0, y: 0 });
|
||||
const width = ref(props.width || 400);
|
||||
const height = ref(props.height || 250);
|
||||
|
||||
// Watch prop changes and sync local ref
|
||||
watch(
|
||||
() => props.width,
|
||||
(newWidth) => {
|
||||
if (newWidth !== undefined && newWidth !== width.value) {
|
||||
width.value = newWidth;
|
||||
}
|
||||
},
|
||||
);
|
||||
watch(
|
||||
() => props.height,
|
||||
(newHeight) => {
|
||||
if (newHeight !== undefined && newHeight !== height.value) {
|
||||
height.value = newHeight;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Dragging (only from header)
|
||||
const handlePan: TouchPanValue = (details) => {
|
||||
if (!minMaxState.value && details.delta) {
|
||||
position.value.x += details.delta.x || 0;
|
||||
position.value.y += details.delta.y || 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Resizing
|
||||
const isResizing = ref(false);
|
||||
function startResizing(e: MouseEvent) {
|
||||
isResizing.value = true;
|
||||
const startX = e.clientX;
|
||||
const startY = e.clientY;
|
||||
const startWidth = width.value;
|
||||
const startHeight = height.value;
|
||||
|
||||
function onMouseMove(e: MouseEvent) {
|
||||
width.value = Math.max(200, startWidth + e.clientX - startX);
|
||||
height.value = Math.max(200, startHeight + e.clientY - startY);
|
||||
}
|
||||
|
||||
function onMouseUp() {
|
||||
isResizing.value = false;
|
||||
window.removeEventListener('mousemove', onMouseMove);
|
||||
window.removeEventListener('mouseup', onMouseUp);
|
||||
}
|
||||
|
||||
window.addEventListener('mousemove', onMouseMove);
|
||||
window.addEventListener('mouseup', onMouseUp);
|
||||
}
|
||||
|
||||
// Styles
|
||||
const cardStyle = computed(() => {
|
||||
if (minMaxState.value) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
width:
|
||||
typeof width.value === 'number' || /^\d+$/.test(width.value)
|
||||
? `${width.value}px`
|
||||
: width.value,
|
||||
height:
|
||||
typeof height.value === 'number' || /^\d+$/.test(height.value)
|
||||
? `${height.value}px`
|
||||
: height.value,
|
||||
transform: `translate(${position.value.x}px, ${position.value.y}px)`,
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.layout {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-radius: 10px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
/* Draggable header */
|
||||
.dialog-header {
|
||||
padding: 8px 0;
|
||||
background: #f5f5f5;
|
||||
cursor: move;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* Scrollable content */
|
||||
.scrollArea {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* Resize handle in bottom right */
|
||||
.resize-handle {
|
||||
position: absolute;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
cursor: nwse-resize;
|
||||
z-index: 10;
|
||||
}
|
||||
</style>
|
83
src/vueLib/general/useNotify.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { getCurrentInstance } from 'vue';
|
||||
import type { Response } from '../models/Response';
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
export function useNotify() {
|
||||
const instance = getCurrentInstance();
|
||||
const $q = instance?.appContext.config.globalProperties.$q;
|
||||
|
||||
function NotifyResponse(
|
||||
response: Response | string | AxiosError | undefined,
|
||||
type?: 'warning' | 'error',
|
||||
timeout: number = 5000,
|
||||
) {
|
||||
let color = 'green';
|
||||
let icon = 'check_circle';
|
||||
|
||||
switch (type) {
|
||||
case 'warning':
|
||||
color = 'orange';
|
||||
icon = 'warning';
|
||||
break;
|
||||
case 'error':
|
||||
color = 'red';
|
||||
icon = 'error';
|
||||
break;
|
||||
}
|
||||
|
||||
if (response) {
|
||||
let message = '';
|
||||
if (response instanceof AxiosError && response.response) {
|
||||
if (response.response.data) {
|
||||
const data = response.response.data as Response;
|
||||
message = data.message;
|
||||
}
|
||||
} else {
|
||||
message = typeof response === 'string' ? response : (response.message ?? '');
|
||||
}
|
||||
if (message === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
color = typeof response === 'string' ? color : type === 'error' ? 'red' : color;
|
||||
icon = typeof response === 'string' ? icon : type === 'error' ? 'error' : icon;
|
||||
if (!$q) {
|
||||
console.error(message);
|
||||
return;
|
||||
}
|
||||
$q?.notify({
|
||||
message: message,
|
||||
color: color,
|
||||
position: 'bottom-right',
|
||||
icon: icon,
|
||||
timeout: timeout,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function NotifyDialog(title: string, text: string, okText?: string, cancelText?: string) {
|
||||
return new Promise((resolve) => {
|
||||
$q
|
||||
?.dialog({
|
||||
title: title,
|
||||
message: text,
|
||||
persistent: true,
|
||||
ok: okText ?? 'OK',
|
||||
cancel: cancelText ?? 'CANCEL',
|
||||
})
|
||||
.onOk(() => {
|
||||
resolve(true);
|
||||
})
|
||||
.onCancel(() => {
|
||||
resolve(false);
|
||||
})
|
||||
.onDismiss(() => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
return {
|
||||
NotifyDialog,
|
||||
NotifyResponse,
|
||||
};
|
||||
}
|
57
src/vueLib/login/LoginDialog.vue
Normal file
@@ -0,0 +1,57 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="300" :height="380" header-title="Login">
|
||||
<LoginForm v-on:update-close="close" />
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, nextTick } from 'vue';
|
||||
import DialogFrame from '../dialog/DialogFrame.vue';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
import LoginForm from './LoginForm.vue';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const Dialog = ref();
|
||||
const refUserInput = ref();
|
||||
|
||||
const open = () => {
|
||||
Dialog.value?.open();
|
||||
nextTick(() => {
|
||||
refUserInput.value?.focus();
|
||||
}).catch((err) => NotifyResponse(err, 'error'));
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
Dialog.value.close();
|
||||
};
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@keyframes shake {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
20% {
|
||||
transform: translateX(-8px);
|
||||
}
|
||||
40% {
|
||||
transform: translateX(8px);
|
||||
}
|
||||
60% {
|
||||
transform: translateX(-6px);
|
||||
}
|
||||
80% {
|
||||
transform: translateX(6px);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
.shake {
|
||||
animation: shake 0.4s ease;
|
||||
border: 2px solid #f44336;
|
||||
}
|
||||
</style>
|
110
src/vueLib/login/LoginForm.vue
Normal file
@@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<div class="text-black"></div>
|
||||
<q-form ref="refForm">
|
||||
<q-item-section class="q-gutter-md q-pa-md">
|
||||
<q-card :class="['q-gutter-xs q-items-center q-pa-lg', { shake: shake }]">
|
||||
<div class="text-h5 text-primary text-center">{{ productName }}</div>
|
||||
<q-input
|
||||
ref="refUserInput"
|
||||
dense
|
||||
filled
|
||||
type="text"
|
||||
:label="$t('user')"
|
||||
v-model="user"
|
||||
:rules="[(val) => !!val || $t('user') + ' ' + $t('isRequired')]"
|
||||
></q-input>
|
||||
<q-input
|
||||
dense
|
||||
filled
|
||||
:type="showPassword ? 'text' : 'password'"
|
||||
:label="$t('password')"
|
||||
v-model="password"
|
||||
@keyup.enter="onSubmit"
|
||||
:rules="[(val) => !!val || $t('password') + ' ' + $t('isRequired')]"
|
||||
>
|
||||
<template #append>
|
||||
<q-btn
|
||||
flat
|
||||
dense
|
||||
:icon="showPassword ? 'visibility_off' : 'visibility'"
|
||||
@mousedown.left="showPassword = true"
|
||||
@mouseup.left="showPassword = false"
|
||||
@mouseleave="showPassword = false"
|
||||
></q-btn>
|
||||
</template>
|
||||
</q-input>
|
||||
<div class="q-pt-sm q-mr-md row justify-end">
|
||||
<q-btn color="primary" :label="$t('login')" @click="onSubmit"></q-btn>
|
||||
</div>
|
||||
</q-card>
|
||||
</q-item-section>
|
||||
</q-form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { productName } from '../../../package.json';
|
||||
import { ref } from 'vue';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
import { useLogin } from './useLogin';
|
||||
|
||||
const refForm = ref();
|
||||
const refUserInput = ref();
|
||||
const user = ref('');
|
||||
const password = ref('');
|
||||
const showPassword = ref(false);
|
||||
const shake = ref(false);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const { login } = useLogin();
|
||||
|
||||
const emit = defineEmits(['update-close']);
|
||||
|
||||
const onSubmit = () => {
|
||||
refForm.value?.validate().then((success: boolean) => {
|
||||
if (success) {
|
||||
login(user.value, password.value)
|
||||
.then(() => {
|
||||
NotifyResponse("logged in as '" + user.value + "'");
|
||||
emit('update-close');
|
||||
})
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
shake.value = true;
|
||||
setTimeout(() => {
|
||||
shake.value = false;
|
||||
}, 500);
|
||||
});
|
||||
} else {
|
||||
NotifyResponse('error submitting login form', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@keyframes shake {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
20% {
|
||||
transform: translateX(-8px);
|
||||
}
|
||||
40% {
|
||||
transform: translateX(8px);
|
||||
}
|
||||
60% {
|
||||
transform: translateX(-6px);
|
||||
}
|
||||
80% {
|
||||
transform: translateX(6px);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
.shake {
|
||||
animation: shake 0.4s ease;
|
||||
border: 2px solid #f44336;
|
||||
}
|
||||
</style>
|
77
src/vueLib/login/LoginMenu.vue
Normal file
@@ -0,0 +1,77 @@
|
||||
<template>
|
||||
<div class="q-gutter-md">
|
||||
<q-btn dense flat round icon="person" :color="currentUser ? 'green' : ''">
|
||||
<q-menu ref="refLoginMenu">
|
||||
<q-list style="min-width: 120px">
|
||||
<q-item v-if="userLogin.getUser()" class="text-primary">{{
|
||||
currentUser?.username
|
||||
}}</q-item>
|
||||
<q-item v-if="showLogin" clickable v-close-popup @click="openLogin">
|
||||
<q-item-section class="text-primary">{{ loginText }}</q-item-section>
|
||||
</q-item>
|
||||
<q-item>
|
||||
<q-select
|
||||
:label="$t('language')"
|
||||
borderless
|
||||
color="primary"
|
||||
dense
|
||||
v-model="langSelected"
|
||||
:options="langSelection"
|
||||
></q-select>
|
||||
</q-item>
|
||||
<q-item v-if="autorized">
|
||||
<q-btn flat color="secondary" icon="settings" to="/settings"></q-btn>
|
||||
</q-item>
|
||||
<q-item v-if="autorized">
|
||||
<q-btn flat color="secondary" icon="group" to="/usersSettings"></q-btn>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
</q-btn>
|
||||
</div>
|
||||
<LoginDialog ref="refLoginDialog"></LoginDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import LoginDialog from './LoginDialog.vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useLogin } from './useLogin';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
import { lang, i18n } from 'src/boot/lang';
|
||||
import { useUserStore } from './userStore';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
const route = useRoute();
|
||||
const showLogin = computed(
|
||||
() => (route.path !== '/' && route.path !== '/login') || currentUser.value?.username === '',
|
||||
);
|
||||
|
||||
const userLogin = useLogin();
|
||||
const user = useUserStore();
|
||||
const autorized = computed(() => !!user.isAuthorizedAs(['admin']));
|
||||
const { NotifyResponse } = useNotify();
|
||||
const currentUser = computed(() => userLogin.getUser());
|
||||
|
||||
const loginText = computed(() => {
|
||||
return currentUser.value ? 'Logout' : 'Login';
|
||||
});
|
||||
|
||||
const refLoginDialog = ref();
|
||||
|
||||
function openLogin() {
|
||||
if (currentUser.value) {
|
||||
userLogin.logout().catch((err) => NotifyResponse(err, 'error'));
|
||||
return;
|
||||
}
|
||||
refLoginDialog.value?.open();
|
||||
}
|
||||
|
||||
const langSelected = ref(i18n.global.locale);
|
||||
const langSelection = ref(lang);
|
||||
|
||||
// Watch for changes and update i18n locale
|
||||
watch(langSelected, (newLang) => {
|
||||
i18n.global.locale = newLang;
|
||||
localStorage.setItem('lang', newLang);
|
||||
});
|
||||
</script>
|
86
src/vueLib/login/useLogin.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { useUserStore } from './userStore';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
import type { Settings } from '../models/settings';
|
||||
import { Logo } from '../models/logo';
|
||||
|
||||
const refreshTime = 10000;
|
||||
let intervalId: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
export function useLogin() {
|
||||
const userStore = useUserStore();
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
async function login(user: string, password: string) {
|
||||
try {
|
||||
await appApi.post('/login', { user, password }).then((resp) => {
|
||||
const sets = resp.data.settings as Settings;
|
||||
|
||||
Logo.value = sets.icon;
|
||||
document.documentElement.style.setProperty('--q-primary', sets.primaryColor);
|
||||
document.documentElement.style.setProperty('--q-secondary', sets.secondaryColor);
|
||||
localStorage.setItem('icon', sets.icon);
|
||||
localStorage.setItem('databaseName', sets.databaseName);
|
||||
localStorage.setItem('primaryColor', sets.primaryColor);
|
||||
localStorage.setItem('secondaryColor', sets.secondaryColor);
|
||||
});
|
||||
|
||||
const resp = await appApi.get('/login/me');
|
||||
userStore.setUser({ id: resp.data.id, username: resp.data.user, role: resp.data.role });
|
||||
|
||||
startRefreshInterval();
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Login error:', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await appApi.get('/logout').catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
});
|
||||
|
||||
userStore.clearUser();
|
||||
stopRefreshInterval();
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
await appApi
|
||||
.post('secure/login/refresh', {}, { withCredentials: true })
|
||||
.then(() => {
|
||||
appApi
|
||||
.get('/login/me')
|
||||
.then((resp) => {
|
||||
userStore.setUser({ id: resp.data.id, username: resp.data.user, role: resp.data.role });
|
||||
if (!intervalId) {
|
||||
startRefreshInterval();
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.catch(() => {});
|
||||
})
|
||||
.catch(() => {
|
||||
userStore.clearUser();
|
||||
});
|
||||
stopRefreshInterval();
|
||||
return false;
|
||||
}
|
||||
function getUser() {
|
||||
return userStore.getUser();
|
||||
}
|
||||
|
||||
function startRefreshInterval() {
|
||||
intervalId = setInterval(() => {
|
||||
refresh().catch((err) => NotifyResponse(err, 'error'));
|
||||
}, refreshTime);
|
||||
}
|
||||
function stopRefreshInterval() {
|
||||
if (intervalId) {
|
||||
clearInterval(intervalId);
|
||||
intervalId = null;
|
||||
}
|
||||
}
|
||||
|
||||
return { login, logout, refresh, getUser };
|
||||
}
|
68
src/vueLib/login/userStore.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { useGlobalRouter } from 'src/utils/globalRouter';
|
||||
import { useGlobalQ } from 'src/utils/globalQ';
|
||||
|
||||
interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
interface UserState {
|
||||
user: User | null;
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({
|
||||
user: null,
|
||||
}),
|
||||
getters: {
|
||||
isAuthenticated: (state): boolean => !!state.user,
|
||||
},
|
||||
actions: {
|
||||
setUser(user: User) {
|
||||
this.user = user;
|
||||
},
|
||||
getUser() {
|
||||
return this.user;
|
||||
},
|
||||
clearUser() {
|
||||
const $q = useGlobalQ();
|
||||
|
||||
if (!this.user) return;
|
||||
if ($q) {
|
||||
$q?.notify({
|
||||
message: "user '" + this.user?.username + "' logged out",
|
||||
color: 'orange',
|
||||
position: 'bottom-right',
|
||||
icon: 'warning',
|
||||
timeout: 5000,
|
||||
});
|
||||
} else {
|
||||
console.error("user '" + this.user?.username + "' logged out");
|
||||
}
|
||||
|
||||
this.user = null;
|
||||
|
||||
const router = useGlobalRouter();
|
||||
|
||||
router?.push('/').catch((err) => {
|
||||
if ($q) {
|
||||
$q?.notify({
|
||||
message: err,
|
||||
color: 'orange',
|
||||
position: 'bottom-right',
|
||||
icon: 'warning',
|
||||
timeout: 5000,
|
||||
});
|
||||
} else {
|
||||
console.error("user '" + this.user?.username + "' logged out");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
isAuthorizedAs(roles: string[]) {
|
||||
return this.user !== null && roles.includes(this.user.role);
|
||||
},
|
||||
},
|
||||
});
|
3
src/vueLib/models/Response.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface Response {
|
||||
message: string;
|
||||
}
|
3
src/vueLib/models/logo.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
export const Logo = ref('');
|
18
src/vueLib/models/member.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export interface Member {
|
||||
id: number;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
birthday: string;
|
||||
age: string;
|
||||
address: string;
|
||||
town: string;
|
||||
zip: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
group: string;
|
||||
responsiblePerson: string;
|
||||
firstVisit: string;
|
||||
lastVisit: string;
|
||||
}
|
||||
|
||||
export type Members = Member[];
|
12
src/vueLib/models/metaData.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export interface MetaData {
|
||||
rowIndex: number;
|
||||
seperator: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
birthday: string;
|
||||
address: string;
|
||||
town: string;
|
||||
zip: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
}
|
8
src/vueLib/models/rights.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export interface Right {
|
||||
name: string;
|
||||
read: boolean;
|
||||
write: boolean;
|
||||
delete: boolean;
|
||||
}
|
||||
|
||||
export type Rights = Right[];
|
9
src/vueLib/models/roles.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { Rights } from './rights';
|
||||
|
||||
export interface Role {
|
||||
id?: number;
|
||||
role: string;
|
||||
rights: Rights | null;
|
||||
}
|
||||
|
||||
export type Roles = Role[];
|
6
src/vueLib/models/settings.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export type Settings = {
|
||||
icon: string;
|
||||
databaseName: string;
|
||||
primaryColor: string;
|
||||
secondaryColor: string;
|
||||
};
|
9
src/vueLib/models/users.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface User {
|
||||
id?: number;
|
||||
user: string;
|
||||
email: string;
|
||||
role: string;
|
||||
expires: string;
|
||||
}
|
||||
|
||||
export type Users = User[];
|
209
src/vueLib/tables/members/MembersTable.ts
Normal file
@@ -0,0 +1,209 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, computed } from 'vue';
|
||||
import type { Member, Members } from 'src/vueLib/models/member';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { i18n } from 'boot/lang';
|
||||
|
||||
export const databaseName = ref('members.dba');
|
||||
|
||||
export function useMemberTable() {
|
||||
const members = ref<Members>([]);
|
||||
|
||||
const pagination = ref({
|
||||
sortBy: 'firstName',
|
||||
descending: false,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
const columns = computed(() => [
|
||||
{ name: 'cake', align: 'center' as const, label: '', field: 'cake', icon: 'cake' },
|
||||
{
|
||||
name: 'firstName',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('prename'),
|
||||
field: 'firstName',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'lastName',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('lastName'),
|
||||
field: 'lastName',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'birthday',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('birthday'),
|
||||
field: 'birthday',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'age',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('age'),
|
||||
field: 'age',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('address'),
|
||||
field: 'address',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'town',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('town'),
|
||||
field: 'town',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'zip',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('zipCode'),
|
||||
field: 'zip',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'phone',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('phone'),
|
||||
field: 'phone',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('email'),
|
||||
field: 'email',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'group',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('group'),
|
||||
field: 'group',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'responsiblePerson',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('responsible'),
|
||||
field: 'responsiblePerson',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'firstVisit',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('firstVisit'),
|
||||
field: 'firstVisit',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'lastVisit',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('lastVisit'),
|
||||
field: 'lastVisit',
|
||||
sortable: true,
|
||||
},
|
||||
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
|
||||
]);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
function calculateAge(birthDateString: string) {
|
||||
if (birthDateString === undefined) return 0;
|
||||
const [day, month, year] = birthDateString.split('.').map(Number); // for format "1.2.2000"
|
||||
if (year === undefined || month === undefined || day === undefined) return 0;
|
||||
const birthDate = new Date(year, month - 1, day); // month is 0-based
|
||||
|
||||
const today = new Date();
|
||||
|
||||
let age = today.getFullYear() - birthDate.getFullYear();
|
||||
|
||||
// Check if birthday has occurred yet this year
|
||||
const hasBirthdayPassed =
|
||||
today.getMonth() > birthDate.getMonth() ||
|
||||
(today.getMonth() === birthDate.getMonth() && today.getDate() >= birthDate.getDate());
|
||||
|
||||
if (!hasBirthdayPassed) {
|
||||
age--;
|
||||
}
|
||||
|
||||
return age;
|
||||
}
|
||||
|
||||
//isThreeDaysBeforeAnnualDate check if upcoming date is less than 3 days from now
|
||||
function isXDaysBeforeAnnualDate(dateString: string, before: number) {
|
||||
if (dateString === undefined) return;
|
||||
const [day, month] = dateString.split('.').map(Number);
|
||||
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0);
|
||||
|
||||
const annualDate = new Date(today.getFullYear(), month ? month - 1 : 0, day);
|
||||
annualDate.setHours(0, 0, 1);
|
||||
|
||||
const xDaysBefore = new Date(annualDate);
|
||||
xDaysBefore.setDate(annualDate.getDate() - before);
|
||||
|
||||
return today >= xDaysBefore && today <= annualDate;
|
||||
}
|
||||
|
||||
function getRowClass(row: Member) {
|
||||
if (isXDaysBeforeAnnualDate(row.birthday, 1)) {
|
||||
return 'bg-red-2 text-red-10';
|
||||
} else if (isXDaysBeforeAnnualDate(row.birthday, 4)) {
|
||||
return 'bg-green-2 text-green-10';
|
||||
} else if (isXDaysBeforeAnnualDate(row.birthday, 8)) {
|
||||
return 'bg-amber-2 text-amber-10';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
//updates member list from database
|
||||
function updateMembers() {
|
||||
loading.value = true;
|
||||
|
||||
appApi
|
||||
.get('secure/members')
|
||||
.then((resp) => {
|
||||
if (resp.data === null) {
|
||||
members.value = [];
|
||||
return;
|
||||
}
|
||||
members.value = resp.data as Members;
|
||||
if (members.value === null) {
|
||||
members.value = [];
|
||||
return;
|
||||
}
|
||||
members.value.forEach((member) => {
|
||||
if (member.birthday !== undefined) {
|
||||
member.age = String(calculateAge(member.birthday));
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
members,
|
||||
pagination,
|
||||
columns,
|
||||
loading,
|
||||
getRowClass,
|
||||
updateMembers,
|
||||
isXDaysBeforeAnnualDate,
|
||||
};
|
||||
}
|
272
src/vueLib/tables/members/MembersTable.vue
Normal file
@@ -0,0 +1,272 @@
|
||||
<template>
|
||||
<div class="q-pa-md">
|
||||
<q-table
|
||||
flat
|
||||
bordered
|
||||
ref="tableRef"
|
||||
title="Members"
|
||||
title-class="text-bold text-blue-9"
|
||||
:no-data-label="$t('noDataAvailable')"
|
||||
:loading-label="$t('loading')"
|
||||
:rows-per-page-label="$t('recordsPerPage')"
|
||||
:selected-rows-label="(val) => val + $t('recordSelected')"
|
||||
:rows="members"
|
||||
:columns="columns"
|
||||
row-key="id"
|
||||
v-model:pagination="pagination"
|
||||
:loading="loading"
|
||||
:filter="filter"
|
||||
:selection="selectOption ? 'multiple' : 'none'"
|
||||
v-model:selected="selected"
|
||||
binary-state-sort
|
||||
class="bigger-table-text"
|
||||
>
|
||||
<template v-slot:top-left>
|
||||
<q-btn-group push flat style="color: grey">
|
||||
<q-btn dense flat icon="add" @click="openAllValueDialog(null)">
|
||||
<q-tooltip>{{ $t('addNewMember') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
style="color: grey"
|
||||
:icon="selectOption ? 'check_box' : 'check_box_outline_blank'"
|
||||
@click="selectOption = !selectOption"
|
||||
>
|
||||
<q-tooltip>{{ $t('selectMemberOptions') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn dense flat icon="upload" @click="openUploadDialog">
|
||||
<q-tooltip>{{ $t('importCSV') }}</q-tooltip>
|
||||
</q-btn>
|
||||
</q-btn-group>
|
||||
<div v-if="selectOption && selected.length > 0">
|
||||
<q-btn flat dense icon="more_vert" @click="openSubmenu = true" />
|
||||
<q-menu v-if="openSubmenu" anchor="bottom middle" self="top middle">
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="openRemoveDialog(...selected)"
|
||||
class="text-negative"
|
||||
>{{ $t('delete') }}</q-item
|
||||
>
|
||||
</q-menu>
|
||||
</div>
|
||||
<div v-if="selectOption && selected.length > 0" class="q-ml-md text-weight-bold">
|
||||
{{ $t('selected') }}: {{ selected.length }}
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:top-right>
|
||||
<q-input filled dense debounce="300" v-model="filter" :placeholder="$t('search')">
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
<template v-slot:body-cell="props">
|
||||
<q-td
|
||||
:props="props"
|
||||
:class="getRowClass(props.row)"
|
||||
@click="openSingleValueDialog(props.col.label, props.col.name, props.row)"
|
||||
>
|
||||
{{ props.value }}
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-cake="props">
|
||||
<q-td :props="props" :class="getRowClass(props.row)">
|
||||
<q-icon
|
||||
:name="isXDaysBeforeAnnualDate(props.row.birthday, 1) ? 'cake' : ''"
|
||||
:color="'red'"
|
||||
size="md"
|
||||
/>
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-option="props">
|
||||
<q-td :props="props">
|
||||
<q-btn flat dense icon="more_vert" @click="openSubmenu = true" />
|
||||
<q-menu v-if="openSubmenu" anchor="top right" self="top left">
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="openAllValueDialog(props.row)"
|
||||
class="text-primary"
|
||||
>{{ $t('edit') }}</q-item
|
||||
>
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="openRemoveDialog(props.row)"
|
||||
class="text-negative"
|
||||
title="zu"
|
||||
>{{ $t('delete') }}</q-item
|
||||
>
|
||||
</q-menu>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</div>
|
||||
<EditOneDialog ref="editOneDialog" v-on:update="updateMembers"></EditOneDialog>
|
||||
<EditAllDialog ref="editAllDialog" v-on:update="updateMembers"></EditAllDialog>
|
||||
<OkDialog
|
||||
ref="okDialog"
|
||||
:dialog-label="$t('delete')"
|
||||
:text="$t('doYouWantToDelete') + ' ' + deleteText"
|
||||
label-color="red"
|
||||
:button-cancel-label="$t('cancel')"
|
||||
:button-ok-label="$t('confirm')"
|
||||
:button-ok-flat="false"
|
||||
button-ok-color="red"
|
||||
v-on:update-confirm="(val) => removeMember(...val)"
|
||||
></OkDialog>
|
||||
<UploadDialog ref="uploadDialog" @update-upload="updateMembers"> </UploadDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import type { Member, Members } from 'src/vueLib/models/member';
|
||||
import EditOneDialog from 'src/components/EditOneDialog.vue';
|
||||
import EditAllDialog from 'src/components/MemberEditAllDialog.vue';
|
||||
import OkDialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useMemberTable } from './MembersTable';
|
||||
import UploadDialog from 'src/components/UploadDialog.vue';
|
||||
import { databaseName } from './MembersTable';
|
||||
|
||||
export interface MemberDialog {
|
||||
getSelected: () => Members;
|
||||
}
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const editOneDialog = ref();
|
||||
const editAllDialog = ref();
|
||||
const uploadDialog = ref();
|
||||
const okDialog = ref();
|
||||
const deleteText = ref('');
|
||||
const selectOption = ref(false);
|
||||
const selected = ref<Members>([]);
|
||||
const openSubmenu = ref(false);
|
||||
const filter = ref('');
|
||||
|
||||
const {
|
||||
members,
|
||||
pagination,
|
||||
loading,
|
||||
columns,
|
||||
getRowClass,
|
||||
updateMembers,
|
||||
isXDaysBeforeAnnualDate,
|
||||
} = useMemberTable();
|
||||
|
||||
//load on mounting page
|
||||
onMounted(() => {
|
||||
loading.value = true;
|
||||
|
||||
appApi
|
||||
.post('secure/database/open', { dbPath: databaseName.value, create: true })
|
||||
.then(() => {
|
||||
updateMembers();
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'))
|
||||
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
|
||||
// opens dialog for all member values
|
||||
function openSingleValueDialog(label: string, field: string, member: Member) {
|
||||
editOneDialog.value?.open(label, field, member);
|
||||
}
|
||||
|
||||
//opens dialog for one value
|
||||
function openAllValueDialog(member: Member | null) {
|
||||
editAllDialog.value?.open(member);
|
||||
}
|
||||
|
||||
//opens remove dialog
|
||||
function openRemoveDialog(...members: Members) {
|
||||
if (members.length === 1) {
|
||||
deleteText.value = "'";
|
||||
if (members[0]?.firstName !== undefined) {
|
||||
deleteText.value += members[0]?.firstName + ' ';
|
||||
}
|
||||
if (members[0]?.lastName !== undefined) {
|
||||
deleteText.value += members[0]?.lastName;
|
||||
}
|
||||
deleteText.value += "'";
|
||||
} else {
|
||||
deleteText.value = String(members.length) + ' members';
|
||||
}
|
||||
okDialog.value?.open(members);
|
||||
}
|
||||
|
||||
//opens uploader dialog
|
||||
function openUploadDialog() {
|
||||
uploadDialog.value?.open();
|
||||
}
|
||||
|
||||
//remove member from database
|
||||
function removeMember(...removeMembers: Members) {
|
||||
const memberIds: number[] = [];
|
||||
|
||||
removeMembers.forEach((member: Member) => {
|
||||
memberIds.push(member.id);
|
||||
});
|
||||
|
||||
appApi
|
||||
.post('secure/members/delete', { ids: memberIds })
|
||||
.then(() => {
|
||||
updateMembers();
|
||||
selected.value = [];
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'))
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
//const blinkingId = ref<number | null>(null);
|
||||
|
||||
// function triggerBlink(id: number) {
|
||||
// blinkingId.value = id;
|
||||
|
||||
// // Optional: stop blinking after 3 seconds
|
||||
// setTimeout(() => {
|
||||
// blinkingId.value = null;
|
||||
// }, 3000);
|
||||
// }
|
||||
|
||||
function getSelected(): Members {
|
||||
if (selected.value.length === 0) return [];
|
||||
return selected.value;
|
||||
}
|
||||
defineExpose({
|
||||
getSelected,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@keyframes blink-yellow {
|
||||
0%,
|
||||
100% {
|
||||
background-color: yellow;
|
||||
}
|
||||
50% {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
.blink-yellow {
|
||||
animation: blink-yellow 1.5s step-start 6 !important;
|
||||
}
|
||||
|
||||
.bigger-table-text .q-table__middle td {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.bigger-table-text .q-table__top,
|
||||
.bigger-table-text .q-table__bottom,
|
||||
.bigger-table-text th {
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
79
src/vueLib/tables/roles/RoleTable.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { i18n } from 'boot/lang';
|
||||
import type { Roles } from 'src/vueLib/models/roles';
|
||||
|
||||
export const roles = ref<Roles>([]);
|
||||
|
||||
export function useRoleTable() {
|
||||
const pagination = ref({
|
||||
sortBy: 'role',
|
||||
descending: false,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
const columns = computed(() => [
|
||||
{
|
||||
name: 'id',
|
||||
align: 'left' as const,
|
||||
label: 'Id',
|
||||
field: 'id',
|
||||
sortable: true,
|
||||
style: 'width: 50px; max-width: 50px;',
|
||||
},
|
||||
{
|
||||
name: 'role',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('role'),
|
||||
field: 'role',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'rights',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('rights'),
|
||||
field: 'rights',
|
||||
sortable: true,
|
||||
style: 'width: 120px; max-width: 120px;',
|
||||
},
|
||||
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
|
||||
]);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
//updates user list from database
|
||||
function updateRoles() {
|
||||
loading.value = true;
|
||||
appApi
|
||||
.get('secure/roles')
|
||||
.then((resp) => {
|
||||
if (resp.data === null) {
|
||||
roles.value = [];
|
||||
return;
|
||||
}
|
||||
roles.value = resp.data as Roles;
|
||||
if (roles.value === null) {
|
||||
roles.value = [];
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
return {
|
||||
roles,
|
||||
pagination,
|
||||
columns,
|
||||
loading,
|
||||
updateRoles,
|
||||
};
|
||||
}
|
201
src/vueLib/tables/roles/RoleTable.vue
Normal file
@@ -0,0 +1,201 @@
|
||||
<template>
|
||||
<div class="q-pa-md">
|
||||
<q-table
|
||||
flat
|
||||
bordered
|
||||
ref="tableRef"
|
||||
title="Roles"
|
||||
title-class="text-bold text-blue-9"
|
||||
:no-data-label="$t('noDataAvailable')"
|
||||
:loading-label="$t('loading')"
|
||||
:rows-per-page-label="$t('recordsPerPage')"
|
||||
:selected-rows-label="(val) => val + $t('recordSelected')"
|
||||
:rows="roles"
|
||||
:columns="columns"
|
||||
row-key="id"
|
||||
v-model:pagination="pagination"
|
||||
:loading="loading"
|
||||
:filter="filter"
|
||||
:selection="selectOption ? 'multiple' : 'none'"
|
||||
v-model:selected="selected"
|
||||
binary-state-sort
|
||||
class="bigger-table-text"
|
||||
>
|
||||
<template v-slot:top-left>
|
||||
<q-btn-group push flat style="color: grey">
|
||||
<q-btn dense flat icon="add" @click="openAllValueDialog(null)">
|
||||
<q-tooltip>{{ $t('addNewRole') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
style="color: grey"
|
||||
:icon="selectOption ? 'check_box' : 'check_box_outline_blank'"
|
||||
@click="selectOption = !selectOption"
|
||||
>
|
||||
<q-tooltip>{{ $t('selectRoleOptions') }}</q-tooltip>
|
||||
</q-btn>
|
||||
</q-btn-group>
|
||||
<div v-if="selectOption && selected.length > 0">
|
||||
<q-btn flat dense icon="more_vert" @click="openSubmenu = true" />
|
||||
<q-menu v-if="openSubmenu" anchor="bottom middle" self="top middle">
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="openRemoveDialog(...selected)"
|
||||
class="text-negative"
|
||||
>{{ $t('delete') }}</q-item
|
||||
>
|
||||
</q-menu>
|
||||
</div>
|
||||
<div v-if="selectOption && selected.length > 0" class="q-ml-md text-weight-bold">
|
||||
{{ $t('selected') }}: {{ selected.length }}
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:top-right>
|
||||
<q-input filled dense debounce="300" v-model="filter" :placeholder="$t('search')">
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
<template v-slot:body-cell="props">
|
||||
<q-td
|
||||
:props="props"
|
||||
@click="openSingleValueDialog(props.col.label, props.col.name, props.row)"
|
||||
>
|
||||
{{ props.value }}
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-option="props">
|
||||
<q-td :props="props">
|
||||
<q-btn flat dense icon="delete" color="negative" @click="openRemoveDialog(props.row)">
|
||||
<q-tooltip> {{ $t('delete') }} </q-tooltip>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</div>
|
||||
<EditOneDialog ref="editOneDialog" v-on:update="updateRoles"></EditOneDialog>
|
||||
<EditAllDialog ref="editAllDialog" v-on:update="updateRoles"></EditAllDialog>
|
||||
<OkDialog
|
||||
ref="okDialog"
|
||||
:dialog-label="$t('delete')"
|
||||
:text="$t('doYouWantToDelete') + ' ' + deleteText"
|
||||
label-color="red"
|
||||
:button-cancel-label="$t('cancel')"
|
||||
:button-ok-label="$t('confirm')"
|
||||
:button-ok-flat="false"
|
||||
button-ok-color="red"
|
||||
v-on:update-confirm="(val) => removeRole(...val)"
|
||||
></OkDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import type { Roles, Role } from 'src/vueLib/models/roles';
|
||||
import EditOneDialog from 'src/components/EditOneDialog.vue';
|
||||
import EditAllDialog from 'src/components/RoleEditAllDialog.vue';
|
||||
import OkDialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useRoleTable } from './RoleTable';
|
||||
import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const editOneDialog = ref();
|
||||
const editAllDialog = ref();
|
||||
const okDialog = ref();
|
||||
const deleteText = ref('');
|
||||
const selectOption = ref(false);
|
||||
const selected = ref<Roles>([]);
|
||||
const openSubmenu = ref(false);
|
||||
const filter = ref('');
|
||||
|
||||
const { roles, pagination, loading, columns, updateRoles } = useRoleTable();
|
||||
|
||||
//load on mounting page
|
||||
onMounted(() => {
|
||||
loading.value = true;
|
||||
updateRoles();
|
||||
});
|
||||
|
||||
// opens dialog for all role values
|
||||
function openSingleValueDialog(label: string, field: string, role: Role) {
|
||||
editOneDialog.value?.open(label, field, role);
|
||||
}
|
||||
|
||||
//opens dialog for one value
|
||||
function openAllValueDialog(role: Role | null) {
|
||||
editAllDialog.value?.open(role);
|
||||
}
|
||||
|
||||
//opens remove dialog
|
||||
function openRemoveDialog(...roles: Roles) {
|
||||
if (roles.length === 1) {
|
||||
deleteText.value = "'" + roles[0]?.role + "'";
|
||||
} else {
|
||||
deleteText.value = String(roles.length) + ' roles';
|
||||
}
|
||||
okDialog.value?.open(roles);
|
||||
}
|
||||
|
||||
//remove role from database
|
||||
function removeRole(...removeRoles: Roles) {
|
||||
const roles: string[] = [];
|
||||
|
||||
removeRoles.forEach((role: Role) => {
|
||||
if (role.role) {
|
||||
roles.push(role.role);
|
||||
}
|
||||
});
|
||||
|
||||
const login = useLogin();
|
||||
const user = login.getUser();
|
||||
|
||||
appApi
|
||||
.post('secure/roles/delete?role=' + user?.role, { roles: roles })
|
||||
.then(() => {
|
||||
updateRoles();
|
||||
selected.value = [];
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'))
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function getSelected(): Roles {
|
||||
if (selected.value.length === 0) return [];
|
||||
return selected.value;
|
||||
}
|
||||
defineExpose({
|
||||
getSelected,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@keyframes blink-yellow {
|
||||
0%,
|
||||
100% {
|
||||
background-color: yellow;
|
||||
}
|
||||
50% {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
.blink-yellow {
|
||||
animation: blink-yellow 1.5s step-start 6 !important;
|
||||
}
|
||||
|
||||
.bigger-table-text .q-table__middle td {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.bigger-table-text .q-table__top,
|
||||
.bigger-table-text .q-table__bottom,
|
||||
.bigger-table-text th {
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
87
src/vueLib/tables/users/UserTable.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { i18n } from 'boot/lang';
|
||||
import type { Users } from 'src/vueLib/models/users';
|
||||
|
||||
export function useUserTable() {
|
||||
const users = ref<Users>([]);
|
||||
|
||||
const pagination = ref({
|
||||
sortBy: 'user',
|
||||
descending: false,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
const columns = computed(() => [
|
||||
{
|
||||
name: 'id',
|
||||
align: 'left' as const,
|
||||
label: 'Id',
|
||||
field: 'id',
|
||||
sortable: true,
|
||||
style: 'width: 50px; max-width: 50px;',
|
||||
},
|
||||
{
|
||||
name: 'user',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('user'),
|
||||
field: 'user',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('email'),
|
||||
field: 'email',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'role',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('role'),
|
||||
field: 'role',
|
||||
sortable: true,
|
||||
style: 'width: 120px; max-width: 120px;',
|
||||
},
|
||||
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
|
||||
]);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
//updates user list from database
|
||||
function updateUsers() {
|
||||
loading.value = true;
|
||||
|
||||
appApi
|
||||
.get('secure/users')
|
||||
.then((resp) => {
|
||||
if (resp.data === null) {
|
||||
users.value = [];
|
||||
return;
|
||||
}
|
||||
users.value = resp.data as Users;
|
||||
if (users.value === null) {
|
||||
users.value = [];
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
return {
|
||||
users,
|
||||
pagination,
|
||||
columns,
|
||||
loading,
|
||||
updateUsers,
|
||||
};
|
||||
}
|
207
src/vueLib/tables/users/UserTable.vue
Normal file
@@ -0,0 +1,207 @@
|
||||
<template>
|
||||
<div class="q-pa-md">
|
||||
<q-table
|
||||
flat
|
||||
bordered
|
||||
ref="tableRef"
|
||||
title="Users"
|
||||
title-class="text-bold text-blue-9"
|
||||
:no-data-label="$t('noDataAvailable')"
|
||||
:loading-label="$t('loading')"
|
||||
:rows-per-page-label="$t('recordsPerPage')"
|
||||
:selected-rows-label="(val) => val + $t('recordSelected')"
|
||||
:rows="users"
|
||||
:columns="columns"
|
||||
row-key="id"
|
||||
v-model:pagination="pagination"
|
||||
:loading="loading"
|
||||
:filter="filter"
|
||||
:selection="selectOption ? 'multiple' : 'none'"
|
||||
v-model:selected="selected"
|
||||
binary-state-sort
|
||||
class="bigger-table-text"
|
||||
>
|
||||
<template v-slot:top-left>
|
||||
<q-btn-group push flat style="color: grey">
|
||||
<q-btn dense flat icon="add" @click="openAllValueDialog(null)">
|
||||
<q-tooltip>{{ $t('addNewUser') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
style="color: grey"
|
||||
:icon="selectOption ? 'check_box' : 'check_box_outline_blank'"
|
||||
@click="selectOption = !selectOption"
|
||||
>
|
||||
<q-tooltip>{{ $t('selectUserOptions') }}</q-tooltip>
|
||||
</q-btn>
|
||||
</q-btn-group>
|
||||
<div v-if="selectOption && selected.length > 0">
|
||||
<q-btn flat dense icon="more_vert" @click="openSubmenu = true" />
|
||||
<q-menu v-if="openSubmenu" anchor="bottom middle" self="top middle">
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="openRemoveDialog(...selected)"
|
||||
class="text-negative"
|
||||
>{{ $t('delete') }}</q-item
|
||||
>
|
||||
</q-menu>
|
||||
</div>
|
||||
<div v-if="selectOption && selected.length > 0" class="q-ml-md text-weight-bold">
|
||||
{{ $t('selected') }}: {{ selected.length }}
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:top-right>
|
||||
<q-input filled dense debounce="300" v-model="filter" :placeholder="$t('search')">
|
||||
<template v-slot:append>
|
||||
<q-icon name="search" />
|
||||
</template>
|
||||
</q-input>
|
||||
</template>
|
||||
<template v-slot:body-cell="props">
|
||||
<q-td v-if="props.col.name === 'role'" :props="props">
|
||||
<q-select dense v-model="props.row.role" :options="localRoles"></q-select>
|
||||
</q-td>
|
||||
<q-td
|
||||
v-else
|
||||
:props="props"
|
||||
@click="openSingleValueDialog(props.col.label, props.col.name, props.row)"
|
||||
>
|
||||
{{ props.value }}
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-option="props">
|
||||
<q-td :props="props">
|
||||
<q-btn flat dense icon="delete" color="negative" @click="openRemoveDialog(props.row)">
|
||||
<q-tooltip> {{ $t('delete') }} </q-tooltip>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</div>
|
||||
<EditOneDialog ref="editOneDialog" v-on:update="updateUsers"></EditOneDialog>
|
||||
<EditAllDialog ref="editAllDialog" v-on:update="updateUsers"></EditAllDialog>
|
||||
<OkDialog
|
||||
ref="okDialog"
|
||||
:dialog-label="$t('delete')"
|
||||
:text="$t('doYouWantToDelete') + ' ' + deleteText"
|
||||
label-color="red"
|
||||
:button-cancel-label="$t('cancel')"
|
||||
:button-ok-label="$t('confirm')"
|
||||
:button-ok-flat="false"
|
||||
button-ok-color="red"
|
||||
v-on:update-confirm="(val) => removeUser(...val)"
|
||||
></OkDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import type { Users, User } from 'src/vueLib/models/users';
|
||||
import EditOneDialog from 'src/components/EditOneDialog.vue';
|
||||
import EditAllDialog from 'src/components/UserEditAllDialog.vue';
|
||||
import OkDialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useUserTable } from './UserTable';
|
||||
import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
import { roles } from '../roles/RoleTable';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const editOneDialog = ref();
|
||||
const editAllDialog = ref();
|
||||
const okDialog = ref();
|
||||
const deleteText = ref('');
|
||||
const localRoles = computed(() => roles.value.map((role) => role.role));
|
||||
const selectOption = ref(false);
|
||||
const selected = ref<Users>([]);
|
||||
const openSubmenu = ref(false);
|
||||
const filter = ref('');
|
||||
|
||||
const { users, pagination, loading, columns, updateUsers } = useUserTable();
|
||||
|
||||
//load on mounting page
|
||||
onMounted(() => {
|
||||
loading.value = true;
|
||||
updateUsers();
|
||||
});
|
||||
|
||||
// opens dialog for all user values
|
||||
function openSingleValueDialog(label: string, field: string, user: User) {
|
||||
editOneDialog.value?.open(label, field, user);
|
||||
}
|
||||
|
||||
//opens dialog for one value
|
||||
function openAllValueDialog(user: User | null) {
|
||||
editAllDialog.value?.open(user);
|
||||
}
|
||||
|
||||
//opens remove dialog
|
||||
function openRemoveDialog(...users: Users) {
|
||||
if (users.length === 1) {
|
||||
deleteText.value = "'" + users[0]?.user + "'";
|
||||
} else {
|
||||
deleteText.value = String(users.length) + ' users';
|
||||
}
|
||||
okDialog.value?.open(users);
|
||||
}
|
||||
|
||||
//remove user from database
|
||||
function removeUser(...removeUsers: Users) {
|
||||
const userIds: number[] = [];
|
||||
|
||||
removeUsers.forEach((user: User) => {
|
||||
if (user.id) {
|
||||
userIds.push(user.id);
|
||||
}
|
||||
});
|
||||
|
||||
const login = useLogin();
|
||||
const user = login.getUser();
|
||||
|
||||
appApi
|
||||
.post('secure/users/delete?id=' + user?.id, { ids: userIds })
|
||||
.then(() => {
|
||||
updateUsers();
|
||||
selected.value = [];
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'))
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function getSelected(): Users {
|
||||
if (selected.value.length === 0) return [];
|
||||
return selected.value;
|
||||
}
|
||||
defineExpose({
|
||||
getSelected,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@keyframes blink-yellow {
|
||||
0%,
|
||||
100% {
|
||||
background-color: yellow;
|
||||
}
|
||||
50% {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
.blink-yellow {
|
||||
animation: blink-yellow 1.5s step-start 6 !important;
|
||||
}
|
||||
|
||||
.bigger-table-text .q-table__middle td {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.bigger-table-text .q-table__top,
|
||||
.bigger-table-text .q-table__bottom,
|
||||
.bigger-table-text th {
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
5
src/vueLib/types/vuedraggable.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module 'vuedraggable' {
|
||||
import type { DefineComponent } from 'vue';
|
||||
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>;
|
||||
export default component;
|
||||
}
|
3
tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "./.quasar/tsconfig.json"
|
||||
}
|