1. biolab
  2. Untitled project
  3. benguru

Commits

Miha Stajdohar  committed d6bcedf

Load a bookmark.

  • Participants
  • Parent commits ba8b1f3
  • Branches master

Comments (0)

Files changed (5)

File main/static/main/js/app.js

View file
             });
 
             // Watch for any changes from outside the directive and refresh
-            scope.$watch(attributes.ngModel, function () {
+            scope.$watch(attributes.ngModel, function (option) {
+                if (option instanceof Array) {
+                    for (var i = 0, l = option.length; i < l; i++) {
+                        element.multiselect('selectText', option[i].label);
+                    }
+                } else if (option !== null) {
+                    element.multiselect('selectText', option.label);
+                }
                 element.multiselect('refresh');
             });
 

File main/static/main/js/controllers.js

View file
 'use strict';
 
-function BenchmarksCtrl($scope, $filter, $routeParams, ngTableParams, Benchmark) {
+function BenchmarksCtrl($scope, $filter, $routeParams, ngTableParams, Benchmark, Bookmark) {
     var bookmarkId = $routeParams.bookmarkId,
         field_names = {},
         orderedData,
-        data,
-        checkboxes;
+        data;
 
     $('#benchmarks-list-item').addClass('active');
     $('#bookmarks-list-item').removeClass('active');
     $scope.error_message = '';
     $scope.success_message = '';
 
-    $scope.tableBenchmarks = new ngTableParams({
-        page: 1,            // show first page
-        total: 0,           // length of data
-        count: 10,          // count per page
-        filter: '',         // initial filter
-        sorting: {
-            date: 'desc'    // initial sorting
-        }
-    });
+    function set_defaults() {
+        $scope.tableBenchmarks = new ngTableParams({
+            page: 1,            // show first page
+            total: 0,           // length of data
+            count: 10,          // count per page
+            filter: '',         // initial filter
+            sorting: {
+                date: 'desc'    // initial sorting
+            }
+        });
 
-    $scope.attribute_x = null;
-    $scope.attribute_y = [];
+        $scope.attribute_x = null;
+        $scope.attribute_y = [];
+
+        $scope.checkboxes = { 'checked': false, items: {}, 'num_checked': 0 };
+    }
+
+    set_defaults();
 
     $scope.attributes_x = [
         {label: 'Date', attribute: 'date'},
         description: ""
     }
 
-    checkboxes = $scope.checkboxes = { 'checked': false, items: {}, 'num_checked': 0 };
-
-    $scope.foolist = ["Foo", "Bar"];
-
     $('.multiselect').multiselect({
         buttonClass: 'btn btn-default',
         maxHeight: 240
     });
 
     $scope.add_bookmark = function () {
-        $scope.bookmark.scope = {
+        $scope.bookmark.scope = JSON.stringify({
             filter: $scope.tableBenchmarks.filter,
             sorting: $scope.tableBenchmarks.sorting,
             checkboxes: $scope.checkboxes,
             attribute_x: $scope.attribute_x,
             attribute_y: $scope.attribute_y
-        };
+        });
 
         if (true) {
             $('#request-demo-email').closest('.control-group').removeClass('error');
 
             var plot_benchmarks = function () {
                 if ($scope.attribute_x !== null && $scope.attribute_y.length > 0 &&
-                    checkboxes.num_checked > 0) {
+                    $scope.checkboxes.num_checked > 0) {
 
                     var counter = 0,
                         ticks = [],
                         bar_width = 4 / ($scope.attribute_y.length + 0.5) / 5;
 
                     for (var i = 0, l = orderedData.length; i < l; i++) {
-                        if (checkboxes.items[orderedData[i].id]) {
+                        if ($scope.checkboxes.items[orderedData[i].id]) {
                             var x = orderedData[i][$scope.attribute_x.attribute],
                                 y;
 
             $scope.$watch('attribute_x', plot_benchmarks);
             $scope.$watch('attribute_y', plot_benchmarks);
 
+            // load bookmarked values
             if (bookmarkId !== undefined) {
+                Bookmark.get({bookmarkId: bookmarkId}, function (bookmark) {
+                    set_defaults();
+
+                    bookmark.scope = JSON.parse(bookmark.scope);
 
-                /*
-                $scope.bookmark.scope = {
-                    filter: $scope.tableBenchmarks.filter,
-                    sorting: $scope.tableBenchmarks.sorting,
-                    checkboxes: $scope.checkboxes,
-                    attribute_x: $scope.attribute_x,
-                    attribute_y: $scope.attribute_y
-                };
-
-                $scope.tableBenchmarks.filter = bookmarkId
-                $scope.tableBenchmarks.sorting
-                $scope.checkboxes
-                $scope.attribute_x
-                $scope.attribute_y
-                */
+                    if (bookmark.scope.filter !== undefined) {
+                        $scope.tableBenchmarks.filter = bookmark.scope.filter;
+                    }
+                    if (bookmark.scope.sorting !== undefined) {
+                        $scope.tableBenchmarks.sorting = bookmark.scope.sorting;
+                    }
+                    if (bookmark.scope.checkboxes !== undefined) {
+                        $scope.checkboxes = bookmark.scope.checkboxes;
+                    }
+                    if (bookmark.scope.attribute_x !== undefined) {
+                        $scope.attribute_x = bookmark.scope.attribute_x;
+                    }
+                    if (bookmark.scope.attribute_y !== undefined) {
+                        $scope.attribute_y = bookmark.scope.attribute_y;
+                    }
+                });
             }
         }
     );
 
     bookmarks = Bookmark.query(function () {
         $scope.bookmarks = bookmarks.objects;
-
-
     });
 }

File main/static/main/lib/bootstrap-multiselect.js

View file
             this.options.onChange($option, false);
         },
 
+        // Select an option by its text.
+        selectText: function(value) {
+            var $option = $('option', this.$select).filter(function() {
+                return $(this).text() == value;
+            });
+            var $checkbox = $('.multiselect-container li input', this.$container).filter(function() {
+                return $(this).val() == $option.val();
+            });
+
+            if (this.options.selectedClass) {
+                $checkbox.parents('li').addClass(this.options.selectedClass);
+            }
+
+            $checkbox.prop('checked', true);
+
+            $option.attr('selected', 'selected').prop('selected', true);
+
+            this.updateButtonText();
+            this.options.onChange($option, true);
+        },
+
         // Rebuild the whole dropdown menu.
         rebuild: function() {
             $('.multiselect-container', this.$container).html('');

File main/static/main/partials/benchmarks.html

View file
     <div class="col-md-12">
         <div class="form-group">
             <label for="attribute-x" class="control-label">Attribute on x-axis:</label>
-            <select id="attribute-x" ng-model="attribute_x" ng-options="a.label for a in attributes_x" class="multiselect form-input" multiselect-dropdown>
+            <select id="attribute-x" ng-model="attribute_x" ng-options="a.attribute as a.label for a in attributes_x" class="multiselect form-input" multiselect-dropdown>
                 <option value=''>None selected</option>
             </select>
         </div>
     <div class="col-md-12">
         <div class="form-group">
             <label for="attribute-y" class="control-label">Attribute(s) on y-axis:</label>
-            <select id="attribute-y" ng-model="attribute_y" ng-options="a.label for a in attributes_y" class="multiselect form-input" multiple="multiple" multiselect-dropdown></select>
+            <select id="attribute-y" ng-model="attribute_y" ng-options="a.attribute as a.label for a in attributes_y" class="multiselect form-input" multiple="multiple" multiselect-dropdown></select>
         </div>
     </div>
 </div>
 
         <div class="alert alert-danger" ng-show="error_message != ''">{{ error_message }}</div>
         <div class="alert alert-success" ng-show="success_message != ''">{{ success_message }}</div>
-
     </div>
 </div>
 

File main/templates/learn.html

View file
-{% extends "base.html" %}
-{% load staticfiles %}
-
-{% block title %}API{% endblock %}
-
-{% block active_api %}active{% endblock %}
-
-{% block content %}
+{% extends "base.html" %} {% load staticfiles %} {% block title %}API{% endblock %} {% block active_api %}
+    active{% endblock %} {% block content %}
     <div class="container">
-
         <div class="row">
-            <div class="col-lg-12">
-                <h1>Help</h1>
+            <div class="col-lg-12"><h1>Help</h1>
                 <ul>
                     <li><a href="#tutorial">Tutorial</a></li>
                     <li><a href="#submit">Submit Benchmarks</a></li>
 
                 <h2>Tutorial</h2>
 
-                <p>We will show how to discover patterns in the <a href="/benchmarks/">benchmark analysis view</a>.
-                    For instructions on how to submit your benchmarks to the platform visit the <a href="#api">API
+                <p>We will show how to discover patterns in the <a href="/benchmarks/">benchmark analysis view</a>. For
+                    instructions on how to submit your benchmarks to the platform visit the <a href="#api">API
                         section</a>. Start your analysis with filtering the benchmarks you wish to visualize. Benguru
-                    supports full-text search over regular and custom fields.
-                </p>
-            </div>
+                    supports full-text search over regular and custom fields. </p></div>
         </div>
         <div class="row">
-            <div class="col-lg-12 text-center">
-                <img src="{% static 'main/img/filter-web.png' %}" width="800px">
-            </div>
+            <div class="col-lg-12 text-center"><img src="{% static 'main/img/filter-web.png' %}" width="800px"></div>
         </div>
         <div class="row">
             <div class="col-lg-12">
-                <p>Select the data instances you wish to visualize and order them. They will be plotted in the same
-                    order as
-                    they appear in the table. Notice that we reversed the order of the <i>Date</i> column.</p>
+                <p>Select the data instances you wish to visualize and order them. They will be
+                    plotted in the same order as they appear in the table. Notice that we reversed the order of the
+                    <i>Date</i> column.</p>
             </div>
         </div>
         <div class="row">
         </div>
         <div class="row">
             <div class="col-lg-12">
-                <p>Finally select the attributes you wish to visualize. You can select multiple attributes on the
-                    y-axis.</p>
+                <p>Finally select the attributes you wish to visualize. You can select multiple
+                    attributes on the y-axis.</p>
             </div>
         </div>
         <div class="row">
         </div>
         <div class="row">
             <div class="col-lg-12">
-                <p>In this toy example we can observe how memory tweaks helped us reduce the number of transactions
-                    per
-                    second.
-                    We can also spot small improvement in performance in <i>Memory Tewaks #4</i> but at the expense
-                    of
-                    huge memory
-                    cost.</p>
+                <p>In this toy example we can observe how memory tweaks helped us reduce the number of transactions per
+                    second. We can also spot small improvement in performance in <i>Memory Tewaks #4</i> but at the
+                    expense of huge memory cost.</p>
             </div>
         </div>
-
         <div class="row">
             <div class="col-lg-12">
                 <a name="submit"></a>
 
                 <h2>Submit Benchmarks</h2>
 
-                <p>Authorized users can submit benchmark data through web form and
-                    <a href="/api/">RESTful API</a>. <a href="/register/">Register</a> and wait for administrator's
-                    approval. We will notify you by email.</p>
+                <p>Authorized users can submit benchmark data through web form and <a href="/api/">RESTful API</a>.
+                    <a href="/register/">Register</a> and wait for administrator's approval. We will notify you by
+                    email.</p>
             </div>
         </div>
 
 
                 <h3>RESTful API</h3>
 
-
                 <p>RESTful API supports <code>GET</code> and <code>POST</code> requests of json data to the following
                     url:</p>