initial commit

This commit is contained in:
Jens Kraemer
2020-04-22 18:03:56 +08:00
commit 70257cdee0
16 changed files with 331 additions and 0 deletions

View 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

View 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 %>

View 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 %>

View File

@@ -0,0 +1,2 @@
$('#ajax-modal').html('<%= j render partial: 'stopwatch_timers/new' %>');
showModal('ajax-modal', '600px');