Skip to content

Commit

Permalink
Added changes page plus various fixes
Browse files Browse the repository at this point in the history
Added controller/template for changes page
Started work on controller for change page
Added some filters for easier date parsing
Widened the UI to use all 12 columns in prep for network pages.

Bug-fix: Change timestamp returned as utc time
  • Loading branch information
gmjosack committed Jan 5, 2015
1 parent 19139bd commit 3031a8c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
2 changes: 2 additions & 0 deletions nsot/handlers/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from sqlalchemy import desc
from sqlalchemy.exc import IntegrityError


Expand Down Expand Up @@ -1328,6 +1329,7 @@ def get(self, site_id):
if resource_id is not None:
changes = changes.filter_by(resource_id=resource_id)

changes = changes.order_by(desc("change_at"))

self.success({
"changes": [change.to_dict() for change in changes],
Expand Down
3 changes: 2 additions & 1 deletion nsot/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

from calendar import timegm
from datetime import datetime
from email.utils import parseaddr
from operator import attrgetter
Expand Down Expand Up @@ -716,7 +717,7 @@ def to_dict(self):
"id": self.id,
"site_id": self.site_id,
"user_id": self.user_id,
"change_at": time.mktime(self.change_at.timetuple()),
"change_at": timegm(self.change_at.timetuple()),
"event": self.event,
"resource_type": RESOURCE_BY_IDX[self.resource_type],
"resource_id": self.resource_id,
Expand Down
50 changes: 49 additions & 1 deletion nsot/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
.otherwise({redirectTo: "/"});
});

app.filter("from_now", function(){
return function(input){
return moment.unix(input).fromNow();
};
});

app.filter("ts_fmt", function(){
return function(input){
return moment.unix(input).format("YYYY/MM/DD hh:mm:ss a");
};
});

app.controller("navigationController", [
"$scope", "$location",
function($scope, $location) {
Expand All @@ -82,7 +94,7 @@

$scope.isActive = function(str){
var path = $location.path();
return path === str
return path === str;
};

}]);
Expand Down Expand Up @@ -232,6 +244,24 @@
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;
$scope.changes = [];
$scope.siteId = $routeParams.siteId;

$q.all([
$http.get(
"/api/sites/" + $scope.siteId +
"/changes"
)
]).then(function(results){
$scope.changes = results[0].data.data.changes;
$scope.loading = false;
}, function(data){
console.log(data);
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

}
]);
Expand All @@ -241,6 +271,24 @@
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;
$scope.change = {};
$scope.siteId = $routeParams.siteId;

$q.all([
$http.get(
"/api/sites/" + $scope.siteId +
"/changes/" + $routeParams.changeId
)
]).then(function(results){
$scope.change = results[0].data.data.change;
$scope.loading = false;
}, function(data){
console.log(data);
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

}]);

Expand Down
35 changes: 35 additions & 0 deletions nsot/static/templates/changes.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
<loading-panel ng-if="loading"></loading-panel>
<div ng-if="!loading">
<heading-bar heading="Changes">
</heading-bar>

<div class="row" class="row"><div class="col-sm-10 col-sm-offset-1">
<panel>
<panel-heading>Changes</panel-heading>
<panel-body>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Event</th>
<th>Resource Type</th>
<th>Resource ID</th>
<th>Change At</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="change in changes">
<td class="col-sm-1">
<a ng-href="/sites/[[siteId]]/changes/[[change.id]]">
[[change.id]]
</a>
</td>
<td class="col-sm-3">[[change.event]]</td>
<td class="col-sm-3">[[change.resource_type]]</td>
<td class="col-sm-2">[[change.resource_id]]</td>
<td class="col-sm-3">[[change.change_at|from_now]]</td>
</tr>
</tbody>
</table>
</panel-body>
</panel>

</div></div>
</div>
2 changes: 1 addition & 1 deletion nsot/templates/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</div>

<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="col-sm-12 col-sm-offset-0">
<div id="content">
<ng-view></ng-view>
</div>
Expand Down

0 comments on commit 3031a8c

Please sign in to comment.