Browse Source

sensor tree on left bar

Chuan Miao 9 years ago
parent
commit
412657310d
7 changed files with 111 additions and 196 deletions
  1. 14 6
      gulpfile.js
  2. 1 0
      package.json
  3. 29 5
      src/css/index.css
  4. 9 2
      src/htdocs/index.html
  5. 1 181
      src/javascript/app.js
  6. 13 0
      src/javascript/data.js
  7. 44 2
      src/javascript/page.js

+ 14 - 6
gulpfile.js

@@ -71,7 +71,7 @@ gulp.task('images', function() {
         .pipe(gulp.dest(dest));
 });
 
-gulp.task('icons', function() {
+gulp.task('font-awesome', function() {
     var src = './node_modules/font-awesome/**/*';
     var dest = config.dest + '/vendor';
     return gulp.src(src, {base: './node_modules'})
@@ -79,14 +79,21 @@ gulp.task('icons', function() {
         .pipe(gulp.dest(dest));
 });
 
-gulp.task('vendor', function() {
-    var src = ['./node_modules/bootstrap/dist/css/bootstrap.css'];
+gulp.task('bootstrap', function() {
+    var src = ['./node_modules/bootstrap/dist/css/bootstrap.css',
+               './node_modules/bootstrap/dist/css/bootstrap.css.map'];
     var dest = config.dest + '/vendor';
     return gulp.src(src)
-        // .pipe(debug({title: 'unicorn:'}))
-        .pipe(gulp.dest(dest));
+               // .pipe(debug({title: 'unicorn:'}))
+               .pipe(gulp.dest(dest));
 });
 
+gulp.task('jstree', function() {
+    var src = './node_modules/jstree/dist/themes/**/*';
+    var dest = config.dest + '/vendor/jstree';
+    return gulp.src(src, {base: './node_modules/jstree/dist'})
+               .pipe(gulp.dest(dest));
+});
 
 /**** gulp watch ***************************************************/
 gulp.task('watch', function() {
@@ -98,5 +105,6 @@ gulp.task('watch', function() {
 });
 
 /***** gulp main tasks *********************************************/
+gulp.task('vendor', ['bootstrap', 'font-awesome', 'jstree']);
 gulp.task('build', ['global', 'images', 'css', 'htdocs', 'app']);
-gulp.task('default', ['vendor', 'icons', 'build']);
+gulp.task('default', ['vendor', 'build']);

+ 1 - 0
package.json

@@ -23,6 +23,7 @@
     "gulp-debug": "^2.0.0",
     "gulp-rename": "~1.2.0",
     "gulp-uglify": "~1.0.0",
+    "jstree": "^3.0.9",
     "react": "~0.12.2",
     "reactify": "~0.17.0",
     "vinyl-buffer": "~1.0.0",

+ 29 - 5
src/css/index.css

@@ -23,21 +23,45 @@
 .HolyGrail-sidebar {
     display: flex;
     flex-direction: column;
-    flex: 0 0 210px;
+    flex: 0 0 250px;
     order: -1;
 }
 
 
 .HolyGrail-header {
-    background: #333;
+    color: white;
+    background: #03a9f4;
     border-bottom: 1px solid #d8d8d8;
+    font-size: 1.4em;
 }
 
 .HolyGrail-header-brand {
-    flex: 0 0 210px;
+    order: -1;
+    flex: 0 0 250px;
     text-align: center;
-    font-size: 1.3em;
+    font-style: bold;
     padding: 0.5em 0;
+    color: white;
+    background-color: #03a9f4;
+    border-right: 1px solid rgba(95,95,95, 0.1);
+}
+
+.HolyGrail-header > nav {
+    flex: 1 0 auto;
+}
+.HolyGrail-header nav ul {
+    display: flex;
+    flex-direction: row;
+    justify-content: flex-end;
+    list-style: none;
+    font-size: 0.7em;
+}
+.HolyGrail-header nav li {
+    flex: 0 1 auto;
+    /*border-bottom: 1px solid #ccc;*/
+    margin: 1.25em 2em 0 0;
+    padding: 0;
+    display: block;
 }
 
 .HolyGrail-sidebar {
@@ -46,7 +70,7 @@
 }
 
 
-#sidebar-search-box {
+#sidebar-search {
     flex: 0 0 auto;
     order: -1;
     padding: 6px 6px;

+ 9 - 2
src/htdocs/index.html

@@ -4,17 +4,24 @@
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="./vendor/bootstrap.css">
   <link rel="stylesheet" href="./vendor/font-awesome/css/font-awesome.css">
+  <link rel="stylesheet" href="./vendor/jstree/themes/default/style.css">
   <link rel="stylesheet" href="css/index.css">
 </head>
 <body class="HolyGrail">
 
   <header class="HolyGrail-header" role="banner">
-      <a href="../" class="HolyGrail-header-brand">Data Display</a>
+      <div class="HolyGrail-header-brand">KITCube Display</div>
+      <nav>
+      <ul>
+        <li>Summary</li>
+        <li>Modules</li>
+      </ul>
+      </nav>
   </header>
 
   <div class="HolyGrail-body">
     <nav class="HolyGrail-sidebar"> 
-      <div id="sidebar-search-box">
+      <div id="sidebar-search">
         <input type="text" class="form-control" placeholder="Search" name="srch-term" id="srch-term">
       </div>
       <div id="sidebar-sensor-tree">Tree</div>

+ 1 - 181
src/javascript/app.js

@@ -15,188 +15,8 @@ config = {
     server: "orca",
 };
 
-var ToggleContent = React.createClass({
-    render: function() {
-        var rightAlign = {
-            marginRight: '10px',
-            float: 'right'
-        }
-        var leftAlign = {
-            marginLeft: '10px',
-            float: 'left'
-        };
-        return (
-            <div className={'toggle-content'}>
-                <div><b style={leftAlign}>ID</b> <span style={rightAlign}>{this.props.id}</span></div><br/>
-                <div><b style={leftAlign}>IP</b> <span style={rightAlign}>{this.props.ip_address}</span></div><br/>
-                <div><b style={leftAlign}>Time to go</b> <span style={rightAlign}>{this.props.timeToGo}</span></div><br/>
-            </div>
-            );
-    }
-});
-
-var MyComponent = React.createClass({
-    mixins: [Backbone.React.Component.mixin],
-    getInitialSate: function() {
-        return {showMore: false}
-    },
-    onClick: function () {
-        this.setState({showMore: !this.state.showMore})
-    },
-    millisecondsToStr: function (milliseconds) {
-        // TIP: to find current time in milliseconds, use:
-        // var  current_time_milliseconds = new Date().getTime();
-
-        function numberEnding (number) {
-            return (number > 1) ? 's' : '';
-        }
-
-        var temp = Math.floor(milliseconds / 1000);
-        var years = Math.floor(temp / 31536000);
-        if (years) {
-            return years + ' year' + numberEnding(years);
-        }
-        //TODO: Months! Maybe weeks? 
-        var days = Math.floor((temp %= 31536000) / 86400);
-        if (days) {
-            return days + ' day' + numberEnding(days);
-        }
-        var hours = Math.floor((temp %= 86400) / 3600);
-        if (hours) {
-            return hours + ' hour' + numberEnding(hours);
-        }
-        var minutes = Math.floor((temp %= 3600) / 60);
-        if (minutes) {
-            return minutes + ' minute' + numberEnding(minutes);
-        }
-        var seconds = temp % 60;
-        if (seconds) {
-            return seconds + ' second' + numberEnding(seconds);
-        }
-        return 'less than a second'; //'just now' //or other string you like;
-    },
-    render: function () { 
-        var arrowStyle = {
-            display: 'block',
-            marginLeft: 'auto',
-            marginRight: 'auto',
-            width: '20px'
-        };
-        var rightAlign = {
-            marginRight: '10px',
-            float: 'right'
-        }
-        var leftAlign = {
-            marginLeft: '10px',
-            float: 'left'
-        };
-        return (
-            <div>
-            <h4>{this.props.name}</h4>
-            <div><b style={leftAlign}>Experiment</b> <span style={rightAlign}>{this.props.experiment}</span></div><br/>
-            <div><b style={leftAlign}>State</b> <span style={rightAlign}>{this.props.state ? 'Running' : 'Stopped'}</span></div><br/>
-            <div><b style={leftAlign}>Run time</b> <span style={rightAlign}>{this.millisecondsToStr(this.props.uptime*1000)}</span></div><br/>
-            { this.state.showMore 
-                ? <div><ToggleContent {...this.props} /> <img src="./images/arrow_up.png" alt="toggle" style={arrowStyle} onClick={this.onClick} /></div>
-                : <img src="./images/arrow_down.png" alt="toggle" style={arrowStyle} onClick={this.onClick} /> }
-            </div>);
-    }
-});
-
-var Run = Backbone.RelationalModel.extend({
-    parse: function(resp) {
-        if (typeof resp.data === 'undefined')
-            return resp;
-        else
-            return resp.data[0];
-    }
-});
-
-var Runs = Backbone.Collection.extend({
-    model: Run,
-    parse: function(resp) {
-        return resp.data;
-    }
-});
-
-var Machine = Backbone.Model.extend({
-    parse: function(resp) {
-        if (typeof resp.data === 'undefined')
-            return resp;
-        else
-            return resp.data[0];
-    }
-});
-
-var Machines = Backbone.Collection.extend({
-    model: Machine,
-    parse: function(resp) {
-        return resp.data;
-    },
-
-});
-
-
-function setup0() {
-    machines.fetch({
-        error: function(c) {
-            console.log('oops');
-        },
-        success: function(c) {
-            _.each(c.models, function(model, key) {
-                var _id = 'block' + (++key);
-                React.render(<MyComponent model={model} />, document.getElementById(_id));    
-            });
-        }
-    });
-}
-
-function setup() {
-    $.when( machines.fetch(), runs.fetch()).then( function(){
-        var run_info = {}
-        _.each(runs.models, function(run) {
-            var run = run.attributes;
-            run_info[run.machine_id] = run;
-        });
-        _.each(machines.models, function(machine, key) {
-            var run = run_info[machine.attributes.machine_id];
-            _.extend(machines.models[key].attributes, run);
-            React.render(<MyComponent model={machines.models[key]} />, document.getElementById('block'+(key+1)));
-        });
-    });
-}
-
-function update() {
-    $.when( machines.fetch(), runs.fetch()).then( function(){
-        var run_info = {}
-        _.each(runs.models, function(run) {
-            run_info[run.machine_id] = run.attributes;
-        });
-        _.each(machines.models, function(machine, key) {
-            var run = run_info[machine.attributes.machine_id];
-            _.extend(machines.models[key].attributes, run);
-        });
-
-    });
-}
-
-var url = config.url + config.server + "/";
-
-machines = new Machines({});
-machines.url = url+'machines';
-
-runs = new Runs({});
-runs.url = url + 'runs';
-
-//setup0();
-setup();
-
-
-setInterval(function() {
-    update();
-}, 10000);
 
 $(document).ready(function() {
     console.log('ready'); 
-    page.toggleSidebar();
+    page.init();
 });

+ 13 - 0
src/javascript/data.js

@@ -0,0 +1,13 @@
+var $ = jQuery = require('jquery');
+var _ = require('underscore');
+var Backbone = require('backbone');
+Backbone.$ = $;
+
+
+
+module.exports = {
+	init: function() {
+		$
+	}
+};
+

+ 44 - 2
src/javascript/page.js

@@ -1,11 +1,53 @@
 var $ = require('jquery');
+var jstree = require('jstree');
 
 module.exports = {
 	toggleSidebar: function() {
 		$('.toggle-sidebar').click(function() {
-			var v = $('.HolyGrail-sidebar').css('visibility');
 			$('.HolyGrail-sidebar').toggle();
-			console.log(v);
 		});		
+	},
+	sensorTree: function() {
+		
+		var sensordata =
+			{
+				'text': 'Katrin',
+				'children': [
+					'sensor1',
+					'sensor2'
+				],
+			};
+
+		$('#sidebar-sensor-tree').jstree({
+			'core': { 'data': sensordata},
+			'plugins': [ 'wholerow', 'checkbox', 'search' ]
+		});
+		var to = false;
+		$('#sidebar-search > input').keyup(function () {
+			if(to) { clearTimeout(to); }
+    		to = setTimeout(function () {
+      			var v = $('#sidebar-search > input').val();
+      			$('#sidebar-sensor-tree').jstree(true).search(v);
+    		}, 250);
+		});
+	},
+	getSensorList: function() {
+		var url = 'http://katrin.kit.edu/newstatus/katrin/api/adeiinfo.json';
+		$.getJSON(url, function(data) {
+			var servers;
+			// data --> servers
+			// servers = {
+			// 	'katrin': {...},
+			// 	'aircoils': {...}
+			// };
+			console.log(servers);
+		});
+
+		var tables = $
+	},
+	init: function() {
+		this.toggleSidebar();
+		this.sensorTree();
+		this.getSensorList();
 	}
 };