redmine_refresh 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redmine_refresh.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 jbbarth
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Redmine Refresh plugin
2
+ ======================
3
+
4
+ This plugins adds an automatic refresh on "Issues" lists and "My Page".
5
+
6
+ Screenshot
7
+ ----------
8
+
9
+ With this plugin you'll have a clickable link on these pages for enabling/disabling automatic refresh. Here's an example on an Issues list:
10
+
11
+ ![redmine_refresh screenshot](http://jbbarth.com/screenshots/redmine_refresh.png)
12
+
13
+ Installation
14
+ ------------
15
+
16
+ This plugin is compatible with Redmine 2.1.x and 2.2.x, and should be compatible with future versions.
17
+
18
+ Add this line to your redmine's Gemfile.local:
19
+
20
+ gem 'redmine_refresh'
21
+
22
+ And then execute:
23
+
24
+ $ bundle install
25
+
26
+ And restart your Redmine instance.
27
+
28
+ This gem aims at working inside a Redmine instance. Any other usage is discouraged.
29
+
30
+ Note that general instructions for plugins [here](http://www.redmine.org/wiki/redmine/Plugins) don't apply here.
31
+
32
+
33
+ Contributing
34
+ ------------
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ Deface::Override.new :virtual_path => 'issues/index',
2
+ :original => '402b3096154c5706049c1de2f9fedeaa63f6b618',
3
+ :name => 'add-refresh-link-to-issues-list',
4
+ :insert_top => 'div.contextual',
5
+ :partial => 'redmine_refresh/refresher'
@@ -0,0 +1,5 @@
1
+ Deface::Override.new :virtual_path => 'my/page',
2
+ :original => '7b02b984dabd756a62959aeea9c05db9d378bf7a',
3
+ :name => 'add-refresh-link-to-my-page',
4
+ :insert_top => 'div.contextual',
5
+ :partial => 'redmine_refresh/refresher'
@@ -0,0 +1,51 @@
1
+ <%
2
+ interval = RedmineRefresh.refresh_interval_for(User.current, params[:refresh])
3
+ should_be_refreshed = RedmineRefresh.refresh_status_for_controller(User.current, controller.controller_name)
4
+ should_be_refreshed ||= params[:refresh].present?
5
+ should_be_refreshed = false if params[:norefresh]
6
+ RedmineRefresh.save_refresh_status_for_controller(User.current, controller.controller_name, should_be_refreshed)
7
+ %>
8
+ <script type="text/javascript">
9
+ //<![CDATA[
10
+ //ADAPTED FROM:
11
+ //http://www.dynamicdrive.com/dynamicindex6/refresh.htm
12
+
13
+ //configure refresh interval (in seconds)
14
+ var countDownTime = <%= interval + 1 %>;
15
+ var counter;
16
+
17
+ function countDown() {
18
+ countDownTime--;
19
+ $('#refresher_seconds').html(countDownTime);
20
+ //refresh
21
+ if (countDownTime <= 0) {
22
+ countDownTime = <%= interval %>
23
+ clearTimeout(counter);
24
+ window.location.reload();
25
+ } else {
26
+ counter = setTimeout("countDown()", 1000);
27
+ }
28
+ }
29
+
30
+ function stopCountDown(url) {
31
+ clearTimeout(counter);
32
+ window.location.href = url
33
+ }
34
+
35
+ function startCountDown(url) {
36
+ window.location.href = url
37
+ }
38
+
39
+ <% if should_be_refreshed %>
40
+ $(function() { countDown(); })
41
+ <% end %>
42
+ //]]>
43
+ </script>
44
+
45
+ <% opts = {:class => 'icon icon-reload', :id => 'refresher'} %>
46
+ <% if should_be_refreshed %>
47
+ <%= link_to_function l(:refresh_in, content_tag(:span, interval, :id => 'refresher_seconds')).html_safe,
48
+ "startCountDown('#{url_for(params.merge(:norefresh => 1).except(:refresh))}')", opts %>
49
+ <% else %>
50
+ <%= link_to_function l(:automatic_refresh), "stopCountDown('#{url_for(params.merge(:refresh => interval).except(:norefresh))}')", opts %>
51
+ <% end %>
@@ -0,0 +1,3 @@
1
+ en:
2
+ refresh_in: "Refresh in %{value}s"
3
+ automatic_refresh: "Automatic refresh"
@@ -0,0 +1,3 @@
1
+ fr:
2
+ refresh_in: "Actualisation dans %{value}s"
3
+ automatic_refresh: "Actualisation automatique"
@@ -0,0 +1,9 @@
1
+ zh:
2
+ refresh_in: "刷新频率 %{value}s"
3
+ automatic_refresh: "自动刷新"
4
+
5
+ # Simplified Chinese strings go here for Rails i18n
6
+ # Author: Steven.W
7
+ # Based on file: en.yml
8
+
9
+
data/init.rb ADDED
@@ -0,0 +1,19 @@
1
+ # Little hack for using the 'deface' gem in redmine:
2
+ # - redmine plugins are not railties nor engines, so deface overrides in app/overrides/ are not detected automatically
3
+ # - deface doesn't support direct loading anymore ; it unloads everything at boot so that reload in dev works
4
+ # - hack consists in adding "app/overrides" path of the plugin in Redmine's main #paths
5
+ # TODO: see if it's complicated to turn a plugin into a Railtie or find something a bit cleaner
6
+ Rails.application.paths["app/overrides"] ||= []
7
+ Rails.application.paths["app/overrides"] << File.expand_path("../app/overrides", __FILE__)
8
+
9
+ Redmine::Plugin.register :redmine_refresh do
10
+ name 'Redmine Refresh plugin'
11
+ description 'This is a plugin for Redmine'
12
+ url 'https://github.com/jbbarth/redmine_refresh'
13
+ author 'Jean-Baptiste BARTH'
14
+ author_url 'mailto:jeanbaptiste.barth@gmail.com'
15
+ #TODO: make it depend on redmine_refresh/version
16
+ version '0.3.0'
17
+ requires_redmine :version_or_higher => '2.1.0'
18
+ #settings :default => { }, :partial => 'settings/sudo_settings'
19
+ end
@@ -0,0 +1,3 @@
1
+ module RedmineRefresh
2
+ VERSION = "0.3.0"
3
+ end
@@ -0,0 +1,48 @@
1
+ require "redmine_refresh/version"
2
+
3
+ module RedmineRefresh
4
+ # Run the classic redmine plugin initializer after rails boot
5
+ class Plugin < ::Rails::Engine
6
+ config.after_initialize do
7
+ require File.expand_path("../../init", __FILE__)
8
+ end
9
+ end
10
+
11
+ extend self #... so we can call RedmineRefresh.<method> directly
12
+
13
+ DEFAULT_INTERVAL = 120
14
+
15
+ def refresh_interval_for(user, refresh_param = nil)
16
+ interval = DEFAULT_INTERVAL
17
+ user_interval = user.pref[:refresh_interval].to_i
18
+ #if parameter is provided
19
+ if refresh_param.to_i >= 10
20
+ interval = refresh_param.to_i
21
+ #save it if modified
22
+ if interval != user_interval
23
+ user.pref[:refresh_interval] = interval
24
+ user.pref.save
25
+ end
26
+ #if not, get the user's
27
+ elsif user_interval >= 10
28
+ interval = user_interval
29
+ end
30
+ interval
31
+ end
32
+
33
+ #if should_be_refreshed != RedmineRefresh.refresh_status_for_controller(controller.controller_name)
34
+ def refresh_status_for_controller(user, controller = nil)
35
+ controller = controller.to_s
36
+ controller.present? && user.pref[:refresh_status].is_a?(Hash) && user.pref[:refresh_status][controller]
37
+ end
38
+
39
+ def save_refresh_status_for_controller(user, controller, current_refresh_status)
40
+ user_refresh_status = refresh_status_for_controller(user, controller)
41
+ controller = controller.to_s
42
+ if controller.present? && user_refresh_status != current_refresh_status
43
+ user.pref[:refresh_status] ||= Hash.new
44
+ user.pref[:refresh_status][controller] = current_refresh_status
45
+ user.pref.save
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redmine_refresh/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redmine_refresh"
8
+ spec.version = RedmineRefresh::VERSION
9
+ spec.authors = ["jbbarth"]
10
+ spec.email = ["jeanbaptiste.barth@gmail.com"]
11
+ spec.description = %q{Adds an automatic refresh option to Redmine's issues list}
12
+ spec.summary = %q{Adds an automatic refresh option to Redmine's issues list}
13
+ spec.homepage = "https://github.com/jbbarth/redmine_refresh"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "deface"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,2 @@
1
+ # Load the normal Rails helper
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
@@ -0,0 +1,103 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RedmineRefreshTest < ActiveSupport::TestCase
4
+ fixtures :users, :user_preferences
5
+
6
+ setup do
7
+ @user = User.find(1) #permissions don't matter
8
+ end
9
+
10
+ context "#refresh_interval_for" do
11
+ should "return 120 by default " do
12
+ assert_equal 120, RedmineRefresh.refresh_interval_for(@user)
13
+ end
14
+
15
+ should "return second params if >= 10" do
16
+ assert_equal 10, RedmineRefresh.refresh_interval_for(@user, "10")
17
+ assert_equal 12, RedmineRefresh.refresh_interval_for(@user, 12)
18
+ end
19
+
20
+ should "not return second param if not >= 10" do
21
+ assert_equal 120, RedmineRefresh.refresh_interval_for(@user, 9)
22
+ assert_equal 120, RedmineRefresh.refresh_interval_for(@user, "abcd")
23
+ assert_equal 120, RedmineRefresh.refresh_interval_for(@user, -20)
24
+ end
25
+
26
+ should "save parameter in user preferences if modified and valid" do
27
+ assert_equal nil, @user.reload.pref[:refresh_interval]
28
+ RedmineRefresh.refresh_interval_for(@user, "10")
29
+ assert_equal 10, @user.reload.pref[:refresh_interval]
30
+ RedmineRefresh.refresh_interval_for(@user, "30")
31
+ assert_equal 30, @user.reload.pref[:refresh_interval]
32
+ RedmineRefresh.refresh_interval_for(@user, "abc")
33
+ assert_equal 30, @user.reload.pref[:refresh_interval]
34
+ end
35
+
36
+ should "not save user preferences if parameter is untouched" do
37
+ RedmineRefresh.refresh_interval_for(@user, "10")
38
+ assert_equal 10, @user.reload.pref[:refresh_interval]
39
+ @user.pref.stubs(:save).raises(Exception, "This shouldn't be called !")
40
+ assert_nothing_raised do
41
+ RedmineRefresh.refresh_interval_for(@user, "10")
42
+ end
43
+ end
44
+
45
+ should "get the user preference if no valid parameter provided" do
46
+ @user.pref[:refresh_interval] = 30
47
+ @user.pref.save
48
+ assert_equal 30, RedmineRefresh.refresh_interval_for(@user)
49
+ end
50
+
51
+ should "not get the user preference if a valid parameter is provided" do
52
+ @user.pref[:refresh_interval] = 30
53
+ @user.pref.save
54
+ assert_equal 30, @user.reload.pref[:refresh_interval]
55
+ assert_equal 50, RedmineRefresh.refresh_interval_for(@user, "50")
56
+ end
57
+ end
58
+
59
+ context "#refresh_status_for_controller" do
60
+ should "return false if no controller provided" do
61
+ assert !RedmineRefresh.refresh_status_for_controller(@user)
62
+ end
63
+
64
+ should "return false by default" do
65
+ assert !RedmineRefresh.refresh_status_for_controller(@user, "my")
66
+ end
67
+
68
+ should "proxy to user preferences for refresh_status" do
69
+ @user.pref[:refresh_status] = {"my" => true}
70
+ @user.pref.save
71
+ @user.reload
72
+ assert RedmineRefresh.refresh_status_for_controller(@user, "my")
73
+ assert !RedmineRefresh.refresh_status_for_controller(@user, "other")
74
+ end
75
+
76
+ should "be falsy for not-logged user" do
77
+ @user = User.anonymous
78
+ @user.pref[:refresh_status] = {"my" => true}
79
+ assert !RedmineRefresh.refresh_status_for_controller(@user, "my")
80
+ end
81
+ end
82
+
83
+ context "#save_refresh_status_for_controller" do
84
+ setup do
85
+ @user.pref[:refresh_status] = {"my" => true}
86
+ @user.pref.save
87
+ @user.reload
88
+ end
89
+
90
+ should "save refresh_status for this controller if needed" do
91
+ RedmineRefresh.save_refresh_status_for_controller(@user, "my", false)
92
+ @user.reload
93
+ assert !RedmineRefresh.refresh_status_for_controller(@user, "my")
94
+ end
95
+
96
+ should "not save refresh_status for this controller if not changed" do
97
+ @user.pref.stubs(:save).raises(Exception, "This shouldn't be called !")
98
+ assert_nothing_raised do
99
+ RedmineRefresh.save_refresh_status_for_controller(@user, "my", true)
100
+ end
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redmine_refresh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jbbarth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: deface
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Adds an automatic refresh option to Redmine's issues list
63
+ email:
64
+ - jeanbaptiste.barth@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - app/overrides/issues/index.rb
75
+ - app/overrides/my/page.rb
76
+ - app/views/redmine_refresh/_refresher.html.erb
77
+ - config/locales/en.yml
78
+ - config/locales/fr.yml
79
+ - config/locales/zh.yml
80
+ - init.rb
81
+ - lib/redmine_refresh.rb
82
+ - lib/redmine_refresh/version.rb
83
+ - redmine_refresh.gemspec
84
+ - test/test_helper.rb
85
+ - test/unit/redmine_refresh_test.rb
86
+ homepage: https://github.com/jbbarth/redmine_refresh
87
+ licenses:
88
+ - MIT
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 3202885522513128351
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 3202885522513128351
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Adds an automatic refresh option to Redmine's issues list
117
+ test_files:
118
+ - test/test_helper.rb
119
+ - test/unit/redmine_refresh_test.rb