diff --git a/api/projects/repository.go b/api/projects/repository.go index 58350e97..5e5498f0 100644 --- a/api/projects/repository.go +++ b/api/projects/repository.go @@ -83,12 +83,16 @@ func AddRepository(c *gin.Context) { func UpdateRepository(c *gin.Context) { oldRepo := c.MustGet("repository").(models.Repository) - var repository models.Repository + var repository struct { + Name string `json:"name" binding:"required"` + GitUrl string `json:"git_url" binding:"required"` + SshKeyID int `json:"ssh_key_id" binding:"required"` + } if err := c.Bind(&repository); err != nil { return } - if _, err := database.Mysql.Exec("update project__repository set git_url=?, ssh_key_id=? where id=?", repository.GitUrl, repository.SshKeyID, oldRepo.ID); err != nil { + if _, err := database.Mysql.Exec("update project__repository set name=?, git_url=?, ssh_key_id=? where id=?", repository.Name, repository.GitUrl, repository.SshKeyID, oldRepo.ID); err != nil { panic(err) } diff --git a/api/router.go b/api/router.go index 02007f39..ba7459f6 100644 --- a/api/router.go +++ b/api/router.go @@ -75,6 +75,7 @@ func Route(r *gin.Engine) { api.GET("/repositories", projects.GetRepositories) api.POST("/repositories", projects.AddRepository) + api.PUT("/repositories/:repository_id", projects.RepositoryMiddleware, projects.UpdateRepository) api.DELETE("/repositories/:repository_id", projects.RepositoryMiddleware, projects.RemoveRepository) api.GET("/inventory", projects.GetInventory) diff --git a/public/html/projects/repositories/add.jade b/public/html/projects/repositories/add.jade index b66ac80d..19cd6b8c 100644 --- a/public/html/projects/repositories/add.jade +++ b/public/html/projects/repositories/add.jade @@ -1,5 +1,8 @@ .modal-header - h4.modal-title Create Repository + h4.modal-title + span(ng-if="!repository.id") Create Repository + span(ng-if="repository.id") Update Repository + .modal-body form.form-horizontal .form-group @@ -15,6 +18,9 @@ .col-sm-6 select.form-control(ng-model="repo.ssh_key_id" ng-options="key.id as key.name for key in keys") option(value="") -- Select SSH Key -- + .modal-footer button.btn.btn-default.pull-left(ng-click="$dismiss()") Dismiss - button.btn.btn-success(ng-click="$close(repo)") Create \ No newline at end of file + button.btn.btn-success(ng-click="$close(repo)") + span(ng-if="!repository.id") Create + span(ng-if="repository.id") Update diff --git a/public/html/projects/repositories/list.jade b/public/html/projects/repositories/list.jade index 06791b29..3e2ec4bc 100644 --- a/public/html/projects/repositories/list.jade +++ b/public/html/projects/repositories/list.jade @@ -11,4 +11,6 @@ table.table td {{ repo.name }} td {{ repo.git_url }} td {{ repo.ssh_key_id }} - td: button.btn.btn-danger.btn-xs.pull-right(ng-click="remove(repo)") delete \ No newline at end of file + td: .btn-group.pull-right + button.btn.btn-default.btn-xs(ng-click="update(repo)") update + button.btn.btn-danger.btn-xs(ng-click="remove(repo)") delete \ No newline at end of file diff --git a/public/js/controllers/projects/repositories.js b/public/js/controllers/projects/repositories.js index de3f3ddb..3a4e857a 100644 --- a/public/js/controllers/projects/repositories.js +++ b/public/js/controllers/projects/repositories.js @@ -14,8 +14,27 @@ define(function () { }); } + $scope.update = function (repo) { + $scope.getKeys(function (keys) { + var scope = $rootScope.$new(); + scope.keys = keys; + scope.repo = JSON.parse(JSON.stringify(repo)); + + $modal.open({ + templateUrl: '/tpl/projects/repositories/add.html', + scope: scope + }).result.then(function (repo) { + $http.put(Project.getURL() + '/repositories/' + repo.id, repo).success(function () { + $scope.reload(); + }).error(function (_, status) { + swal('Error', 'Repository not updated: ' + status, 'error'); + }) + }); + }); + } + $scope.add = function () { - $http.get(Project.getURL() + '/keys?type=ssh').success(function (keys) { + $scope.getKeys(function (keys) { var scope = $rootScope.$new(); scope.keys = keys; @@ -33,6 +52,11 @@ define(function () { }); } + $scope.getKeys = function (cb) { + $http.get(Project.getURL() + '/keys?type=ssh') + .success(cb); + } + $scope.reload(); }]); }); \ No newline at end of file