Skip to content

Commit

Permalink
Merge pull request #14 from centosadmin/develop
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
vladislav-yashin committed Apr 5, 2018
2 parents 704bc7e + f29afbb commit 42214b2
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.2.0

* Add issue open time to user account options
* Add sidekiq-cron support

# 0.1.3

* Use datetime for reopen schedule
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,28 @@ Specify in the plugin settings which tickets will be considered as _**New**_ or

## CRON

Plugin supports two ways of scheduling jobs:

### Whenever

Perform this to add tasks to CRON:

```
bundle exec whenever -i redmine_issue_open_date -f plugins/redmine_issue_open_date/config/schedule.rb
bundle exec whenever -i redmine_issue_open_date -f *path_to_your_app*/plugins/redmine_issue_open_date/config/schedule.rb
```

Perform this to remove tasks from CRON:

```
bundle exec whenever -c redmine_issue_open_date -f plugins/redmine_issue_open_date/config/schedule.rb
bundle exec whenever -c redmine_issue_open_date -f *path_to_your_app*/plugins/redmine_issue_open_date/config/schedule.rb
```

### Sidekiq-cron

Run this task to inititalize sidekiq-cron job:

```
bundle exec rake issue_open_date:sidekiq:init RAILS_ENV=production
```

Note that you need to have [sidekiq-cron](https://github.com/ondrejbartas/sidekiq-cron) gem installed.
18 changes: 16 additions & 2 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,28 @@ bundle exec rake redmine:plugins:migrate

## CRON

Плагин поддерживает 2 способа запуска задачи по расписанию:

### Whenever

Для добавления ежедневной задачи в CRON:

```
bundle exec whenever -i redmine_issue_open_date -f plugins/redmine_issue_open_date/config/schedule.rb
bundle exec whenever -i redmine_issue_open_date -f *путь к приложению*/plugins/redmine_issue_open_date/config/schedule.rb
```

Для очистки CRON:

```
bundle exec whenever -c redmine_issue_open_date -f plugins/redmine_issue_open_date/config/schedule.rb
bundle exec whenever -c redmine_issue_open_date -f *путь к приложению*/plugins/redmine_issue_open_date/config/schedule.rb
```

### Sidekiq-cron

Запустите для добавления задачи в sidekiq-cron:

```
bundle exec rake issue_open_date:sidekiq:init RAILS_ENV=production
```

Для работы в этом случае необходим gem [sidekiq-cron](https://github.com/ondrejbartas/sidekiq-cron).
13 changes: 11 additions & 2 deletions app/views/issues/_open_date_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<% if User.current.allowed_to?(:edit_issues, @project) &&
Setting.plugin_redmine_issue_open_date['freezed_statuses'].include?(issue.status_id.to_s) %>
<style type="text/css">
#open_date_area select {
width: auto;
}
</style>

<p id="open_date_area">
<%= form.label :open_date %>
<% current_time = Time.now %>
<%= form.datetime_select :open_date, default: current_time - (current_time.min % 5).minutes, minute_step: 5 %>
<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 %>
</span>
</p>

<% end %>
4 changes: 4 additions & 0 deletions app/views/my/_open_date.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>
<%= label :user, :issue_open_time, l(:field_issue_open_time) %>
<%= form.time_select :issue_open_time, { minute_step: 5, include_blank: true }, style: 'width: auto' %>
</p>
18 changes: 18 additions & 0 deletions app/workers/issue_open_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class IssueOpenWorker
include Sidekiq::Worker if Gem.loaded_specs.key?('sidekiq')

def perform
log = Rails.env.production? ? Logger.new(Rails.root.join('log/issue_open_date', 'switch-task.log')) : Logger.new(STDOUT)

freezed_status_ids = Setting.plugin_redmine_issue_open_date['freezed_statuses'] || []
open_status_id = Setting.plugin_redmine_issue_open_date['open_status']

Issue.where('status_id IN(?) AND open_date <= ?', freezed_status_ids, Time.now).find_each do |issue|
log.debug issue.inspect
issue.init_journal(User.anonymous)
issue.status_id = open_status_id
issue.open_date = nil
issue.save
end
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
en:
field_open_date: Open date
field_issue_open_time: Issue open time
issue_open_date:
freezed_statuses: 'Freezed statuses'
open_status: 'Open with status'
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ru:
field_open_date: Открыть заново
field_issue_open_time: Время открытия задач
issue_open_date:
freezed_statuses: 'Статус "Заморожена"'
open_status: 'Открывать со статусом'
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/003_add_issue_open_time_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIssueOpenTimeToUsers < ActiveRecord::Migration
def change
add_column :users, :issue_open_time, :time
end
end
3 changes: 2 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
require 'redmine'
require_dependency 'issue_open_date/hook_listener'
require_dependency 'issue_open_date/patches/issue_patch'
require_dependency 'issue_open_date/patches/user_patch'

Redmine::Plugin.register :redmine_issue_open_date do
name 'Redmine Issue Open Date plugin'
url 'https://github.com/centosadmin/redmine_issue_open_date'
description 'This is a plugin for Redmine which open freezed issues with specified oped date'
version '0.1.3'
version '0.2.0'
author 'Southbridge'
author_url 'https://southbridge.io'
settings(default: {
Expand Down
3 changes: 2 additions & 1 deletion lib/issue_open_date/hook_listener.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class IssueOpenDateHookListener < Redmine::Hook::ViewListener
render_on :view_issues_form_details_bottom, partial: 'issues/open_date_field'
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 = {})
return unless User.current.allowed_to?(:edit_issues, context[:issue].project)

Time.use_zone(User.current.time_zone) do
Time.use_zone(User.current.time_zone || Time.now.localtime.utc_offset / 3600) do
context[:issue].assign_attributes(context[:params][:issue].slice(*(1..5).map { |i| "open_date(#{i}i)" }))
end
end
Expand Down
9 changes: 0 additions & 9 deletions lib/issue_open_date/hooks/update_hook.rb

This file was deleted.

20 changes: 20 additions & 0 deletions lib/issue_open_date/patches/user_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
User.send(:include,
Module.new do
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
time =
begin
tomorrow = Date.tomorrow
super ? super.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
)
20 changes: 9 additions & 11 deletions lib/tasks/issue_open_date.rake
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
namespace :issue_open_date do
task :switch => :environment do
log = Rails.env.production? ? Logger.new(Rails.root.join('log/issue_open_date', 'switch-task.log')) : Logger.new(STDOUT)

freezed_status_ids = Setting.plugin_redmine_issue_open_date['freezed_statuses'] || []
open_status_id = Setting.plugin_redmine_issue_open_date['open_status']
IssueOpenWorker.new.perform
end

Issue.where('status_id IN(?) AND open_date <= ?', freezed_status_ids, Time.now).find_each do |issue|
log.debug issue.inspect
issue.init_journal(User.current)
issue.status_id = open_status_id
issue.open_date = nil
issue.save
namespace :sidekiq do
task init: :environment do
unless Gem.loaded_specs.key?('sidekiq-cron')
puts 'sidekiq-cron not found!'
next
end
Sidekiq::Cron::Job.create(name: 'issue_open_job', cron: '*/5 * * * *', class: 'IssueOpenWorker')
end

end
end

0 comments on commit 42214b2

Please sign in to comment.