mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-04-02 09:51:57 -04:00
initial commit
This commit is contained in:
51
app/controllers/stopwatch_timers_controller.rb
Normal file
51
app/controllers/stopwatch_timers_controller.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
class StopwatchTimersController < ApplicationController
|
||||
helper :timelog
|
||||
|
||||
before_action :require_login
|
||||
before_action :find_optional_data, only: %i(new create)
|
||||
|
||||
def new
|
||||
@time_entry = new_time_entry
|
||||
respond_to :js
|
||||
end
|
||||
|
||||
def create
|
||||
@time_entry = new_time_entry
|
||||
@time_entry.safe_attributes = params[:time_entry]
|
||||
@result = Stopwatch::StartTimer.new(@time_entry).call
|
||||
unless @result.success?
|
||||
if @result.error == :unauthorized
|
||||
render_403
|
||||
else
|
||||
render_error status: 422, message: "could not start timer: #{@result.error}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def new_time_entry
|
||||
TimeEntry.new(project: @project, issue: @issue,
|
||||
user: User.current, spent_on: User.current.today)
|
||||
end
|
||||
|
||||
def find_optional_data
|
||||
if params[:issue_id].present?
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
elsif params[:project_id].present?
|
||||
@project = Project.find(params[:project_id])
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
||||
11
app/views/stopwatch_timers/_edit.html.erb
Normal file
11
app/views/stopwatch_timers/_edit.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<h3 class="title"><%= l(:label_spent_time) %></h3>
|
||||
|
||||
<%= labelled_form_for @time_entry, url: stopwatch_path, remote: true do |f| %>
|
||||
<% @time_entry.hours ||= 0 %>
|
||||
<%= render partial: 'timelog/form', locals: { f: f } %>
|
||||
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= submit_tag l(:button_cancel), name: nil, onclick: "hideModal(this);", type: 'button' %>
|
||||
</p>
|
||||
<% end %>
|
||||
12
app/views/stopwatch_timers/_new.html.erb
Normal file
12
app/views/stopwatch_timers/_new.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<h3 class="title"><%= l(:button_log_time) %></h3>
|
||||
|
||||
<%= labelled_form_for @time_entry, url: stopwatch_timer_path, method: :post, remote: true do |f| %>
|
||||
<% @time_entry.hours ||= 0 %>
|
||||
<%= render partial: 'timelog/form', locals: { f: f } %>
|
||||
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= submit_tag l(:button_cancel), name: nil, onclick: "hideModal(this);", type: 'button' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
2
app/views/stopwatch_timers/new.js.erb
Normal file
2
app/views/stopwatch_timers/new.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
$('#ajax-modal').html('<%= j render partial: 'stopwatch_timers/new' %>');
|
||||
showModal('ajax-modal', '600px');
|
||||
Reference in New Issue
Block a user