Skip to content

Commit aa2926e

Browse files
committed
Snapshots page
1 parent e86b190 commit aa2926e

File tree

6 files changed

+85
-49
lines changed

6 files changed

+85
-49
lines changed

lib/snapshot.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

public/js/app.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ var app = Sammy('body', function() {
219219
l = urls.length, url, date;
220220
for (; i < l; i++) {
221221
url = urls[i];
222-
try {
223-
date = new Date(parseInt(url.match(/\/(\d+)\.png/)[1], 10)).toString();
224-
} catch (e) { }
222+
date = this.snapshotURLToDate(url);
225223
$('<option />', {
226224
value: url,
227225
text: date
@@ -314,6 +312,34 @@ var app = Sammy('body', function() {
314312
});
315313
},
316314

315+
loadAndRenderSnapshots: function() {
316+
var ctx = this;
317+
this.load('/graphs/' + this.params.uuid + '.js', {cache: false})
318+
.then(function(graph_data) {
319+
var $snapshots = ctx.showPane('snapshots', '<h2>' + graph_data.title + '</h2>');
320+
var snapshots = graph_data.snapshots,
321+
i = 0, l = snapshots.length, snapshot,
322+
$snapshot = $('#templates .snapshot').clone();
323+
for (; i < l; i++) {
324+
snapshot = snapshots[i];
325+
$snapshot.clone()
326+
.find('a.view').attr('href', snapshot).end()
327+
.find('img').attr('src', snapshot).end()
328+
.find('h3.title').text(ctx.snapshotURLToDate(snapshot)).end()
329+
.show()
330+
.appendTo($snapshots);
331+
}
332+
});
333+
},
334+
335+
snapshotURLToDate: function(url) {
336+
var date;
337+
try {
338+
date = new Date(parseInt(url.match(/\/(\d+)\.png/)[1], 10)).toString();
339+
} catch (e) { }
340+
return date;
341+
},
342+
317343
bindEditorPanes: function() {
318344
var ctx = this;
319345
$('#editor-pane')
@@ -388,10 +414,7 @@ var app = Sammy('body', function() {
388414
});
389415

390416
this.get('/graphs/:uuid/snapshots', function(ctx) {
391-
this.load('/graphs/' + this.params.uuid + '.js', {cache: false})
392-
.then(function(graph_data) {
393-
ctx.buildSnapshotsDropdown(graph_data.snapshots, true);
394-
});
417+
this.loadAndRenderSnapshots();
395418
});
396419

397420
this.get('/graphs', function(ctx) {

public/js/default.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12531,7 +12531,7 @@ Graphiti.Graph = function(targetsAndOptions){
1253112531
this.parsedTargets = [];
1253212532

1253312533
var defaults = {
12534-
width: 800,
12534+
width: 950,
1253512535
height: 400,
1253612536
from: '-6hour',
1253712537
fontSize: "10",
@@ -12894,9 +12894,7 @@ var app = Sammy('body', function() {
1289412894
l = urls.length, url, date;
1289512895
for (; i < l; i++) {
1289612896
url = urls[i];
12897-
try {
12898-
date = new Date(parseInt(url.match(/\/(\d+)\.png/)[1], 10)).toString();
12899-
} catch (e) { }
12897+
date = this.snapshotURLToDate(url);
1290012898
$('<option />', {
1290112899
value: url,
1290212900
text: date
@@ -12989,6 +12987,34 @@ var app = Sammy('body', function() {
1298912987
});
1299012988
},
1299112989

12990+
loadAndRenderSnapshots: function() {
12991+
var ctx = this;
12992+
this.load('/graphs/' + this.params.uuid + '.js', {cache: false})
12993+
.then(function(graph_data) {
12994+
var $snapshots = ctx.showPane('snapshots', '<h2>' + graph_data.title + '</h2>');
12995+
var snapshots = graph_data.snapshots,
12996+
i = 0, l = snapshots.length, snapshot,
12997+
$snapshot = $('#templates .snapshot').clone();
12998+
for (; i < l; i++) {
12999+
snapshot = snapshots[i];
13000+
$snapshot.clone()
13001+
.find('a.view').attr('href', snapshot).end()
13002+
.find('img').attr('src', snapshot).end()
13003+
.find('h3.title').text(ctx.snapshotURLToDate(snapshot)).end()
13004+
.show()
13005+
.appendTo($snapshots);
13006+
}
13007+
});
13008+
},
13009+
13010+
snapshotURLToDate: function(url) {
13011+
var date;
13012+
try {
13013+
date = new Date(parseInt(url.match(/\/(\d+)\.png/)[1], 10)).toString();
13014+
} catch (e) { }
13015+
return date;
13016+
},
13017+
1299213018
bindEditorPanes: function() {
1299313019
var ctx = this;
1299413020
$('#editor-pane')
@@ -13063,10 +13089,7 @@ var app = Sammy('body', function() {
1306313089
});
1306413090

1306513091
this.get('/graphs/:uuid/snapshots', function(ctx) {
13066-
this.load('/graphs/' + this.params.uuid + '.js', {cache: false})
13067-
.then(function(graph_data) {
13068-
ctx.buildSnapshotsDropdown(graph_data.snapshots, true);
13069-
});
13092+
this.loadAndRenderSnapshots();
1307013093
});
1307113094

1307213095
this.get('/graphs', function(ctx) {

public/js/graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Graphiti.Graph = function(targetsAndOptions){
3030
this.parsedTargets = [];
3131

3232
var defaults = {
33-
width: 800,
33+
width: 950,
3434
height: 400,
3535
from: '-6hour',
3636
fontSize: "10",

views/index.haml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
%h2 ... Loading ...
3131
#dashboards-pane.pane{style: 'display:none;'}
3232
#graphs-pane.pane{style: 'display:none;'}
33+
#snapshots-pane.pane{style: 'display:none;'}
3334
#editor-pane.pane{style: 'display:none;'}
3435
#graph-preview
3536
%img{src: '/images/loading.gif'}
@@ -67,7 +68,9 @@
6768
%input.save.create{type: 'submit', value: 'Save New'}
6869
%form.select{"data-action" => '/graphs/:uuid/snapshots', method: 'get'}
6970
%select{name: 'snapshot'}
70-
%input.save{type: 'submit', value: 'View'}
71+
%input.save.create{type: 'submit', value: 'View'}
72+
%form.select{"data-action" => '/graphs/:uuid/snapshots', method: 'get'}
73+
%input.save{type: 'submit', value: 'View All'}
7174
.clear
7275
.edit-group{'data-group' => 'options'}
7376
.edit-head.closed
@@ -210,7 +213,7 @@
210213
%a.edit
211214
%button Edit
212215
.snapshot{style: 'display:none'}
213-
%a.view
216+
%a.view{target: 'blank'}
214217
%img{src: '/images/loading.gif'}
215218
.desc
216219
%h3.title &nbsp;

views/stylesheets/screen.scss

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ body.bp {
109109
font-size: 12px;
110110
}
111111
select[name=snapshot] {
112-
width: 220px;
112+
width: 190px;
113113
}
114114
h4 {
115115
@include fancy-font;
@@ -279,10 +279,23 @@ h2 {
279279
width: 100%;
280280
height: $blueprint-grid-width * ($blueprint-grid-columns / 2) * 0.75;
281281
}
282-
.desc {
283-
padding: 5px;
284-
background: #f3f3f3;
285-
margin-bottom: 10px;
282+
}
283+
}
284+
.desc {
285+
padding: 5px;
286+
background: #f3f3f3;
287+
margin-bottom: 10px;
288+
}
289+
#snapshots-pane {
290+
.snapshot {
291+
@include column($blueprint-grid-columns);
292+
h3 {
293+
@include fancy-font;
294+
margin: 0px;
295+
padding: 0px;
296+
}
297+
img {
298+
width: 100%;
286299
}
287300
}
288301
}

0 commit comments

Comments
 (0)