-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/start-stop-ticket'
- Loading branch information
Showing
28 changed files
with
562 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# base class for stopwatch controllers | ||
class StopwatchController < ApplicationController | ||
helper :timelog, :custom_fields | ||
|
||
before_action :require_login | ||
|
||
private | ||
|
||
def authorize_edit_time | ||
@time_entry.editable_by?(User.current) or deny_access | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class StopwatchIssueTimersController < StopwatchController | ||
before_action :find_issue | ||
before_action :authorize_log_time | ||
|
||
def start | ||
t = Stopwatch::IssueTimer.new(issue: @issue) | ||
if t.running? | ||
head 422; return | ||
end | ||
|
||
time_entry = User.current.todays_time_entry_for(@issue) | ||
if time_entry.new_record? | ||
sys_default_activity = time_entry.activity | ||
time_entry.activity = Stopwatch.default_activity_for time_entry | ||
end | ||
|
||
r = Stopwatch::StartTimer.new(time_entry).call | ||
if r.success? | ||
@started_time_entry = time_entry | ||
render status: :created | ||
else | ||
@time_entry = time_entry | ||
# in case the setting is 'always ask', still preset the form to the global default | ||
@time_entry.activity ||= sys_default_activity | ||
@time_entry.errors.clear | ||
render status: :ok | ||
end | ||
end | ||
|
||
def stop | ||
r = Stopwatch::StopTimer.new.call | ||
unless r.success? | ||
logger.error "unable to stop timer" | ||
head 422; return | ||
end | ||
end | ||
|
||
private | ||
|
||
def authorize_log_time | ||
User.current.allowed_to?(:log_time, @project) or deny_access | ||
end | ||
|
||
def find_issue | ||
@issue = Issue.find params[:issue_id] | ||
@project = @issue.project | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p> | ||
<label for="settings_default_activity"><%= t '.label_default_activity' %> </label> | ||
<%= select_tag 'settings[default_activity]', options_from_collection_for_select( [['always_ask', t('.label_always_ask')], ['system', t('.label_system')]] + TimeEntryActivity.system.active.to_a.pluck(:id, :name), :first, :last, Stopwatch.settings['default_activity'] ) %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<h3 class="title"><%= l(:button_log_time) %> - <%= format_date User.current.today %> - <%= "#{@issue.tracker} #{@issue.id}: #{truncate @issue.subject}" %></h3> | ||
|
||
<%= labelled_form_for @time_entry, url: stopwatch_timers_path, method: :post, remote: true do |f| %> | ||
<% @time_entry.hours ||= 0 %> | ||
<%= f.hidden_field :issue_id, value: @issue.id %> | ||
|
||
<fieldset class="box tabular"> | ||
<legend><%= t 'stopwatch_timers.entry_form.legend_new' %></legend> | ||
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p> | ||
<p><%= f.text_field :comments, :size => 100, :maxlength => 1024, :required => Setting.timelog_required_fields.include?('comments') %></p> | ||
<% @time_entry.custom_field_values.each do |value| %> | ||
<p><%= custom_field_tag_with_label :time_entry, value %></p> | ||
<% end %> | ||
</fieldset> | ||
|
||
<p class="buttons"> | ||
<%= submit_tag l(:button_create) %> | ||
</p> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% if @started_time_entry %> | ||
contextMenuHide(); | ||
window.stopwatch.timerStarted( | ||
<%= raw Stopwatch::Timer.new(User.current).to_json %> | ||
); | ||
<% else %> | ||
$('#ajax-modal').html('<%= j render partial: 'new' %>'); | ||
showModal('ajax-modal', '700px'); | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
contextMenuHide(); | ||
window.stopwatch.updateStartStopLink( | ||
'#stopwatch_stop_timer_<%= @issue.id %>', | ||
'<%= j Stopwatch::IssueLinks.new(@issue).start_timer %>' | ||
); | ||
window.stopwatch.timerStopped(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
hideModal(); | ||
window.stopwatch.highlightRunningTimer( | ||
window.stopwatch.timerStarted( | ||
<%= raw Stopwatch::Timer.new(User.current).to_json %> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$('#stopwatch_time_entry_activity_id').html('<%= escape_javascript options_for_select(activity_collection_for_select_options(@time_entry), @time_entry.activity_id) %>'); | ||
$('#stopwatch_time_entry_issue').html('<%= escape_javascript link_to_issue(@time_entry.issue) if @time_entry.issue.try(:visible?) %>'); | ||
$('#stopwatch_time_entry_project_id').html('<%= escape_javascript project_tree_options_for_select(Project.allowed_to(:log_time).to_a, :selected => @time_entry.project, :include_blank => true) %>'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
resources :stopwatch_timers, only: %i(new create edit update) do | ||
collection do | ||
get :current | ||
post :update_form | ||
end | ||
member do | ||
put :start | ||
put :stop | ||
end | ||
end | ||
|
||
scope 'issues/:issue_id' do | ||
post 'timer/start', to: 'stopwatch_issue_timers#start', as: :start_issue_timer | ||
post 'timer/stop', to: 'stopwatch_issue_timers#stop', as: :stop_issue_timer | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.