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 spend time to page title #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions app/controllers/time_loggers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def render_menu
render partial: 'embed_menu'
end

def current_timer
@time_logger = current
if @time_logger.nil?
render json: {}
else
render json: { "time_spent" => @time_logger.time_spent_to_s }
end
end

protected

def current
Expand Down
17 changes: 17 additions & 0 deletions app/views/time_loggers/_update_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ $.ajax({
$('#time-logger-menu').html(data);
},
});

$.ajax({
url:"<%=url_for :controller => '/time_loggers',:action => 'current_timer' %>",
cache:false,
success: function(data){
if (!data.hasOwnProperty('time_spent')) {
return;
}
var r = /^([0-9]+:[0-9]+) (.*)$/g;
var match = r.exec(document.title);
if (match) {
document.title = data['time_spent'] + ' ' + match[2];
} else {
document.title = data['time_spent'] + ' ' + document.title;
}
},
});
}
<% end %>

Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
match 'time_loggers/suspend', to: 'time_loggers#suspend', via: %i[get post]
match 'time_loggers/resume', to: 'time_loggers#resume', via: %i[get post]
match 'time_loggers/render_menu', to: 'time_loggers#render_menu', via: %i[get post]
match 'time_loggers/current_timer', to: 'time_loggers#current_timer', via: %i[get post]
match 'time_loggers/add_status_transition', to: 'time_loggers#add_status_transition', via: %i[get post]
match 'time_loggers/delete_status_transition', to: 'time_loggers#delete_status_transition', via: %i[get post]
match 'time_loggers/show_report', to: 'time_loggers#show_report', via: %i[get post]
Expand All @@ -18,6 +19,7 @@
match 'time_loggers/suspend', to: 'time_loggers#suspend'
match 'time_loggers/resume', to: 'time_loggers#resume'
match 'time_loggers/render_menu', to: 'time_loggers#render_menu'
match 'time_loggers/current_timer', to: 'time_loggers#current_timer'
match 'time_loggers/add_status_transition', to: 'time_loggers#add_status_transition'
match 'time_loggers/delete_status_transition', to: 'time_loggers#delete_status_transition'
match 'time_loggers/show_report', to: 'time_loggers#show_report'
Expand Down