Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Merging:
- redesigned simpler layout
- multicolumn searching
- config language to JSON from YAML
- user definable colours

Closes #33

Reviewed-on: https://code.speleo.dev/IdlePhysicist/cave-logger/pulls/34
  • Loading branch information
IdlePhysicist committed Aug 19, 2020
2 parents cbd4af8 + 4080b1d commit 801eee1
Show file tree
Hide file tree
Showing 26 changed files with 470 additions and 634 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Project
*.db
config/config.yml
config/
build/
_old

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Eoghan Conlon O'Neill (IdlePhysicist)
Copyright (c) 2020 Eoghan Conlon O'Neill (IdlePhysicist)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
## Summary
Cave Logger is a basic SQLite database interface written in Go, and it allows cavers to track the caves that they have been to, who with, and when.

I indend to make the code more generic to allow other outdoorsy people to use this app with less fuss.

## What It Looks Like
<p align="center"><img src="assets/screenshot.png"></p>

Expand Down Expand Up @@ -35,22 +33,3 @@ To run in docker:
2. Follow step 3 from above
3. `./docker/run.sh`

## Help

### Keybindings

| Key | Function |
|:---:|:--------:|
| <kbd>q</kbd> | quit |
| <kbd>n</kbd> | new |
| <kbd>u</kbd> | update |
| <kbd>d</kbd> | delete |
| <kbd>j</kbd> | down |
| <kbd>k</kbd> | up |
| <kbd>g</kbd> | end |
| <kbd>G</kbd> | home |
| <kbd>Tab</kbd> | see menu |
| <kbd>Enter</kbd> | inspect record |

