Skip to content

Commit

Permalink
Code refactor and networks page
Browse files Browse the repository at this point in the history
Moved controllers and filters into their own js files.
Added Network controller and ui for it
  • Loading branch information
gmjosack committed Jan 13, 2015
1 parent 42ead5b commit bb0d607
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 319 deletions.
46 changes: 46 additions & 0 deletions nsot/static/css/nsot.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,52 @@ body {
margin-bottom: 20px;
}

.form-subheading {
position:relative;
overflow:hidden;
}

.form-subheading:after {
content: "";
top: 40%;
width: 100%;
margin-left: 5px;
height: 2px;
position: absolute;
background: rgba(81, 8, 39, 0.7);
}

.attr-buttons {
margin-left: -20px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}

.rm-attr-btn {
padding-top: 11px;
padding-left: 5px;
color: #d9534f;
}

.rm-attr-btn:hover {
color: #c9302c;
cursor: pointer;
text-decoration: none;
}

.add-attr-btn {
padding-top: 11px;
padding-left: 5px;
color: #5cb85c;
}

.add-attr-btn:hover {
color: #398439;
cursor: pointer;
text-decoration: none;
}

.navbar .divider-vertical {
height: 30px;
margin: 10px 9px;
Expand Down
318 changes: 0 additions & 318 deletions nsot/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,322 +71,4 @@
.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) {

$scope.siteId = null;
$scope.$on('$routeChangeStart', function(next, current) {
$scope.siteId = current.params.siteId;
});

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

}]);

app.controller("IndexController", [
"$http", "$location",
function($http, $location) {

$http.get("/api/sites").success(function(data){
var sites = data.data.sites;
if (!sites.length || sites.length > 1) {
$location.path("/sites");
} else {
// If there's a single site, just go there.
$location.path("/sites/" + sites[0].id);
}
$location.replace();
});
}]);

app.controller("SitesController", [
"$scope", "$http", "$q", "$location",
function($scope, $http, $q, $location) {

$scope.loading = true;
$scope.user = {};
$scope.sites = [];
$scope.site = {};
$scope.error = null;

$q.all([
$http.get("/api/users/0"),
$http.get("/api/sites")
]).then(function(results){
$scope.user = results[0].data.data.user;
$scope.sites = results[1].data.data.sites;
$scope.loading = false;
});

$scope.createSite = function(site){
$http.post("/api/sites", site).success(function(data){
var site = data.data.site;
$location.path("/sites/" + site.id);
}).error(function(data){
$scope.error = data.error;
});
};
}]);

app.controller("SiteController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;
$scope.user = {};
$scope.site = {};
$scope.admin = false;
$scope.updateError = null;
$scope.deleteError = null;


$q.all([
$http.get("/api/users/0"),
$http.get("/api/sites/" + $routeParams.siteId)
]).then(function(results){
$scope.user = results[0].data.data.user;
$scope.site = results[1].data.data.site;
var permissions = $scope.user.permissions[$routeParams.siteId] || {};
permissions = permissions.permissions || [];
$scope.admin = _.any(permissions, function(value){
return _.contains(["admin"], value);
});

$scope.loading = false;
}, function(data){
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

$scope.updateSite = function(site){
$http.put("/api/sites/" + $routeParams.siteId, site).success(function(data){
$route.reload();
}).error(function(data){
$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.deleteError = data.error;
});
};

}]);

app.controller("UsersController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;

}
]);

app.controller("UserController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;

}]);

app.controller("NetworksController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;

}
]);

app.controller("NetworkController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;

}]);

app.controller("NetworkAttributesController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;
$scope.user = {};
$scope.attributes = [];
$scope.attribute = {};
$scope.error = null;
$scope.admin = false;
var siteId = $scope.siteId = $routeParams.siteId;

$q.all([
$http.get("/api/users/0"),
$http.get("/api/sites/" + siteId + "/network_attributes")
]).then(function(results){
$scope.user = results[0].data.data.user;
$scope.attributes = results[1].data.data.network_attributes;
var permissions = $scope.user.permissions[$routeParams.siteId] || {};
permissions = permissions.permissions || [];
$scope.admin = _.any(permissions, function(value){
return _.contains(["admin", "network_attrs"], value);
});
$scope.loading = false;
}, function(data){
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

$scope.createAttribute = function(attr){
$http.post("/api/sites/" + siteId +
"/network_attributes", attr).success(function(data){
var attr = data.data.network_attribute;
$location.path("/sites/" + siteId + "/network_attributes/" + attr.id);
}).error(function(data){
$scope.error = data.error;
});
};

}
]);

app.controller("NetworkAttributeController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

$scope.loading = true;
$scope.user = {};
$scope.attribute = {};
$scope.admin = false;
$scope.updateError = null;
$scope.deleteError = null;
var siteId = $scope.siteId = $routeParams.siteId;
var attributeId = $scope.attributeId = $routeParams.networkAttributeId;


$q.all([
$http.get("/api/users/0"),
$http.get("/api/sites/" + siteId + "/network_attributes/" + attributeId)
]).then(function(results){
$scope.user = results[0].data.data.user;
$scope.attribute = results[1].data.data.network_attribute;
var permissions = $scope.user.permissions[$routeParams.siteId] || {};
permissions = permissions.permissions || [];
$scope.admin = _.any(permissions, function(value){
return _.contains(["admin", "network_attrs"], value);
});

$scope.loading = false;
}, function(data){
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

$scope.updateAttribute = function(attr){
$http.put("/api/sites/" + siteId +
"/network_attributes/" + attributeId, attr).success(function(data){
$route.reload();
}).error(function(data){
$scope.updateError = data.error;
});
};

$scope.deleteAttribute = function(attr){
$http.delete("/api/sites/" + siteId +
"/network_attributes/" + attributeId).success(function(data){
$location.path("/sites/" + siteId + "/network_attributes");
}).error(function(data){
$scope.deleteError = data.error;
});
};

}]);

app.controller("ChangesController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
function($scope, $http, $route, $location, $q, $routeParams) {

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

var params = {limit: 10};
var search = $location.search();
if (search.offset) params.offset = search.offset;
if (search.limit) params.limit = search.limit;

$q.all([
$http.get(
"/api/sites/" + $scope.siteId +
"/changes",
{params: params}
)
]).then(function(results){
var data = results[0].data.data;
$scope.changes = data.changes;
$scope.pager = new nsot.Pager(
data.offset, data.limit, data.total, $location
);
$scope.limiter = new nsot.Limiter(data.limit, $location);
$scope.loading = false;
}, function(data){
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

}]);

app.controller("ChangeController", [
"$scope", "$http", "$route", "$location", "$q", "$routeParams",
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){
if (data.status === 404) {
$location.path("/");
$location.replace();
}
});

}]);

})();

0 comments on commit bb0d607

Please sign in to comment.