Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react UI #270

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e6ca30c
add react ui app and init basics
vsimakhin Dec 15, 2024
b824aa4
building logbook page
vsimakhin Dec 16, 2024
45b44af
custom filters
vsimakhin Dec 22, 2024
8ed33ae
add ladings filter
vsimakhin Dec 22, 2024
5ba2ffc
add quick csv export for full table or filtered columns only
vsimakhin Dec 22, 2024
7367e54
save column visibility in the local storage
vsimakhin Dec 22, 2024
b79c97b
continue working on adding features
vsimakhin Dec 22, 2024
7cea064
update few packages and working on flight record page
vsimakhin Dec 22, 2024
8c9f28f
remove redundant csv export, now it's implemented in UI part
vsimakhin Dec 22, 2024
20fca7b
continue working on flight record page
vsimakhin Dec 24, 2024
38747a4
continue working on flight record page
vsimakhin Dec 29, 2024
9897ac2
continue working on flight record page
vsimakhin Jan 1, 2025
80543fc
attachments
vsimakhin Jan 11, 2025
cef2d1c
update golang packages
vsimakhin Jan 17, 2025
7b86981
update npm packages
vsimakhin Jan 17, 2025
46ec23b
Merge branch 'main' of github.com:vsimakhin/web-logbook into react-ui…
vsimakhin Jan 17, 2025
92e36a0
Add attachments button
vsimakhin Jan 17, 2025
05a24d5
update attachment menu
vsimakhin Jan 17, 2025
8388859
update attachment structure
vsimakhin Jan 17, 2025
da8b899
started working on licencins module
vsimakhin Jan 24, 2025
52eb5e4
ff
vsimakhin Jan 24, 2025
86369f3
continue on licensing page
vsimakhin Jan 24, 2025
ff6664b
update npm packages
vsimakhin Jan 24, 2025
f701330
working on license record page
vsimakhin Jan 28, 2025
a9cbd15
save license record button
vsimakhin Jan 28, 2025
3bda7a3
Licensing module plus some additional updates for other modules
vsimakhin Jan 29, 2025
e68cbe5
few side adjustments
vsimakhin Jan 29, 2025
3e933d8
making some tests run in github actions
vsimakhin Jan 29, 2025
9481b63
install npm packages in makefile
vsimakhin Jan 29, 2025
2f91185
working on settings page
vsimakhin Feb 3, 2025
7890ff2
logbook signature
vsimakhin Feb 3, 2025
66cf599
reqrite authentication method
vsimakhin Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ jobs:
with:
go-version: 1.23.4

- name: build_ui
run: make npm_install build_ui

- name: go vet
run: go vet ./...

- name: go fmt
run: go fmt ./...
- name: test
run: make test

- name: Test
run: go test -v ./...
- name: build backend
run: make build_backend
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ jobs:
push: true
tags: |
vsimakhin/web-logbook:${{ env.TAG }}
vsimakhin/web-logbook:latest
vsimakhin/web-logbook:3
# vsimakhin/web-logbook:latest
39 changes: 25 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,83 @@ clean:
fmt:
@go fmt ./...

npm_install:
@echo "Installing npm packages..."
@cd app/ui && npm install
@cd ../../

## build ui
build_ui:
@echo "Building UI..."
@cd app/ui && npm run build
@cd ../../

## tests
test: fmt
@go test -v ./... -coverpkg=./...

## build: builds the binaty
build: clean
## build: builds the binary
build_backend: clean
@echo "Building..."
@go build -ldflags="-s -w" -o dist/web-logbook ./app
@echo "Web-logbook built!"

## start: starts the web-logbook
start: build
start: build_ui build_backend
@echo "Starting the app..."
@env ./dist/web-logbook -port=${PORT} -env="${ENV}"

start_tls: build
@echo "Starting the app with https enabled..."
@env ./dist/web-logbook -port=${PORT} -env="${ENV}" -enable-https
start_backend: clean build_backend
@echo "Starting the app..."
@env ./dist/web-logbook -port=${PORT} -env="${ENV}"