### Menu
In the Menu the <kbd>Tab</kbd> key will select the highlighted item, and hitting <kbd>Tab</kbd> again will navigate to the Menu.
Binary file modified assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -48,21 +48,21 @@ func main() {


// Read config file
cfg := func (_yamlFile string) *model.Config {
cfg := func(_file string) *model.Config {
var _cfg model.Config

if _yamlFile == `` {
_yamlFile = fmt.Sprintf("%s/.config/cave-logger/config.yml", os.Getenv("HOME"))
if _file == `` {
_file = fmt.Sprintf("%s/.config/cave-logger/config.json", os.Getenv("HOME"))
}

yamlFile, err := ioutil.ReadFile(_yamlFile)
file, err := ioutil.ReadFile(_file)
if err != nil {
log.Fatalf("main.readfile: %v", err)
}

err = yaml.Unmarshal(yamlFile, &_cfg)
err = json.Unmarshal(file, &_cfg)
if err != nil {
log.Fatalf("main.unmarshalYAML: %v", err)
log.Fatalf("main.unmarshal: %v", err)
}

return &_cfg
Expand All @@ -78,6 +78,7 @@ func main() {

// Initialise the Gui / Tui
gui := gui.New(db)
gui.ProcessColors(cfg.Colors)

if err := gui.Start(); err != nil {
log.Fatalf("main: Cannot start tui: %s", err)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ require (
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.2
)
62 changes: 31 additions & 31 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func (db *Database) AddTrip(date, location, names, notes string) error {
if err != nil {
return err
}

if err = db.conn.Begin(); err != nil {
return err
}

// Insert the trip itself
tripID, err := db.execute(query, params)
if err != nil {
Expand Down Expand Up @@ -163,14 +163,14 @@ func (db *Database) GetAllTrips() ([]*model.Log, error) {
trips.notes AS 'notes'
FROM trips, locations
WHERE trips.caveid = locations.id`

result, err := db.conn.Prepare(query)
if err != nil {
db.log.Errorf("db.prepare: Failed to query database", err)
return nil, err
}
defer result.Close()

trips := make([]*model.Log, 0)
for {
var stamp int64
Expand All @@ -185,17 +185,17 @@ func (db *Database) GetAllTrips() ([]*model.Log, error) {
if !rowExists {
break
}

err = result.Scan(&trip.ID, &stamp, &trip.Cave, &trip.Names, &trip.Notes)
if err != nil {
db.log.Error(err)
return trips, err
}

trip.Date = time.Unix(stamp, 0).Format(date)

// Add this formatted row to the rows map
trips = append(trips, &trip)
trips = append(trips, &trip)
}

return trips, err
Expand Down Expand Up @@ -225,7 +225,7 @@ func (db *Database) GetTrip(logID string) (*model.Log, error) { //FIXME:
return nil, err
}
defer result.Close()

trips := make([]*model.Log, 0)
for {
var stamp int64
Expand All @@ -240,17 +240,17 @@ func (db *Database) GetTrip(logID string) (*model.Log, error) { //FIXME:
if !rowExists {
break
}

err = result.Scan(&trip.ID, &stamp, &trip.Cave, &trip.Names, &trip.Notes)
if err != nil {
db.log.Error(err)
return trips[0], err
}

trip.Date = time.Unix(stamp, 0).Format(date)

// Add this formatted row to the rows map
trips = append(trips, &trip)
trips = append(trips, &trip)
}

return trips[0], err
Expand Down Expand Up @@ -281,7 +281,7 @@ func (db *Database) GetAllPeople() ([]*model.Caver, error) {
cavers := make([]*model.Caver, 0)
for {
var c model.Caver

rowExists, err := result.Step()
if err != nil {
db.log.Errorf("db.get: Step error: %s", err)
Expand All @@ -291,7 +291,7 @@ func (db *Database) GetAllPeople() ([]*model.Caver, error) {
if !rowExists {
break
}

err = result.Scan(&c.ID, &c.Name, &c.Club, &c.Count)
if err != nil {
db.log.Errorf("Scan: %v", err)
Expand Down Expand Up @@ -321,7 +321,7 @@ func (db *Database) GetTopPeople() ([]*model.Statistic, error) {
cavers := make([]*model.Statistic, 0)
for {
var c model.Statistic

rowExists, err := result.Step()
if err != nil {
db.log.Errorf("db.get: Step error: %s", err)
Expand All @@ -331,7 +331,7 @@ func (db *Database) GetTopPeople() ([]*model.Statistic, error) {
if !rowExists {
break
}

err = result.Scan(&c.Name, &c.Value)
if err != nil {
db.log.Errorf("Scan: %v", err)
Expand Down Expand Up @@ -363,7 +363,7 @@ func (db *Database) GetPerson(personID string) (*model.Caver, error) {
return nil, err
}
defer result.Close()

people := make([]*model.Caver, 0)
for {
var person model.Caver
Expand All @@ -377,15 +377,15 @@ func (db *Database) GetPerson(personID string) (*model.Caver, error) {
if !rowExists {
break
}

err = result.Scan(&person.ID, &person.Name, &person.Club, &person.Count)
if err != nil {
db.log.Error(err)
return people[0], err
}

// Add this formatted row to the rows map
people = append(people, &person)
people = append(people, &person)
}

return people[0], err
Expand Down Expand Up @@ -418,7 +418,7 @@ func (db *Database) GetAllLocations() ([]*model.Cave, error) {
caves := make([]*model.Cave, 0)
for {
var c model.Cave

rowExists, err := result.Step()
if err != nil {
db.log.Errorf("db.get: Step error: %s", err)
Expand All @@ -428,7 +428,7 @@ func (db *Database) GetAllLocations() ([]*model.Cave, error) {
if !rowExists {
break
}

err = result.Scan(&c.ID, &c.Name, &c.Region, &c.Country, &c.SRT, &c.Visits)
if err != nil {
db.log.Errorf("Scan: %v", err)
Expand Down Expand Up @@ -458,7 +458,7 @@ func (db *Database) GetTopLocations() ([]*model.Statistic, error) {
stats := make([]*model.Statistic, 0)
for {
var s model.Statistic

rowExists, err := result.Step()
if err != nil {
db.log.Errorf("db.get: Step error: %s", err)
Expand All @@ -468,7 +468,7 @@ func (db *Database) GetTopLocations() ([]*model.Statistic, error) {
if !rowExists {
break
}

err = result.Scan(&s.Name, &s.Value)
if err != nil {
db.log.Errorf("Scan: %v", err)
Expand Down Expand Up @@ -500,7 +500,7 @@ func (db *Database) GetLocation(caveID string) (*model.Cave, error) {
return nil, err
}
defer result.Close()

caves := make([]*model.Cave, 0)
for {
//var caverIDstr string
Expand All @@ -516,15 +516,15 @@ func (db *Database) GetLocation(caveID string) (*model.Cave, error) {
if !rowExists {
break
}

err = result.Scan(&cave.ID, &cave.Name, &cave.Region, &cave.Country, &cave.SRT, &cave.Visits)
if err != nil {
db.log.Error(err)
return caves[0], err
}

// Add this formatted row to the rows map
caves = append(caves, &cave)
caves = append(caves, &cave)
}

return caves[0], err
Expand All @@ -538,7 +538,7 @@ func (db *Database) RemoveTrip(id string) error {
if err := db.conn.Begin(); err != nil {
return err
}

// Delete trip entry
err := db.conn.Exec(`DELETE FROM trips WHERE id = ?`, id)
if err != nil {
Expand Down Expand Up @@ -571,7 +571,7 @@ func (db *Database) RemovePerson(id string) error {
if err := db.conn.Begin(); err != nil {
return err
}

// Delete trip entry
err := db.conn.Exec(`DELETE FROM people WHERE id = ?`, id)
if err != nil {
Expand All @@ -596,7 +596,7 @@ func (db *Database) RemoveLocation(id string) error {
if err := db.conn.Begin(); err != nil {
return err
}

// Delete trip entry
err := db.conn.Exec(`DELETE FROM locations WHERE id = ?`, id)
if err != nil {
Expand Down Expand Up @@ -627,13 +627,13 @@ func (db *Database) ModifyTrip(id, date, location, names, notes string) error {
if err != nil {
return err
}

params = append(params, id)

if err = db.conn.Begin(); err != nil {
return err
}

// Update the trip itself
_, err = db.execute(query, params)
if err != nil {
Expand All @@ -650,7 +650,7 @@ func (db *Database) ModifyTrip(id, date, location, names, notes string) error {
panic(rb_err)
}
return err
}
}

_, err = db.execute(db.addTripGroups(id, caverIDs))
if err != nil {
Expand Down
Loading

0 comments on commit 801eee1

Please sign in to comment.