From 4224f0de409a446fdbf4bdc7d27caaf3714d3752 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sun, 27 Apr 2014 18:59:50 -0400 Subject: [PATCH] Added Time entries index page --- app/assets/javascripts/application.js | 1 + app/controllers/time_entries_controller.rb | 4 +++- app/models/time_entry.rb | 8 ++++++++ app/views/time_entries/index.haml | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 624d531..019f687 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,6 +13,7 @@ //= require jquery //= require jquery_ujs //= require twitter/bootstrap/bootstrap-button +//= require twitter/bootstrap/bootstrap-modal //= require utils //= require bootstrap-datepicker //= require bootstrap-timepicker diff --git a/app/controllers/time_entries_controller.rb b/app/controllers/time_entries_controller.rb index ce9913d..e019dc9 100644 --- a/app/controllers/time_entries_controller.rb +++ b/app/controllers/time_entries_controller.rb @@ -9,6 +9,8 @@ class TimeEntriesController < AuthenticatedController end def index - + @user_time_entries = TimeEntry.where(loggable_id: current_user.id) + @credits_available = current_user.total_credits + @hours_worked = current_user.total_hours end end diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 1fbbc7a..af86b09 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -12,4 +12,12 @@ class TimeEntry < ActsAsLoggable::Log copy_action_id: 4 }) end + + def duration + end_date - start_date + end + + def duration_in_hours + (duration / 1.hour).round(2) + end end diff --git a/app/views/time_entries/index.haml b/app/views/time_entries/index.haml index e40505f..ca3c142 100644 --- a/app/views/time_entries/index.haml +++ b/app/views/time_entries/index.haml @@ -5,5 +5,27 @@ %p Total Hours Worked: #{@hours_worked} %p Total Credits Available: #{@credits_available} +%table.table + %tbody + - @user_time_entries.each do |entry| + %tr + %td #{entry.start_date.to_date.to_formatted_s(:rfc822)} + %td #{entry.duration_in_hours} + %td #{truncate(entry.description)} + %td + %button{ class: "btn icon-remove btn-danger", role: "button", "data-toggle" => "modal", "data-target" => "#confirmation" } + %a{class: "btn btn-lg btn-block btn-primary", href: new_time_entry_path } Add Time Entry +.modal{ id: "confirmation", class: "hide", role: "dialog", "aria-labelledby" => "confirmation_title", "aria-hidden" => "true", tabindex: -1 } + .modal-header + %button{ class: "close", "data-dismiss" => "modal", "aria-hidden" => "true"}x + %h4{ id: "confirmation_title" } header + .modal-body + Are you sure? + .modal-footer + %button{ class: "btn", "data-dismiss" => "modal", "aria-hidden" => "true"} Close + %button{ class: "btn btn-primary" } Delete + + +