sorting working
diff --git a/planetstack/core/xoslib/dashboards/xosDeveloper.html b/planetstack/core/xoslib/dashboards/xosDeveloper.html
index 33d7ee7..dd4076b 100644
--- a/planetstack/core/xoslib/dashboards/xosDeveloper.html
+++ b/planetstack/core/xoslib/dashboards/xosDeveloper.html
@@ -13,10 +13,10 @@
<script type="text/template" id="developer-slicetable-template">
<thead>
<tr class='header'>
- <th>Slice</th>
- <th>Privilege</th>
- <th>Number of Slivers</th>
- <th>Number of Sites</th>
+ <th>Slice <span class="sort" id="sort-asc-name">▲</span><span class="sort" id="sort-desc-name">▼</span></th>
+ <th>Privilege<span class="sort" id="sort-asc-sliceInfo.roles">▲</span><span class="sort" id="sort-desc-sliceInfo.roles">▼</span></th>
+ <th>Number of Slivers<span class="sort" id="sort-asc-sliceInfo.sliverCount">▲</span><span class="sort" id="sort-desc-sliceInfo.sliverCount">▼</span></th>
+ <th>Number of Sites<span class="sort" id="sort-asc-sliceInfo.siteCount">▲</span><span class="sort" id="sort-desc-sliceInfo.siteCount">▼</span></th>
</tr>
</thead>
<tbody>
@@ -24,6 +24,6 @@
</script>
<script type="text/template" id="developer-slicedetail-template">
- <td><%= name %></td><td><%= sliceInfo.roles[0] %></td><td><%= sliceInfo.sliverCount %></td><td><%= sliceInfo.siteCount %></td>
-</script>
+ <td><a href="http://{{request.get_host}}/admin/core/slice/<%= id %>/"><%= name %></a></td><td><%= sliceInfo.roles[0] %></td><td><%= sliceInfo.sliverCount %></td><td><%= sliceInfo.siteCount %></td>
+</script>
diff --git a/planetstack/core/xoslib/static/js/xosDeveloper.js b/planetstack/core/xoslib/static/js/xosDeveloper.js
index 6ea2d59..33c8b7d 100644
--- a/planetstack/core/xoslib/static/js/xosDeveloper.js
+++ b/planetstack/core/xoslib/static/js/xosDeveloper.js
@@ -10,21 +10,24 @@
className: 'developer_slicedetail'
});
-/*
-DeveloperApp.SliceListView = Marionette.CollectionView.extend({
- tagName: "table",
- className: "table table-hover",
- template: "#developer-slicetable-template",
- childView: DeveloperApp.SliceDetailView,
-});
-*/
-
-DeveloperApp.SliceListView = Marionette.CompositeView.extend({
+DeveloperApp.SliceListView = Marionette.CompositeView.extend({
tagName: "table",
className: "table-striped table-bordered",
template: "#developer-slicetable-template",
childView: DeveloperApp.SliceDetailView,
childViewContainer: "tbody",
+
+ events: {"click .sort": "changeSort"},
+
+ changeSort: function(e) {
+ parts=$(e.currentTarget).attr("id").split('-');
+ order=parts[1];
+ fieldName=parts[2];
+ console.log(fieldName);
+ this.collection.sortVar = fieldName;
+ this.collection.sortOrder = order;
+ this.collection.sort();
+ }
});
DeveloperApp.on("start", function() {
@@ -33,7 +36,7 @@
});
console.log(developerSliceListView);
DeveloperApp.mainRegion.show(developerSliceListView);
- xos.slicesPlus.startPolling(); //fetch();
+ xos.slicesPlus.startPolling();
});
$(document).ready(function(){
diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
index fe918ea..5403212 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
@@ -51,7 +51,35 @@
return this.models.map(function(element) { return element.attributes; });
},
- startPolling: function() {
+ initialize: function(){
+ this.sortVar = 'name';
+ this.sortOrder = 'asc';
+ },
+
+ simpleComparator: function( model ){
+ parts=this.sortVar.split(".");
+ result = model.get(parts[0]);
+ for (index=1; index<parts.length; ++index) {
+ result=result[parts[index]];
+ }
+ return result;
+ },
+
+ comparator: function (left, right) {
+ var l = this.simpleComparator(left);
+ var r = this.simpleComparator(right);
+
+ if (l === void 0) return -1;
+ if (r === void 0) return 1;
+
+ if (this.sortOrder=="desc") {
+ return l < r ? 1 : l > r ? -1 : 0;
+ } else {
+ return l < r ? -1 : l > r ? 1 : 0;
+ }
+ },
+
+ startPolling: function() {
if (!this._polling) {
collection=this;
setInterval(function() { console.log(collection); collection.fetch(); }, 10000);