jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r1565193 - in /jena/branches/jena-fuseki-new-ui/pages: ./ js/app/ js/app/controllers/ js/app/models/ js/app/templates/ js/app/views/
Date Thu, 06 Feb 2014 12:15:36 GMT
Author: ijd
Date: Thu Feb  6 12:15:36 2014
New Revision: 1565193

URL: http://svn.apache.org/r1565193
Log:
First cut at stats display

Added:
    jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset-stats.js
Modified:
    jena/branches/jena-fuseki-new-ui/pages/admin-stats.html
    jena/branches/jena-fuseki-new-ui/pages/js/app/controllers/dataset-stats-controller.js
    jena/branches/jena-fuseki-new-ui/pages/js/app/main.stats.js
    jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js
    jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-selection-list.tpl
    jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-stats.tpl
    jena/branches/jena-fuseki-new-ui/pages/js/app/views/dataset-stats.js

Modified: jena/branches/jena-fuseki-new-ui/pages/admin-stats.html
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/admin-stats.html?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/admin-stats.html (original)
+++ jena/branches/jena-fuseki-new-ui/pages/admin-stats.html Thu Feb  6 12:15:36 2014
@@ -75,6 +75,7 @@
       <div class="row">
         <h1>Statistics</h1>
       </div>
+      <div id="stats"></div>
     </div>
 
     <script src="../js/lib/jquery-1.10.2.min.js"></script>

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/controllers/dataset-stats-controller.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/controllers/dataset-stats-controller.js?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/controllers/dataset-stats-controller.js
(original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/controllers/dataset-stats-controller.js
Thu Feb  6 12:15:36 2014
@@ -5,7 +5,9 @@ define(
         Backbone = require( "backbone" ),
         _ = require( "underscore" ),
         fui = require( "fui" ),
-        DatasetStatsView = require( "views/dataset-stats" );
+        DatasetStatsView = require( "views/dataset-stats" ),
+        DatasetStatsModel = require( "models/dataset-stats" ),
+        PageUtils = require( "util/page-utils" );
 
     var DatasetStatsController = function() {
       this.initEvents();
@@ -18,23 +20,12 @@ define(
         fui.vent.on( "models.fuseki-server.ready", this.onServerModelReady );
       },
 
-      /** When the fuseki server is ready, we can list the initial datasets */
       onServerModelReady: function( event ) {
-        new DatasetStatsView( {model: this.assembleViewModel( fui )} ).render();
-      },
-
-      /** Assemble a model which we can pass to the dataset details view to render */
-      assembleViewModel: function( fui ) {
-        var viewModel = {};
-
-        viewModel.fusekiServer = fui.models.fusekiServer;
-
-        return viewModel;
-      },
-
-      getDatasetId: function() {
-        var dsId = $.trim( location.hash );
-        return (dsId == "") ? null : dsId.substr(1).replace( "/", "" );
+        var dsName = PageUtils.queryParam( "ds" );
+        if (dsName) {
+          fui.models.datasetStats = new DatasetStatsModel( fui.models.fusekiServer, dsName
);
+          new DatasetStatsView( {model: fui.models.datasetStats} ).render();
+        }
       }
 
     } );

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/main.stats.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/main.stats.js?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/main.stats.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/main.stats.js Thu Feb  6 12:15:36 2014
@@ -4,7 +4,7 @@ define( ['require', '../common-config'],
     require(
       ['underscore', 'jquery', 'backbone', 'marionette', 'fui', 'controllers/dataset-stats-controller',
        'sprintf', 'bootstrap',
-       'models/fuseki-server', 'models/dataset',
+       'models/fuseki-server', 'models/dataset-stats',
        'views/dataset-stats',
        'services/ping-service',
        'lib/jquery.xdomainrequest',

Added: jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset-stats.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset-stats.js?rev=1565193&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset-stats.js (added)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/models/dataset-stats.js Thu Feb  6 12:15:36
2014
@@ -0,0 +1,116 @@
+/**
+ * Backbone model denoting statistics on a dataset
+ */
+define(
+  function( require ) {
+    "use strict";
+
+    var Marionette = require( "marionette" ),
+        Backbone = require( "backbone" ),
+        _ = require( "underscore" ),
+        fui = require( "fui" ),
+        sprintf = require( "sprintf" );
+
+    /**
+     * This model represents the statistics available on a given named dataset
+     */
+    var DatasetStats = Backbone.Model.extend( {
+      initialize: function( fusekiServer, dsName ) {
+        _.bindAll( this, "onLoadDone", "onLoadFail" );
+        this.set( {"ds.name": dsName,
+                   url: fusekiServer.statsURL( dsName )
+                  } );
+
+        this.load();
+      },
+
+      load: function() {
+        $.getJSON( this.url() )
+         .done( this.onLoadDone )
+         .fail( this.onLoadFail );
+      },
+
+      /** Return the number of datasets we have statistics for */
+      size: function() {
+        return _.keys( datasets() ).length;
+      },
+
+      name: function() {
+        return this.get( "ds.name" );
+      },
+
+      toJSON: function() {
+        return this.table();
+      },
+
+      /** Return a table of the statistics we have, one row per dataset */
+      table: function() {
+        var ds = this.datasets();
+        var services = this.collectServices( ds );
+        var rows = [];
+
+        _.each( ds, function( d, dsName ) {
+          var row = [dsName, d.Requests, d.RequestsGood, d.RequestsBad];
+          var s = d.services;
+
+          _.each( services, function( service ) {
+            if (s[service]) {
+              var servStats = s[service];
+
+              if (servStats.Requests === 0) {
+                row.push( "0" );
+              }
+              else {
+                row.push( sprintf( "%d (%d bad)", servStats.Requests, servStats.RequestsBad
))
+              }
+            }
+            else {
+              row.push( "" );
+            }
+          } );
+
+          rows.push( row );
+        } );
+
+        return {headings: this.columnHeadings( services ), rows: rows};
+      },
+
+      url: function() {
+        return this.get( "url" );
+      },
+
+      stats: function() {
+        return this.get( "stats" );
+      },
+
+      datasets: function() {
+        return this.stats() ? this.stats().datasets : {};
+      },
+
+      onLoadDone: function( data ) {
+        this.set( {stats: data} );
+        fui.vent.trigger( "model.stats.loaded" );
+      },
+
+      onLoadFail: function() {
+        fui.vent.trigger( "model.stats.loadFailed" );
+      },
+
+      // internal methods
+
+      collectServices: function( ds ) {
+        var services = [];
+        _.each( ds, function( d ) {
+          services = services.concat( _.keys( d.services ) );
+        } );
+        return _.uniq( services ).sort();
+      },
+
+      columnHeadings: function( services ) {
+        return ["Service name", "overall", "good", "bad"].concat( services );
+      }
+    } );
+
+    return DatasetStats;
+  }
+);
\ No newline at end of file

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/models/fuseki-server.js Thu Feb  6 12:15:36
2014
@@ -33,6 +33,11 @@ define(
         return this._managementURL;
       },
 
+      /** Return the URL for getting the stats for a named dataset */
+      statsURL: function( dsName ) {
+        return sprintf( "%s/$/stats%s", this.managementURL(), dsName ? dsName : "" );
+      },
+
       /** Return the list of datasets that this server knows about. Each dataset will be
a Dataset model object */
       datasets: function() {
         return this.get( "datasets" );

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-selection-list.tpl
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-selection-list.tpl?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-selection-list.tpl (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-selection-list.tpl Thu
Feb  6 12:15:36 2014
@@ -14,7 +14,7 @@
         <td>
           <a class="btn btn-sm action remove btn-primary" href="query.html?ds=<%= ds.name()
%>"><i class='fa fa-question-circle'></i> query</a>
           <a class="btn btn-sm action remove btn-primary" href="explore.html?ds=<%=
ds.name() %>"><i class='fa fa-globe'></i> explore</a>
-          <a class="btn btn-sm action configure btn-primary" href="admin-dataset-details.html?ds=<%=
ds.name() %>"><i class='fa fa-wrench'></i> manage</a>
+          <a class="btn btn-sm action configure btn-primary" href="admin-stats.html?ds=<%=
ds.name() %>"><i class='fa fa-dashboard'></i> stats</a>
         </td>
       </tr>
     <% }) %>

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-stats.tpl
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-stats.tpl?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-stats.tpl (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/templates/dataset-stats.tpl Thu Feb  6 12:15:36
2014
@@ -1 +1,14 @@
-<p>Dataset stats TODO</p>
\ No newline at end of file
+<table class="table">
+  <tr>
+    <% _.each( headings, function( h ) { %>
+      <th><%= h %></th>
+    <% } ); %>
+  </tr>
+  <% _.each( rows, function( row ) { %>
+    <tr>
+      <% _.each( row, function( cell ) { %>
+        <td><span class="text-right"><%= cell %></span></td>
+      <% } ); %>
+    </tr>
+  <% } ) %>
+</table>
\ No newline at end of file

Modified: jena/branches/jena-fuseki-new-ui/pages/js/app/views/dataset-stats.js
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/pages/js/app/views/dataset-stats.js?rev=1565193&r1=1565192&r2=1565193&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/pages/js/app/views/dataset-stats.js (original)
+++ jena/branches/jena-fuseki-new-ui/pages/js/app/views/dataset-stats.js Thu Feb  6 12:15:36
2014
@@ -14,7 +14,7 @@ define(
       ui: {
       },
 
-      el: "#dataset-stats",
+      el: "#stats",
 
       events: {
 //        "click a.action.commit.simple": "onCommitSimple",
@@ -24,8 +24,12 @@ define(
       templateHelpers: {
       },
 
-      serializeData: function() {
-        return this.model;
+      modelEvents: {
+        'change': "modelChanged"
+      },
+
+      modelChanged: function() {
+          this.render();
       }
 
       // event handlers



Mime
View raw message