Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
11b48c548e | ||
![]() |
9585fb1b7a | ||
![]() |
a648be3bcb | ||
![]() |
33f7775800 | ||
![]() |
ac412bbffb | ||
![]() |
6f532ef4b0 | ||
![]() |
1155bafb30 | ||
![]() |
0e3a14d69c | ||
![]() |
de88b2773c | ||
![]() |
1697a4dcfd |
120
.gitea/workflows/build.yml
Normal file
120
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,120 @@
|
||||
name: Build Quasar SPA and Go Backend for lightController
|
||||
|
||||
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="../server-${{ 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: lightcontroller-${{ matrix.goos }}-${{ matrix.arch }}
|
||||
path: |
|
||||
./dist/spa
|
||||
server-${{ matrix.goos }}-${{ matrix.arch }}${{ matrix.ext }}
|
71
.github/workflows/build.yml
vendored
71
.github/workflows/build.yml
vendored
@@ -1,71 +0,0 @@
|
||||
name: Build Quasar SPA and Go Backend for lightController
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [linux, windows]
|
||||
goarch: [amd64, arm, arm64]
|
||||
exclude:
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
- goos: windows
|
||||
goarch: arm64
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set ip Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Install dependecies
|
||||
run: npm install
|
||||
|
||||
- name: Install Quasar CLI
|
||||
run: npm install -g @quasar/cli
|
||||
|
||||
- name: Build Quasar SPA
|
||||
run: quasar build
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.24.0'
|
||||
cache-dependency-path: backend/go.sum
|
||||
|
||||
- name: Set up Git credentials for private modules
|
||||
run: |
|
||||
git config --global url."https://oauth2:${{ secrets.GH_PAT }}@github.com".insteadOf "https://github.com"
|
||||
env:
|
||||
GH_PAT_FOR_MODULES: ${{ secrets.GH_PAT }}
|
||||
|
||||
- name: Go Mod Tidy & Download
|
||||
working-directory: ./backend
|
||||
run: go mod tidy -v
|
||||
|
||||
- name: Build go backend binary
|
||||
working-directory: ./backend
|
||||
run: |
|
||||
if [ "${{ matrix.goos }}" == "windows" ]; then
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -trimpath -o ../server-${{ matrix.goos }}-${{ matrix.goarch }}.exe main.go
|
||||
else
|
||||
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -trimpath -o ../server-${{ matrix.goos }}-${{ matrix.goarch }} main.go
|
||||
fi
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lightcontroller-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: |
|
||||
./dist/spa
|
||||
server-${{ matrix.goos }}-${{ matrix.goarch }}${{ (matrix.goos == 'windows' && '.exe') || '' }}
|
@@ -1,6 +1,7 @@
|
||||
package dbRequest
|
||||
|
||||
import (
|
||||
"backend/models"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -10,25 +11,22 @@ import (
|
||||
var DBCreate string = `CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
password TEXT NOT NULL
|
||||
);`
|
||||
|
||||
var DBNewUser string = `INSERT INTO users (username, password) VALUES (?, ?)`
|
||||
var DBQueryPassword string = `SELECT password FROM users WHERE username = ?`
|
||||
var DBNewUser string = `INSERT INTO users (username, role, password) VALUES (?, ?, ?)`
|
||||
var DBQueryPassword string = `SELECT role, password FROM users WHERE username = ?`
|
||||
var DBUserLookup string = `SELECT EXISTS(SELECT 1 FROM users WHERE username = ?)`
|
||||
var DBRemoveUser string = `DELETE FROM users WHERE username = $1`
|
||||
|
||||
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, gin.H{
|
||||
"error": fmt.Sprintf("no user '%s' found", username),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse(fmt.Sprintf("no user '%s' found", username)))
|
||||
return true
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
1
backend/dist/cfg/configuration.json
vendored
Executable file
1
backend/dist/cfg/configuration.json
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"services":[{"name":"ArtNet Driver","description":"ArtNet Driver DMX over UDP/IP","executablePath":"../../tecamino-driver-artNet/artNet","workingDirectory":"../../tecamino-driver-artNet","arguments":["-cfg ./dist/cfg","-serverIp 127.0.0.1","-serverPort 8100","-port 8200"]}]}
|
29
backend/dist/cfg/defaultConfigurations.json
vendored
Normal file
29
backend/dist/cfg/defaultConfigurations.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"cfgFileName": "configuration.json",
|
||||
"services":[{
|
||||
"name":"ArtNet Driver",
|
||||
"description":"ArtNet Driver DMX over UDP/IP",
|
||||
"executablePath":"bin/tecamino-driver-artNet-linux-arm64",
|
||||
"workingDirectory":"bin",
|
||||
"arguments":[
|
||||
"-cfg './cfg'",
|
||||
"-serverIp '127.0.0.1'",
|
||||
"-serverPort 8100",
|
||||
"-port 8200"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name":"OSC Driver",
|
||||
"description":"OSC Driver Music Mixer over UDP/IP",
|
||||
"executablePath":"bin/tecamino-driver-osc-linux-arm64",
|
||||
"workingDirectory":"bin",
|
||||
"arguments":[
|
||||
"-cfg './cfg'",
|
||||
"-serverIp '127.0.0.1'",
|
||||
"-serverPort 8100",
|
||||
"-port 8300"
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
}
|
@@ -5,27 +5,31 @@ go 1.24.0
|
||||
toolchain go1.24.3
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/cors v1.7.5
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
gitea.tecamino.com/paadi/statusServer v1.0.3
|
||||
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.10.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/tecamino/tecamino-dbm v0.0.10
|
||||
github.com/tecamino/tecamino-logger v0.2.0
|
||||
golang.org/x/crypto v0.36.0
|
||||
golang.org/x/crypto v0.39.0
|
||||
modernc.org/sqlite v1.37.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.13.2 // indirect
|
||||
gitea.tecamino.com/paadi/pubSub v1.0.2 // indirect
|
||||
gitea.tecamino.com/paadi/tecamino-json_data v0.1.0 // indirect
|
||||
github.com/bytedance/sonic v1.13.3 // indirect
|
||||
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||
github.com/gin-contrib/sse v1.0.0 // 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.26.0 // indirect
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/gorilla/websocket v1.5.3 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
@@ -33,17 +37,17 @@ require (
|
||||
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.3 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.15.0 // indirect
|
||||
golang.org/x/arch v0.18.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
|
||||
golang.org/x/net v0.38.0 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
@@ -1,5 +1,15 @@
|
||||
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=
|
||||
github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||
gitea.tecamino.com/paadi/pubSub v1.0.2 h1:9Q9KLTIHRSjxrTkDyuF8mDYOLkI8DjjPNSnoS2GKflY=
|
||||
gitea.tecamino.com/paadi/pubSub v1.0.2/go.mod h1:SBPTSD/JQWRbwqsSNoSPhV81IDTreP0TMyvLhmK3P2M=
|
||||
gitea.tecamino.com/paadi/statusServer v1.0.3 h1:bRw+Jz9AIoiwqNLTBnrus2aUxq2Em2gA8NDANtqVHEA=
|
||||
gitea.tecamino.com/paadi/statusServer v1.0.3/go.mod h1:kNO/ASrrmsLGgo+k49TLpVP6PpxG3I3D1moJ6Ke+ocg=
|
||||
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-json_data v0.1.0 h1:zp3L8qUvkVqzuesQdMh/SgZZZbX3pGD9NYa6jtz+JvA=
|
||||
gitea.tecamino.com/paadi/tecamino-json_data v0.1.0/go.mod h1:/FKhbVYuhiNlQp4552rJJQIhynjLarDzfrgXpupkwZU=
|
||||
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.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
|
||||
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
||||
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||
@@ -11,14 +21,14 @@ 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.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
||||
github.com/gin-contrib/cors v1.7.5 h1:cXC9SmofOrRg0w9PigwGlHG3ztswH6bqq4vJVXnvYMk=
|
||||
github.com/gin-contrib/cors v1.7.5/go.mod h1:4q3yi7xBEDDWKapjT2o1V7mScKDDr8k+jZ0fSquGoy0=
|
||||
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
||||
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
|
||||
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
||||
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
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.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
|
||||
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
||||
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=
|
||||
@@ -31,13 +41,15 @@ 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/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.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
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/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
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.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
@@ -59,8 +71,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
||||
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.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
||||
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
||||
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/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
@@ -70,46 +82,40 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po
|
||||
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/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
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.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tecamino/tecamino-dbm v0.0.10 h1:+6OTl7yTsqLuYqE8QVB8ski3x0seI5yBFLnuHdVz99k=
|
||||
github.com/tecamino/tecamino-dbm v0.0.10/go.mod h1:8YYOr/jQ9mGVmmNj2NE8HajDvlJAVY3iGOZNfMjd8kA=
|
||||
github.com/tecamino/tecamino-logger v0.2.0 h1:NPH/Gg9qRhmVoW8b39i1eXu/LEftHc74nyISpcRG+XU=
|
||||
github.com/tecamino/tecamino-logger v0.2.0/go.mod h1:0M1E9Uei/qw3e3WA1x3lBo1eP3H5oeYE7GjYrMahnj8=
|
||||
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.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
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/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.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=
|
||||
golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=
|
||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||
golang.org/x/arch v0.18.0 h1:WN9poc33zL4AzGxqf8VtpKUnGvMi8O9lhNyBMF/85qc=
|
||||
golang.org/x/arch v0.18.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM=
|
||||
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8=
|
||||
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
|
||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
|
||||
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
|
||||
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
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.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
|
||||
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
|
||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
|
||||
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
|
@@ -19,25 +19,19 @@ import (
|
||||
func (lm *LoginManager) AddUser(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
user := models.User{}
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsValid() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "user empty",
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("user empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -54,20 +48,16 @@ func (lm *LoginManager) AddUser(c *gin.Context) {
|
||||
}
|
||||
|
||||
if exists {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"error": fmt.Sprintf("user '%s' exists already", user.Name),
|
||||
})
|
||||
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, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
if _, err := db.Exec(dbRequest.DBNewUser, user.Name, hash); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
if _, err := db.Exec(dbRequest.DBNewUser, user.Role, user.Name, hash); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -79,25 +69,19 @@ func (lm *LoginManager) AddUser(c *gin.Context) {
|
||||
func (lm *LoginManager) RemoveUser(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
user := models.User{}
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsValid() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "user empty",
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("user empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -108,14 +92,12 @@ func (lm *LoginManager) RemoveUser(c *gin.Context) {
|
||||
defer db.Close()
|
||||
|
||||
var storedPassword string
|
||||
if err := db.QueryRow(dbRequest.DBQueryPassword, user.Name).Scan(&storedPassword); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
if err := db.QueryRow(dbRequest.DBQueryPassword, user.Name).Scan(&storedPassword, &user.Role); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.CheckPassword(user.Password, storedPassword) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "wrong password",
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("wrong password"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -131,27 +113,19 @@ func (lm *LoginManager) RemoveUser(c *gin.Context) {
|
||||
func (lm *LoginManager) Login(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
user := models.User{}
|
||||
err = json.Unmarshal(body, &user)
|
||||
if err != nil {
|
||||
fmt.Println(2)
|
||||
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsValid() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "user empty",
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("user empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,41 +136,36 @@ func (lm *LoginManager) Login(c *gin.Context) {
|
||||
defer db.Close()
|
||||
|
||||
var storedPassword string
|
||||
if err := db.QueryRow(dbRequest.DBQueryPassword, user.Name).Scan(&storedPassword); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
if err := db.QueryRow(dbRequest.DBQueryPassword, user.Name).Scan(&user.Role, &storedPassword); dbRequest.CheckDBError(c, user.Name, err) {
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.CheckPassword(user.Password, storedPassword) {
|
||||
fmt.Println(2, user.Password)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "wrong password",
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse("wrong password"))
|
||||
return
|
||||
}
|
||||
|
||||
// Create token
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"username": user.Name,
|
||||
"exp": time.Now().Add(time.Hour * 72).Unix(), // expires in 72h
|
||||
"role": user.Role,
|
||||
"exp": time.Now().Add(time.Minute * 60).Unix(), // expires in 72h
|
||||
})
|
||||
|
||||
secret, err := utils.GenerateJWTSecret(32) // 32 bytes = 256 bits
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "error generate jwt token"})
|
||||
c.JSON(http.StatusInternalServerError, models.NewJsonErrorMessageResponse("error generate jwt token"))
|
||||
return
|
||||
}
|
||||
|
||||
// Sign and get the complete encoded token as a string
|
||||
tokenString, err := token.SignedString(secret)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Could not generate token"})
|
||||
c.JSON(http.StatusInternalServerError, models.NewJsonErrorMessageResponse("Could not generate token"))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.User{
|
||||
Name: user.Name,
|
||||
Token: tokenString,
|
||||
})
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ func NewLoginManager(dir string) (*LoginManager, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = db.Exec(dbRequest.DBNewUser, "admin", hash)
|
||||
_, err = db.Exec(dbRequest.DBNewUser, "admin", "admin", hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"backend/models"
|
||||
secenes "backend/scenes"
|
||||
"backend/server"
|
||||
"backend/services"
|
||||
"backend/utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -15,9 +16,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.tecamino.com/paadi/statusServer"
|
||||
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tecamino/tecamino-logger/logging"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -27,6 +29,8 @@ func main() {
|
||||
flag.Var(&allowOrigins, "allowOrigin", "Allowed origin (can repeat this flag)")
|
||||
|
||||
spa := flag.String("spa", "./dist/spa", "quasar spa files")
|
||||
cfgDir := flag.String("cfg", "./cfg", "config dir")
|
||||
servicesCfg := flag.String("services", "defaultConfigurations.json", "services config file name")
|
||||
workingDir := flag.String("workingDirectory", ".", "quasar spa files")
|
||||
ip := flag.String("ip", "0.0.0.0", "server listening ip")
|
||||
port := flag.Uint("port", 9500, "server listening port")
|
||||
@@ -35,7 +39,6 @@ func main() {
|
||||
|
||||
//change working directory only if value is given
|
||||
if *workingDir != "." && *workingDir != "" {
|
||||
fmt.Println(1, *workingDir)
|
||||
os.Chdir(*workingDir)
|
||||
}
|
||||
|
||||
@@ -69,15 +72,25 @@ func main() {
|
||||
//new scenes handler
|
||||
scenesHandler := secenes.NewScenesHandler("")
|
||||
|
||||
//new scenes handler
|
||||
servicesHandler := services.NewServicesHandler(*cfgDir, *servicesCfg)
|
||||
|
||||
// new server
|
||||
s := server.NewServer()
|
||||
|
||||
// new status websocket
|
||||
statusWs, err := statusServer.NewStatusWebsocket(5, 256, logger)
|
||||
if err != nil {
|
||||
logger.Error("main", fmt.Sprintf("initialize status websocket: %s", err.Error()))
|
||||
}
|
||||
|
||||
servicesHandler.LinkStatusServer(statusWs)
|
||||
//get local ip
|
||||
allowOrigins = append(allowOrigins, "http://localhost:9000", "http://localhost:9500")
|
||||
|
||||
localIP, err := utils.GetLocalIP()
|
||||
if err != nil {
|
||||
logger.Error("main", fmt.Sprintf("get local ip : %s", err.Error()))
|
||||
logger.Error("main", fmt.Sprintf("get local ip: %s", err.Error()))
|
||||
} else {
|
||||
allowOrigins = append(allowOrigins, fmt.Sprintf("http://%s:9000", localIP), fmt.Sprintf("http://%s:9500", localIP))
|
||||
}
|
||||
@@ -91,20 +104,28 @@ func main() {
|
||||
|
||||
api := s.Routes.Group("/api")
|
||||
//set routes
|
||||
api.GET("/loadScenes", scenesHandler.LoadScenes)
|
||||
api.GET("/status", statusWs.NewConection)
|
||||
api.GET("/scenes/all", scenesHandler.LoadScenes)
|
||||
api.GET("/services/all", servicesHandler.GetAllAvaiableServices)
|
||||
api.GET("/services/load", servicesHandler.LoadAllServices)
|
||||
api.GET("/services/:service/start", servicesHandler.StartService)
|
||||
api.GET("/services/:service/stop", servicesHandler.StopService)
|
||||
api.POST("/login", loginManager.Login)
|
||||
api.POST("/user/add", loginManager.AddUser)
|
||||
api.POST("/saveScene", scenesHandler.SaveScene)
|
||||
api.POST("/loadScene", scenesHandler.LoadScene)
|
||||
api.DELETE("/user", loginManager.RemoveUser)
|
||||
api.DELETE("/deleteScene", scenesHandler.DeleteScene)
|
||||
api.POST("/scenes/save", scenesHandler.SaveScene)
|
||||
api.POST("/scenes/load", scenesHandler.LoadScene)
|
||||
api.POST("/services/add", servicesHandler.AddNewService)
|
||||
|
||||
api.DELETE("/user",
|
||||
loginManager.RemoveUser)
|
||||
api.DELETE("/scenes", scenesHandler.DeleteScene)
|
||||
|
||||
// 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, gin.H{"error": "API endpoint not found"})
|
||||
c.JSON(http.StatusNotFound, models.NewJsonErrorMessageResponse("API endpoint not found"))
|
||||
return
|
||||
}
|
||||
// Try to serve file from SPA directory
|
||||
|
6
backend/models/configuration.go
Normal file
6
backend/models/configuration.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package models
|
||||
|
||||
type Configuration struct {
|
||||
CfgFileName string `json:"cfgFileName,omitempty"`
|
||||
Services []Service `json:"services,omitempty"`
|
||||
}
|
20
backend/models/jsonResponse.go
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(),
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
package models
|
||||
|
||||
type LightBar []Value
|
@@ -1,3 +0,0 @@
|
||||
package models
|
||||
|
||||
type MovingHead []Value
|
80
backend/models/service.go
Normal file
80
backend/models/service.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ExecutablePath string `json:"executablePath,omitempty"`
|
||||
WorkingDirectory string `json:"workingDirectory,omitempty"`
|
||||
Arguments []string `json:"arguments,omitempty"`
|
||||
State string `json:"-"`
|
||||
Cmd *exec.Cmd `json:"-"`
|
||||
Stopping bool `json:"-"`
|
||||
}
|
||||
|
||||
func (s *Service) Start(errFunc func(e string)) error {
|
||||
s.State = "Error"
|
||||
absolutePath, err := filepath.Abs(s.ExecutablePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var arguments []string
|
||||
|
||||
for _, a := range s.Arguments {
|
||||
arguments = append(arguments, strings.Split(a, " ")...)
|
||||
}
|
||||
s.Cmd = exec.Command(absolutePath, arguments...)
|
||||
s.Cmd.Dir = s.WorkingDirectory
|
||||
s.Cmd.Stdout = os.Stdout
|
||||
s.Cmd.Stderr = os.Stderr
|
||||
|
||||
err = s.Cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := s.Cmd.Wait()
|
||||
if err != nil {
|
||||
// Process exited with error
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
if !s.Stopping {
|
||||
errFunc(fmt.Sprintf("Command failed with exit code %d: %v", exitErr.ExitCode(), err))
|
||||
}
|
||||
} else {
|
||||
errFunc(fmt.Sprintf("Command wait error: %v", err))
|
||||
}
|
||||
}
|
||||
s.Stopping = false
|
||||
}()
|
||||
|
||||
s.State = "Running"
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) Stop() error {
|
||||
s.State = "Error"
|
||||
|
||||
if s.Cmd == nil {
|
||||
return errors.New("process nil pointer")
|
||||
}
|
||||
|
||||
// Stop (kill) the process
|
||||
s.Stopping = true
|
||||
err := s.Cmd.Process.Kill()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.State = "Stopped"
|
||||
return nil
|
||||
}
|
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
type User struct {
|
||||
Name string `json:"user"`
|
||||
Role string `json:"role"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package models
|
||||
|
||||
type Values struct {
|
||||
MovingHead *MovingHead `json:"movingHead"`
|
||||
LightBar *LightBar `json:"lightBar"`
|
||||
Value any `json:"value"`
|
||||
Stagelights []Value `json:"stageLights,omitempty"`
|
||||
LightBar []Value `json:"lightBar,omitempty"`
|
||||
FloogLights []Value `json:"floodLights,omitempty"`
|
||||
MovingHead []Value `json:"movingHead,omitempty"`
|
||||
Value any `json:"value"`
|
||||
}
|
||||
|
@@ -31,45 +31,35 @@ func NewScenesHandler(dir string) *ScenesHandler {
|
||||
func (sh *ScenesHandler) SaveScene(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
var scene models.Scene
|
||||
err = json.Unmarshal(body, &scene)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path.Join(sh.dir)); err != nil {
|
||||
err := os.MkdirAll(sh.dir, 0755)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(path.Join(sh.dir, scene.Name+".scene"), os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.Write(body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,26 +71,20 @@ func (sh *ScenesHandler) SaveScene(c *gin.Context) {
|
||||
func (sh *ScenesHandler) DeleteScene(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
var scene models.Scene
|
||||
err = json.Unmarshal(body, &scene)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
err = os.Remove(path.Join(sh.dir, scene.Name+".scene"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -114,26 +98,20 @@ func (sh *ScenesHandler) LoadScenes(c *gin.Context) {
|
||||
|
||||
files, err := utils.FindAllFiles("./scenes", ".scene")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
content, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
var scene models.Scene
|
||||
err = json.Unmarshal(content, &scene)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
sceneMap[scene.Name] = scene
|
||||
@@ -160,9 +138,7 @@ func (sh *ScenesHandler) LoadScenes(c *gin.Context) {
|
||||
func (sh *ScenesHandler) LoadScene(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -170,17 +146,13 @@ func (sh *ScenesHandler) LoadScene(c *gin.Context) {
|
||||
|
||||
err = json.Unmarshal(body, &scene)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
files, err := utils.FindAllFiles("./scenes", ".scene")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -190,24 +162,18 @@ func (sh *ScenesHandler) LoadScene(c *gin.Context) {
|
||||
}
|
||||
content, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(content, &scene)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": err.Error(),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, scene)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": fmt.Errorf("scene '%s' not found", scene.Name),
|
||||
})
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse(fmt.Sprintf("scene '%s' not found", scene.Name)))
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"gitea.tecamino.com/paadi/tecamino-dbm/cert"
|
||||
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tecamino/tecamino-dbm/cert"
|
||||
"github.com/tecamino/tecamino-logger/logging"
|
||||
)
|
||||
|
||||
// server model for database manager websocket
|
||||
|
260
backend/services/services.go
Normal file
260
backend/services/services.go
Normal file
@@ -0,0 +1,260 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"backend/models"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.tecamino.com/paadi/statusServer"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ServicesHandler struct {
|
||||
cfgDir string
|
||||
cfgFile string
|
||||
config models.Configuration
|
||||
statusWs *statusServer.StatusWebsocket
|
||||
}
|
||||
|
||||
func NewServicesHandler(cfgDir, cfgFile string) *ServicesHandler {
|
||||
return &ServicesHandler{cfgDir: cfgDir, cfgFile: cfgFile}
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) LinkStatusServer(statusServer *statusServer.StatusWebsocket) {
|
||||
s.statusWs = statusServer
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) GetAllAvaiableServices(c *gin.Context) {
|
||||
var services []models.Service
|
||||
|
||||
defaultCfg, err := s.readDefaultConfig()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
configFile := filepath.Join(s.cfgDir, defaultCfg.CfgFileName)
|
||||
if _, err := os.Stat(configFile); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"services": defaultCfg.Services})
|
||||
return
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
var cfg models.Configuration
|
||||
err = json.Unmarshal(content, &cfg)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
// check wether service was already initiated then skip
|
||||
next:
|
||||
for _, new := range defaultCfg.Services {
|
||||
for _, old := range cfg.Services {
|
||||
if new.Name == old.Name {
|
||||
continue next
|
||||
}
|
||||
}
|
||||
services = append(services, new)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"services": services})
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) LoadAllServices(c *gin.Context) {
|
||||
|
||||
defaultCfg, err := s.readDefaultConfig()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
configFile := filepath.Join(s.cfgDir, defaultCfg.CfgFileName)
|
||||
if _, err := os.Stat(configFile); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "no services"})
|
||||
return
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(content, &s.config)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
if len(s.config.Services) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "no services"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"services": s.config.Services})
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) AddNewService(c *gin.Context) {
|
||||
body, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
var newService struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &newService)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
defaultCfg, err := s.readDefaultConfig()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
var config models.Configuration
|
||||
|
||||
if _, err := os.Stat(filepath.Join(s.cfgDir, defaultCfg.CfgFileName)); err == nil {
|
||||
content, err := os.ReadFile(filepath.Join(s.cfgDir, defaultCfg.CfgFileName))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(content, &config)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, service := range defaultCfg.Services {
|
||||
if service.Name == newService.Name {
|
||||
config.Services = append(config.Services, service)
|
||||
|
||||
f, err := os.OpenFile(filepath.Join(s.cfgDir, defaultCfg.CfgFileName), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0774)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
output, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
_, err = f.Write(output)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "service '" + newService.Name + "' added"})
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(errors.New("no service '"+newService.Name+"' found")))
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) StartService(c *gin.Context) {
|
||||
service := c.Param("service")
|
||||
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Starting",
|
||||
})
|
||||
|
||||
for i := range s.config.Services {
|
||||
if s.config.Services[i].Name == service {
|
||||
if err := s.config.Services[i].Start(func(e string) {
|
||||
s.statusWs.Publish("status/"+service, gin.H{"state": "Error", "message": e})
|
||||
}); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Error",
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("service '%s' started", service),
|
||||
})
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Started",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse(fmt.Sprintf("no service '%s' found", service)))
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Error",
|
||||
"message": fmt.Sprintf("no service '%s' found", service),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) StopService(c *gin.Context) {
|
||||
service := c.Param("service")
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Stopping",
|
||||
})
|
||||
|
||||
for i := range s.config.Services {
|
||||
if s.config.Services[i].Name == service {
|
||||
if err := s.config.Services[i].Stop(); err != nil {
|
||||
c.JSON(http.StatusBadGateway, gin.H{
|
||||
"error": true,
|
||||
"message": fmt.Sprintf("service '%s' error; %v", service, err),
|
||||
})
|
||||
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Error",
|
||||
"message": fmt.Sprintf("service '%s' error; %v", service, err),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": fmt.Sprintf("service '%s' stopped", service),
|
||||
})
|
||||
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Stopped",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": true,
|
||||
"message": fmt.Sprintf("no service '%s' found", service),
|
||||
})
|
||||
|
||||
s.statusWs.Publish("status/"+service, gin.H{
|
||||
"state": "Stopped",
|
||||
"message": fmt.Sprintf("no service '%s' found", service),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *ServicesHandler) readDefaultConfig() (data models.Configuration, err error) {
|
||||
content, err := os.ReadFile(filepath.Join(s.cfgDir, s.cfgFile))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(content, &data)
|
||||
return
|
||||
}
|
BIN
backend/user.db
BIN
backend/user.db
Binary file not shown.
@@ -8,7 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/tecamino/tecamino-logger/logging"
|
||||
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||
)
|
||||
|
||||
func OpenBrowser(url string, logger *logging.Logger) error {
|
||||
@@ -33,7 +33,7 @@ func OpenBrowser(url string, logger *logging.Logger) error {
|
||||
return fmt.Errorf("os is running i headless mode do not start browser")
|
||||
}
|
||||
commands = [][]string{
|
||||
{"chromium-browser", "--kiosk", url},
|
||||
{"chromium-browser", url},
|
||||
{"google-chrome", "--kiosk", url},
|
||||
{"firefox", "--kiosk", url},
|
||||
{"xdg-open", url}, // fallback
|
||||
|
1756
package-lock.json
generated
1756
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lightcontrol",
|
||||
"version": "0.0.21",
|
||||
"version": "0.1.4",
|
||||
"description": "A Tecamino App",
|
||||
"productName": "Light Control",
|
||||
"author": "A. Zuercher",
|
||||
@@ -15,9 +15,12 @@
|
||||
"postinstall": "quasar prepare"
|
||||
},
|
||||
"dependencies": {
|
||||
"@quasar/cli": "^2.5.0",
|
||||
"@quasar/extras": "^1.16.4",
|
||||
"axios": "^1.10.0",
|
||||
"quasar": "^2.16.0",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"pinia": "^3.0.3",
|
||||
"quasar": "^2.18.2",
|
||||
"vue": "^3.4.18",
|
||||
"vue-router": "^4.0.12"
|
||||
},
|
||||
|
@@ -11,7 +11,7 @@ export default defineConfig((/* ctx */) => {
|
||||
// app boot file (/src/boot)
|
||||
// --> boot files are part of "main.js"
|
||||
// https://v2.quasar.dev/quasar-cli-vite/boot-files
|
||||
boot: ['websocket', 'axios'],
|
||||
boot: ['websocket', 'axios', 'auth'],
|
||||
|
||||
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#css
|
||||
css: ['app.scss'],
|
||||
|
13
src/boot/auth.ts
Normal file
13
src/boot/auth.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { boot } from 'quasar/wrappers';
|
||||
import { createPinia } from 'pinia';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import type { QVueGlobals } from 'quasar';
|
||||
|
||||
export default boot(({ app }) => {
|
||||
const $q = app.config.globalProperties.$q as QVueGlobals;
|
||||
const pinia = createPinia();
|
||||
app.use(pinia);
|
||||
const useStore = useUserStore();
|
||||
useStore.initStore($q);
|
||||
useStore.loadFromStorage();
|
||||
});
|
@@ -2,19 +2,29 @@ import { boot } from 'quasar/wrappers';
|
||||
import axios from 'axios';
|
||||
|
||||
const host = window.location.hostname;
|
||||
const port = 8100;
|
||||
const portDbm = 8100;
|
||||
const portApp = 9500;
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: `http://${host}:${port}`,
|
||||
const dbmApi = axios.create({
|
||||
baseURL: `http://${host}:${portDbm}`,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const appApi = axios.create({
|
||||
baseURL: `http://${host}:${portApp}/api`,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
export default boot(({ app }) => {
|
||||
app.config.globalProperties.$axios = axios;
|
||||
app.config.globalProperties.$api = api;
|
||||
app.config.globalProperties.$dbmApi = dbmApi;
|
||||
app.config.globalProperties.$appApi = appApi;
|
||||
});
|
||||
|
||||
export { axios, api };
|
||||
export { axios, dbmApi, appApi };
|
||||
|
98
src/components/lights/FloodPanel.vue
Normal file
98
src/components/lights/FloodPanel.vue
Normal file
@@ -0,0 +1,98 @@
|
||||
<template>
|
||||
<div>
|
||||
<q-card>
|
||||
<div class="q-pt-md text-black text-bold text-center">{{ cardTitle }}</div>
|
||||
<q-card-section class="row items-start">
|
||||
<div class="column justify-center q-mr-xs" style="height: 200px">
|
||||
<q-btn
|
||||
@click="changeState"
|
||||
round
|
||||
:color="brightness > 0 ? 'yellow' : 'blue'"
|
||||
icon="lightbulb"
|
||||
style="position: relative"
|
||||
/>
|
||||
</div>
|
||||
<LightSlider
|
||||
mainTitle="Dimmer"
|
||||
:dbm-path="props.path + ':Brightness'"
|
||||
:opacity="0.5"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Red"
|
||||
:dbm-path="props.path + ':Red'"
|
||||
color="red"
|
||||
:opacity="0.8"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Green"
|
||||
:dbm-path="props.path + ':Green'"
|
||||
:opacity="0.8"
|
||||
color="green"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Blue"
|
||||
:dbm-path="props.path + ':Blue'"
|
||||
:opacity="0.8"
|
||||
color="blue"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import LightSlider from './LightSlider.vue';
|
||||
import { onMounted, onUnmounted } from 'vue';
|
||||
import { unsubscribe, subscribeToPath } from 'src/vueLib/services/websocket';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { updateValue } from 'src/vueLib/dbm/dbmTree';
|
||||
import { removeAllSubscriptions } from 'src/vueLib/models/Subscriptions';
|
||||
import { catchError } from 'src/vueLib/models/error';
|
||||
|
||||
const props = defineProps({
|
||||
cardTitle: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
path: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
const { NotifyResponse } = useNotify();
|
||||
const brightness = updateValue(NotifyResponse, props.path + ':Brightness');
|
||||
const state = updateValue(NotifyResponse, props.path + ':State');
|
||||
|
||||
onMounted(() => {
|
||||
subscribeToPath(NotifyResponse, props.path + ':.*');
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
unsubscribe([
|
||||
{
|
||||
path: props.path,
|
||||
depth: 0,
|
||||
},
|
||||
]).catch((err) => {
|
||||
NotifyResponse(catchError(err), 'error');
|
||||
});
|
||||
removeAllSubscriptions();
|
||||
});
|
||||
|
||||
function changeState() {
|
||||
if (brightness.value === 0) {
|
||||
if (state.value === 0) {
|
||||
brightness.value = 255;
|
||||
return;
|
||||
}
|
||||
brightness.value = state.value;
|
||||
return;
|
||||
}
|
||||
state.value = brightness.value;
|
||||
brightness.value = 0;
|
||||
}
|
||||
</script>
|
18
src/components/lights/FloodPanels.vue
Normal file
18
src/components/lights/FloodPanels.vue
Normal file
@@ -0,0 +1,18 @@
|
||||
<template>
|
||||
<div class="">
|
||||
<q-card>
|
||||
<div class="row items-start">
|
||||
<q-card-section>
|
||||
<FloodPanel card-title="Left" path="FloodPanels:001" />
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<FloodPanel card-title="Right" path="FloodPanels:002" />
|
||||
</q-card-section>
|
||||
</div>
|
||||
</q-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import FloodPanel from './FloodPanel.vue';
|
||||
</script>
|
@@ -56,10 +56,6 @@
|
||||
color="blue"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<div class="colums q-ma-xl">
|
||||
<q-btn color="secondary" @click="settings = !settings" icon="settings">Settings</q-btn>
|
||||
<SettingDialog :settings-dialog="settings"></SettingDialog>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
@@ -67,16 +63,14 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import LightSlider from './LightSlider.vue';
|
||||
import { ref, onMounted, onUnmounted } from 'vue';
|
||||
import { onMounted, onUnmounted } from 'vue';
|
||||
import { unsubscribe, subscribeToPath } from 'src/vueLib/services/websocket';
|
||||
import SettingDialog from 'src/components/lights/SettingDomeLight.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { updateValue } from 'src/vueLib/dbm/dbmTree';
|
||||
import { removeAllSubscriptions } from 'src/vueLib/models/Subscriptions';
|
||||
import { catchError } from 'src/vueLib/models/error';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const settings = ref(false);
|
||||
const brightness = updateValue(NotifyResponse, 'LightBar:Brightness');
|
||||
const state = updateValue(NotifyResponse, 'LightBar:State');
|
||||
onMounted(() => {
|
||||
|
@@ -26,7 +26,7 @@ select
|
||||
:toggle-high-low="true"
|
||||
dbm-path="MovingHead:Brightness"
|
||||
dbm-path2="MovingHead:BrightnessFine"
|
||||
dbm-path3="MovingHead:Strobe"
|
||||
dbm-path3="MovingHead:Strobe'"
|
||||
:dbm-value3="255"
|
||||
:opacity="0.5"
|
||||
class="q-ma-md"
|
||||
@@ -114,14 +114,13 @@ import { findSubscriptionByPath, removeAllSubscriptions } from 'src/vueLib/model
|
||||
import { catchError } from 'src/vueLib/models/error';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const brightness = updateBrightnessValue('MovingHead:Brightness');
|
||||
const state = updateValue(NotifyResponse, 'MovingHead:State');
|
||||
const settings = ref<Settings>({
|
||||
show: false,
|
||||
reversePan: false,
|
||||
reverseTilt: false,
|
||||
startAddress: 0,
|
||||
});
|
||||
const brightness = updateBrightnessValue('MovingHead:Brightness');
|
||||
const state = updateValue(NotifyResponse, 'MovingHead:State');
|
||||
|
||||
onMounted(() => {
|
||||
settings.value.reversePan = LocalStorage.getItem('reversePan') ?? false;
|
||||
|
@@ -21,13 +21,6 @@
|
||||
>{{ settings.reversePan ? 'Reversed Pan' : 'Normal Pan' }}</q-btn
|
||||
>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-input
|
||||
type="number"
|
||||
label="Start Address"
|
||||
v-model:model-value="settings.startAddress"
|
||||
></q-input>
|
||||
</q-card-section>
|
||||
<q-card-actions align="right">
|
||||
<q-btn flat label="Cancel" v-close-popup />
|
||||
<q-btn flat label="Save" @click="saveSettings" />
|
||||
@@ -45,7 +38,6 @@ const settings = defineModel<Settings>('settings', {
|
||||
show: false,
|
||||
reversePan: false,
|
||||
reverseTilt: false,
|
||||
startAddress: 0,
|
||||
},
|
||||
required: true,
|
||||
});
|
||||
|
117
src/components/lights/StageLight.vue
Normal file
117
src/components/lights/StageLight.vue
Normal file
@@ -0,0 +1,117 @@
|
||||
<template>
|
||||
<div>
|
||||
<q-card>
|
||||
<div class="q-pt-md text-black text-bold text-center">{{ cardTitle }}</div>
|
||||
<q-card-section class="row items-start">
|
||||
<div class="column justify-center q-mr-xs" style="height: 200px">
|
||||
<q-btn
|
||||
@click="changeState"
|
||||
round
|
||||
:color="brightness > 0 ? 'yellow' : 'blue'"
|
||||
icon="lightbulb"
|
||||
style="position: relative"
|
||||
/>
|
||||
</div>
|
||||
<LightSlider
|
||||
mainTitle="Dimmer"
|
||||
:dbm-path="props.path + ':Brightness'"
|
||||
:opacity="0.5"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Strobe"
|
||||
:dbm-path="props.path + ':Strobe'"
|
||||
:opacity="0.5"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="DimmerFade"
|
||||
:dbm-path="props.path + ':DimmerFade'"
|
||||
:opacity="0.5"
|
||||
:step="50"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Red"
|
||||
:dbm-path="props.path + ':Red'"
|
||||
color="red"
|
||||
:opacity="0.8"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Green"
|
||||
:dbm-path="props.path + ':Green'"
|
||||
:opacity="0.8"
|
||||
color="green"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="Blue"
|
||||
:dbm-path="props.path + ':Blue'"
|
||||
:opacity="0.8"
|
||||
color="blue"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
<LightSlider
|
||||
mainTitle="White"
|
||||
:dbm-path="props.path + ':White'"
|
||||
:opacity="0.5"
|
||||
class="q-ma-sm"
|
||||
></LightSlider>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import LightSlider from './LightSlider.vue';
|
||||
import { onMounted, onUnmounted } from 'vue';
|
||||
import { unsubscribe, subscribeToPath } from 'src/vueLib/services/websocket';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { updateValue } from 'src/vueLib/dbm/dbmTree';
|
||||
import { removeAllSubscriptions } from 'src/vueLib/models/Subscriptions';
|
||||
import { catchError } from 'src/vueLib/models/error';
|
||||
|
||||
const props = defineProps({
|
||||
cardTitle: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
path: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
const { NotifyResponse } = useNotify();
|
||||
const brightness = updateValue(NotifyResponse, props.path + ':Brightness');
|
||||
const state = updateValue(NotifyResponse, props.path + ':State');
|
||||
|
||||
onMounted(() => {
|
||||
subscribeToPath(NotifyResponse, props.path + ':.*');
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
unsubscribe([
|
||||
{
|
||||
path: props.path,
|
||||
depth: 0,
|
||||
},
|
||||
]).catch((err) => {
|
||||
NotifyResponse(catchError(err), 'error');
|
||||
});
|
||||
removeAllSubscriptions();
|
||||
});
|
||||
|
||||
function changeState() {
|
||||
if (brightness.value === 0) {
|
||||
if (state.value === 0) {
|
||||
brightness.value = 255;
|
||||
return;
|
||||
}
|
||||
brightness.value = state.value;
|
||||
return;
|
||||
}
|
||||
state.value = brightness.value;
|
||||
brightness.value = 0;
|
||||
}
|
||||
</script>
|
18
src/components/lights/StageLights.vue
Normal file
18
src/components/lights/StageLights.vue
Normal file
@@ -0,0 +1,18 @@
|
||||
<template>
|
||||
<div class="">
|
||||
<q-card>
|
||||
<div class="row items-start">
|
||||
<q-card-section>
|
||||
<StageLight card-title="Left" path="StageLights:001" />
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<StageLight card-title="Right" path="StageLights:002" />
|
||||
</q-card-section>
|
||||
</div>
|
||||
</q-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import StageLight from './StageLight.vue';
|
||||
</script>
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<!-- new edit scene dialog-->
|
||||
<DialogFrame ref="sceneDialog" width="350px">
|
||||
<DialogFrame ref="sceneDialog" :height="500" :width="350">
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<div class="text-primary text-h6">{{ dialogLabel }}</div>
|
||||
@@ -27,8 +27,10 @@
|
||||
/>
|
||||
<div class="q-py-md">
|
||||
<div class="q-gutter-sm">
|
||||
<q-checkbox v-model="newScene.movingHead" label="Moving Head" />
|
||||
<q-checkbox v-model="newScene.stageLights" label="Stage Lights" />
|
||||
<q-checkbox v-model="newScene.lightBar" label="Light Bar" />
|
||||
<q-checkbox v-model="newScene.floodPanels" label="Flood Panels" />
|
||||
<q-checkbox v-model="newScene.movingHead" label="Moving Head" />
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
@@ -52,6 +54,7 @@
|
||||
>
|
||||
<q-btn
|
||||
rounded
|
||||
no-caps
|
||||
color="primary"
|
||||
:class="['q-ma-md', 'text-bold', 'text-white']"
|
||||
@click="openDialog('add')"
|
||||
@@ -102,6 +105,7 @@
|
||||
<div>No scenes available</div>
|
||||
<q-btn
|
||||
rounded
|
||||
no-caps
|
||||
color="primary"
|
||||
:class="['q-ma-md', 'text-bold', 'text-white']"
|
||||
@click="openDialog('add')"
|
||||
@@ -114,13 +118,13 @@
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import type { Scene } from 'src/models/Scene';
|
||||
import type { Set } from 'src/vueLib/models/Set';
|
||||
import axios from 'axios';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { dbmApi } from 'src/boot/axios';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import Dialog from 'src/components/dialog/OkDialog.vue';
|
||||
import { setValues } from 'src/vueLib/services/websocket';
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { catchError } from 'src/vueLib/models/error';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
|
||||
const { NotifyResponse, NotifyDialog } = useNotify();
|
||||
const sceneDialog = ref();
|
||||
@@ -130,26 +134,17 @@ const editIndex = ref(-1);
|
||||
const dialogLabel = ref('');
|
||||
const newScene = reactive<Scene>({
|
||||
name: '',
|
||||
movingHead: false,
|
||||
stageLights: false,
|
||||
lightBar: false,
|
||||
floodPanels: false,
|
||||
movingHead: false,
|
||||
});
|
||||
|
||||
const scenes = ref<Scene[]>([]);
|
||||
const host = window.location.hostname;
|
||||
const port = 9500;
|
||||
const baseURL = `http://${host}:${port}`;
|
||||
|
||||
const quasarApi = axios.create({
|
||||
baseURL: baseURL,
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
quasarApi
|
||||
.get('/api/loadScenes')
|
||||
appApi
|
||||
.get('/scenes/all')
|
||||
.then((resp) => {
|
||||
if (resp.data) {
|
||||
scenes.value = resp.data;
|
||||
@@ -166,9 +161,8 @@ function removeScene(name: string) {
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
scenes.value = scenes.value.filter((s) => s.name !== name);
|
||||
|
||||
quasarApi
|
||||
.delete('/api/deleteScene', {
|
||||
appApi
|
||||
.delete('/scenes', {
|
||||
data: { name },
|
||||
})
|
||||
.then((res) => {
|
||||
@@ -190,8 +184,11 @@ function openDialog(dialogType: string, scene?: Scene, index?: number) {
|
||||
dialog.value = 'add';
|
||||
dialogLabel.value = 'Add Scene';
|
||||
newScene.name = '';
|
||||
newScene.movingHead = true;
|
||||
newScene.stageLights = true;
|
||||
newScene.lightBar = true;
|
||||
newScene.floodPanels = true;
|
||||
newScene.movingHead = true;
|
||||
|
||||
break;
|
||||
case 'edit':
|
||||
if (!scene) return;
|
||||
@@ -205,8 +202,8 @@ function openDialog(dialogType: string, scene?: Scene, index?: number) {
|
||||
if (!scene) return;
|
||||
dialog.value = 'load';
|
||||
dialogLabel.value = 'Load Scene';
|
||||
quasarApi
|
||||
.post('/api/loadScene', scene)
|
||||
appApi
|
||||
.post('/scenes/load', scene)
|
||||
.then((res) => {
|
||||
if (res.data) {
|
||||
Object.assign(newScene, JSON.parse(JSON.stringify(res.data)));
|
||||
@@ -236,9 +233,9 @@ const saveScene = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newScene.movingHead) {
|
||||
if (newScene.stageLights) {
|
||||
sendValues.push({
|
||||
path: 'MovingHead',
|
||||
path: 'StageLights',
|
||||
query: { depth: 0 },
|
||||
});
|
||||
}
|
||||
@@ -250,9 +247,23 @@ const saveScene = async () => {
|
||||
});
|
||||
}
|
||||
|
||||
if (newScene.floodPanels) {
|
||||
sendValues.push({
|
||||
path: 'FloodPanels',
|
||||
query: { depth: 0 },
|
||||
});
|
||||
}
|
||||
|
||||
if (newScene.movingHead) {
|
||||
sendValues.push({
|
||||
path: 'MovingHead',
|
||||
query: { depth: 0 },
|
||||
});
|
||||
}
|
||||
|
||||
if (sendValues.length > 0) {
|
||||
try {
|
||||
const res = await api.post('/json_data', { get: sendValues });
|
||||
const res = await dbmApi.post('/json_data', { get: sendValues });
|
||||
newScene.values = res.data.get;
|
||||
} catch (err) {
|
||||
NotifyResponse(err as Error, 'error');
|
||||
@@ -266,8 +277,8 @@ const saveScene = async () => {
|
||||
// Sort alphabetically by scene name
|
||||
scenes.value.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
quasarApi
|
||||
.post('/api/saveScene', JSON.stringify(newScene))
|
||||
appApi
|
||||
.post('/scenes/save', JSON.stringify(newScene))
|
||||
.then((res) => {
|
||||
if (res.data) {
|
||||
NotifyResponse(res.data);
|
||||
@@ -285,9 +296,9 @@ const saveScene = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newScene.movingHead) {
|
||||
if (newScene.stageLights) {
|
||||
sendValues.push({
|
||||
path: 'MovingHead',
|
||||
path: 'StageLights',
|
||||
query: { depth: 0 },
|
||||
});
|
||||
}
|
||||
@@ -299,9 +310,23 @@ const saveScene = async () => {
|
||||
});
|
||||
}
|
||||
|
||||
if (newScene.floodPanels) {
|
||||
sendValues.push({
|
||||
path: 'FloodPanels',
|
||||
query: { depth: 0 },
|
||||
});
|
||||
}
|
||||
|
||||
if (newScene.movingHead) {
|
||||
sendValues.push({
|
||||
path: 'MovingHead',
|
||||
query: { depth: 0 },
|
||||
});
|
||||
}
|
||||
|
||||
if (sendValues.length > 0) {
|
||||
try {
|
||||
const res = await api.post('/json_data', { get: sendValues });
|
||||
const res = await dbmApi.post('/json_data', { get: sendValues });
|
||||
newScene.values = res.data.get;
|
||||
} catch (err) {
|
||||
NotifyResponse(err as Error, 'error');
|
||||
@@ -313,8 +338,8 @@ const saveScene = async () => {
|
||||
scenes.value.sort((a, b) => a.name.localeCompare(b.name));
|
||||
scenes.value = [...scenes.value];
|
||||
|
||||
quasarApi
|
||||
.post('/api/saveScene', JSON.stringify(newScene))
|
||||
appApi
|
||||
.post('/scene/save', JSON.stringify(newScene))
|
||||
.then((res) => {
|
||||
if (res.data) {
|
||||
NotifyResponse(res.data);
|
||||
@@ -333,11 +358,17 @@ const saveScene = async () => {
|
||||
newScene.values?.forEach((element) => {
|
||||
if (!element.path) return;
|
||||
|
||||
if (newScene.movingHead && element.path.includes('MovingHead'))
|
||||
if (newScene.stageLights && element.path.includes('StageLights'))
|
||||
setPaths.push({ uuid: element.uuid, path: element.path, value: element.value });
|
||||
|
||||
if (newScene.lightBar && element.path.includes('LightBar'))
|
||||
setPaths.push({ uuid: element.uuid, path: element.path, value: element.value });
|
||||
|
||||
if (newScene.floodPanels && element.path.includes('FloodPanels'))
|
||||
setPaths.push({ uuid: element.uuid, path: element.path, value: element.value });
|
||||
|
||||
if (newScene.movingHead && element.path.includes('MovingHead'))
|
||||
setPaths.push({ uuid: element.uuid, path: element.path, value: element.value });
|
||||
});
|
||||
|
||||
setValues(setPaths)
|
||||
|
@@ -10,10 +10,11 @@
|
||||
/>
|
||||
<q-btn flat dense round icon="menu" aria-label="Menu" @click="toggleLeftDrawer" />
|
||||
|
||||
<q-toolbar-title> Light Control </q-toolbar-title>
|
||||
<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>
|
||||
|
||||
@@ -25,9 +26,12 @@
|
||||
<q-item to="/scenes" clickable v-ripple @click="closeDrawer">
|
||||
<q-item-section>Scenes</q-item-section>
|
||||
</q-item>
|
||||
<q-item to="/data" clickable v-ripple @click="closeDrawer">
|
||||
<q-item v-if="autorized" to="/data" clickable v-ripple @click="closeDrawer">
|
||||
<q-item-section>Data</q-item-section>
|
||||
</q-item>
|
||||
<q-item to="/services" clickable v-ripple @click="closeDrawer">
|
||||
<q-item-section>Services</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-drawer>
|
||||
<q-page-container>
|
||||
@@ -38,10 +42,14 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import logo from 'src/assets/LOGO_CF-ICON_color.svg';
|
||||
import { ref } from 'vue';
|
||||
import { version } from '../..//package.json';
|
||||
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';
|
||||
|
||||
const leftDrawerOpen = ref(false);
|
||||
const user = useUserStore();
|
||||
const autorized = computed(() => !!user.isAuthorizedAs(['admin']));
|
||||
|
||||
function toggleLeftDrawer() {
|
||||
leftDrawerOpen.value = !leftDrawerOpen.value;
|
||||
|
@@ -14,5 +14,4 @@ export type Settings = {
|
||||
show: boolean;
|
||||
reversePan: boolean;
|
||||
reverseTilt: boolean;
|
||||
startAddress: number;
|
||||
};
|
||||
|
@@ -3,7 +3,9 @@ import type { Value } from '../vueLib/models/Value';
|
||||
export interface Scene {
|
||||
name: string;
|
||||
description?: string;
|
||||
movingHead: boolean;
|
||||
stageLights: boolean;
|
||||
lightBar: boolean;
|
||||
floodPanels: boolean;
|
||||
movingHead: boolean;
|
||||
values?: Value[];
|
||||
}
|
||||
|
@@ -5,15 +5,15 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import DBMTree from 'src/vueLib/dbm/DBMTree.vue';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { dbmApi } from 'src/boot/axios';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { catchError } from 'src/vueLib/models/error';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
function saveDBM() {
|
||||
api
|
||||
.get('saveData')
|
||||
dbmApi
|
||||
.get('data/save')
|
||||
.then((resp) => NotifyResponse(resp.data))
|
||||
.catch((err) => NotifyResponse(catchError(err), 'error'));
|
||||
}
|
||||
|
@@ -1,16 +1,20 @@
|
||||
<template>
|
||||
<q-page>
|
||||
<q-tabs v-model="tab">
|
||||
<q-tab name="movingHead" label="Moving Head" />
|
||||
<q-tab name="lightBar" label="Light Bar" />
|
||||
<q-tab no-caps name="movingHead" label="Moving Head" />
|
||||
<q-tab no-caps name="lightBar" label="Light Bar" />
|
||||
<q-tab no-caps name="floodPanels" label="Flood Panels" />
|
||||
</q-tabs>
|
||||
<q-tab-panels v-model="tab" animated class="text-white">
|
||||
<q-tab-panel name="movingHead">
|
||||
<moving-head />
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="lightBar">
|
||||
<LightBar />
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="floodPanels">
|
||||
<FloodPanels />
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="movingHead">
|
||||
<moving-head />
|
||||
</q-tab-panel>
|
||||
</q-tab-panels>
|
||||
</q-page>
|
||||
</template>
|
||||
@@ -18,6 +22,7 @@
|
||||
<script setup lang="ts">
|
||||
import MovingHead from 'src/components/lights/MovingHead.vue';
|
||||
import LightBar from 'src/components/lights/LightBarCBL.vue';
|
||||
import FloodPanels from 'src/components/lights/FloodPanels.vue';
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
const tab = ref('movingHead');
|
||||
const STORAGE_KEY = 'lastTabUsed';
|
||||
|
157
src/pages/ServicesPage.vue
Normal file
157
src/pages/ServicesPage.vue
Normal file
@@ -0,0 +1,157 @@
|
||||
<template>
|
||||
<div>
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<div class="text-bold text-primary">Services</div>
|
||||
</q-card-section>
|
||||
<div class="row justify-center">
|
||||
<q-card-section class="col-8">
|
||||
<div class="q-py-md text-grey text-left">
|
||||
<div v-if="driverRows?.length == 0">No services available</div>
|
||||
<q-btn
|
||||
no-caps
|
||||
rounded
|
||||
color="primary"
|
||||
:style="'font-size: 12px;'"
|
||||
:class="[, 'text-bold', 'text-white']"
|
||||
:disable="userStore.user?.role !== 'admin'"
|
||||
@click="addNewDriver"
|
||||
>
|
||||
Add {{ driverRows?.length == 0 ? 'First' : '' }} Service
|
||||
</q-btn>
|
||||
</div>
|
||||
<q-table v-if="driverRows?.length > 0" :rows="driverRows" :columns="columns">
|
||||
<template v-slot:body-cell-settings="props">
|
||||
<q-td :props="props">
|
||||
<q-btn
|
||||
dense
|
||||
flat
|
||||
size="md"
|
||||
icon="more_vert"
|
||||
@click="openSubMenu($event, props.row)"
|
||||
></q-btn>
|
||||
</q-td>
|
||||
</template>
|
||||
<template v-slot:body-cell-state="props">
|
||||
<q-td :props="props">
|
||||
<q-badge
|
||||
:color="props.row.stateColor"
|
||||
:text-color="props.row.stateTextColor"
|
||||
:label="props.row.state"
|
||||
/>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-card-section>
|
||||
</div>
|
||||
<sub-menu ref="subMenuRef" />
|
||||
</q-card>
|
||||
|
||||
<service-dialog ref="refServiceDialog"></service-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref, toRef } from 'vue';
|
||||
import { useQuasar, type QTableProps } from 'quasar';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import ServiceDialog from 'src/vueLib/services/dialog/ServiceDialog.vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import type { Service, Services, State } from 'src/vueLib/models/Services';
|
||||
import { useServices } from 'src/vueLib/models/Services';
|
||||
import SubMenu from 'src/vueLib/services/dialog/SubMenu.vue';
|
||||
import { useStatusServer } from 'src/vueLib/services/statusServer/useStatusServer';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const userStore = useUserStore();
|
||||
const refServiceDialog = ref();
|
||||
const { initServices } = useServices();
|
||||
const driverRows = reactive<Services>([]);
|
||||
const { connect, subscribe } = useStatusServer(
|
||||
'127.0.0.1',
|
||||
9500,
|
||||
'api/status',
|
||||
'quasar',
|
||||
(response) => {
|
||||
// normalize topic to service name
|
||||
const serviceName = response.topic.replace('status/', '').replace(' ', '');
|
||||
const driver = driverRows.find((d) => d.name.replace(' ', '') === serviceName);
|
||||
|
||||
if (driver && response.data?.state !== undefined) {
|
||||
// update state reactively
|
||||
driver.state = response.data?.state as State;
|
||||
|
||||
// update colors depending on state
|
||||
switch (driver.state) {
|
||||
case 'Running':
|
||||
driver.stateColor = 'green';
|
||||
driver.stateTextColor = 'white';
|
||||
break;
|
||||
case 'Starting':
|
||||
driver.stateColor = 'orange';
|
||||
driver.stateTextColor = 'black';
|
||||
break;
|
||||
case 'Stopping':
|
||||
driver.stateColor = 'orange';
|
||||
driver.stateTextColor = 'black';
|
||||
break;
|
||||
case 'Error':
|
||||
driver.stateColor = 'red';
|
||||
driver.stateTextColor = 'white';
|
||||
NotifyResponse(response.data?.message, 'error');
|
||||
break;
|
||||
case 'Stopped':
|
||||
default:
|
||||
driver.stateColor = 'grey-4';
|
||||
driver.stateTextColor = 'black';
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
useQuasar(),
|
||||
);
|
||||
|
||||
const subMenuRef = ref();
|
||||
|
||||
const columns = [
|
||||
{ name: 'name', label: 'Name', field: 'name', align: 'left', style: 'font-size:12px;' },
|
||||
{
|
||||
name: 'description',
|
||||
label: 'Description',
|
||||
field: 'description',
|
||||
align: 'center',
|
||||
style: 'font-size:12px;',
|
||||
},
|
||||
{
|
||||
name: 'settings',
|
||||
label: '',
|
||||
field: 'settings',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
name: 'state',
|
||||
label: 'State',
|
||||
field: 'state',
|
||||
align: 'left',
|
||||
},
|
||||
] as QTableProps['columns'];
|
||||
|
||||
onMounted(() => {
|
||||
initServices()
|
||||
.then((resp) => {
|
||||
driverRows.push(...resp);
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
connect();
|
||||
subscribe('*').catch((err) => NotifyResponse(err, 'error'));
|
||||
});
|
||||
|
||||
function addNewDriver() {
|
||||
refServiceDialog.value.open();
|
||||
}
|
||||
|
||||
function openSubMenu(event: Event, service: Service) {
|
||||
subMenuRef.value?.open(event, toRef(driverRows.find((d) => d.name === service.name)!));
|
||||
}
|
||||
</script>
|
@@ -19,7 +19,9 @@ import routes from './routes';
|
||||
export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
const createHistory = process.env.SERVER
|
||||
? createMemoryHistory
|
||||
: (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory);
|
||||
: process.env.VUE_ROUTER_MODE === 'history'
|
||||
? createWebHistory
|
||||
: createWebHashHistory;
|
||||
|
||||
const Router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
@@ -30,6 +32,5 @@ export default defineRouter(function (/* { store, ssrContext } */) {
|
||||
// quasar.conf.js -> build -> publicPath
|
||||
history: createHistory(process.env.VUE_ROUTER_BASE),
|
||||
});
|
||||
|
||||
return Router;
|
||||
});
|
||||
|
@@ -6,8 +6,16 @@ const routes: RouteRecordRaw[] = [
|
||||
component: () => import('layouts/MainLayout.vue'),
|
||||
children: [
|
||||
{ path: '', component: () => import('pages/MainPage.vue') },
|
||||
{ path: '/data', component: () => import('pages/DataPage.vue') },
|
||||
{
|
||||
path: '/data',
|
||||
component: () => import('pages/DataPage.vue'),
|
||||
meta: { requiresAuth: true, requiresAdmin: true },
|
||||
},
|
||||
{ path: '/scenes', component: () => import('components/scenes/ScenesPage.vue') },
|
||||
{
|
||||
path: '/services',
|
||||
component: () => import('pages/ServicesPage.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
|
@@ -60,11 +60,16 @@
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
<RenameDialog width="400px" button-ok-label="Rename" ref="renameDialog" />
|
||||
<UpdateDialog width="400px" button-ok-label="Write" ref="updateDialog" />
|
||||
<UpdateDriver width="400px" ref="updateDriverDialog" />
|
||||
<RenameDialog
|
||||
dialogLabel="Rename Datapoint"
|
||||
:width="400"
|
||||
button-ok-label="Rename"
|
||||
ref="renameDialog"
|
||||
/>
|
||||
<UpdateDialog :width="400" button-ok-label="Write" ref="updateDialog" />
|
||||
<UpdateDriver :width="400" ref="updateDriverDialog" />
|
||||
<UpdateDatatype
|
||||
width="400px"
|
||||
:width="400"
|
||||
button-ok-label="Update"
|
||||
ref="updateDatatype"
|
||||
dialog-label="Update Datatype"
|
||||
@@ -89,7 +94,6 @@ const updateDriverDialog = ref();
|
||||
const updateDatatype = ref();
|
||||
|
||||
const openDialog = (sub: Subscribe, type?: string) => {
|
||||
console.log(11, sub);
|
||||
if (sub.path?.split(':')[0] === 'System' && sub.path !== 'DBM') return;
|
||||
switch (type) {
|
||||
case 'type':
|
||||
@@ -103,7 +107,7 @@ const openDialog = (sub: Subscribe, type?: string) => {
|
||||
updateDialog.value?.open(ref(sub), type);
|
||||
break;
|
||||
case 'drivers':
|
||||
if (sub.type === 'NONE') return;
|
||||
if (sub.path === 'DBM' || sub.type === 'NONE') return;
|
||||
updateDriverDialog.value?.open(sub);
|
||||
break;
|
||||
}
|
||||
|
@@ -101,13 +101,13 @@
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
<RenameDatapoint :dialogLabel="label" width="700px" button-ok-label="Rename" ref="renameDialog" />
|
||||
<AddDialog :dialogLabel="label" width="700px" button-ok-label="Add" ref="addDialog" />
|
||||
<RemoveDialog :dialogLabel="label" width="350px" button-ok-label="Remove" ref="removeDialog" />
|
||||
<CopyDialog :dialogLabel="label" width="300px" button-ok-label="Copy" ref="copyDialog" />
|
||||
<RenameDatapoint :dialogLabel="label" :width="700" button-ok-label="Rename" ref="renameDialog" />
|
||||
<AddDialog :dialogLabel="label" :width="750" button-ok-label="Add" ref="addDialog" />
|
||||
<RemoveDialog :dialogLabel="label" :width="350" button-ok-label="Remove" ref="removeDialog" />
|
||||
<CopyDialog :dialogLabel="label" :width="300" button-ok-label="Copy" ref="copyDialog" />
|
||||
<UpdateDatapoint
|
||||
:dialogLabel="label"
|
||||
width="300px"
|
||||
:width="300"
|
||||
button-ok-label="Update"
|
||||
ref="datatypeDialog"
|
||||
/>
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="props.dialogLabel"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
@@ -37,9 +42,11 @@
|
||||
filled
|
||||
v-model="addingForm.value"
|
||||
></q-input>
|
||||
<q-btn no-caps class="q-mb-xl q-mx-xl q-px-lg" @click="onSubmit" color="primary">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
<div class="row justify-end">
|
||||
<q-btn no-caps class="q-mb-xl q-mx-xl q-px-lg" @click="onSubmit" color="primary">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
</div>
|
||||
</q-form>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
@@ -129,8 +136,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 650,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="props.dialogLabel"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
@@ -27,9 +32,11 @@
|
||||
>
|
||||
</q-input>
|
||||
<div class="q-mx-sm">
|
||||
<q-btn no-caps class="q-mb-xl q-ml-lg q-px-lg" @click="onSubmit" color="primary">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
<div class="row justify-end">
|
||||
<q-btn no-caps class="q-mb-xl q-mr-md q-px-lg" @click="onSubmit" color="primary">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
</q-form>
|
||||
</DialogFrame>
|
||||
@@ -114,8 +121,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 400,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,19 +1,23 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="localDialogLabel">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="localDialogLabel"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel || localDialogLabel"
|
||||
v-if="dialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
:class="'text-' + props.labelColor"
|
||||
>{{ props.dialogLabel || localDialogLabel }}</q-card-section
|
||||
>
|
||||
>{{ 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-form ref="form">
|
||||
<q-card-section class="q-gutter-xs row q-col-gutter-xs">
|
||||
<q-card-section class="q-gutter-xs row q-col-gutter-xs q-ml-sm">
|
||||
<div>
|
||||
<q-select
|
||||
class="col-8"
|
||||
filled
|
||||
label="Driver Name"
|
||||
type="text"
|
||||
@@ -24,7 +28,6 @@
|
||||
v-model="driverForm.type"
|
||||
/>
|
||||
<q-input
|
||||
class="col-8"
|
||||
filled
|
||||
label="Bus"
|
||||
type="text"
|
||||
@@ -35,18 +38,17 @@
|
||||
/>
|
||||
<q-input
|
||||
v-if="driverForm.isAddress"
|
||||
class="col-8"
|
||||
filled
|
||||
dense
|
||||
label="Address"
|
||||
type="number"
|
||||
name="Address"
|
||||
@keyup.enter="updateDriver"
|
||||
v-model.number="driverForm.address"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="!driverForm.isAddress" class="q-gutter-xs row q-col-gutter-xs">
|
||||
<q-input
|
||||
class="col-8"
|
||||
filled
|
||||
dense
|
||||
label="Subscribe"
|
||||
@@ -55,21 +57,21 @@
|
||||
v-model="driverForm.subscribe"
|
||||
/>
|
||||
<q-input
|
||||
class="col-8"
|
||||
filled
|
||||
dense
|
||||
label="Publish"
|
||||
type="text"
|
||||
name="Address"
|
||||
@keyup.enter="updateDriver"
|
||||
v-model="driverForm.publish"
|
||||
/>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-form>
|
||||
<q-card-actions class="text-primary">
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn v-if="props.buttonCancelLabel" flat :label="props.buttonCancelLabel" v-close-popup />
|
||||
<q-btn
|
||||
class="q-mb-xl q-ml-lg q-px-lg"
|
||||
class="q-mb-xl q-mr-lg"
|
||||
v-if="props.buttonOkLabel"
|
||||
color="primary"
|
||||
no-caps
|
||||
@@ -82,10 +84,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { reactive, ref, watch, computed } from 'vue';
|
||||
import DialogFrame from '../../dialog/DialogFrame.vue';
|
||||
import type { Driver } from '../../models/Drivers';
|
||||
import { setRequest } from 'src/vueLib/models/Request';
|
||||
import { deleteRequest, setRequest } from 'src/vueLib/models/Request';
|
||||
import { addRawSubscriptions } from 'src/vueLib/models/Subscriptions';
|
||||
import { convertToSubscribe, type RawSubs } from 'src/vueLib/models/Subscribe';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
@@ -95,6 +97,7 @@ import { updateDriverTable, type DriverTableRow } from 'src/vueLib/models/driver
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const Dialog = ref();
|
||||
const dialogLabel = computed(() => props.dialogLabel || localDialogLabel.value);
|
||||
const options = ['ArtNetDriver', 'OSCDriver'];
|
||||
const driverForm = reactive({
|
||||
type: 'ArtNetDriver',
|
||||
@@ -127,8 +130,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 480,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -138,6 +145,7 @@ let dpUuid = '';
|
||||
const form = ref();
|
||||
const address = ref();
|
||||
const topic = ref();
|
||||
const edit = ref(false);
|
||||
|
||||
watch(
|
||||
() => driverForm.type,
|
||||
@@ -158,13 +166,20 @@ const open = (uuid: string, drvs: DriverTableRow, type: 'add' | 'edit') => {
|
||||
switch (type) {
|
||||
case 'add':
|
||||
localDialogLabel.value = 'Add Driver';
|
||||
driverForm.type = 'ArtNetDriver';
|
||||
driverForm.isAddress = true;
|
||||
edit.value = false;
|
||||
Object.assign(driverForm, {
|
||||
type: 'ArtNetDriver',
|
||||
bus: '',
|
||||
isAddress: true,
|
||||
address: 0,
|
||||
subscribe: '',
|
||||
publish: '',
|
||||
});
|
||||
break;
|
||||
case 'edit':
|
||||
localDialogLabel.value = 'Edit Driver';
|
||||
driverForm.type = drvs.type;
|
||||
driverForm.bus = drvs.bus;
|
||||
edit.value = true;
|
||||
fillDriverFormFromRow(drvs);
|
||||
}
|
||||
|
||||
dpUuid = uuid;
|
||||
@@ -177,9 +192,9 @@ const open = (uuid: string, drvs: DriverTableRow, type: 'add' | 'edit') => {
|
||||
Dialog.value?.open();
|
||||
};
|
||||
|
||||
function updateDriver() {
|
||||
form.value?.validate();
|
||||
if (!driverForm.type || !driverForm.bus) {
|
||||
async function updateDriver() {
|
||||
const valid = await form.value?.validate();
|
||||
if (!valid) {
|
||||
NotifyResponse('Please fill in all required fields', 'warning');
|
||||
return;
|
||||
}
|
||||
@@ -191,6 +206,15 @@ function updateDriver() {
|
||||
topic.value = { subscribe: [driverForm.subscribe], publish: [driverForm.publish] };
|
||||
}
|
||||
|
||||
if (edit.value) {
|
||||
deleteRequest(dpUuid, '', driver.value)
|
||||
.then((resp) => {
|
||||
resp.forEach((set) => {
|
||||
updateDriverTable(convertToSubscribe(set));
|
||||
});
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
setRequest('', undefined, undefined, undefined, dpUuid, {
|
||||
type: driverForm.type,
|
||||
buses: [
|
||||
@@ -216,6 +240,14 @@ function updateDriver() {
|
||||
});
|
||||
}
|
||||
|
||||
function fillDriverFormFromRow(drvs: DriverTableRow) {
|
||||
driverForm.type = drvs.type;
|
||||
driverForm.bus = drvs.buses?.[0]?.name ?? '';
|
||||
driverForm.address = drvs.buses?.[0]?.address?.[0] ?? -1;
|
||||
driverForm.subscribe = drvs.topic?.subscribe?.[0] ?? '';
|
||||
driverForm.publish = drvs.topic?.publish?.[0] ?? '';
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
|
@@ -8,12 +8,14 @@
|
||||
</q-card-section>
|
||||
<div class="text-center text-bold text-primary">
|
||||
Do you want to remove Datapoint
|
||||
<br />
|
||||
<br /><br />
|
||||
'{{ datapoint.path ?? '' }}'
|
||||
</div>
|
||||
<q-btn no-caps class="q-ma-md" filled color="negative" @click="remove">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
<div class="row justify-end">
|
||||
<q-btn no-caps class="q-ma-lg q-mr-xl" filled color="negative" @click="remove">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
@@ -84,8 +86,8 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="props.dialogLabel"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
@@ -26,7 +31,7 @@
|
||||
:rules="[(val) => !!val || 'Path is required']"
|
||||
>
|
||||
</q-input>
|
||||
<div class="q-mx-sm">
|
||||
<div class="row justify-end q-mr-lg">
|
||||
<q-btn no-caps class="q-mb-xl q-ml-lg q-px-lg" @click="onSubmit" color="primary">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
@@ -95,7 +100,6 @@ function onSubmit() {
|
||||
)
|
||||
.then((res) => {
|
||||
addRawSubscriptions(res as RawSubs);
|
||||
console.log(80, res);
|
||||
buildTree(convertToSubscribes(res as RawSubs));
|
||||
UpdateTable();
|
||||
})
|
||||
@@ -124,8 +128,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 400,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,10 +1,17 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="props.dialogLabel">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="props.dialogLabel"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
:class="'text-' + props.labelColor"
|
||||
>DBM:{{ datapoint.path }}
|
||||
>{{
|
||||
datapoint.uuid === '00000000-0000-0000-0000-000000000000' ? 'DBM' : 'DBM:' + datapoint.path
|
||||
}}
|
||||
</q-card-section>
|
||||
<q-form ref="datatypeForm" class="q-gutter-md">
|
||||
<q-input
|
||||
@@ -12,7 +19,7 @@
|
||||
filled
|
||||
dense
|
||||
v-model="currentDatatype"
|
||||
label="Current Path"
|
||||
label="Current Datatype"
|
||||
label-color="primary"
|
||||
readonly
|
||||
>
|
||||
@@ -20,6 +27,7 @@
|
||||
<q-select
|
||||
class="q-mt-lg q-mt-none q-pl-md q-mx-lg"
|
||||
popup-content-class="small-dropdown"
|
||||
label="New Datatype"
|
||||
filled
|
||||
dense
|
||||
v-model="selectedDatatype"
|
||||
@@ -27,7 +35,7 @@
|
||||
option-label="label"
|
||||
>
|
||||
</q-select>
|
||||
<div class="q-mx-sm">
|
||||
<div class="row justify-end q-mr-lg">
|
||||
<q-btn no-caps class="q-mb-xl q-ml-lg q-px-lg" @click="onSubmit" color="primary">{{
|
||||
props.buttonOkLabel
|
||||
}}</q-btn>
|
||||
@@ -111,8 +119,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 340,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="datapoint?.path">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="'DBM:' + datapoint?.path"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel || localDialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
@@ -44,12 +49,16 @@
|
||||
<q-menu ref="contextMenuRef" context-menu>
|
||||
<q-list>
|
||||
<q-item>
|
||||
<q-item-section class="cursor-pointer" @click="handleRow(driver, 'edit')">
|
||||
<q-item-section v-close-popup class="cursor-pointer" @click="handleRow(driver, 'edit')">
|
||||
Edit
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item>
|
||||
<q-item-section class="text-negative cursor-pointer" @click="deleteDriver(driver)">
|
||||
<q-item-section
|
||||
v-close-popup
|
||||
class="text-negative cursor-pointer"
|
||||
@click="deleteDriver(driver)"
|
||||
>
|
||||
Delete
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
@@ -59,7 +68,7 @@
|
||||
<q-card-section v-if="props.text" class="text-center" style="white-space: pre-line">{{
|
||||
props.text
|
||||
}}</q-card-section>
|
||||
<q-card-actions align="left" class="text-primary">
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn v-if="props.buttonCancelLabel" flat :label="props.buttonCancelLabel" v-close-popup>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
@@ -117,8 +126,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 500,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="props.width" :header-title="datapoint?.path">
|
||||
<DialogFrame
|
||||
ref="Dialog"
|
||||
:width="props.width"
|
||||
:height="props.height"
|
||||
:header-title="datapoint?.path"
|
||||
>
|
||||
<q-card-section
|
||||
v-if="props.dialogLabel || localDialogLabel"
|
||||
class="text-bold text-left q-mb-none q-pb-none"
|
||||
@@ -45,11 +50,11 @@
|
||||
<q-card-section v-if="props.text" class="text-center" style="white-space: pre-line">{{
|
||||
props.text
|
||||
}}</q-card-section>
|
||||
<q-card-actions align="left" class="text-primary">
|
||||
<q-card-actions align="right" class="text-primary">
|
||||
<q-btn v-if="props.buttonCancelLabel" flat :label="props.buttonCancelLabel" v-close-popup>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
class="q-mb-xl q-ml-lg q-mt-none"
|
||||
class="q-mb-xl q-mr-lg q-mt-none"
|
||||
v-if="props.buttonOkLabel"
|
||||
color="primary"
|
||||
no-caps
|
||||
@@ -101,8 +106,12 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
type: Number,
|
||||
default: 300,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default: 350,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -7,18 +7,30 @@
|
||||
:no-refocus="!minMaxState"
|
||||
:seamless="!minMaxState"
|
||||
>
|
||||
<q-card class="layout" :style="cardStyle" v-touch-pan.mouse.prevent.stop="handlePan">
|
||||
<div :class="props.headerTitle ? 'row items-center justify-between' : ''">
|
||||
<div v-if="headerTitle" class="q-mx-sm q-mt-xs text-left text-bold text-caption">
|
||||
{{ props.headerTitle }}
|
||||
<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 class="text-left text-bold text-caption q-mx-sm">
|
||||
{{ headerTitle }}
|
||||
</div>
|
||||
<div class="row justify-end q-mx-sm q-mt-xs">
|
||||
<q-btn dense flat :icon="minMaxIcon" size="md" @click="minMax()"></q-btn>
|
||||
<q-btn dense flat icon="close" size="md" v-close-popup></q-btn>
|
||||
<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" class="q-my-none" />
|
||||
<div class="scrollArea"><slot /></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>
|
||||
@@ -29,54 +41,107 @@ import { ref, computed } from 'vue';
|
||||
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() {
|
||||
if (minMaxState.value) {
|
||||
minMaxIcon.value = 'fullscreen';
|
||||
} else {
|
||||
minMaxIcon.value = 'fullscreen_exit';
|
||||
}
|
||||
minMaxState.value = !minMaxState.value;
|
||||
minMaxIcon.value = minMaxState.value ? 'fullscreen_exit' : 'fullscreen';
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
headerTitle: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
width: {
|
||||
type: String,
|
||||
default: '300px',
|
||||
},
|
||||
});
|
||||
|
||||
// Position and Size
|
||||
const position = ref({ x: 0, y: 0 });
|
||||
const width = ref(props.width);
|
||||
const height = ref(props.height);
|
||||
|
||||
// This makes the dialog draggable
|
||||
// Dragging (only from header)
|
||||
const handlePan = (details: { delta: { x: number; y: number } }) => {
|
||||
position.value.x += details.delta.x;
|
||||
position.value.y += details.delta.y;
|
||||
if (!minMaxState.value) {
|
||||
position.value.x += details.delta.x;
|
||||
position.value.y += details.delta.y;
|
||||
}
|
||||
};
|
||||
|
||||
const cardStyle = computed(() => ({
|
||||
width: props.width,
|
||||
transform: `translate(${position.value.x}px, ${position.value.y}px)`,
|
||||
}));
|
||||
// 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;
|
||||
|
||||
defineExpose({ open, close });
|
||||
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: `${width.value}px`,
|
||||
height: `${height.value}px`,
|
||||
transform: `translate(${position.value.x}px, ${position.value.y}px)`,
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.layout {
|
||||
border-radius: 10px;
|
||||
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 {
|
||||
overflow-y: auto;
|
||||
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>
|
||||
|
@@ -22,6 +22,19 @@ export function useNotify() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (response instanceof Error) {
|
||||
const resp = response as Response;
|
||||
if (resp.response?.data?.error) {
|
||||
$q?.notify({
|
||||
message: resp.response.data.message as string,
|
||||
color: color,
|
||||
position: 'bottom-right',
|
||||
icon: icon,
|
||||
timeout: timeout,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (response) {
|
||||
const message = typeof response === 'string' ? response : (response.message ?? '');
|
||||
if (message === '') {
|
||||
|
109
src/vueLib/login/LoginForm.vue
Normal file
109
src/vueLib/login/LoginForm.vue
Normal file
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<DialogFrame ref="Dialog" :width="300" :height="380" header-title="Login">
|
||||
<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="User"
|
||||
v-model="user"
|
||||
:rules="[(val) => !!val || 'User is required']"
|
||||
></q-input>
|
||||
<q-input
|
||||
dense
|
||||
filled
|
||||
type="password"
|
||||
label="Password"
|
||||
v-model="password"
|
||||
@keyup.enter="onSubmit"
|
||||
:rules="[(val) => !!val || 'Password is required']"
|
||||
></q-input>
|
||||
<div class="q-pt-sm q-mr-md row justify-end">
|
||||
<q-btn color="primary" label="Login" @click="onSubmit"></q-btn>
|
||||
</div>
|
||||
</q-card>
|
||||
</q-item-section>
|
||||
</q-form>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { productName } from '../../../package.json';
|
||||
import { ref, nextTick } from 'vue';
|
||||
import DialogFrame from '../dialog/DialogFrame.vue';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
import { useLogin } from './login';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const Dialog = ref();
|
||||
const refForm = ref();
|
||||
const refUserInput = ref();
|
||||
const user = ref('');
|
||||
const password = ref('');
|
||||
const { login } = useLogin();
|
||||
|
||||
const shake = ref(false);
|
||||
|
||||
const open = () => {
|
||||
Dialog.value?.open();
|
||||
nextTick(() => {
|
||||
refUserInput.value?.focus();
|
||||
}).catch((err) => console.error(err));
|
||||
};
|
||||
|
||||
const onSubmit = () => {
|
||||
refForm.value?.validate().then((success: boolean) => {
|
||||
if (success) {
|
||||
login(user.value, password.value)
|
||||
.then(() => {
|
||||
NotifyResponse("logged in as '" + user.value + "'");
|
||||
Dialog.value.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
shake.value = true;
|
||||
setTimeout(() => {
|
||||
shake.value = false;
|
||||
}, 500);
|
||||
});
|
||||
} else {
|
||||
NotifyResponse('error submitting login form', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
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>
|
43
src/vueLib/login/LoginMenu.vue
Normal file
43
src/vueLib/login/LoginMenu.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<div class="q-gutter-md">
|
||||
<q-btn dense flat round icon="person" :color="userStore.user ? 'green' : ''">
|
||||
<q-menu ref="refLoginMenu">
|
||||
<q-list style="min-width: 100px">
|
||||
<q-item v-if="userStore.user" class="text-primary">{{ userStore.user?.username }}</q-item>
|
||||
<q-item clickable v-close-popup @click="openLogin">
|
||||
<q-item-section class="text-primary">{{ loginText }}</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
</q-btn>
|
||||
</div>
|
||||
<LoginForm ref="refLoginForm"></LoginForm>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import LoginForm from './LoginForm.vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useLogin } from './login';
|
||||
import { useUserStore } from './userStore';
|
||||
import { useNotify } from '../general/useNotify';
|
||||
|
||||
const userStore = useUserStore();
|
||||
const userLogin = useLogin();
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loginText = computed(() => {
|
||||
return userStore.user ? 'Logout' : 'Login';
|
||||
});
|
||||
|
||||
const refLoginForm = ref();
|
||||
|
||||
function openLogin() {
|
||||
if (userStore.user) {
|
||||
const username = userStore.user.username;
|
||||
userLogin.logout();
|
||||
NotifyResponse("user '" + username + "' logged out", 'warning');
|
||||
return;
|
||||
}
|
||||
refLoginForm.value?.open();
|
||||
}
|
||||
</script>
|
31
src/vueLib/login/login.ts
Normal file
31
src/vueLib/login/login.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { useUserStore } from './userStore';
|
||||
|
||||
const useStore = useUserStore();
|
||||
|
||||
export function useLogin() {
|
||||
async function login(user: string, password: string) {
|
||||
await appApi
|
||||
.post('/login', { user: user, password: password })
|
||||
.then((resp) => {
|
||||
useStore.setToken(resp.data.token);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
function logout() {
|
||||
useStore.logout();
|
||||
}
|
||||
|
||||
function isTokenValid() {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token === null) return false;
|
||||
const payload = JSON.parse(atob(token.split('.')[1] ?? ''));
|
||||
const currentTime = Math.floor(Date.now() / 1000);
|
||||
return payload.exp > currentTime;
|
||||
}
|
||||
|
||||
return { login, logout, isTokenValid };
|
||||
}
|
80
src/vueLib/login/userStore.ts
Normal file
80
src/vueLib/login/userStore.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
import type { QVueGlobals } from 'quasar';
|
||||
|
||||
interface JwtPayload {
|
||||
id: string;
|
||||
role: string;
|
||||
username: string;
|
||||
exp?: number;
|
||||
iat?: number;
|
||||
}
|
||||
|
||||
interface UserState {
|
||||
token: string | null;
|
||||
user: JwtPayload | null;
|
||||
}
|
||||
|
||||
let $q = <QVueGlobals>{};
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: (): UserState => ({
|
||||
token: null,
|
||||
user: null,
|
||||
}),
|
||||
getters: {
|
||||
isAuthenticated: (state): boolean => !!state.token && !!state.user,
|
||||
},
|
||||
actions: {
|
||||
isAuthorizedAs(roles: string[]) {
|
||||
return !!this.token && !!this.user && roles.includes(this.user.role);
|
||||
},
|
||||
setToken(token: string) {
|
||||
try {
|
||||
const decoded = jwtDecode<JwtPayload>(token);
|
||||
this.token = token;
|
||||
this.user = decoded;
|
||||
localStorage.setItem('token', token);
|
||||
|
||||
if (decoded.exp) {
|
||||
const timeUntilExpiry = decoded.exp * 1000 - Date.now();
|
||||
if (timeUntilExpiry > 0) {
|
||||
setTimeout(() => {
|
||||
this.logout();
|
||||
}, timeUntilExpiry);
|
||||
} else {
|
||||
this.logout();
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Invalid token:', err);
|
||||
this.logout();
|
||||
}
|
||||
},
|
||||
logout() {
|
||||
$q?.notify({
|
||||
message: "user '" + this.user?.username + "' logged out",
|
||||
color: 'orange',
|
||||
position: 'bottom-right',
|
||||
icon: 'warning',
|
||||
timeout: 5000,
|
||||
});
|
||||
this.token = null;
|
||||
this.user = null;
|
||||
localStorage.removeItem('token');
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 5000);
|
||||
},
|
||||
loadFromStorage() {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
this.setToken(token);
|
||||
}
|
||||
},
|
||||
initStore(q: QVueGlobals) {
|
||||
$q = q;
|
||||
},
|
||||
},
|
||||
});
|
@@ -2,7 +2,7 @@ import type { Driver } from './Drivers';
|
||||
import type { Gets } from './Get';
|
||||
import type { Sets } from './Set';
|
||||
import type { Subs } from './Subscribe';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { dbmApi } from 'src/boot/axios';
|
||||
|
||||
export type Request = {
|
||||
get?: Gets;
|
||||
@@ -25,7 +25,7 @@ export async function getRequest(
|
||||
payload = { path: path, query: { depth: depth } };
|
||||
}
|
||||
|
||||
const resp = await api.post(query, {
|
||||
const resp = await dbmApi.post(query, {
|
||||
get: [payload],
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function getRequest(
|
||||
}
|
||||
|
||||
export async function getRequests(gets: Gets): Promise<Gets> {
|
||||
const resp = await api.post(query, {
|
||||
const resp = await dbmApi.post(query, {
|
||||
get: gets,
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ export async function getRequests(gets: Gets): Promise<Gets> {
|
||||
}
|
||||
|
||||
export async function rawSetsRequest(sets: Sets): Promise<Sets> {
|
||||
const resp = await api.post(query, {
|
||||
const resp = await dbmApi.post(query, {
|
||||
set: sets,
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ export async function setRequest(
|
||||
rename: rename,
|
||||
};
|
||||
|
||||
const resp = await api.post(query, {
|
||||
const resp = await dbmApi.post(query, {
|
||||
set: [payload],
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export async function setRequest(
|
||||
}
|
||||
|
||||
export async function setsRequest(sets: Sets): Promise<Sets> {
|
||||
const resp = await api.post(query, {
|
||||
const resp = await dbmApi.post(query, {
|
||||
set: sets,
|
||||
});
|
||||
|
||||
@@ -114,7 +114,7 @@ export async function deleteRequest(
|
||||
} else if (path) {
|
||||
payload = { path: path, driver: driver };
|
||||
}
|
||||
const resp = await api.delete('/json_data', {
|
||||
const resp = await dbmApi.delete('/json_data', {
|
||||
data: {
|
||||
set: [payload],
|
||||
},
|
||||
|
@@ -11,4 +11,10 @@ export type Response = {
|
||||
publish?: Pubs;
|
||||
error?: boolean;
|
||||
message?: string;
|
||||
response?: {
|
||||
data?: {
|
||||
error?: boolean;
|
||||
message?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
64
src/vueLib/models/Services.ts
Normal file
64
src/vueLib/models/Services.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
//import { ref } from 'vue';
|
||||
|
||||
export interface Service {
|
||||
name: string;
|
||||
workingDirectory: string;
|
||||
executablePath: string;
|
||||
description: string;
|
||||
arguments: string[];
|
||||
state: State;
|
||||
stateColor: string;
|
||||
stateTextColor: string;
|
||||
}
|
||||
export type Services = Service[];
|
||||
export type State = 'Stopped' | 'Stopping' | 'Starting' | 'Running' | 'Error';
|
||||
|
||||
export function useServices() {
|
||||
async function initServices() {
|
||||
return appApi
|
||||
.get('services/load')
|
||||
.then((resp) => {
|
||||
const normalized = resp.data.services.map((item: Service) => {
|
||||
if (!item.state) {
|
||||
item.state = 'Stopped';
|
||||
}
|
||||
|
||||
let stateColor = 'grey-4';
|
||||
let stateTextColor = 'black';
|
||||
|
||||
switch (item.state) {
|
||||
case 'Running':
|
||||
stateColor = 'green';
|
||||
stateTextColor = 'white';
|
||||
break;
|
||||
case 'Starting':
|
||||
case 'Stopping':
|
||||
stateColor = 'green';
|
||||
stateTextColor = 'white';
|
||||
break;
|
||||
case 'Stopped':
|
||||
default:
|
||||
stateColor = 'grey-4';
|
||||
stateTextColor = 'black';
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
stateColor,
|
||||
stateTextColor,
|
||||
};
|
||||
});
|
||||
|
||||
return normalized;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
initServices,
|
||||
};
|
||||
}
|
@@ -1,9 +1,13 @@
|
||||
import { reactive, ref } from 'vue';
|
||||
import type { QTableColumn } from 'quasar';
|
||||
import type { Subscribe } from './Subscribe';
|
||||
import type { Bus } from './Bus';
|
||||
import type { Topic } from './Topic';
|
||||
|
||||
export type DriverTableRow = {
|
||||
type: string;
|
||||
buses?: Bus[];
|
||||
topic?: Topic;
|
||||
bus: string;
|
||||
address?: number | undefined;
|
||||
subscribe?: string;
|
||||
|
43
src/vueLib/services/dialog/ServiceDialog.vue
Normal file
43
src/vueLib/services/dialog/ServiceDialog.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<DialogFrame ref="refDialog" :width="250" header-title="Add new Service">
|
||||
<div class="row justify-center">
|
||||
<div>
|
||||
<div class="q-ma-md text-primary text-bold">Choose new service</div>
|
||||
<q-select dense filled class="col-4" :options="opts" v-model="option"></q-select>
|
||||
<div class="row justify-end">
|
||||
<q-btn class="q-mt-md" no-caps color="primary">Add Service</q-btn>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</DialogFrame>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import { ref } from 'vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const refDialog = ref();
|
||||
const driverRows = ref([]);
|
||||
const opts = ref();
|
||||
const option = ref('');
|
||||
|
||||
interface conf {
|
||||
name: string;
|
||||
}
|
||||
function open() {
|
||||
appApi
|
||||
.get('services/all')
|
||||
.then((resp) => {
|
||||
driverRows.value = resp.data;
|
||||
opts.value = resp.data.services.map((item: conf) => item.name);
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
refDialog.value.open();
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
92
src/vueLib/services/dialog/SubMenu.vue
Normal file
92
src/vueLib/services/dialog/SubMenu.vue
Normal file
@@ -0,0 +1,92 @@
|
||||
<template>
|
||||
<q-menu ref="refMenu" context-menu>
|
||||
<q-list>
|
||||
<q-item :disable="!startEnabled" clickable @click="start">
|
||||
<q-item-section>
|
||||
<q-icon :color="startEnabled ? 'green' : 'green-2'" name="play_arrow" size="sm" />
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item :disable="!stopEnabled" clickable @click="stop">
|
||||
<q-item-section>
|
||||
<q-icon :color="stopEnabled ? 'red' : 'red-2'" name="stop" size="sm" />
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
<q-item :disable="!restartEnabled" clickable>
|
||||
<q-item-section>
|
||||
<q-icon
|
||||
:color="restartEnabled ? 'orange' : 'orange-3'"
|
||||
name="restart_alt"
|
||||
size="sm"
|
||||
@click="console.log('restart')"
|
||||
/>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</q-menu>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import type { Service } from 'src/vueLib/models/Services';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const refMenu = ref();
|
||||
const startEnabled = computed(() => localService.value?.state === 'Stopped' || 'Error');
|
||||
const stopEnabled = computed(() => localService.value?.state === 'Running');
|
||||
const restartEnabled = computed(() => localService.value?.state === 'Running');
|
||||
const localService = ref<Service>();
|
||||
|
||||
const open = (event: MouseEvent, service: Service) => {
|
||||
localService.value = service;
|
||||
refMenu.value?.show(event);
|
||||
};
|
||||
|
||||
function start() {
|
||||
if (!localService.value) {
|
||||
return;
|
||||
}
|
||||
localService.value.state = 'Starting';
|
||||
localService.value.stateColor = 'yellow';
|
||||
localService.value.stateTextColor = 'black';
|
||||
appApi
|
||||
.get(`/services/${localService.value.name}/start`)
|
||||
.then(() => {
|
||||
if (!localService.value) {
|
||||
return;
|
||||
}
|
||||
localService.value.state = 'Running';
|
||||
localService.value.stateColor = 'green';
|
||||
localService.value.stateTextColor = 'white';
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
NotifyResponse(err, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function stop() {
|
||||
if (!localService.value) {
|
||||
return;
|
||||
}
|
||||
localService.value.state = 'Stopping';
|
||||
localService.value.stateColor = 'yellow';
|
||||
localService.value.stateTextColor = 'black';
|
||||
|
||||
appApi
|
||||
.get(`/services/${localService.value.name}/stop`)
|
||||
.then(() => {
|
||||
if (!localService.value) {
|
||||
return;
|
||||
}
|
||||
localService.value.state = 'Stopped';
|
||||
localService.value.stateColor = 'grey-4';
|
||||
localService.value.stateTextColor = 'black';
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
7
src/vueLib/services/statusServer/models.ts
Normal file
7
src/vueLib/services/statusServer/models.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export type Payload = {
|
||||
action?: Action;
|
||||
topic: string;
|
||||
data: { state?: string; message?: string };
|
||||
};
|
||||
|
||||
export type Action = 'subscribe' | 'publish';
|
115
src/vueLib/services/statusServer/useStatusServer.ts
Normal file
115
src/vueLib/services/statusServer/useStatusServer.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import type { Response } from '../../models/Response';
|
||||
import type { QVueGlobals } from 'quasar';
|
||||
import { ref } from 'vue';
|
||||
import type { Payload } from './models';
|
||||
|
||||
let socket: WebSocket | null = null;
|
||||
|
||||
const isConnected = ref(false);
|
||||
|
||||
export function useStatusServer(
|
||||
host: string,
|
||||
port: number = 9500,
|
||||
path: string,
|
||||
id: string,
|
||||
callback: (payload: Payload) => void,
|
||||
$q?: QVueGlobals,
|
||||
) {
|
||||
const connect = () => {
|
||||
socket = new WebSocket(`ws://${host}:${port}/${path}?id=${id}`);
|
||||
|
||||
socket.onopen = () => {
|
||||
console.log('WebSocket connected');
|
||||
isConnected.value = true;
|
||||
};
|
||||
|
||||
socket.onclose = () => {
|
||||
isConnected.value = false;
|
||||
console.log('WebSocket disconnected');
|
||||
$q?.notify({
|
||||
message: 'WebSocket disconnected',
|
||||
color: 'orange',
|
||||
position: 'bottom-right',
|
||||
icon: 'warning',
|
||||
timeout: 10000,
|
||||
});
|
||||
};
|
||||
socket.onerror = (err) => {
|
||||
console.log(`WebSocket error: ${err.type}`);
|
||||
isConnected.value = false;
|
||||
$q?.notify({
|
||||
message: `WebSocket error: ${err.type}`,
|
||||
color: 'red',
|
||||
position: 'bottom-right',
|
||||
icon: 'error',
|
||||
timeout: 10000,
|
||||
});
|
||||
};
|
||||
socket.onmessage = (event) => {
|
||||
callback(JSON.parse(event.data));
|
||||
};
|
||||
};
|
||||
|
||||
function subscribe(topic: string): Promise<Response | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
waitForSocketConnection()
|
||||
.then(() => {
|
||||
socket?.send('{"action":"subscribe", "topic":"' + topic + '"}');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('WebSocket send failed:', err);
|
||||
resolve(undefined); // or reject(err) if strict failure is desired
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function publish(topic: string, data: unknown): Promise<Response | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
waitForSocketConnection()
|
||||
.then(() => {
|
||||
socket?.send(
|
||||
'{"action":"publish", "topic":"' + topic + '", "data":' + JSON.stringify(data) + '}',
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('WebSocket send failed:', err);
|
||||
resolve(undefined); // or reject(err) if strict failure is desired
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
if (socket) {
|
||||
socket.close();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
connect,
|
||||
close,
|
||||
subscribe,
|
||||
publish,
|
||||
};
|
||||
}
|
||||
|
||||
function waitForSocketConnection(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const maxWait = 5000; // timeout after 5 seconds
|
||||
const interval = 50;
|
||||
let waited = 0;
|
||||
|
||||
const check = () => {
|
||||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||||
resolve();
|
||||
} else {
|
||||
waited += interval;
|
||||
if (waited >= maxWait) {
|
||||
reject(new Error('WebSocket connection timeout'));
|
||||
} else {
|
||||
setTimeout(check, interval);
|
||||
}
|
||||
}
|
||||
};
|
||||
check();
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user