Browse Source

Added Time entries index page

denney-fix-saving-dates
Jason Denney 11 years ago
parent
commit
4224f0de40
  1. 1
      app/assets/javascripts/application.js
  2. 4
      app/controllers/time_entries_controller.rb
  3. 8
      app/models/time_entry.rb
  4. 22
      app/views/time_entries/index.haml

1
app/assets/javascripts/application.js

@ -13,6 +13,7 @@
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require twitter/bootstrap/bootstrap-button //= require twitter/bootstrap/bootstrap-button
//= require twitter/bootstrap/bootstrap-modal
//= require utils //= require utils
//= require bootstrap-datepicker //= require bootstrap-datepicker
//= require bootstrap-timepicker //= require bootstrap-timepicker

4
app/controllers/time_entries_controller.rb

@ -9,6 +9,8 @@ class TimeEntriesController < AuthenticatedController
end end
def index 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
end end

8
app/models/time_entry.rb

@ -12,4 +12,12 @@ class TimeEntry < ActsAsLoggable::Log
copy_action_id: 4 copy_action_id: 4
}) })
end end
def duration
end_date - start_date
end
def duration_in_hours
(duration / 1.hour).round(2)
end
end end

22
app/views/time_entries/index.haml

@ -5,5 +5,27 @@
%p Total Hours Worked: #{@hours_worked} %p Total Hours Worked: #{@hours_worked}
%p Total Credits Available: #{@credits_available} %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 %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

Loading…
Cancel
Save