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

Add option in vehicle stats to choose what mileage metric to show #108

Closed
wants to merge 32 commits into from
Closed
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
8410674
Add vin field vehicle data
AlfHou Mar 8, 2022
c00c6bc
Map VIN number to db model from request model when creating vehicle
AlfHou Apr 28, 2022
ab94997
Add basic tests
djjudas21 May 17, 2022
966cac2
Add utils for converting imperial and metric
AlfHou Oct 15, 2022
2ecb113
Add mileage options to frontend
AlfHou Oct 15, 2022
c0db2c5
Calculate mileage based on mileageOption
AlfHou Oct 15, 2022
2d24c4b
Merge pull request #1 from djjudas21/ci
AlfHou Nov 26, 2022
afdfa31
Add vscode specific files to gitignore
AlfHou Nov 26, 2022
d3ce692
Merge branch 'master' into add-vin
AlfHou Nov 26, 2022
0b450dc
added translations
boerniee Jan 12, 2023
961ec30
set locale to browser locale
boerniee Jan 13, 2023
bb68c8c
translate units
boerniee Jan 13, 2023
5aabeda
update axios version fixes #104 (#4)
boerniee Jan 19, 2023
f9d24bc
Fix indentation in db migration
Jan 19, 2023
47810a8
Merge pull request #3 from AlfHou/add-vin
AlfHou Jan 19, 2023
311ac75
Update the package lock file
AlfHou Jan 22, 2023
e6e90d9
Merge pull request #9 from AlfHou/chore/update-package-lock
AlfHou Jan 22, 2023
19680b1
Remove the github action which ran npm tests
AlfHou Jan 24, 2023
0035897
Merge pull request #12 from AlfHou/bug/remove-npm-github-action
AlfHou Jan 24, 2023
6871a40
added not translated texts, changed translations
boerniee Jan 25, 2023
c588e34
translating fuelly import page
boerniee Jan 25, 2023
ee964a6
Fixed another translations
boerniee Jan 25, 2023
7d4b763
Merge branch 'master' into i18n
AlfHou Jan 25, 2023
ba27697
Merge pull request #5 from boerniee/i18n
AlfHou Jan 25, 2023
126aff7
Update workflow action for publishing to new docker hub repo
AlfHou Jan 24, 2023
08f2a35
Rename docker secret variable
AlfHou Jan 24, 2023
f96638d
Update readme with the correct url's and remove some specifics from f…
AlfHou Jan 24, 2023
a89ca5e
Update links in docker files to point to this repo
AlfHou Jan 25, 2023
9dab3d1
Point to this repo in ubuntu install docs
AlfHou Jan 25, 2023
4a55879
Update links in more info view in settings
AlfHou Jan 25, 2023
8e89484
Merge pull request #13 from AlfHou/chore/docker-push
AlfHou Jan 26, 2023
091cfdc
Merge branch 'master' into feat/state_mileage_option
AlfHou Jan 28, 2023
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
23 changes: 13 additions & 10 deletions .github/workflows/hub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: ci
name: Build docker image

on:
push:
branches: master
release:
types: [published]