build_linux_amd64:
build_linux_amd64: build_ui
@OS=linux; ARCH=amd64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_linux_arm64:
build_linux_arm64: build_ui
@OS=linux; ARCH=arm64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_linux_arm_6:
build_linux_arm_6: build_ui
@OS=linux; ARCH=arm; ARM=6; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH GOARM=$$ARM \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH-$$ARM.tar.gz $(BINARY_NAME)-$$OS-$$ARCH-$$ARM;

build_linux_arm_7:
build_linux_arm_7: build_ui
@OS=linux; ARCH=arm; ARM=7; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH GOARM=$$ARM \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH-$$ARM.tar.gz $(BINARY_NAME)-$$OS-$$ARCH-$$ARM;

build_darwin_amd64:
build_darwin_amd64: build_ui
@OS=darwin; ARCH=amd64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_darwin_arm64:
build_darwin_arm64: build_ui
@OS=darwin; ARCH=arm64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_windows_amd64:
build_windows_amd64: build_ui
@OS=windows; ARCH=amd64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); mv $(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) $(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME).exe; zip -r $(BINARY_NAME)-$$OS-$$ARCH.zip $(BINARY_NAME)-$$OS-$$ARCH;

build_all: test clean build_linux_amd64 build_linux_arm64 build_linux_arm_6 build_linux_arm_7 build_darwin_amd64 build_darwin_arm64 build_windows_amd64
build_all: test clean build_ui build_linux_amd64 build_linux_arm64 build_linux_arm_6 build_linux_arm_7 build_darwin_amd64 build_darwin_arm64 build_windows_amd64
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,13 @@ In case you'd like to add some other features to the logbook or you found a bug,
* Signature Pad https://github.com/szimek/signature_pad
* PapaParse https://github.com/mholt/PapaParse
* arc.js https://github.com/springmeyer/arc.js


* Golang go-pdf https://github.com/go-pdf/fpdf
* Golang chi web-server https://github.com/go-chi/chi
* React https://react.dev/
* Material UI https://mui.com/material-ui/
* Material React Table https://material-react-table.com
* dayjs https://github.com/iamkun/dayjs
* TanStack Query https://tanstack.com/query/
* export-to-csv https://github.com/alexcaza/export-to-csv
12 changes: 11 additions & 1 deletion app/handlers_aircraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/vsimakhin/web-logbook/internal/models"
)

// HandlerNightTime is a handler for calculating night time
func (app *application) HandlerAircrafts(w http.ResponseWriter, r *http.Request) {

var aircrafts map[string]string
Expand All @@ -27,3 +26,14 @@ func (app *application) HandlerAircrafts(w http.ResponseWriter, r *http.Request)

app.writeJSON(w, http.StatusOK, aircrafts)
}

// HandlerApiAircraftModels is a handler for getting the list of aircraft models/types
func (app *application) HandlerApiAircraftModels(w http.ResponseWriter, r *http.Request) {

models, err := app.db.GetAircraftModels()
if err != nil {
app.handleError(w, err)
}

app.writeJSON(w, http.StatusOK, models)
}
11 changes: 8 additions & 3 deletions app/handlers_airport.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ import (

// HandlerAirportByID returns airport record by ID (ICAO or IATA)
func (app *application) HandlerAirportByID(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "id")
uuid := strings.ToUpper(chi.URLParam(r, "id"))

airport, err := app.db.GetAirportByID(uuid)
if err != nil {
app.errorLog.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}

if airport.IATA == "" && airport.ICAO == "" {
// looks like there is no such ID in airport database
app.warningLog.Printf("cannot find %s in the airport database\n", uuid)
app.writeJSON(w, http.StatusNotFound, models.JSONResponse{OK: false, Message: "Airport not found"})
return
}

app.writeJSON(w, http.StatusOK, airport)
}

/////////////////////////////////////////////////
// for futher review
/////////////////////////////////////////////////

