Skip to content

Commit

Permalink
Work on Change page and misc
Browse files Browse the repository at this point in the history
Updated Change api to include site/user instead of ids
Auto join users/sites on all change queries
Hide update/delete buttons on site page if not admin
Include user on changes list in UI
Add entire sites page
Fix bug with error display on site page
  • Loading branch information
gmjosack committed Jan 6, 2015
1 parent 3031a8c commit b900344
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 22 deletions.
22 changes: 18 additions & 4 deletions nsot/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,8 +1267,15 @@ def get(self, site_id):
"changes": [
{
"id": 1,
"site_id": 1,
"user_id": 1,
"site": {
"id": 1,
"name": "Site 1",
"description": ""
},
"user": {
"id": 1,
"email": "user@localhost"
},
"change_at": 1420062748,
"event": "Create",
"resource_type": "Site",
Expand Down Expand Up @@ -1360,8 +1367,15 @@ def get(self, site_id, change_id):
"data": {
"change": {
"id": 1,
"site_id": 1,
"user_id": 1,
"site": {
"id": 1,
"name": "Site 1",
"description": ""
},
"user": {
"id": 1,
"email": "user@localhost"
},
"change_at": 1420062748,
"event": "Create",
"resource_type": "Site",
Expand Down
11 changes: 8 additions & 3 deletions nsot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import relationship, object_session, aliased, validates
from sqlalchemy.orm import synonym, sessionmaker, Session as _Session
from sqlalchemy.orm import synonym, sessionmaker, Session as _Session, backref
from sqlalchemy.schema import Column, ForeignKey, Index
from sqlalchemy.sql import func, label, literal
from sqlalchemy.types import Integer, String, Text, Boolean, SmallInteger
Expand Down Expand Up @@ -672,8 +672,13 @@ class Change(Model):
__tablename__ = "changes"

id = Column(Integer, primary_key=True)

site_id = Column(Integer, ForeignKey("sites.id", ondelete="CASCADE"), nullable=False, index=True)
site = relationship(Site, lazy="joined", backref=backref("changes", cascade="all,delete-orphan"))

user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
user = relationship(User, lazy="joined", backref="changes")

change_at = Column(DateTime, default=datetime.utcnow, nullable=False)

event = Column(Enum(*CHANGE_EVENTS), nullable=False)
Expand Down Expand Up @@ -715,8 +720,8 @@ def to_dict(self):

return {
"id": self.id,
"site_id": self.site_id,
"user_id": self.user_id,
"site": self.site.to_dict(),
"user": self.user.to_dict(),
"change_at": timegm(self.change_at.timetuple()),
"event": self.event,
"resource_type": RESOURCE_BY_IDX[self.resource_type],
Expand Down
4 changes: 4 additions & 0 deletions nsot/static/css/nsot.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ body {
border-left: 1px solid #5C052A;
}

.resource-block {
margin: 5px 80px 10px 0px;
}

.modal-open {
overflow-y: scroll;
}
Expand Down
12 changes: 9 additions & 3 deletions nsot/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
$scope.loading = true;
$scope.user = {};
$scope.site = {};
$scope.admin = false;
$scope.updateError = null;
$scope.deleteError = null;

Expand All @@ -161,6 +162,12 @@
]).then(function(results){
$scope.user = results[0].data.data.user;
$scope.site = results[1].data.data.site;
var permissions = $scope.user.permissions[$routeParams.siteId] || {};
var permissions = permissions.permissions || [];
$scope.admin = _.any(permissions, function(value){
return _.contains(["admin", "networks"], value);
});

$scope.loading = false;
}, function(data){
if (data.status === 404) {
Expand All @@ -173,16 +180,15 @@
$http.put("/api/sites/" + $routeParams.siteId, site).success(function(data){
$route.reload();
}).error(function(data){
console.log(data);
$scope.error = data.error;
$scope.updateError = data.error;
});
};

$scope.deleteSite = function(site){
$http.delete("/api/sites/" + $routeParams.siteId, site).success(function(data){
$location.path("/sites");
}).error(function(data){
$scope.error = data.error;
$scope.deleteError = data.error;
});
};

Expand Down
35 changes: 35 additions & 0 deletions nsot/static/templates/change.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"
subheading="[[change.resource_type]] [[change.resource_id]]">
</heading-bar>
<div class="row"><div class="col-sm-8 col-sm-offset-2">
<panel>
<panel-heading>
Change
</panel-heading>
<panel-body>
<dl class="dl-horizontal">
<dt>Event</dt>
<dd>[[change.event]]</dd>

<dt>Resource Type</dt>
<dd>[[change.resource_type]]</dd>

<dt>Resource ID</dt>
<dd>[[change.resource_id]]</dd>

<dt>User</dt>
<dd>[[change.user.email]]</dd>

<dt>Change At</dt>
<dd>[[change.change_at|from_now]]</dd>

<dt>Resource</dt>
<dd><pre class="resource-block">[[change.resource|json:4]]</pre></dd>
</dl>

</panel-body>
</panel>
</div></div>

</div>
22 changes: 12 additions & 10 deletions nsot/static/templates/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@
<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>
<th class="col-sm-1">ID</th>
<th class="col-sm-2">User</th>
<th class="col-sm-1">Event</th>
<th class="col-sm-1">Resource Type</th>
<th class="col-sm-1">Resource ID</th>
<th class="col-sm-2">Change At</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="change in changes">
<td class="col-sm-1">
<td>
<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>
<td>[[change.user.email]]</td>
<td>[[change.event]]</td>
<td>[[change.resource_type]]</td>
<td>[[change.resource_id]]</td>
<td>[[change.change_at|from_now]]</td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 2 additions & 2 deletions nsot/static/templates/site.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<loading-panel ng-if="loading"></loading-panel>
<div ng-if="!loading">
<heading-bar heading="Sites" subheading="[[site.name]]">
<button
<button ng-if="admin"
class="btn btn-info"
data-toggle="modal"
data-target="#updateSiteModal"
>Update Site</button>
<button
<button ng-if="admin"
class="btn btn-danger"
data-toggle="modal"
data-target="#deleteSiteModal"
Expand Down

0 comments on commit b900344

Please sign in to comment.