suricate 0.0.2 → 0.0.3
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 +4 -4
- data/lib/suricate.rb +1 -0
- data/lib/suricate/generator/assets/javascript/application.js +1 -1
- data/lib/suricate/generator/assets/javascript/chart-js-chart-factory.js +2 -0
- data/lib/suricate/generator/assets/javascript/widget-view.js +32 -1
- data/lib/suricate/generator/assets/javascript/widgets/counter-widget.js +7 -7
- data/lib/suricate/generator/assets/javascript/widgets/widget.js +15 -0
- data/lib/suricate/generator/assets/stylesheets/suricate.css +12 -0
- data/lib/suricate/version.rb +1 -1
- data/lib/suricate/widgets/responses/chart_widget_response.rb +5 -2
- data/lib/suricate/widgets/responses/counter_widget_response.rb +5 -2
- data/lib/suricate/widgets/responses/widget_response.rb +23 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac902ad9c42da7826dd54eac991f2ad0e335fbcd
|
4
|
+
data.tar.gz: b56b7f691abc48903c1f046cf6716cb959583501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aef33555cd23cdf3c0bddce0e166e29c746725338582cd37e123ac21dfc2f76e1aa5fb71860ed816522333e8a4f2889aa3a739b496ce3c983bc78ed583a8ceba
|
7
|
+
data.tar.gz: 3ff8a9850671e7cb19093c69e9a7036ccdcc44ebaa7ace586f993a99c47af0d71198f03bc331eb98a1725dee27fd1bf0d11b9e326aba4ef839c8e2943af67a84
|
data/lib/suricate.rb
CHANGED
@@ -23,6 +23,7 @@ module Suricate
|
|
23
23
|
autoload :LineChartWidget, 'suricate/widgets/line_chart_widget'
|
24
24
|
|
25
25
|
# Responses
|
26
|
+
autoload :WidgetResponse, 'suricate/widgets/responses/widget_response'
|
26
27
|
autoload :CounterWidgetResponse, 'suricate/widgets/responses/counter_widget_response'
|
27
28
|
autoload :ChartWidgetResponse, 'suricate/widgets/responses/chart_widget_response'
|
28
29
|
|
@@ -2,8 +2,15 @@
|
|
2
2
|
"use strict";
|
3
3
|
window.Suricate = window.Suricate || {};
|
4
4
|
|
5
|
+
var statuses = {
|
6
|
+
ok: "ok",
|
7
|
+
alert: "danger",
|
8
|
+
warning: "warning"
|
9
|
+
};
|
10
|
+
|
5
11
|
Suricate.WidgetView = function(content) {
|
6
|
-
this.content
|
12
|
+
this.content = $(content);
|
13
|
+
this.currentStatus = statuses.ok;
|
7
14
|
};
|
8
15
|
|
9
16
|
/*
|
@@ -37,10 +44,34 @@
|
|
37
44
|
this.getPlaceholder(name).html(value);
|
38
45
|
};
|
39
46
|
|
47
|
+
|
48
|
+
Suricate.WidgetView.prototype.setStatusOK = function() {
|
49
|
+
this.setStatus(statuses.ok);
|
50
|
+
};
|
51
|
+
|
52
|
+
Suricate.WidgetView.prototype.setStatusAlert = function() {
|
53
|
+
this.setStatus(statuses.alert);
|
54
|
+
};
|
55
|
+
|
56
|
+
Suricate.WidgetView.prototype.setStatusWarning = function() {
|
57
|
+
this.setStatus(statuses.warning);
|
58
|
+
};
|
59
|
+
|
40
60
|
/*
|
41
61
|
* Private
|
42
62
|
*/
|
43
63
|
Suricate.WidgetView.prototype.getPlaceholder = function(name) {
|
44
64
|
return this.content.find("[data-widget-binding='" + name + "']");
|
45
65
|
};
|
66
|
+
|
67
|
+
Suricate.WidgetView.prototype.setStatus = function(status) {
|
68
|
+
if(this.currentStatus !== status) {
|
69
|
+
var statuses = ["ok", "danger", "warning"];
|
70
|
+
var statusIndex = statuses.indexOf(status);
|
71
|
+
var classesToRemove = statuses.splice(statusIndex, 1);
|
72
|
+
this.content.removeClass(classesToRemove);
|
73
|
+
this.content.addClass(status);
|
74
|
+
this.currentStatus = status;
|
75
|
+
}
|
76
|
+
};
|
46
77
|
}());
|
@@ -8,16 +8,16 @@
|
|
8
8
|
|
9
9
|
Suricate.CounterWidget.prototype = new Suricate.Widget();
|
10
10
|
|
11
|
-
/*
|
12
|
-
*
|
13
|
-
*/
|
14
|
-
|
15
11
|
Suricate.CounterWidget.prototype.setData = function(data) {
|
16
|
-
var
|
12
|
+
var value = this.formatNumber(data.value);
|
13
|
+
this.view.setPlaceholder('value', value);
|
14
|
+
};
|
15
|
+
|
16
|
+
Suricate.CounterWidget.prototype.formatNumber = function(number) {
|
17
|
+
var precision = number % 1 === 0 ? 0 : 2;
|
17
18
|
// From http://stackoverflow.com/a/14428340/610531
|
18
|
-
|
19
|
+
return number.toFixed(precision).replace(/./g, function(c, i, a) {
|
19
20
|
return i && c !== "." && ((a.length - i) % 3 === 0) ? ',' + c : c;
|
20
21
|
});
|
21
|
-
this.view.setPlaceholder('value', value);
|
22
22
|
};
|
23
23
|
}());
|
@@ -32,6 +32,7 @@
|
|
32
32
|
var self = this;
|
33
33
|
this.updater.update(now, function(data) {
|
34
34
|
self.view.setLastUpdateAt(now);
|
35
|
+
self.updateStatus(data.status);
|
35
36
|
self.setData(data);
|
36
37
|
});
|
37
38
|
};
|
@@ -40,6 +41,20 @@
|
|
40
41
|
* Private
|
41
42
|
*/
|
42
43
|
|
44
|
+
Suricate.Widget.prototype.updateStatus = function(status) {
|
45
|
+
switch (status) {
|
46
|
+
case "ok":
|
47
|
+
this.view.setStatusOK();
|
48
|
+
break;
|
49
|
+
case "alert":
|
50
|
+
this.view.setStatusAlert();
|
51
|
+
break;
|
52
|
+
case "warning":
|
53
|
+
this.view.setStatusWarning();
|
54
|
+
break;
|
55
|
+
}
|
56
|
+
};
|
57
|
+
|
43
58
|
Suricate.Widget.prototype.setData = function(data) {
|
44
59
|
console.error("function setData(data) is not defined in Suricate.Widget's subclass", this);
|
45
60
|
};
|
@@ -7,6 +7,7 @@
|
|
7
7
|
border-radius: 5px;
|
8
8
|
height: 100%;
|
9
9
|
position: relative;
|
10
|
+
margin-bottom: 20px;
|
10
11
|
}
|
11
12
|
|
12
13
|
.widget .body {
|
@@ -38,6 +39,13 @@
|
|
38
39
|
font-weight: 500;
|
39
40
|
}
|
40
41
|
|
42
|
+
.widget.danger .body {
|
43
|
+
background-color: #F59F97;
|
44
|
+
}
|
45
|
+
|
46
|
+
.widget.warning .body {
|
47
|
+
background-color: #f5ce97;
|
48
|
+
}
|
41
49
|
|
42
50
|
/*
|
43
51
|
* CounterWidget
|
@@ -58,6 +66,10 @@
|
|
58
66
|
width: 100% !important;
|
59
67
|
}
|
60
68
|
|
69
|
+
.line-chart-widget .name {
|
70
|
+
padding-top: 20px;
|
71
|
+
}
|
72
|
+
|
61
73
|
.line-chart-widget .legend {
|
62
74
|
height: 20px;
|
63
75
|
width: 100%;
|
data/lib/suricate/version.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
|
3
3
|
module Suricate
|
4
|
-
class ChartWidgetResponse
|
4
|
+
class ChartWidgetResponse < WidgetResponse
|
5
5
|
def initialize
|
6
6
|
@builder = ChartBuilder.new
|
7
|
+
super
|
7
8
|
end
|
8
9
|
|
9
10
|
def chart
|
@@ -11,7 +12,9 @@ module Suricate
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def to_h
|
14
|
-
|
15
|
+
super.tap do |hash|
|
16
|
+
hash.merge!(chart: @builder.chart.to_h)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Suricate
|
2
|
-
class CounterWidgetResponse
|
2
|
+
class CounterWidgetResponse < WidgetResponse
|
3
3
|
class NotAnNumberError < StandardError; end
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@value = nil
|
7
|
+
super
|
7
8
|
end
|
8
9
|
|
9
10
|
def value(value)
|
@@ -12,7 +13,9 @@ module Suricate
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def to_h
|
15
|
-
|
16
|
+
super.tap do |hash|
|
17
|
+
hash.merge!(value: @value)
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Suricate
|
2
|
+
class WidgetResponse
|
3
|
+
def initialize
|
4
|
+
@status = 'ok'
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_h
|
8
|
+
{ status: @status }
|
9
|
+
end
|
10
|
+
|
11
|
+
def warning!
|
12
|
+
@status = 'warning'
|
13
|
+
end
|
14
|
+
|
15
|
+
def alert!
|
16
|
+
@status = 'alert';
|
17
|
+
end
|
18
|
+
|
19
|
+
def ok!
|
20
|
+
@status = 'ok'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suricate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aurélien AMILIN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- lib/suricate/widgets/line_chart_widget.rb
|
172
172
|
- lib/suricate/widgets/responses/chart_widget_response.rb
|
173
173
|
- lib/suricate/widgets/responses/counter_widget_response.rb
|
174
|
+
- lib/suricate/widgets/responses/widget_response.rb
|
174
175
|
- lib/suricate/widgets/widget.rb
|
175
176
|
homepage: https://github.com/holinnn/suricate
|
176
177
|
licenses:
|
@@ -192,9 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
193
|
version: '0'
|
193
194
|
requirements: []
|
194
195
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.4.
|
196
|
+
rubygems_version: 2.4.6
|
196
197
|
signing_key:
|
197
198
|
specification_version: 4
|
198
199
|
summary: Suricate aims to be an application template for building dashboards.
|
199
200
|
test_files: []
|
200
|
-
has_rdoc:
|