Skip to content

Commit

Permalink
Work on sites UI
Browse files Browse the repository at this point in the history
Added support for updating/deleting sites
    - still needs validations and some deduplication of code
  • Loading branch information
gmjosack committed Jan 4, 2015
1 parent fb04d4b commit 2c36459
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 5 deletions.
25 changes: 23 additions & 2 deletions nsot/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function() {
"use strict";

var app = angular.module("nsotApp", ["ngRoute"]);

Expand Down Expand Up @@ -98,12 +99,15 @@
}]);

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

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


$q.all([
$http.get("/api/users/0"),
Expand All @@ -114,6 +118,23 @@
$scope.loading = false;
});

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

}]);

})();
1 change: 1 addition & 0 deletions nsot/static/js/directives.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(function() {
"use strict";

var app = angular.module("nsotApp");

Expand Down
90 changes: 88 additions & 2 deletions nsot/static/templates/site.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,93 @@
<loading-panel ng-if="loading"></loading-panel>
<div ng-if="!loading">
<heading-bar heading="Sites" subheading="[[site.name]]">
<button class="btn btn-info">Update Site</button>
<button class="btn btn-danger">Delete Site</button>
<button
class="btn btn-info"
data-toggle="modal"
data-target="#updateSiteModal"
>Update Site</button>
<button
class="btn btn-danger"
data-toggle="modal"
data-target="#deleteSiteModal"
>Delete Site</button>
</heading-bar>

<div class="modal fade" id="updateSiteModal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close close-light" data-dismiss="modal">
<span class="fa fa-close"</span>
</button>
<h4 class="modal-title">Update Site</h4>
</div>
<div class="modal-body">
<div ng-if="updateError" class="alert alert-danger">
[[updateError.code]] - [[updateError.message]]
</div>
<form novalidate class="nsot-form">
<div class="form-group">
<input type="text"
class="form-control"i
placeholder="Name"
ng-model="site.name"
required
>
</div>
<div class="form-group">
<textarea style="resize: vertical;"
class="form-control"
rows="5"
placeholder="Description"
ng-model="site.description"
>
</textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-default"
data-dismiss="modal"
>Close</button>
<button type="submit"
ng-click="updateSite(site)"
class="btn btn-primary"
>Update</button>
</div>
</div>
</div>
</div>

<div class="modal fade" id="deleteSiteModal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close close-light" data-dismiss="modal">
<span class="fa fa-close"</span>
</button>
<h4 class="modal-title">Delete Site</h4>
</div>
<div class="modal-body">
<div ng-if="deleteError" class="alert alert-danger">
[[deleteError.code]] - [[deleteError.message]]
</div>
Are you sure you want to delete this site?
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-default"
data-dismiss="modal"
>Close</button>
<button type="submit"
ng-click="deleteSite(site)"
class="btn btn-primary"
>Delete</button>
</div>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
mrproxy==0.3.2
mrproxy==0.3.3
py==1.4.26
pytest==2.6.4
Pygments==2.0.1
Expand Down

0 comments on commit 2c36459

Please sign in to comment.