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

Develop #20

Open
wants to merge 7 commits 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
11 changes: 6 additions & 5 deletions app/views/issues/_open_date_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<% if User.current.allowed_to?(:edit_issues, @project) &&
Setting.plugin_redmine_issue_open_date['freezed_statuses'].include?(issue.status_id.to_s) %>
<%= stylesheet_link_tag 'jquery.datetimepicker.min', plugin: 'redmine_issue_open_date' %>
<%= javascript_include_tag 'jquery.datetimepicker.full.min', plugin: 'redmine_issue_open_date' %>
<%= javascript_include_tag 'issue_open_date', plugin: 'redmine_issue_open_date' %>


<style type="text/css">
#open_date_area select {
width: auto;
}
</style>

<p id="open_date_area">
<%= form.label :open_date %>
<span style="display: inline-block;">
<%= form.date_select :open_date, default: User.current.issue_open_time , minute_step: 5 %>
</span>
<span style="display: inline-block;">
<%= form.time_select :open_date, default: User.current.issue_open_time , minute_step: 5, ignore_date: true %>
<%= form.text_field :open_date, value: (issue.open_date || User.current.suggested_issue_open_time).strftime('%d.%m.%Y %H:%M'), class: 'datetimepicker' %>
</span>
</p>

Expand Down
4 changes: 2 additions & 2 deletions app/views/issues/_open_date_field_bulk.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<p id="open_date_area">
<%= label_tag t('field_open_date') %>
<span style="display: inline-block;">
<%= date_select :issue, :open_date, default: User.current.issue_open_time , minute_step: 5 %>
<%= date_select :issue, :open_date, default: User.current.suggested_issue_open_time , minute_step: 5 %>
</span>
<span style="display: inline-block;">
<%= time_select :issue, :open_date, default: User.current.issue_open_time , minute_step: 5, ignore_date: true %>
<%= time_select :issue, :open_date, default: User.current.suggested_issue_open_time , minute_step: 5, ignore_date: true %>
</span>
</p>

Expand Down
8 changes: 8 additions & 0 deletions assets/javascripts/issue_open_date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$(document).ready(function () {
jQuery.datetimepicker.setLocale('ru');
$('#issue_open_date').datetimepicker({
format: 'd.m.Y H:i',
step: 5,
minDate: '-1970/01/01'
});
});
1 change: 1 addition & 0 deletions assets/javascripts/jquery.datetimepicker.full.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assets/stylesheets/jquery.datetimepicker.min.css

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions lib/issue_open_date/hook_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,4 @@ class IssueOpenDateHookListener < Redmine::Hook::ViewListener
render_on :view_issues_bulk_edit_details_bottom, partial: 'issues/open_date_field_bulk'
render_on :view_issues_show_details_bottom, partial: 'issues/open_date'
render_on :view_my_account, partial: 'my/open_date'

def controller_issues_edit_before_save(context = {})
assign_issue_attributes(context)
end

def controller_issues_bulk_edit_before_save(context = {})
assign_issue_attributes(context)
end

def controller_issues_new_before_save(context = {})
assign_issue_attributes(context)
end

private

def assign_issue_attributes(context)
params, issue = context[:params].to_unsafe_h, context[:issue]
Time.use_zone(User.current.time_zone || Time.now.localtime.utc_offset / 3600) do
issue.assign_attributes(params[:issue].slice(*(1..5).map { |i| "open_date(#{i}i)" }))
end
end
end
10 changes: 8 additions & 2 deletions lib/issue_open_date/patches/issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ def self.included(base) # :nodoc:

before_save :clear_open_date

safe_attributes :open_date

def open_date
super.in_time_zone(User.current.time_zone) if super
end

def open_date=(value)
user = User.current
return super unless value && user.logged? && user.time_zone
super(value.to_datetime.change(offset: user.time_zone.formatted_offset))
end

private

def clear_open_date
if self.open_date.present? and !self.closed?
self.open_date = nil
end
end

end
end

end
end
Issue.send(:include, IssueOpenDate::IssuePatch)
14 changes: 5 additions & 9 deletions lib/issue_open_date/patches/user_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
def self.included(base)
(1..5).each { |i| base.send(:safe_attributes, "issue_open_time(#{i}i)") }
end
end
)

User.send(:prepend,
Module.new do
def issue_open_time
def suggested_issue_open_time
time =
begin
tomorrow = Date.tomorrow
super ? super.change(year: tomorrow.year, month: tomorrow.month, day: tomorrow.day) : tomorrow.to_time
end
begin
tomorrow = Date.tomorrow
issue_open_time ? issue_open_time.change(year: tomorrow.year, month: tomorrow.month, day: tomorrow.day) : tomorrow.to_time
end
time_zone ? time.to_datetime.change(offset: time_zone.formatted_offset) : time.to_datetime
end
end
Expand Down