Skip to content

Commit 2d3cad9

Browse files
committed
extra page for stats
1 parent 056c011 commit 2d3cad9

6 files changed

Lines changed: 92 additions & 66 deletions

File tree

src/main/java/de/unirostock/sems/cbarchive/web/Fields.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,17 @@ public class Fields {
7676
/** Link to the sedML WebTools for starting a simulation */
7777
public static String SEDML_WEBTOOLS_URL = null;
7878

79-
/** max time for caching statistic data */
80-
public static long MAX_STATS_AGE = 180;
81-
8279
/** Link to a feedback form */
8380
public static String FEEDBACK_URL = "https://sems.uni-rostock.de/trac/combinearchive-web/newticket?from=WEBCAT-INTERFACE";
81+
82+
/** max time for caching statistic data */
83+
public static long STATS_MAX_AGE = 180;
84+
85+
/** switch the open stats page on or off, also limits the access to the rest-endpoint, when set to false */
86+
public static boolean STATS_PUBLIC = true;
87+
88+
/** is set to something != null, it enables the full access to all stats, when added as URL-Parameter */
89+
public static String STATS_SECRET = null;
8490

8591
// ------------------------------------------------------------------------
8692
// Quotas
@@ -152,7 +158,7 @@ else if (desiredLogLevel.equals ("NONE"))
152158
Fields.SEDML_WEBTOOLS_URL = null;
153159

154160
// max stats age
155-
MAX_STATS_AGE = parseLong( context.getInitParameter("MAX_STATS_AGE"), MAX_STATS_AGE );
161+
STATS_MAX_AGE = parseLong( context.getInitParameter("MAX_STATS_AGE"), STATS_MAX_AGE );
156162

157163
// feedback Url
158164
String feedbackUrl = context.getInitParameter("FEEDBACK_URL");

src/main/java/de/unirostock/sems/cbarchive/web/QuotaManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public long updateWorkspace( String workspaceId ) {
118118
public StatisticData getStats() {
119119

120120
// if cache is ok
121-
if( stats == null || statsTimestamp == null || (new Date().getTime() - statsTimestamp.getTime() + workerExecutionTime)/1000 > Fields.MAX_STATS_AGE )
121+
if( stats == null || statsTimestamp == null || (new Date().getTime() - statsTimestamp.getTime() + workerExecutionTime)/1000 > Fields.STATS_MAX_AGE )
122122
generateStats();
123123

124124
LOGGER.debug( "return stats, generated at ", stats.getGenerated() );
@@ -272,7 +272,7 @@ public void run() {
272272
if( Fields.QUOTA_ARCHIVE_LIMIT != Fields.QUOTA_UNLIMITED )
273273
stats.setAverageArchiveCountQuota( stats.getAverageArchiveCount() / (double) Fields.QUOTA_ARCHIVE_LIMIT );
274274

275-
stats.setMaxStatsAge( Fields.MAX_STATS_AGE );
275+
stats.setMaxStatsAge( Fields.STATS_MAX_AGE );
276276

277277
// tranfer the results to the main class
278278
quotaManager.workspaceCache = cache;

src/main/webapp/WEB-INF/Index.jsp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@
7474
<div class="nav-container">
7575
<small>The current workspace contains the following archives:</small>
7676
<div style="clear: both;"></div>
77-
<ul id="nav-workspace" style="float: left; width: 70%;">
77+
<ul id="nav-workspace" style="float: left; width: 65%;">
7878
{{# _.each(entries, function(entry) { }}
7979
<li><a class="mainLinks archive-link archives" data-linktype="archive" data-archiveid="{{# print(entry.id); }}" id="nav-archivelink-{{# print(entry.id); }}" title="Archive {{# print(escape(entry.name)); }} in current Workspace">{{# print(escape(entry.name)); }}</a></li>
8080
{{# }); }}
8181
</ul>
82-
<ul id="nav-main" style="float: right; width: 29%;">
82+
<ul id="nav-main" style="float: right; width: 34%;">
8383
<li><a class="mainLinks command-link highlight" data-linktype="page" data-page="start-page" id="nav-startlink">start</a></li>
8484
<li><a class="mainLinks command-link" data-linktype="page" data-page="about-page" id="nav-aboutlink">about</a></li>
85+
<% if( Fields.STATS_PUBLIC ) { %>
86+
<li><a class="mainLinks command-link" data-linktype="page" data-page="stats-page" id="nav-statslink">stats</a></li>
87+
<% } %>
8588
<li><a class="mainLinks command-link" data-linktype="page" data-page="create-page" id="nav-createlink">create</a></li>
8689
</ul>
8790
<div style="clear: both;"></div>
@@ -660,6 +663,9 @@
660663
<div id="start-page" class="subPage"></div>
661664

662665
<div id="about-page" class="subPage" style="display: none;"></div>
666+
<% if( Fields.STATS_PUBLIC ) { %>
667+
<div id="stats-page" class="subPage" style="display: none;"></div>
668+
<% } %>
663669
<div id="create-page" class="subPage" style="display: none;"></div>
664670
<div id="archivePage" class="subPage" style="display: none;"></div>
665671
</div>

src/main/webapp/res/js/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var navigationView = null;
66
var archiveView = null;
77
var startView = null;
88
var createView = null;
9+
var statsView = null;
910
var aboutView = null;
1011
var messageView = null;
1112
var templateCache = {};
@@ -67,7 +68,6 @@ $(document).ready(function () {
6768
var html = $el.html();
6869

6970
if( id != undefined && html != undefined && html.length > 1) {
70-
console.log(html);
7171
html = html.replace(__deescape.amp, "&").replace(__deescape.lt, "<").replace(__deescape.gt, ">");
7272
templateCache[ id ] = _.template(html);
7373
}

src/main/webapp/res/js/models.js

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ var NavigationView = Backbone.View.extend({
213213
doNavigation: function ($target, setHistory) {
214214

215215
// hide current page
216-
$(".subPage").hide();
216+
$(".subPage").trigger("hide").hide();
217217
// do highlighting
218218
this.$el.find(".mainLinks").removeClass("highlight");
219219
$target.addClass("highlight");
@@ -226,8 +226,6 @@ var NavigationView = Backbone.View.extend({
226226
var archiveId = $target.data("archiveid");
227227
var archiveModel = this.collection.get(archiveId);
228228

229-
console.log( archiveId );
230-
231229
if( archiveModel ) {
232230
archiveView.setArchive( archiveModel );
233231
if( setHistory == true )
@@ -238,7 +236,7 @@ var NavigationView = Backbone.View.extend({
238236
}
239237
else if( linkType == "page" ) {
240238
var page = $target.data("page");
241-
$( "#" + page ).show();
239+
$( "#" + page ).trigger("show").show();
242240

243241
if( setHistory == true )
244242
pageRouter.navigate( page.split("-")[0] );
@@ -247,7 +245,7 @@ var NavigationView = Backbone.View.extend({
247245
}
248246
else {
249247
// seems to be no valid navlink
250-
$("#start-page").show();
248+
$("#start-page").trigger("show").show();
251249
if( setHistory == true )
252250
pageRouter.navigate( "start" );
253251

@@ -1875,59 +1873,10 @@ var CreateView = Backbone.View.extend({
18751873

18761874
});
18771875

1878-
var StatsView = Backbone.View.extend({
1879-
1880-
el: null,
1881-
model: null,
1882-
1883-
initialize: function() {
1884-
this.template = templateCache["template-stats"];
1885-
this.model = new StatsModel();
1886-
this.fetch();
1887-
1888-
// var self = this;
1889-
//setInterval( function() { self.fetch(); }, 10000 );
1890-
},
1891-
render: function() {
1892-
1893-
var json = { "stats": this.model.toJSON() };
1894-
this.$el.html( this.template(json) );
1895-
1896-
// show if not already is shown
1897-
if( this.$el.is(":visible") == false )
1898-
this.$el.fadeIn();
1899-
},
1900-
fetch: function() {
1901-
1902-
if( this.model == null )
1903-
return;
1904-
1905-
var self = this;
1906-
this.model.fetch({
1907-
success: function(model, response, options) {
1908-
self.render();
1909-
setTimeout( function() { self.fetch(); }, model.has("maxStatsAge") ? (model.get("maxStatsAge")+5) * 1000 : 30000 );
1910-
},
1911-
error: function(model, response, options) {
1912-
self.$el.fadeOut();
1913-
if( response.responseJSON !== undefined && response.responseJSON.status == "error" )
1914-
console.log("Error while fetching stats: " + response.responseJSON.errors);
1915-
else
1916-
console.log("Error while fetching stats!");
1917-
}
1918-
});
1919-
1920-
},
1921-
1922-
events: {
1923-
}
1924-
});
1925-
19261876
var StartView = Backbone.View.extend({
19271877

19281878
el: "#start-page",
19291879
collection: null,
1930-
statsView: null,
19311880

19321881
initialize: function() {
19331882
this.template = templateCache["template-start"];
@@ -1940,9 +1889,6 @@ var StartView = Backbone.View.extend({
19401889
var json = { "history": this.collection.toJSON(), "current": current.toJSON(), "baseUrl": this.getBaseUrl() };
19411890
this.$el.html( this.template(json) );
19421891

1943-
this.statsView = new StatsView({
1944-
el: this.$el.find(".stats-div")
1945-
});
19461892
},
19471893
fetch: function() {
19481894

@@ -2050,6 +1996,69 @@ var StartView = Backbone.View.extend({
20501996
}
20511997
});
20521998

1999+
var StatsView = Backbone.View.extend({
2000+
2001+
el: "#stats-page",
2002+
model: null,
2003+
timeout: null,
2004+
2005+
initialize: function() {
2006+
2007+
if( this.$el.length <= 0 )
2008+
return;
2009+
2010+
this.template = templateCache["template-stats"];
2011+
this.model = new StatsModel();
2012+
2013+
var self = this;
2014+
this.$el.on( "show", function() {
2015+
console.log("show stats");
2016+
self.fetch();
2017+
}).on( "hide", function() {
2018+
// cancel fetching
2019+
if( self.timeout != null ) {
2020+
clearTimeout(self.timeout);
2021+
self.timeout = null;
2022+
}
2023+
});
2024+
2025+
this.fetch();
2026+
2027+
},
2028+
render: function() {
2029+
2030+
var json = { "stats": this.model.toJSON() };
2031+
this.$el.html( this.template(json) );
2032+
2033+
},
2034+
fetch: function() {
2035+
2036+
if( this.model == null )
2037+
return;
2038+
2039+
this.timeout = null;
2040+
var self = this;
2041+
this.model.fetch({
2042+
success: function(model, response, options) {
2043+
self.render();
2044+
if( self.$el.is(":visible") && self.timeout == null )
2045+
self.timeout = setTimeout( function() { self.fetch(); }, model.has("maxStatsAge") ? (model.get("maxStatsAge")+5) * 1000 : 30000 );
2046+
},
2047+
error: function(model, response, options) {
2048+
self.$el.fadeOut();
2049+
if( response.responseJSON !== undefined && response.responseJSON.status == "error" )
2050+
console.log("Error while fetching stats: " + response.responseJSON.errors);
2051+
else
2052+
console.log("Error while fetching stats!");
2053+
}
2054+
});
2055+
2056+
},
2057+
2058+
events: {
2059+
}
2060+
});
2061+
20532062
var AboutView = Backbone.View.extend({
20542063

20552064
el: "#about-page",

src/main/webapp/res/js/router.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var PageRouter = Backbone.Router.extend({
55
"": "start",
66
"start": "start",
77
"create": "create",
8+
"stats": "stats",
89
"about": "about",
910
"archive/:archiveId": "archive",
1011
},
@@ -17,6 +18,7 @@ var PageRouter = Backbone.Router.extend({
1718
archiveView = new ArchiveView();
1819
startView = new StartView();
1920
createView = new CreateView();
21+
statsView = new StatsView();
2022
aboutView = new AboutView();
2123
messageView = new MessageView();
2224

@@ -49,6 +51,9 @@ var PageRouter = Backbone.Router.extend({
4951
create: function() {
5052
navigationView.goToPage("create-page", false);
5153
},
54+
stats: function() {
55+
navigationView.goToPage("stats-page", false);
56+
},
5257
about: function() {
5358
navigationView.goToPage("about-page", false);
5459
},

0 commit comments

Comments
 (0)