prosperity 0.0.6 → 0.0.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 +4 -4
- data/app/assets/javascripts/prosperity/graph.js.coffee +14 -3
- data/app/assets/stylesheets/prosperity/graph.css.scss +4 -6
- data/app/controllers/prosperity/graphs_controller.rb +24 -15
- data/app/models/prosperity/graph.rb +4 -1
- data/app/views/layouts/prosperity/application.html.erb +1 -1
- data/app/views/layouts/prosperity/embedabble.html.erb +16 -0
- data/app/views/prosperity/graphs/edit.html.erb +20 -3
- data/app/views/prosperity/graphs/show.html.erb +3 -0
- data/db/migrate/20140516222642_add_graph_type_to_graphs.rb +11 -0
- data/lib/prosperity/version.rb +1 -1
- data/spec/controllers/prosperity/dashboard_graphs_controller_spec.rb +1 -1
- data/spec/controllers/prosperity/graphs_controller_spec.rb +31 -12
- data/spec/dummy/db/schema.rb +2 -1
- data/spec/dummy/log/development.log +4244 -0
- data/spec/dummy/log/test.log +14113 -0
- data/spec/dummy/tmp/cache/assets/development/sass/34a577735054231563e7022ea73e1468db9203ba/graph.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/197492ed379339e17a0f5d01d3b01b8c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1c55cf24465f311353197ce336df0178 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/210050da208fb75a75b701bfa4e8470f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/27a59e08207d3ae723f2b2b3d22264c3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5f7660fd92b228b2de09f92d54ca6b49 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6882b260ae69f1594eff540d803e5ac3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/828a046f0e7dc2dad0eecfe49d31e14d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a2b14d5c46db32da9183354fb3fcd0bf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a6d6196cfd275dea0718553a95f997a5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aacfd4457155e8607cbe66d5fdaf11b3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d94883bc533251c5e4b4821c716ae300 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f4648036e284d9aa3468f4f7b9bbb967 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sass/34a577735054231563e7022ea73e1468db9203ba/graph.css.scssc +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/197492ed379339e17a0f5d01d3b01b8c +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/1c55cf24465f311353197ce336df0178 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/210050da208fb75a75b701bfa4e8470f +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/27a59e08207d3ae723f2b2b3d22264c3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/6882b260ae69f1594eff540d803e5ac3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a2b14d5c46db32da9183354fb3fcd0bf +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a6d6196cfd275dea0718553a95f997a5 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/aacfd4457155e8607cbe66d5fdaf11b3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d94883bc533251c5e4b4821c716ae300 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f4648036e284d9aa3468f4f7b9bbb967 +0 -0
- data/spec/models/prosperity/graph_spec.rb +7 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5c67a59270ef33317323ebdc699936e5e89ac5f
|
4
|
+
data.tar.gz: 21df5064d10dc796a58e8d7510ac7c0a0e26e5a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faf49f6e8fe66d517f58b6f53bd95280f1ebff3cb5673288d9db7da7f879fb072374d97e4d30eefb37a278840d657f15bbe59837eaa8191cc681e13b1b3c4680
|
7
|
+
data.tar.gz: bfb5e793939e5d190935b0dde676a4ef7fdf07632e041245e111650519a0a47d141daff898f54edbf3f4c5ca18a7f237e0b70a33eef8dc040aa6a8bcab317b2e
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class SubGraph
|
2
2
|
constructor: (options = {}) ->
|
3
3
|
@el = $('<div>', class: 'sub-graph')
|
4
|
+
@graphType = options.graphType
|
5
|
+
|
4
6
|
if options.showTitle
|
5
7
|
@el.append("<div class='title'>Loading...</div>")
|
6
8
|
|
@@ -37,11 +39,17 @@ class SubGraph
|
|
37
39
|
|
38
40
|
@el
|
39
41
|
|
42
|
+
class: =>
|
43
|
+
if @graphType == 'area'
|
44
|
+
Morris.Area
|
45
|
+
else
|
46
|
+
Morris.Line
|
47
|
+
|
40
48
|
draw: ->
|
41
49
|
# Because of a bug in Morris (https://github.com/morrisjs/morris.js/issues/388)
|
42
50
|
# it's not possible to add data on a hidden element. We just redraw the
|
43
51
|
# entire thing in the meantime.
|
44
|
-
@chart = new
|
52
|
+
@chart = new @class()(@chartOptions)
|
45
53
|
|
46
54
|
class Graph
|
47
55
|
constructor: (options) ->
|
@@ -54,7 +62,11 @@ class Graph
|
|
54
62
|
$.getJSON @url, (json) =>
|
55
63
|
for extractor, index in json.extractors
|
56
64
|
$.get extractor.url, (line_json) =>
|
57
|
-
subgraph = @getSubgraph
|
65
|
+
subgraph = @getSubgraph
|
66
|
+
label: line_json.label
|
67
|
+
key: line_json.key
|
68
|
+
graphType: json.graph_type
|
69
|
+
|
58
70
|
subgraph.addSeries(line_json)
|
59
71
|
|
60
72
|
if @$el.hasClass('dashboard')
|
@@ -100,5 +112,4 @@ $(document).on "change", ".edit_graph .metric-title-select select", (e) ->
|
|
100
112
|
$ ->
|
101
113
|
$(".edit_graph .metric-title-select select").each (i, el) ->
|
102
114
|
updateMetricOptions el
|
103
|
-
|
104
115
|
|
@@ -3,10 +3,8 @@
|
|
3
3
|
They will automatically be included in application.css.
|
4
4
|
*/
|
5
5
|
|
6
|
-
.sub-graph {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
font-weight: bold;
|
11
|
-
}
|
6
|
+
.sub-graph .title, .metric-title {
|
7
|
+
text-align: center;
|
8
|
+
font-size: 14px;
|
9
|
+
font-weight: bold;
|
12
10
|
}
|
@@ -17,20 +17,29 @@ module Prosperity
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def show
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
respond_to do |format|
|
21
|
+
format.json do
|
22
|
+
render json: {
|
23
|
+
title: @graph.title,
|
24
|
+
graph_type: @graph.graph_type,
|
25
|
+
extractors: @graph.graph_lines.map do |line|
|
26
|
+
{
|
27
|
+
key: line.extractor,
|
28
|
+
url: data_metric_path(id: line.metric,
|
29
|
+
extractor: line.extractor,
|
30
|
+
option: line.option,
|
31
|
+
period: @graph.period,
|
32
|
+
start_time: start_time,
|
33
|
+
end_time: end_time),
|
34
|
+
}
|
35
|
+
end
|
31
36
|
}
|
32
37
|
end
|
33
|
-
|
38
|
+
|
39
|
+
format.html {
|
40
|
+
render layout: 'prosperity/embedabble'
|
41
|
+
}
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
def update
|
@@ -42,7 +51,7 @@ module Prosperity
|
|
42
51
|
|
43
52
|
def create
|
44
53
|
@graph = Graph.new
|
45
|
-
[:title, :period].each do |attr|
|
54
|
+
[:title, :period, :graph_type].each do |attr|
|
46
55
|
@graph.send("#{attr}=", graph_params[attr])
|
47
56
|
end
|
48
57
|
|
@@ -53,7 +62,7 @@ module Prosperity
|
|
53
62
|
render action: :new
|
54
63
|
end
|
55
64
|
end
|
56
|
-
|
65
|
+
|
57
66
|
private
|
58
67
|
|
59
68
|
def get_graph
|
@@ -65,7 +74,7 @@ module Prosperity
|
|
65
74
|
params.require(:graph).
|
66
75
|
permit(Graph::ATTR_ACCESSIBLE + [:graph_lines_attributes => (GraphLine::ATTR_ACCESSIBLE + [:id])])
|
67
76
|
else
|
68
|
-
params.fetch(:graph, {})
|
77
|
+
params.fetch(:graph, {})
|
69
78
|
end
|
70
79
|
end
|
71
80
|
end
|
@@ -4,10 +4,13 @@ module Prosperity
|
|
4
4
|
validates_presence_of :title, :period
|
5
5
|
accepts_nested_attributes_for :graph_lines, reject_if: :not_filled?
|
6
6
|
|
7
|
-
ATTR_ACCESSIBLE = [:title, :period, :graph_lines].freeze
|
7
|
+
ATTR_ACCESSIBLE = [:title, :period, :graph_lines, :graph_type].freeze
|
8
8
|
|
9
9
|
attr_accessible *ATTR_ACCESSIBLE unless defined?(ActionController::StrongParameters)
|
10
10
|
|
11
|
+
VALID_GRAPH_TYPES = %w(line area)
|
12
|
+
validates :graph_type, inclusion: {in: VALID_GRAPH_TYPES}
|
13
|
+
|
11
14
|
private
|
12
15
|
def not_filled?(line)
|
13
16
|
if line[:id]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<%= csrf_meta_tags %>
|
5
|
+
<!-- Le HTML5 shim, for IE6-8 support of HTML elements
|
6
|
+
-->
|
7
|
+
<!--[if lt IE 9]
|
8
|
+
<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" %>
|
9
|
+
-->
|
10
|
+
<%= stylesheet_link_tag "prosperity/application", :media => "all" %>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
<%= javascript_include_tag "prosperity/application" %>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -1,10 +1,18 @@
|
|
1
1
|
<h1>Edit Graph</h1>
|
2
2
|
|
3
|
-
<p>Title: <%= @graph.title%></p>
|
4
|
-
|
5
3
|
<div class="row">
|
6
4
|
<div class="span6">
|
7
5
|
<%= form_for @graph, data: {metric_options: @options} do |f| %>
|
6
|
+
<div class="form-group">
|
7
|
+
<%= f.label :title %>
|
8
|
+
<%= f.text_field :title %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="form-group">
|
12
|
+
<%= f.label :graph_type %>
|
13
|
+
<%= f.select :graph_type, Prosperity::Graph::VALID_GRAPH_TYPES %>
|
14
|
+
</div>
|
15
|
+
|
8
16
|
<h4>Lines</h4>
|
9
17
|
<%= f.fields_for :graph_lines do |l| %>
|
10
18
|
<% if l.object.new_record? %>
|
@@ -35,7 +43,16 @@
|
|
35
43
|
|
36
44
|
<div class="span8">
|
37
45
|
<div class="graph well"/>
|
38
|
-
<div class="metric" data-url="<%= graph_path(@graph) %>"></div>
|
46
|
+
<div class="metric dashboard" data-url="<%= graph_path(@graph) %>"></div>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<div>
|
50
|
+
<p>
|
51
|
+
You can embed this graph by embedding the following snippet in your web page.
|
52
|
+
</p>
|
53
|
+
<input disabled value='<iframe height="400px" src="<%= graph_url(@graph) %>" style="border: none;" width="512px"></iframe>' />
|
54
|
+
|
55
|
+
</div>
|
39
56
|
</div>
|
40
57
|
</div>
|
41
58
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddGraphTypeToGraphs < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :prosperity_graphs, :graph_type, :string
|
4
|
+
execute "UPDATE prosperity_graphs SET graph_type='line'"
|
5
|
+
change_column :prosperity_graphs, :graph_type, :string, null: false
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
remove_column :prosperity_graphs, :graph_type, :string
|
10
|
+
end
|
11
|
+
end
|
data/lib/prosperity/version.rb
CHANGED
@@ -8,6 +8,7 @@ module Prosperity
|
|
8
8
|
{
|
9
9
|
title: "My Graph",
|
10
10
|
period: "month",
|
11
|
+
graph_type: 'line',
|
11
12
|
}
|
12
13
|
end
|
13
14
|
|
@@ -48,20 +49,38 @@ module Prosperity
|
|
48
49
|
end
|
49
50
|
|
50
51
|
describe "GET 'show'" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
context "in JSON" do
|
53
|
+
it "renders the JSON representation of the graph" do
|
54
|
+
get :show, id: graph.id, format: 'json'
|
55
|
+
response.should be_success
|
56
|
+
json['title'].should == graph.title
|
57
|
+
json['extractors'].should == []
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns one extractor per graph line" do
|
61
|
+
get :show, id: graph_w_line, format: 'json'
|
62
|
+
response.should be_success
|
63
|
+
json['extractors'].count.should == 1
|
64
|
+
ext = json['extractors'].first
|
65
|
+
ext['key'].should == valid_line_attributes[:extractor]
|
66
|
+
ext['url'].should be_present
|
67
|
+
end
|
56
68
|
end
|
57
69
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
70
|
+
context "as embedabble HTML" do
|
71
|
+
before do
|
72
|
+
get :show, id: graph.id, format: 'html'
|
73
|
+
response.should be_success
|
74
|
+
end
|
75
|
+
|
76
|
+
it "renders html" do
|
77
|
+
response.content_type.should == 'text/html'
|
78
|
+
response.body.should include('metric dashboard')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should render the embedabble layout" do
|
82
|
+
response.body.should_not include('navbar')
|
83
|
+
end
|
65
84
|
end
|
66
85
|
end
|
67
86
|
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20140516222642) do
|
15
15
|
|
16
16
|
# These are extensions that must be enabled in order to support this database
|
17
17
|
enable_extension "plpgsql"
|
@@ -49,6 +49,7 @@ ActiveRecord::Schema.define(version: 20140217005117) do
|
|
49
49
|
t.string "period", null: false
|
50
50
|
t.datetime "created_at"
|
51
51
|
t.datetime "updated_at"
|
52
|
+
t.string "graph_type", null: false
|
52
53
|
end
|
53
54
|
|
54
55
|
create_table "users", force: true do |t|
|