Skip to content

Commit

Permalink
Merge pull request #20 from felix1251/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
felix1251 authored Mar 16, 2024
2 parents 48633b3 + 2ece274 commit aeec5f4
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 92 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ docker compose -f docker-compose.dev.yml up -d
> We control all the commands inside our time_tracker_container.
> All logic or changes will reflect in our project directory because volume are shared between our container
Local server port (this is served from our docker container)

```
http://127.0.0.1:3000/
```

Open rails project container

```
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class TagsController < ApplicationController
def index; end

def create; end

def update; end

def destroy; end
end
18 changes: 1 addition & 17 deletions app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
# frozen_string_literal: true

class TracksController < ApplicationController
before_action :set_track, only: %i[show edit update destroy]

# GET /tracks or /tracks.json
def index
@tracks = Track.all
end

# GET /tracks/1 or /tracks/1.json
def show; end

# GET /tracks/new
def new
@track = Track.new
end

# GET /tracks/1/edit
def edit; end
before_action :set_track, only: %i[update destroy]

# POST /tracks or /tracks.json
def create
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/tags_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module TagsHelper
end
2 changes: 2 additions & 0 deletions app/javascript/controllers/countdown_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default class extends Controller {

connect() {
this.secondsUntilEndTime = Number(this.countdownTarget.dataset.secondsUntilEndTime)

// update coundown every one second
this.countdown = setInterval(this.countdown.bind(this), 1000);
}

Expand Down
2 changes: 2 additions & 0 deletions app/javascript/controllers/tracks_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export default class extends Controller {
// Create an observer instance
const observer = new MutationObserver(() => this.calculate());

// detect if chiild element is changing
observer.observe(this.element, { childList: true });
}

calculate() {
if(this.itemTargets.length == 0){
this.element.remove()
return;
// remove element if no chuld element
}

this.totalSeconds = 0
Expand Down
5 changes: 3 additions & 2 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Track < ApplicationRecord

validates :started_at, comparison: { less_than_or_equal_to: :ended_at }, if: :ended_at

before_save :capture_total_hour, if: :ended_at
# capture total time for easier query of total time using group_by
before_save :capture_total_time, if: :ended_at

def countdown?
ended_at.blank?
Expand All @@ -27,7 +28,7 @@ def date_started

private

def capture_total_hour
def capture_total_time
self.total_seconds = ended_at.to_i - started_at.to_i
end
end
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/_sidebar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.flex.flex-col.mt-2
= render SidebarItemComponent.new path: root_path, name: "Manual", fa_icon: "keyboard"
= render SidebarItemComponent.new path: root_path(mode: "timer"), name: "Timer", fa_icon: "clock-rotate-left"
= render SidebarItemComponent.new path: tags_path, name: "Tags", fa_icon: "tag"
= render SidebarItemComponent.new path: reports_path, name: "Reports", fa_icon: "file"
.py-4.px-4.grid.gap-2.sticky.bottom-0.bg-white.z-10
%span.truncate.flex.items-center.gap-2
Expand Down
4 changes: 2 additions & 2 deletions app/views/reports/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.px-8.py-5.bg-white.rounded.flex.flex-col.gap-2.shadow.border
%h1.text-zinc-600 Total hours spent
%span.font-medium.text-xl
= seconds_to_hms(current_user.tracks.sum(:total_seconds))
= seconds_to_hms(current_user.tracks.complete.sum(:total_seconds))
.px-8.py-5.bg-white.rounded.flex.flex-col.gap-2.shadow.border
%h1.text-zinc-600 Total tracks
%span.font-medium.text-xl
= current_user.tracks.count
= current_user.tracks.complete.count
Empty file added app/views/tags/_form.html.haml
Empty file.
3 changes: 3 additions & 0 deletions app/views/tags/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.margin-max-screen.py-8.grid.gap-3.relative
%h1 Tags#index
%p Find me in app/views/tags/index.html.haml
19 changes: 0 additions & 19 deletions app/views/tracks/_form.html.haml

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/tracks/edit.html.haml

This file was deleted.

25 changes: 0 additions & 25 deletions app/views/tracks/index.html.haml

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/tracks/new.html.haml

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/tracks/show.html.haml

This file was deleted.

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

resources :tracks, only: %i[update create destroy]
resources :reports, only: :index
resources :tags, only: %i[index update create destroy]
end

# == Route Map
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/tags_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'test_helper'

class TagsControllerTest < ActionDispatch::IntegrationTest
test 'should get index' do
get tags_index_url
assert_response :success
end

test 'should get create' do
get tags_create_url
assert_response :success
end

test 'should get update' do
get tags_update_url
assert_response :success
end

test 'should get destroy' do
get tags_destroy_url
assert_response :success
end
end

0 comments on commit aeec5f4

Please sign in to comment.