jobs:
multi:
Expand All @@ -26,17 +26,20 @@ jobs:
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Parse the git tag
id: get_tag
run: echo ::set-output name=TAG::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Login to GitHub
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
Expand All @@ -49,7 +52,7 @@ jobs:
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache
tags: |
akhilrex/hammond:latest
akhilrex/hammond:1.0.0
ghcr.io/akhilrex/hammond:latest
ghcr.io/akhilrex/hammond:1.0.0
alfhou/hammond:latest
alfhou/hammond:${{ steps.get_tag.outputs.TAG }}
ghcr.io/alfhou/hammond:latest
ghcr.io/alfhou/hammond:${{ steps.get_tag.outputs.TAG }}
16 changes: 16 additions & 0 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [push, pull_request]
name: Test server
jobs:
test:
strategy:
matrix:
go-version: [1.17.x, 1.18.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- run: go test ./...
working-directory: server
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN npm run build


FROM alpine:latest
LABEL org.opencontainers.image.source="https://github.com/akhilrex/hammond"
LABEL org.opencontainers.image.source="https://github.com/alfhou/hammond"
ENV CONFIG=/config
ENV DATA=/assets
ENV UID=998
Expand Down
71 changes: 25 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
[![Contributors][contributors-shield]][contributors-url] [![Forks][forks-shield]][forks-url] [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![MIT License][license-shield]][license-url] [![LinkedIn][linkedin-shield]][linkedin-url]

<!-- PROJECT LOGO -->
<br />
<p align="center">
<!-- <a href="https://github.com/akhilrex/hammond">
<img src="images/logo.png" alt="Logo" width="80" height="80">
</a> -->

<h1 align="center" style="margin-bottom:0">Hammond</h1>
<p align="center">Current Version - 2022.07.06</p>

<p align="center">
A self-hosted vehicle expense tracking system with support for multiple users.
<br />
<a href="https://github.com/akhilrex/hammond"><strong>Explore the docs »</strong></a>
<a href="https://github.com/AlfHou/hammond"><strong>Explore the docs »</strong></a>
<br />
<br />
<!-- <a href="https://github.com/akhilrex/hammond">View Demo</a>
· -->
<a href="https://github.com/akhilrex/hammond/issues">Report Bug</a>
<a href="https://github.com/AlfHou/hammond/issues">Report Bug</a>
·
<a href="https://github.com/akhilrex/hammond/issues">Request Feature</a>
<a href="https://github.com/AlfHou/hammond/issues">Request Feature</a>
·
<a href="Screenshots.md">Screenshots</a>
</p>
Expand All @@ -44,18 +34,22 @@

## About The Project

Hammond is a self hosted vehicle management system to track fuel and other expenses related to all of your vehicles. It supports multiple users sharing multiple vehicles. It is the logical successor to Clarkson which has not been updated for quite some time now.

_Developers Note: This project is under active development which means I release new updates very frequently. It is recommended that you use something like [watchtower](https://github.com/containrrr/watchtower) which will automatically update your containers whenever I release a new version or periodically rebuild the container with the latest image manually._
Hammond is a self hosted vehicle management system to track fuel and other
expenses related to all of your vehicles.
It supports multiple users sharing multiple vehicles.
It is the logical successor to Clarkson which has not been updated for quite some time now.
This repo is again a fork of akhilrex's great [project](https://github.com/akhilrex/hammond).

__Also check out my other self-hosted, open-source solution - [Podgrab](https://github.com/akhilrex/podgrab) - Podcast download and archive manager and player.__
### Motivation and Developer Notes

I was looking for a fuel tracking system and stumbled upon Clarkson. Although it did most of what I needed it has not been updated for quite a lot of time. Since I had some bandwidth available as my previous open source project [Podgrab](http://github.com/akhilrex/podgrab) had become quite stable now, my first thought was to contribute to the Clarkson project only. I soon realized that the architecture that Clarkson had used was not really be that extensible now and would warrant a complete rewrite only. So I decided to build Hammond - The successor to Clarkson.
As mentioned, this project is a fork of
akhilrex's [project](https://github.com/akhilrex/hammond) which is no longer active.
To prevent the same from happeing to this project, we are seeking to add more
maintainers/collaborators who have access to merge PRs.

The current version of Hammond is written using GO for backend and Vuejs for the front end. Originally I had thought of using the same tech stack for both frontend and the backend so that it became easier for users and other developers to use, deploy and contribute. Which is why the first version of Hammond has a NestJS backend complete with all the bells and whistles (GraphQL, Prisma and what nots). But I eventually decided to rebuild the backend in GO just to keep the container size small. No matter how much you can optimize the sheer size of the node_modules will always add bulk to your containers. I host all my tools on my Raspberry Pi. It only makes sense to keep the container size as small as possible.
We are trying our best to update with new features and feedback is very welcome.

Also I had initially thought of a 2 container approach (1 for backend and 1 for the frontend) so that they can be independently maintained and updated. I eventually decided against this idea for the sake of simplicity. Although it is safe to assume that most self-hosters are fairly tech capable it still is much better to have a single container that you can fire and forget.
The project is written using Go for the backend and Vuejs for the front end.

![Product Name Screen Shot][product-screenshot] [More Screenshots](Screenshots.md)

Expand All @@ -79,7 +73,7 @@ Also I had initially thought of a 2 container approach (1 for backend and 1 for
- Save attachment against vehicles
- Quick Entries (take a photo of a receipt or pump screen to make entry later)
- Vehicle level and overall reporting
- Import from Fuelly (more apps coming soon)
- Import from Fuelly and Drivvo

## Installation

Expand All @@ -90,24 +84,25 @@ The easiest way to run Hammond is to run it as a docker container.
Simple setup without mounted volumes (for testing and evaluation)

```sh
docker run -d -p 3000:3000 --name=hammond akhilrex/hammond
docker run -d -p 3000:3000 --name=hammond alfhou/hammond
```

Binding local volumes to the container

```sh
docker run -d -p 3000:3000 --name=hammond -v "/host/path/to/assets:/assets" -v "/host/path/to/config:/config" akhilrex/hammond
docker run -d -p 3000:3000 --name=hammond -v "/host/path/to/assets:/assets" -v "/host/path/to/config:/config" alfhou/hammond
```

### Using Docker-Compose

Modify the docker compose file provided [here](https://github.com/akhilrex/hammond/blob/master/docker-compose.yml) to update the volume and port binding and run the following command
Modify the docker compose file provided [here](https://github.com/alfhou/hammond/blob/master/docker-compose.yml)
to update the volume and port binding and run the following command

```yaml
version: '2.1'
services:
hammond:
image: akhilrex/hammond
image: alfhou/hammond
container_name: hammond
volumes:
- /path/to/config:/config
Expand All @@ -123,7 +118,10 @@ services:

### Build from Source / Ubuntu Installation

Although personally I feel that using the docker container is the best way of using and enjoying something like hammond, a lot of people in the community are still not comfortable with using Docker and wanted to host it natively on their Linux servers. Follow the link below to get a guide on how to build hammond from source.
Although personally I feel that using the docker container is the best way of using
and enjoying something like hammond, a lot of people in the community are still not
comfortable with using Docker and wanted to host it natively on their Linux servers.
Follow the link below to get a guide on how to build hammond from source.

[Build from source / Ubuntu Guide](docs/ubuntu-install.md)

Expand Down Expand Up @@ -197,25 +195,6 @@ Distributed under the GPL-3.0 License. See `LICENSE` for more information.

## Contact

Akhil Gupta - [@akhilrex](https://twitter.com/akhilrex)

Project Link: [https://github.com/akhilrex/hammond](https://github.com/akhilrex/hammond)

<a href="https://www.buymeacoffee.com/akhilrex" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="width: 217px !important;height: 60px !important;" ></a>

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
Project Link: [https://github.com/AlfHou/hammond](https://github.com/AlfHou/hammond)

[contributors-shield]: https://img.shields.io/github/contributors/akhilrex/hammond.svg?style=flat-square
[contributors-url]: https://github.com/akhilrex/hammond/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/akhilrex/hammond.svg?style=flat-square
[forks-url]: https://github.com/akhilrex/hammond/network/members
[stars-shield]: https://img.shields.io/github/stars/akhilrex/hammond.svg?style=flat-square
[stars-url]: https://github.com/akhilrex/hammond/stargazers
[issues-shield]: https://img.shields.io/github/issues/akhilrex/hammond.svg?style=flat-square
[issues-url]: https://github.com/akhilrex/hammond/issues
[license-shield]: https://img.shields.io/github/license/akhilrex/hammond.svg?style=flat-square
[license-url]: https://github.com/akhilrex/hammond/blob/master/LICENSE
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/akhilrex
[product-screenshot]: images/screenshot.jpg
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "2.1"
services:
hammond:
image: akhilrex/hammond
image: alfhou/hammond
container_name: hammond
environment:
- JWT_SECRET=somethingverystrong
Expand Down
4 changes: 2 additions & 2 deletions docs/ubuntu-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Following steps will only work if Go and Node are installed and configured prope
## Clone from Git

``` bash
git clone --depth 1 https://github.com/akhilrex/hammond
git clone --depth 1 https://github.com/alfhou/hammond
```

## Build and Copy dependencies
Expand Down Expand Up @@ -110,7 +110,7 @@ sudo systemctl stop hammond.service
## Clone from Git

``` bash
git clone --depth 1 https://github.com/akhilrex/hammond
git clone --depth 1 https://github.com/alfhou/hammond
```

## Build and Copy dependencies
Expand Down
4 changes: 4 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*.out
*.db

# MS VSCode
.vscode
__debug_bin

# Dependency directories (remove the comment below to include it)
# vendor/
assets/*
Expand Down
4 changes: 2 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN go build -o ./app ./main.go

FROM alpine:latest

LABEL org.opencontainers.image.source="https://github.com/akhilrex/hammond"
LABEL org.opencontainers.image.source="https://github.com/alfhou/hammond"

ENV CONFIG=/config
ENV DATA=/assets
Expand All @@ -38,4 +38,4 @@ COPY dist ./dist

EXPOSE 3000

ENTRYPOINT ["./app"]
ENTRYPOINT ["./app"]
27 changes: 27 additions & 0 deletions server/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ func RandString(n int) string {
return string(b)
}

// A helper to convert from litres to gallon
func LitreToGallon(litres float32) float32 {
gallonConversionFactor := 0.21997
return litres * float32(gallonConversionFactor);
}

// A helper to convert from gallon to litres
func GallonToLitre(gallons float32) float32 {
litreConversionFactor := 3.785412
return gallons * float32(litreConversionFactor);
}


// A helper to convert from km to miles
func KmToMiles(km float32) float32 {
kmConversionFactor := 0.62137119
return km * float32(kmConversionFactor);
}

// A helper to convert from miles to km
func MilesToKm(miles float32) float32 {
milesConversionFactor := 1.609344
return miles * float32(milesConversionFactor);
}



// A Util function to generate jwt_token which can be used in the request header
func GenToken(id string, role db.Role) (string, string) {
jwt_token := jwt.New(jwt.GetSigningMethod("HS256"))
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func userLogin(c *gin.Context) {
Email: user.Email,
Token: token,
RefreshToken: refreshToken,
Role: user.RoleDetail().Long,
Role: user.RoleDetail().Key,
}
c.JSON(http.StatusOK, response)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func refresh(c *gin.Context) {
Email: user.Email,
Token: token,
RefreshToken: refreshToken,
Role: user.RoleDetail().Long,
Role: user.RoleDetail().Key,
}
c.JSON(http.StatusOK, response)
} else {
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getMileageForVehicle(c *gin.Context) {
return
}

fillups, err := service.GetMileageByVehicleId(searchByIdQuery.Id, model.Since)
fillups, err := service.GetMileageByVehicleId(searchByIdQuery.Id, model.Since, model.MileageOption)
if err != nil {
c.JSON(http.StatusUnprocessableEntity, common.NewError("getMileageForVehicle", err))
return
Expand Down
1 change: 1 addition & 0 deletions server/db/dbModels.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Vehicle struct {
Base
Nickname string `json:"nickname"`
Registration string `json:"registration"`
VIN string `json:"vin"`
Make string `json:"make"`
Model string `json:"model"`
YearOfManufacture int `json:"yearOfManufacture"`
Expand Down
Loading