Compare commits
14 Commits
v1.0.8
...
fb27e9c026
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb27e9c026 | ||
|
|
14d2270260 | ||
|
|
7d4d2e4c54 | ||
|
|
352d0aa4c6 | ||
|
|
76269e7358 | ||
|
|
87297a3b97 | ||
|
|
b12574994c | ||
|
|
66bb7c1942 | ||
|
|
f8b79de6a2 | ||
|
|
c7fe7490f1 | ||
|
|
334c14a307 | ||
|
|
b9f009162d | ||
|
|
b844f487bc | ||
|
|
829dc074e2 |
1
backend/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.env
|
||||
62
backend/env/env.go
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type EnvKey string
|
||||
|
||||
const (
|
||||
Env EnvKey = "ENV"
|
||||
GinMode EnvKey = "GIN_MODE"
|
||||
Debug EnvKey = "DEBUG"
|
||||
PrivKey EnvKey = "PRIVKEY"
|
||||
Fullchain EnvKey = "FULLCHAIN"
|
||||
Https EnvKey = "HTTPS"
|
||||
HostUrl EnvKey = "HOST_URL"
|
||||
HostPort EnvKey = "HOST_PORT"
|
||||
WorkingDir EnvKey = "WORKING_DIR"
|
||||
Spa EnvKey = "SPA"
|
||||
AccessSecret EnvKey = "ACCESS_SECRET"
|
||||
RefreshSecret EnvKey = "REFRESH_SECRET"
|
||||
Organization EnvKey = "ORGANIZATION"
|
||||
DOMAIN EnvKey = "DOMAIN"
|
||||
AllowOrigin EnvKey = "ALLOWORIGIN"
|
||||
)
|
||||
|
||||
const (
|
||||
EnvDevelopment = "development"
|
||||
EnvProduction = "Prodction"
|
||||
)
|
||||
|
||||
func (key EnvKey) GetValue() string {
|
||||
return os.Getenv(string(key))
|
||||
}
|
||||
|
||||
func (key EnvKey) GetBoolValue() bool {
|
||||
return strings.ToLower(os.Getenv(string(key))) == "true"
|
||||
}
|
||||
|
||||
func (key EnvKey) GetUIntValue() uint {
|
||||
value, err := strconv.ParseUint(os.Getenv(string(key)), 10, 32)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return uint(value)
|
||||
}
|
||||
|
||||
func Load(file string) error {
|
||||
return godotenv.Load(file)
|
||||
}
|
||||
|
||||
func InDevelopmentMode() bool {
|
||||
return Env.GetValue() == EnvDevelopment
|
||||
}
|
||||
|
||||
func InDebugMode() bool {
|
||||
return strings.ToLower(Debug.GetValue()) == "true"
|
||||
}
|
||||
14
backend/example/example.env
Normal file
@@ -0,0 +1,14 @@
|
||||
ENV=development
|
||||
GIN_MODE=release
|
||||
DEBUG=false
|
||||
SPA=directory_of_spa_files
|
||||
WORKING_DIR=.
|
||||
HOST_URL=your_local_url
|
||||
HOST_PORT=your_local_port
|
||||
HTTPS=true
|
||||
PRIVKEY=your_certificate_key_file
|
||||
FULLCHAIN=your_certificate_fullchain_file
|
||||
ACCESS_SECRET=your_32bit_long_access_secret
|
||||
REFRESH_SECRET=your_32bit_long_referesh_secret
|
||||
ALLOWORIGIN=all_allowed_urls
|
||||
DOMAIN=your_domain
|
||||
@@ -3,12 +3,13 @@ module backend
|
||||
go 1.24.5
|
||||
|
||||
require (
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.19
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.24
|
||||
gitea.tecamino.com/paadi/memberDB v1.1.2
|
||||
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/joho/godotenv v1.5.1
|
||||
golang.org/x/crypto v0.43.0
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.19 h1:L51Qg5RNjdIGeQsHwGUTV+ADRpUqPt3qdnu7A7UQbsw=
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.19/go.mod h1:wKsB5/Rvaj580gdg3+GbUf5V/0N00XN6cID+C/8135M=
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.24 h1:wgCMJg1tgtPSCCVWLyNx1bT3B1N2NwHth0UJAH2nZIY=
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.24/go.mod h1:wKsB5/Rvaj580gdg3+GbUf5V/0N00XN6cID+C/8135M=
|
||||
gitea.tecamino.com/paadi/dbHandler v1.0.8 h1:ZWSBM/KFtLwTv2cBqwK1mOxWAxAfL0BcWEC3kJ9JALU=
|
||||
gitea.tecamino.com/paadi/dbHandler v1.0.8/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw=
|
||||
gitea.tecamino.com/paadi/memberDB v1.1.2 h1:j/Tsr7JnzAkdOvgjG77TzTVBWd4vBrmEFzPXNpW7GYk=
|
||||
@@ -56,6 +56,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
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=
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"backend/env"
|
||||
"backend/models"
|
||||
"backend/server"
|
||||
"backend/utils"
|
||||
@@ -23,24 +24,37 @@ import (
|
||||
)
|
||||
|
||||
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")
|
||||
// set cli flage
|
||||
envFile := flag.String("env", ".env", "enviroment file")
|
||||
flag.Parse()
|
||||
|
||||
// load enviroment file if exists
|
||||
if err := env.Load(*envFile); err != nil {
|
||||
fmt.Println("no .env found path: ", *envFile)
|
||||
}
|
||||
|
||||
devMode := env.InDevelopmentMode()
|
||||
// set gin mode
|
||||
if !devMode {
|
||||
gin.SetMode(env.GinMode.GetValue())
|
||||
}
|
||||
|
||||
workingDir := env.WorkingDir.GetValue()
|
||||
spa := env.Spa.GetValue()
|
||||
|
||||
//change working directory only if value is given
|
||||
if *workingDir != "." && *workingDir != "" {
|
||||
os.Chdir(*workingDir)
|
||||
if workingDir != "." && workingDir != "" {
|
||||
os.Chdir(workingDir)
|
||||
}
|
||||
|
||||
//set allowed origins
|
||||
var allowOrigins models.StringSlice
|
||||
|
||||
if strings.Contains(env.DOMAIN.GetValue(), "http") {
|
||||
allowOrigins.Set(env.DOMAIN.GetValue())
|
||||
}
|
||||
if env.AllowOrigin.GetValue() != "" {
|
||||
allowOrigins.Set(env.AllowOrigin.GetValue())
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
@@ -55,7 +69,7 @@ func main() {
|
||||
MaxSize: 1,
|
||||
MaxBackup: 3,
|
||||
MaxAge: 28,
|
||||
Debug: *debug,
|
||||
Debug: env.InDebugMode(),
|
||||
TerminalOut: true,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -82,11 +96,11 @@ func main() {
|
||||
|
||||
//get local ip
|
||||
httpString := "http://"
|
||||
if *https {
|
||||
if env.Https.GetBoolValue() {
|
||||
httpString = "https://"
|
||||
|
||||
}
|
||||
allowOrigins = append(allowOrigins, httpString+"localhost:9000", httpString+"localhost:9500", httpString+"127.0.0.1:9500", httpString+"0.0.0.0:9500")
|
||||
allowOrigins = append(allowOrigins, httpString+"localhost:9000", httpString+"localhost:9500", httpString+"127.0.0.1:9000", httpString+"0.0.0.0:9500")
|
||||
|
||||
localIP, err := utils.GetLocalIP()
|
||||
if err != nil {
|
||||
@@ -95,6 +109,8 @@ func main() {
|
||||
allowOrigins = append(allowOrigins, fmt.Sprintf("%s%s:9000", httpString, localIP), fmt.Sprintf("%s%s:9500", httpString, localIP))
|
||||
}
|
||||
|
||||
fmt.Println(100, allowOrigins)
|
||||
|
||||
s.Routes.Use(cors.New(cors.Config{
|
||||
AllowOrigins: allowOrigins,
|
||||
//AllowOrigins: []string{"*"},
|
||||
@@ -153,7 +169,7 @@ func main() {
|
||||
api.POST("/login/refresh", accessHandler.Refresh)
|
||||
|
||||
// Serve static files
|
||||
s.Routes.StaticFS("/assets", gin.Dir(filepath.Join(*spa, "assets"), true))
|
||||
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") {
|
||||
@@ -161,44 +177,44 @@ func main() {
|
||||
return
|
||||
}
|
||||
// Try to serve file from SPA directory
|
||||
filePath := filepath.Join(*spa, c.Request.URL.Path)
|
||||
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"))
|
||||
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 {
|
||||
if err := utils.OpenBrowser(fmt.Sprintf("%slocalhost:%s", httpString, env.HostPort.GetValue()), logger); err != nil {
|
||||
logger.Error("main", fmt.Sprintf("starting browser error : %s", err))
|
||||
}
|
||||
}()
|
||||
|
||||
if *https {
|
||||
if *sslFullchain == "" {
|
||||
if env.Https.GetBoolValue() {
|
||||
if env.Fullchain.GetValue() == "" {
|
||||
logger.Error("ssl certificate", "-cert flag not given for https server")
|
||||
log.Fatal("-cert flag not given for https server")
|
||||
}
|
||||
if *sslKey == "" {
|
||||
if env.PrivKey.GetValue() == "" {
|
||||
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.Info("main", fmt.Sprintf("https listen on ip: %s port: %s", env.HostUrl.GetValue(), env.HostPort.GetValue()))
|
||||
if err := s.ServeHttps(env.HostUrl.GetValue(), env.HostPort.GetUIntValue(), cert.Cert{Organization: env.Organization.GetValue(), CertFile: env.Fullchain.GetValue(), KeyFile: env.PrivKey.GetValue()}); 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.Info("main", fmt.Sprintf("http listen on ip: %s port: %s", env.HostUrl.GetValue(), env.HostPort.GetValue()))
|
||||
if err := s.ServeHttp(env.HostUrl.GetValue(), env.HostPort.GetUIntValue()); err != nil {
|
||||
logger.Error("main", "error http server "+err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package models
|
||||
|
||||
// type Rights struct {
|
||||
// Name string `json:"name"`
|
||||
// Rights int `json:"rights"`
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
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 != ""
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
package models
|
||||
|
||||
// type Settings struct {
|
||||
// PrimaryColor string `json:"primaryColor,omitempty"`
|
||||
// PrimaryColorText string `json:"primaryColorText,omitempty"`
|
||||
// SecondaryColor string `json:"secondaryColor,omitempty"`
|
||||
// SecondaryColorText string `json:"secondaryColorText,omitempty"`
|
||||
// Icon string `json:"icon,omitempty"`
|
||||
// DatabaseName string `json:"databaseName,omitempty"`
|
||||
// DatabaseToken string `json:"databaseToken,omitempty"`
|
||||
// }
|
||||
@@ -4,11 +4,10 @@ import "strings"
|
||||
|
||||
type StringSlice []string
|
||||
|
||||
func (s *StringSlice) String() string {
|
||||
return strings.Join(*s, ",")
|
||||
}
|
||||
|
||||
func (s *StringSlice) Set(value string) error {
|
||||
func (s *StringSlice) Set(value string) {
|
||||
if strings.Contains(value, ",") {
|
||||
*s = append(*s, strings.Split(value, ",")...)
|
||||
return
|
||||
}
|
||||
*s = append(*s, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
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 != ""
|
||||
// }
|
||||
25
index.html
@@ -1,19 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<!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<% } %>">
|
||||
<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">
|
||||
<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 -->
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "lightcontrol",
|
||||
"version": "1.0.8",
|
||||
"version": "1.1.0",
|
||||
"description": "A Tecamino App",
|
||||
"productName": "Member Database",
|
||||
"productName": "Attendence Records",
|
||||
"author": "A. Zuercher",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 859 B After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 6.9 KiB |
@@ -15,6 +15,7 @@ lastVisit: Letscht Bsuech
|
||||
search: Suechi
|
||||
noDataAvailable: Keni Date
|
||||
importCSV: importier CSV
|
||||
exportCSV: exportier CSV
|
||||
selectMemberOptions: Wähle Mitglieder Optione
|
||||
addNewMember: Neues Mitglied
|
||||
csvOptions: CSV Optionen
|
||||
@@ -32,6 +33,7 @@ settings: Iistellige
|
||||
databaseName: Datebank Name
|
||||
token: Schlüssu
|
||||
login: Amäude
|
||||
logout: Abmäude
|
||||
user: Benutzer
|
||||
password: Passwort
|
||||
isRequired: isch erforderlich
|
||||
@@ -115,3 +117,7 @@ expiration: Ablauf
|
||||
never: Nie
|
||||
responsibles: Verantwortliche
|
||||
comment: Bemerkung
|
||||
dark_mode: Dunkel-Modus
|
||||
light_mode: Hell-Modus
|
||||
import: Import
|
||||
export: Export
|
||||
|
||||
@@ -15,6 +15,7 @@ lastVisit: Letzter Besuch
|
||||
search: Suche
|
||||
noDataAvailable: Keine Daten
|
||||
importCSV: importiere CSV
|
||||
exportCSV: exportiere CSV
|
||||
selectMemberOptions: Wähle Mitglieder Optionen
|
||||
addNewMember: Neues Mitglied
|
||||
csvOptions: CSV Optionen
|
||||
@@ -32,6 +33,7 @@ settings: Einstellungen
|
||||
databaseName: Datenbank Name
|
||||
token: Schlüssel
|
||||
login: Anmelden
|
||||
logout: Abmelden
|
||||
user: Benutzer
|
||||
password: Passwort
|
||||
isRequired: ist erforderlich
|
||||
@@ -115,3 +117,7 @@ expiration: Ablauf
|
||||
never: Nie
|
||||
responsibles: Verantwortliche
|
||||
comment: Bemerkung
|
||||
dark_mode: Dunkel-Modus
|
||||
light_mode: Hell-Modus
|
||||
import: Import
|
||||
export: Export
|
||||
|
||||
@@ -15,6 +15,7 @@ lastVisit: Last Visit
|
||||
search: search
|
||||
noDataAvailable: No data available
|
||||
importCSV: Import CSV
|
||||
exportCSV: Export CSV
|
||||
selectMemberOptions: Select Member Options
|
||||
addNewMember: Add new Member
|
||||
csvOptions: CSV Options
|
||||
@@ -32,6 +33,7 @@ settings: Settings
|
||||
databaseName: Database Name
|
||||
token: Token
|
||||
login: Login
|
||||
logout: Logout
|
||||
user: User
|
||||
password: Password
|
||||
isRequired: is required
|
||||
@@ -115,3 +117,7 @@ expiration: Expiration
|
||||
never: Never
|
||||
responsibles: Responsibles
|
||||
comment: Comment
|
||||
dark_mode: Dark-Mode
|
||||
light_mode: Light-Mode
|
||||
import: Import
|
||||
export: Export
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { boot } from 'quasar/wrappers';
|
||||
import { setQuasarInstance } from 'src/vueLib/utils/globalQ';
|
||||
import { setRouterInstance } from 'src/vueLib/utils/globalRouter';
|
||||
import { databaseName } from 'src/vueLib/tables/members/MembersTable';
|
||||
import { Logo } from 'src/vueLib/models/logo';
|
||||
import { databaseName, logo, appName } from 'src/vueLib/models/settings';
|
||||
import { Dark } from 'quasar';
|
||||
|
||||
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;
|
||||
Dark.set(localStorage.getItem('mode') === 'true');
|
||||
|
||||
logo.value = localStorage.getItem('icon') ?? logo.value;
|
||||
appName.value = localStorage.getItem('appName') ?? appName.value;
|
||||
databaseName.value = localStorage.getItem('databaseName') ?? databaseName.value;
|
||||
let primaryColor = localStorage.getItem('primaryColor');
|
||||
if (primaryColor == null || primaryColor === 'undefined' || primaryColor.trim() === '') {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
ref="dialog"
|
||||
:header-title="newRole ? $t('addNewRole') : 'Edit ' + localRole.role"
|
||||
:height="700"
|
||||
:width="500"
|
||||
:width="700"
|
||||
>
|
||||
<div class="row justify-center">
|
||||
<q-input
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/>
|
||||
<q-btn flat dense round icon="menu" aria-label="Menu" @click="toggleLeftDrawer" />
|
||||
|
||||
<q-toolbar-title class="text-primary-text"> {{ productName }} </q-toolbar-title>
|
||||
<q-toolbar-title class="text-primary-text"> {{ $t(appName) }} </q-toolbar-title>
|
||||
|
||||
<div>Version {{ version }}</div>
|
||||
<q-btn dense icon="refresh" square class="q-px-md q-ml-md" @click="refresh" />
|
||||
@@ -18,7 +18,7 @@
|
||||
</q-toolbar>
|
||||
</q-header>
|
||||
|
||||
<q-drawer v-model="leftDrawerOpen" bordered>
|
||||
<q-drawer v-model="leftDrawerOpen" bordered :width="drawerWidth" :overlay="$q.screen.lt.sm">
|
||||
<q-list>
|
||||
<q-item v-if="!autorized" to="/login" exact clickable v-ripple @click="closeDrawer">
|
||||
<q-item-section>{{ $t('login') }}</q-item-section>
|
||||
@@ -63,12 +63,13 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { version, productName } from '../../package.json';
|
||||
import { version } 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';
|
||||
import { logo, appName } from 'src/vueLib/models/settings';
|
||||
import { useQuasar } from 'quasar';
|
||||
|
||||
const localLogo = ref(Logo);
|
||||
const localLogo = ref(logo);
|
||||
|
||||
const leftDrawerOpen = ref(false);
|
||||
const user = useUserStore();
|
||||
@@ -87,4 +88,10 @@ function closeDrawer() {
|
||||
function refresh() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
// Change width based on screen size
|
||||
const drawerWidth = computed(() => {
|
||||
const $q = useQuasar();
|
||||
return $q.screen.lt.sm ? 220 : 300; // phone: 220px, desktop: 300px
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
<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
|
||||
:readonly="!user.isPermittedTo('settings', 'write')"
|
||||
: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('appName')"
|
||||
v-model="settings.appName"
|
||||
></q-input>
|
||||
<q-input
|
||||
:readonly="!user.isPermittedTo('settings', 'write')"
|
||||
:class="[
|
||||
@@ -133,8 +145,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { databaseName } from 'src/vueLib/tables/members/MembersTable';
|
||||
import { Logo } from 'src/vueLib/models/logo';
|
||||
import { logo, appName, databaseName } from 'src/vueLib/models/settings';
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
@@ -146,7 +157,8 @@ const colorGroup = ref(false);
|
||||
const user = useUserStore();
|
||||
|
||||
const settings = reactive<Settings>({
|
||||
icon: Logo.value,
|
||||
appName: appName.value,
|
||||
icon: logo.value,
|
||||
databaseName: databaseName.value,
|
||||
primaryColor: document.documentElement.style.getPropertyValue('--q-primary'),
|
||||
primaryColorText: document.documentElement.style.getPropertyValue('--q-primary-text'),
|
||||
@@ -155,7 +167,8 @@ const settings = reactive<Settings>({
|
||||
});
|
||||
|
||||
watch(settings, (newSettings) => {
|
||||
Logo.value = newSettings.icon;
|
||||
logo.value = newSettings.icon;
|
||||
appName.value = newSettings.appName;
|
||||
databaseName.value = newSettings.databaseName;
|
||||
});
|
||||
|
||||
@@ -175,8 +188,10 @@ function save() {
|
||||
document.documentElement.style.setProperty('--q-primary-text', settings.primaryColorText);
|
||||
document.documentElement.style.setProperty('--q-secondary', settings.secondaryColor);
|
||||
document.documentElement.style.setProperty('--q-secondary-text', settings.secondaryColorText);
|
||||
Logo.value = settings.icon;
|
||||
appName.value = settings.appName;
|
||||
logo.value = settings.icon;
|
||||
localStorage.setItem('icon', settings.icon);
|
||||
localStorage.setItem('appName', settings.appName);
|
||||
localStorage.setItem('databaseName', settings.databaseName);
|
||||
localStorage.setItem('primaryColor', settings.primaryColor);
|
||||
localStorage.setItem('primaryColorText', settings.primaryColorText);
|
||||
|
||||
@@ -24,6 +24,20 @@
|
||||
@update:model-value="(val) => toggleBit(index, 2, val)"
|
||||
>{{ i18n.global.t('delete') }}</q-checkbox
|
||||
>
|
||||
<q-checkbox
|
||||
v-if="permission.permissionNumber > 3"
|
||||
class="q-mx-md"
|
||||
:model-value="isFlagSet(permission.permission, 1 << 3)"
|
||||
@update:model-value="(val) => toggleBit(index, 3, val)"
|
||||
>{{ i18n.global.t('import') }}</q-checkbox
|
||||
>
|
||||
<q-checkbox
|
||||
v-if="permission.permissionNumber > 4"
|
||||
class="q-mx-md"
|
||||
:model-value="isFlagSet(permission.permission, 1 << 4)"
|
||||
@update:model-value="(val) => toggleBit(index, 4, val)"
|
||||
>{{ i18n.global.t('export') }}</q-checkbox
|
||||
>
|
||||
</div>
|
||||
</q-card>
|
||||
</q-card>
|
||||
@@ -47,6 +61,7 @@ const localPermission = ref(
|
||||
props.permissions.map((e) => ({
|
||||
name: e.name,
|
||||
permission: e.permission ?? 0,
|
||||
permissionNumber: e.name === 'members' ? 5 : 3,
|
||||
})),
|
||||
);
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
:no-refocus="!minMaxState"
|
||||
:seamless="!minMaxState"
|
||||
>
|
||||
<q-card class="layout" :style="cardStyle">
|
||||
<q-card class="layout bg-surface text-on-surface" :style="cardStyle">
|
||||
<!-- Draggable Header -->
|
||||
<div
|
||||
class="dialog-header row items-center justify-between bg-grey-1"
|
||||
class="dialog-header row items-center justify-between bg-transparent"
|
||||
v-touch-pan.mouse.prevent.stop="handlePan"
|
||||
>
|
||||
<div v-if="headerTitle" class="text-left text-bold text-caption q-mx-sm">
|
||||
@@ -139,13 +139,11 @@ const cardStyle = computed(() => {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<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>
|
||||
<div class="text-h5 text-primary text-center">{{ $t(appName) }}</div>
|
||||
<q-input
|
||||
ref="refUserInput"
|
||||
dense
|
||||
@@ -47,7 +47,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { productName } from '../../../package.json';
|
||||
import { appName } from '../models/settings';
|
||||
import { ref } from 'vue';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
import { useLogin } from './useLogin';
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
<q-item-section class="text-primary">{{ loginText }}</q-item-section>
|
||||
</q-item>
|
||||
<q-item>
|
||||
<q-btn flat :icon="Dark.mode ? 'light_mode' : 'dark_mode'" @click="Dark.toggle"></q-btn>
|
||||
<q-btn flat :icon="darkMode" @click="toggleDarkMode"
|
||||
><q-tooltip>{{ $t(darkMode) }}</q-tooltip></q-btn
|
||||
>
|
||||
</q-item>
|
||||
<q-item>
|
||||
<q-select
|
||||
@@ -18,7 +20,8 @@
|
||||
dense
|
||||
v-model="langSelected"
|
||||
:options="langSelection"
|
||||
></q-select>
|
||||
><q-tooltip>{{ $t('language') }}</q-tooltip></q-select
|
||||
>
|
||||
</q-item>
|
||||
<q-item
|
||||
v-if="
|
||||
@@ -54,21 +57,34 @@ import { useLogin } from './useLogin';
|
||||
|
||||
const userLogin = useLogin();
|
||||
const route = useRoute();
|
||||
const refLoginDialog = ref();
|
||||
const user = useUserStore();
|
||||
const { NotifyResponse } = useNotify();
|
||||
const currentUser = computed(() => user.user);
|
||||
const darkMode = computed(() => {
|
||||
if (Dark.mode) {
|
||||
return 'light_mode';
|
||||
}
|
||||
return 'dark_mode';
|
||||
});
|
||||
const showLogin = computed(
|
||||
() => (route.path !== '/' && route.path !== '/login') || currentUser.value?.username === '',
|
||||
);
|
||||
|
||||
const user = useUserStore();
|
||||
const autorized = computed(() => !!user.isAuthorizedAs(['admin']));
|
||||
const { NotifyResponse } = useNotify();
|
||||
const currentUser = computed(() => user.user);
|
||||
|
||||
// switch between logged in or logged out text
|
||||
const loginText = computed(() => {
|
||||
return currentUser.value ? 'Logout' : 'Login';
|
||||
return currentUser.value ? i18n.global.t('logout') : i18n.global.t('login');
|
||||
});
|
||||
|
||||
const refLoginDialog = ref();
|
||||
//switch between dark and light mode and save it in localStorage
|
||||
function toggleDarkMode() {
|
||||
Dark.toggle();
|
||||
localStorage.setItem('mode', String(Dark.mode));
|
||||
}
|
||||
|
||||
// opens login page if no user is logged in otherwise it serves as logout
|
||||
function openLogin() {
|
||||
if (currentUser.value) {
|
||||
userLogin.logout().catch((err) => NotifyResponse(err, 'error'));
|
||||
|
||||
@@ -2,7 +2,7 @@ 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';
|
||||
import { appName, logo } from '../models/settings';
|
||||
|
||||
const refreshTime = 10000;
|
||||
let intervalId: ReturnType<typeof setInterval> | null = null;
|
||||
@@ -16,7 +16,8 @@ export function useLogin() {
|
||||
await appApi.post('/login', { user, password }).then((resp) => {
|
||||
const sets = resp.data.settings as Settings;
|
||||
|
||||
Logo.value = sets.icon;
|
||||
logo.value = sets.icon;
|
||||
appName.value = sets.appName;
|
||||
document.documentElement.style.setProperty('--q-primary', sets.primaryColor);
|
||||
document.documentElement.style.setProperty('--q-primary-text', sets.primaryColorText);
|
||||
document.documentElement.style.setProperty('--q-secondary', sets.secondaryColor);
|
||||
|
||||
@@ -24,7 +24,7 @@ export const useUserStore = defineStore('user', {
|
||||
};
|
||||
},
|
||||
isPermittedTo: (state: UserState) => {
|
||||
return (name: string, type: 'read' | 'write' | 'delete'): boolean => {
|
||||
return (name: string, type: 'read' | 'write' | 'delete' | 'import' | 'export'): boolean => {
|
||||
const permission = state.user?.permissions?.find((r: Permission) => r.name === name);
|
||||
switch (type) {
|
||||
case 'read':
|
||||
@@ -33,6 +33,10 @@ export const useUserStore = defineStore('user', {
|
||||
return permission?.permission ? (permission.permission & (1 << 1)) === 2 : false;
|
||||
case 'delete':
|
||||
return permission?.permission ? (permission.permission & (1 << 2)) === 4 : false;
|
||||
case 'import':
|
||||
return permission?.permission ? (permission.permission & (1 << 3)) === 8 : false;
|
||||
case 'export':
|
||||
return permission?.permission ? (permission.permission & (1 << 4)) === 16 : false;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
export const Logo = ref('');
|
||||
@@ -1,4 +1,11 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
export const logo = ref('');
|
||||
export const appName = ref('Attendance Records');
|
||||
export const databaseName = ref('members.dba');
|
||||
|
||||
export type Settings = {
|
||||
appName: string;
|
||||
icon: string;
|
||||
databaseName: string;
|
||||
primaryColor: string;
|
||||
@@ -9,6 +16,7 @@ export type Settings = {
|
||||
|
||||
export function DefaultSettings(): Settings {
|
||||
return {
|
||||
appName: 'Attendance Records',
|
||||
icon: '',
|
||||
databaseName: 'members.dba',
|
||||
primaryColor: document.documentElement.style.getPropertyValue('--q-primary-text'),
|
||||
|
||||
@@ -153,7 +153,7 @@ import EditAllDialog from 'src/components/EventEditAllDialog.vue';
|
||||
import OkDialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useEventTable } from './EventsTable';
|
||||
import { databaseName } from '../members/MembersTable';
|
||||
import { databaseName } from 'src/vueLib/models/settings';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import AttendeesTable from '../attendees/AttendeesTable.vue';
|
||||
import type { Members } from 'src/vueLib/models/member';
|
||||
|
||||
@@ -4,8 +4,7 @@ import type { Member, Members } from 'src/vueLib/models/member';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { i18n } from 'boot/lang';
|
||||
import { useResponsibleTable } from '../responsible/ResponsibleTable';
|
||||
|
||||
export const databaseName = ref('members.dba');
|
||||
import { appName } from 'src/vueLib/models/settings';
|
||||
|
||||
export function useMemberTable() {
|
||||
const members = ref<Members>([]);
|
||||
@@ -232,7 +231,6 @@ export function useMemberTable() {
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
console.log(4545, members.value.length);
|
||||
//filter same members out so list is shorter
|
||||
if (filter) {
|
||||
members.value = members.value.filter(
|
||||
@@ -245,7 +243,6 @@ export function useMemberTable() {
|
||||
}),
|
||||
);
|
||||
}
|
||||
console.log(4546, members.value.length);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -257,6 +254,47 @@ export function useMemberTable() {
|
||||
});
|
||||
}
|
||||
|
||||
function exportCsv() {
|
||||
const comma = ';';
|
||||
// Extract only columns that have a field (not icons/options)
|
||||
const exportableColumns = columns.value.filter(
|
||||
(col) => typeof col.field === 'string' && col.field !== 'cake' && col.field !== 'option',
|
||||
) as { field: keyof Member; label: string }[];
|
||||
|
||||
// Build CSV header row
|
||||
const header = exportableColumns.map((col) => col.field).join(comma);
|
||||
|
||||
// Build CSV rows
|
||||
const data = members.value.map((member) =>
|
||||
exportableColumns
|
||||
.map((col) => {
|
||||
const value = member[col.field];
|
||||
// handle nested objects (e.g. responsiblePerson)
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if ('firstName' in value && 'lastName' in value)
|
||||
return `"${value.firstName} ${value.lastName}"`;
|
||||
return `"${JSON.stringify(value)}"`;
|
||||
}
|
||||
return `"${value ?? ''}"`;
|
||||
})
|
||||
.join(comma),
|
||||
);
|
||||
|
||||
// Combine into CSV string
|
||||
const csv = [header, ...data].join('\n');
|
||||
|
||||
// Create blob and trigger download
|
||||
const BOM = '\uFEFF';
|
||||
const blob = new Blob([BOM + csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', i18n.global.t(appName.value) + '.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
return {
|
||||
members,
|
||||
responsibles,
|
||||
@@ -267,5 +305,6 @@ export function useMemberTable() {
|
||||
updateMembers,
|
||||
isXDaysBeforeAnnualDate,
|
||||
disableColumns,
|
||||
exportCsv,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<q-tooltip>{{ $t('selectMemberOptions') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="user.isPermittedTo('members', 'write')"
|
||||
v-if="user.isPermittedTo('members', 'import')"
|
||||
dense
|
||||
flat
|
||||
icon="upload"
|
||||
@@ -51,6 +51,15 @@
|
||||
>
|
||||
<q-tooltip>{{ $t('importCSV') }}</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="user.isPermittedTo('members', 'export')"
|
||||
dense
|
||||
flat
|
||||
icon="download"
|
||||
@click="exportCsv"
|
||||
>
|
||||
<q-tooltip>{{ $t('exportCSV') }}</q-tooltip>
|
||||
</q-btn>
|
||||
</q-btn-group>
|
||||
<div v-if="selectOption && selected.length > 0">
|
||||
<q-btn
|
||||
@@ -201,7 +210,7 @@ import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useMemberTable } from './MembersTable';
|
||||
import UploadDialog from 'src/components/UploadDialog.vue';
|
||||
import AddToEvent from 'src/components/AddToEvent.vue';
|
||||
import { databaseName } from './MembersTable';
|
||||
import { databaseName } from 'src/vueLib/models/settings';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { i18n } from 'src/boot/lang';
|
||||
|
||||
@@ -240,6 +249,7 @@ const {
|
||||
updateMembers,
|
||||
isXDaysBeforeAnnualDate,
|
||||
disableColumns,
|
||||
exportCsv,
|
||||
} = useMemberTable();
|
||||
|
||||
//load on mounting page
|
||||
|
||||
@@ -136,7 +136,7 @@ import type { Member, Members } from 'src/vueLib/models/member';
|
||||
import OkDialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { useResponsibleTable } from './ResponsibleTable';
|
||||
import { databaseName } from '../members/MembersTable';
|
||||
import { databaseName } from 'src/vueLib/models/settings';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { i18n } from 'src/boot/lang';
|
||||
|
||||
|
||||