func (app *application) downloadAirportDB(source string) ([]models.Airport, error) {
var airports []models.Airport
var airportsDB map[string]interface{}
Expand Down
105 changes: 37 additions & 68 deletions app/handlers_attachments.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"fmt"
"io"
"net/http"
Expand All @@ -13,40 +12,63 @@ import (
)

// HandlerGetAttachments generates attachments
func (app *application) HandlerGetAttachments(w http.ResponseWriter, r *http.Request) {
func (app *application) HandlerApiGetAttachments(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "uuid")

attachments, err := app.db.GetAttachments(uuid)
if err != nil {
app.errorLog.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}

app.writeJSON(w, http.StatusOK, attachments)
}

// HandlerUploadAttachment handles attachments upload
func (app *application) HandlerUploadAttachment(w http.ResponseWriter, r *http.Request) {
// HandlerApiGetAttachment is a hadnler for attachment download
func (app *application) HandlerApiGetAttachment(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "uuid")

att, err := app.db.GetAttachmentByID(uuid)
if err != nil {
app.handleError(w, err)
return
}

app.writeJSON(w, http.StatusOK, att)
}

// HandlerApiDeleteAttachment is a handler for removing attachments
func (app *application) HandlerApiDeleteAttachment(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "uuid")

err := app.db.DeleteAttachment(uuid)
if err != nil {
app.handleError(w, err)
return
}

var response models.JSONResponse
app.writeOkResponse(w, "Attachment removed")
}

// HandlerApiUploadAttachment handles attachments upload
func (app *application) HandlerApiUploadAttachment(w http.ResponseWriter, r *http.Request) {

err := r.ParseMultipartForm(32 << 20)
if err != nil {
app.errorLog.Println(fmt.Errorf("cannot parse the data, probably the attachment is too big - %s", err))
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}

attachment := models.Attachment{
RecordID: r.PostFormValue("record_id"),
RecordID: r.PostFormValue("id"),
}

// check attached file
file, header, err := r.FormFile("document")
if err != nil {
if !strings.Contains(err.Error(), "no such file") {
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}
} else {
Expand All @@ -56,7 +78,7 @@ func (app *application) HandlerUploadAttachment(w http.ResponseWriter, r *http.R
// read file
bs, err := io.ReadAll(file)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}
attachment.Document = bs
Expand All @@ -65,70 +87,17 @@ func (app *application) HandlerUploadAttachment(w http.ResponseWriter, r *http.R
// new record
uuid, err := uuid.NewRandom()
if err != nil {
app.errorLog.Println(err)
response.OK = false
response.Message = err.Error()
app.handleError(w, err)
return
}

attachment.UUID = uuid.String()

err = app.db.InsertAttachmentRecord(attachment)
if err != nil {
app.errorLog.Println(err)
response.OK = false
response.Message = err.Error()
} else {
response.OK = true
response.Message = "Attachment has been uploaded"

}

app.writeJSON(w, http.StatusOK, response)
}

// HandlerDeleteAttachment is a handler for removing attachments
func (app *application) HandlerDeleteAttachment(w http.ResponseWriter, r *http.Request) {

var att models.Attachment
var response models.JSONResponse

err := json.NewDecoder(r.Body).Decode(&att)
if err != nil {
app.errorLog.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

err = app.db.DeleteAttachment(att.UUID)
if err != nil {
app.errorLog.Println(err)
response.OK = false
response.Message = err.Error()
} else {
response.OK = true

}

app.writeJSON(w, http.StatusOK, response)
}

// HandlerAttachmentDownload is a hadnler for attachment download
func (app *application) HandlerAttachmentDownload(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "uuid")

att, err := app.db.GetAttachmentByID(uuid)
if err != nil {
app.errorLog.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}

w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", att.DocumentName))

_, err = w.Write(att.Document)
if err != nil {
app.errorLog.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
app.writeOkResponse(w, "Attachment has been uploaded")
}
Loading
Loading