dashing-contrib 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e54448da41d937f2b532cb8420c43d5ef2eb75
|
4
|
+
data.tar.gz: 643f2e2c444ec3f54528b0a0f9922caffcc521a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d4a13508c10409834e8c952624b2382833e3d29e9517db6d07b3836eb27ee01bb01e025bab90082cac26125dc16a55733f4fb294adfc8b7d51491dd0bdf1f9
|
7
|
+
data.tar.gz: 9c2832cbe11f170bb114325aae859b2416b56aafbc61818adea566773f1f35b6905eb588bfe76ce7e88e47e2e72819622d607c0b7f70a1e335d6ae703fedb6a5
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/**
|
2
|
+
* jquery.timer.js
|
3
|
+
*
|
4
|
+
* Copyright (c) 2011 Jason Chavannes <jason.chavannes@gmail.com>
|
5
|
+
*
|
6
|
+
* http://jchavannes.com/jquery-timer
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person
|
9
|
+
* obtaining a copy of this software and associated documentation
|
10
|
+
* files (the "Software"), to deal in the Software without
|
11
|
+
* restriction, including without limitation the rights to use, copy,
|
12
|
+
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
13
|
+
* of the Software, and to permit persons to whom the Software is
|
14
|
+
* furnished to do so, subject to the following conditions:
|
15
|
+
*
|
16
|
+
* The above copyright notice and this permission notice shall be
|
17
|
+
* included in all copies or substantial portions of the Software.
|
18
|
+
*
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
23
|
+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
24
|
+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
25
|
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
* SOFTWARE.
|
27
|
+
*/
|
28
|
+
|
29
|
+
;(function($) {
|
30
|
+
$.timer = function(func, time, autostart) {
|
31
|
+
this.set = function(func, time, autostart) {
|
32
|
+
this.init = true;
|
33
|
+
if(typeof func == 'object') {
|
34
|
+
var paramList = ['autostart', 'time'];
|
35
|
+
for(var arg in paramList) {if(func[paramList[arg]] != undefined) {eval(paramList[arg] + " = func[paramList[arg]]");}};
|
36
|
+
func = func.action;
|
37
|
+
}
|
38
|
+
if(typeof func == 'function') {this.action = func;}
|
39
|
+
if(!isNaN(time)) {this.intervalTime = time;}
|
40
|
+
if(autostart && !this.isActive) {
|
41
|
+
this.isActive = true;
|
42
|
+
this.setTimer();
|
43
|
+
}
|
44
|
+
return this;
|
45
|
+
};
|
46
|
+
this.once = function(time) {
|
47
|
+
var timer = this;
|
48
|
+
if(isNaN(time)) {time = 0;}
|
49
|
+
window.setTimeout(function() {timer.action();}, time);
|
50
|
+
return this;
|
51
|
+
};
|
52
|
+
this.play = function(reset) {
|
53
|
+
if(!this.isActive) {
|
54
|
+
if(reset) {this.setTimer();}
|
55
|
+
else {this.setTimer(this.remaining);}
|
56
|
+
this.isActive = true;
|
57
|
+
}
|
58
|
+
return this;
|
59
|
+
};
|
60
|
+
this.pause = function() {
|
61
|
+
if(this.isActive) {
|
62
|
+
this.isActive = false;
|
63
|
+
this.remaining -= new Date() - this.last;
|
64
|
+
this.clearTimer();
|
65
|
+
}
|
66
|
+
return this;
|
67
|
+
};
|
68
|
+
this.stop = function() {
|
69
|
+
this.isActive = false;
|
70
|
+
this.remaining = this.intervalTime;
|
71
|
+
this.clearTimer();
|
72
|
+
return this;
|
73
|
+
};
|
74
|
+
this.toggle = function(reset) {
|
75
|
+
if(this.isActive) {this.pause();}
|
76
|
+
else if(reset) {this.play(true);}
|
77
|
+
else {this.play();}
|
78
|
+
return this;
|
79
|
+
};
|
80
|
+
this.reset = function() {
|
81
|
+
this.isActive = false;
|
82
|
+
this.play(true);
|
83
|
+
return this;
|
84
|
+
};
|
85
|
+
this.clearTimer = function() {
|
86
|
+
window.clearTimeout(this.timeoutObject);
|
87
|
+
};
|
88
|
+
this.setTimer = function(time) {
|
89
|
+
var timer = this;
|
90
|
+
if(typeof this.action != 'function') {return;}
|
91
|
+
if(isNaN(time)) {time = this.intervalTime;}
|
92
|
+
this.remaining = time;
|
93
|
+
this.last = new Date();
|
94
|
+
this.clearTimer();
|
95
|
+
this.timeoutObject = window.setTimeout(function() {timer.go();}, time);
|
96
|
+
};
|
97
|
+
this.go = function() {
|
98
|
+
if(this.isActive) {
|
99
|
+
this.action();
|
100
|
+
this.setTimer();
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
if(this.init) {
|
105
|
+
return new $.timer(func, time, autostart);
|
106
|
+
} else {
|
107
|
+
this.set(func, time, autostart);
|
108
|
+
return this;
|
109
|
+
}
|
110
|
+
};
|
111
|
+
})(jQuery);
|
@@ -15,7 +15,7 @@ class DashboardSwitcher
|
|
15
15
|
@dashboardNames = (name.trim() for name in names.split(/[ ,]+/).filter(Boolean))
|
16
16
|
|
17
17
|
start: (interval=60000) ->
|
18
|
-
|
18
|
+
interval = parseInt(interval, 10)
|
19
19
|
@maxPos = @dashboardNames.length - 1
|
20
20
|
|
21
21
|
# Skip switching if no names defined
|
@@ -32,7 +32,14 @@ class DashboardSwitcher
|
|
32
32
|
@curPos = 0
|
33
33
|
@curName = @dashboardNames[@curPos]
|
34
34
|
|
35
|
-
#
|
35
|
+
# instantiate switcher controls for countdown and manual switching
|
36
|
+
@switcherControls = new DashboardSwitcherControls(interval, @)
|
37
|
+
@switcherControls.start() if @switcherControls.present()
|
38
|
+
|
39
|
+
@startLoop(interval)
|
40
|
+
|
41
|
+
startLoop: (interval) ->
|
42
|
+
self = @
|
36
43
|
@handle = setTimeout(() ->
|
37
44
|
# Increase the position or reset back to zero
|
38
45
|
self.curPos += 1
|
@@ -43,7 +50,19 @@ class DashboardSwitcher
|
|
43
50
|
self.curName = self.dashboardNames[self.curPos]
|
44
51
|
window.location.pathname = "/#{self.curName}"
|
45
52
|
|
46
|
-
,
|
53
|
+
, interval)
|
54
|
+
|
55
|
+
stopLoop: () ->
|
56
|
+
clearTimeout @handle
|
57
|
+
|
58
|
+
currentName: () ->
|
59
|
+
@curName
|
60
|
+
|
61
|
+
nextName: () ->
|
62
|
+
@dashboardNames[@curPos + 1] || @dashboardNames[0]
|
63
|
+
|
64
|
+
previousName: () ->
|
65
|
+
@dashboardNames[@curPos - 1] || @dashboardNames[@dashboardNames.length - 1]
|
47
66
|
|
48
67
|
|
49
68
|
# Switches (hides and shows) elements within on list item
|
@@ -82,6 +101,107 @@ class WidgetSwitcher
|
|
82
101
|
stop: () ->
|
83
102
|
clearInterval(@handle)
|
84
103
|
|
104
|
+
# Adds a countdown timer to show when next dashboard will appear
|
105
|
+
# TODO:
|
106
|
+
# - show the name of the next dashboard
|
107
|
+
# - add controls for manually cycling through dashboards
|
108
|
+
class DashboardSwitcherControls
|
109
|
+
arrowContent = "→"
|
110
|
+
stopTimerContent = "stop timer"
|
111
|
+
startTimerContent = "start timer"
|
112
|
+
|
113
|
+
constructor: (interval=60000, dashboardSwitcher) ->
|
114
|
+
@currentTime = parseInt(interval, 10)
|
115
|
+
@interval = parseInt(interval, 10)
|
116
|
+
@$elements = $('#dc-switcher-controls')
|
117
|
+
@dashboardSwitcher = dashboardSwitcher
|
118
|
+
@incrementTime = 1000 # refresh every 1000 milliseconds
|
119
|
+
@arrowContent = @$elements.data('next-dashboard-content') || DashboardSwitcherControls.arrowContent
|
120
|
+
@stopTimerContent = @$elements.data('stop-timer-content') || DashboardSwitcherControls.stopTimerContent
|
121
|
+
@startTimerContent = @$elements.data('start-timer-content') || DashboardSwitcherControls.startTimerContent
|
122
|
+
@
|
123
|
+
|
124
|
+
present: () ->
|
125
|
+
@$elements.length
|
126
|
+
|
127
|
+
start: () ->
|
128
|
+
@addElements()
|
129
|
+
@$timer = $.timer(@updateTimer, @incrementTime, true)
|
130
|
+
|
131
|
+
addElements: () ->
|
132
|
+
template = @$elements.find('dashboard-name-template')
|
133
|
+
if template.length
|
134
|
+
@$nextDashboardNameTemplate = template
|
135
|
+
@$nextDashboardNameTemplate.remove()
|
136
|
+
else
|
137
|
+
@$nextDashboardNameTemplate = $("<dashboard-name-template>Next dashboard: $nextName in </dashboard-name-template>")
|
138
|
+
@$nextDashboardNameContainer = $("<span id='dc-switcher-next-name'></span>")
|
139
|
+
@$countdown = $("<span id='dc-switcher-countdown'></span>")
|
140
|
+
@$manualSwitcher = $("<span id='dc-switcher-next' class='fa fa-forward'></span>").
|
141
|
+
html(@arrowContent).
|
142
|
+
click () =>
|
143
|
+
location.href = "/#{@dashboardSwitcher.nextName()}"
|
144
|
+
@$switcherStopper = $("<span id='dc-switcher-pause-reset' class='fa fa-pause'></span>").
|
145
|
+
html(@stopTimerContent).
|
146
|
+
click(@pause)
|
147
|
+
@$elements.
|
148
|
+
append(@$nextDashboardNameContainer).
|
149
|
+
append(@$countdown).
|
150
|
+
append(@$manualSwitcher).
|
151
|
+
append(@$switcherStopper)
|
152
|
+
|
153
|
+
formatTime: (time) ->
|
154
|
+
time = time / 10;
|
155
|
+
min = parseInt(time / 6000, 10)
|
156
|
+
sec = parseInt(time / 100, 10) - (min * 60)
|
157
|
+
"#{(if min > 0 then @pad(min, 2) else "00")}:#{@pad(sec, 2)}"
|
158
|
+
|
159
|
+
pad: (number, length) =>
|
160
|
+
str = "#{number}"
|
161
|
+
while str.length < length
|
162
|
+
str = "0#{str}"
|
163
|
+
str
|
164
|
+
|
165
|
+
pause: () =>
|
166
|
+
@$timer.toggle()
|
167
|
+
if @isRunning()
|
168
|
+
@dashboardSwitcher.stopLoop()
|
169
|
+
@$switcherStopper.removeClass('fa-pause').addClass('fa-play').html(@startTimerContent)
|
170
|
+
else
|
171
|
+
@dashboardSwitcher.startLoop @currentTime
|
172
|
+
@$switcherStopper.removeClass('fa-play').addClass('fa-pause').html(@stopTimerContent)
|
173
|
+
|
174
|
+
isRunning: () =>
|
175
|
+
@$switcherStopper.hasClass('fa-pause')
|
176
|
+
|
177
|
+
resetCountdown: () ->
|
178
|
+
# Get time from form
|
179
|
+
newTime = @interval
|
180
|
+
if newTime > 0
|
181
|
+
@currentTime = newTime
|
182
|
+
|
183
|
+
# Stop and reset timer
|
184
|
+
@$timer.stop().once()
|
185
|
+
|
186
|
+
updateTimer: () =>
|
187
|
+
# Update dashboard name
|
188
|
+
@$nextDashboardNameContainer.html(
|
189
|
+
@$nextDashboardNameTemplate.html().replace('$nextName', @dashboardSwitcher.nextName())
|
190
|
+
)
|
191
|
+
# Output timer position
|
192
|
+
timeString = @formatTime(@currentTime)
|
193
|
+
@$countdown.html(timeString)
|
194
|
+
|
195
|
+
# If timer is complete, trigger alert
|
196
|
+
if @currentTime is 0
|
197
|
+
@pause()
|
198
|
+
@resetCountdown()
|
199
|
+
return
|
200
|
+
|
201
|
+
# Increment timer position
|
202
|
+
@currentTime -= @incrementTime
|
203
|
+
if @currentTime < 0
|
204
|
+
@currentTime = 0
|
85
205
|
|
86
206
|
# Dashboard loaded and ready
|
87
207
|
Dashing.on 'ready', ->
|
@@ -7,9 +7,10 @@ module DashingContrib
|
|
7
7
|
critical = client.service_status(default_critical_options.merge(options))
|
8
8
|
warning = client.service_status(default_warning_options.merge(options))
|
9
9
|
ok = client.service_status(default_ok_options.merge(options))
|
10
|
+
unknown = client.service_status(default_unknown_options.merge(options))
|
10
11
|
ok.select! { |check| check['status'] == 'OK' }
|
11
12
|
|
12
|
-
{ critical: critical, warning: warning, ok: ok }
|
13
|
+
{ critical: critical, warning: warning, unknown: unknown, ok: ok }
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
@@ -21,6 +22,10 @@ module DashingContrib
|
|
21
22
|
{ :service_status_types => [:warning], :sort_type => :descending, :sort_option => :last_check }
|
22
23
|
end
|
23
24
|
|
25
|
+
def default_unknown_options
|
26
|
+
{ :service_status_types => [:unknown], :sort_type => :descending, :sort_option => :last_check }
|
27
|
+
end
|
28
|
+
|
24
29
|
def default_ok_options
|
25
30
|
{ :sort_option => :last_check, :sort_type => :descending }
|
26
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dashing-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jing Dong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- Rakefile
|
196
196
|
- dashing-contrib.gemspec
|
197
197
|
- lib/dashing-contrib.rb
|
198
|
+
- lib/dashing-contrib/assets/javascripts/jquery-timer/jquery.timer.js
|
198
199
|
- lib/dashing-contrib/assets/javascripts/rickshaw/rickshaw.min.js
|
199
200
|
- lib/dashing-contrib/assets/stylesheets/font-awesome/scss/_bordered-pulled.scss
|
200
201
|
- lib/dashing-contrib/assets/stylesheets/font-awesome/scss/_core.scss
|
@@ -277,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
277
278
|
version: '0'
|
278
279
|
requirements: []
|
279
280
|
rubyforge_project:
|
280
|
-
rubygems_version: 2.
|
281
|
+
rubygems_version: 2.4.4
|
281
282
|
signing_key:
|
282
283
|
specification_version: 4
|
283
284
|
summary: An extension to Dashing that makes easier to maintaining, sharing widgets
|