Skip to content

Commit

Permalink
Allow tagging of repo and version and deletion of multiple tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevana committed Nov 27, 2015
1 parent 640c0b3 commit 1dd1ce2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
25 changes: 18 additions & 7 deletions app/components/image/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<div class="detail">

<h4>Image: {{ tag }}</h4>
<h4>Image: {{ id }}</h4>

<div class="btn-group detail">
<button class="btn btn-success" data-toggle="modal" data-target="#create-modal">Create</button>
<button class="btn btn-success" data-toggle="modal" data-target="#create-modal">Start Container</button>
</div>

<div>
Expand All @@ -22,9 +22,19 @@ <h4>Containers created:</h4>

<table class="table table-striped">
<tbody>
<tr>
<td>Tags:</td>
<td>
<ul>
<li ng-repeat="tag in RepoTags">{{ tag }}
<button ng-click="removeImage(tag)" class="btn btn-sm btn-danger">Remove tag</button>
</li>
</ul>
</td>
</tr>
<tr>
<td>Created:</td>
<td>{{ image.Created }}</td>
<td>{{ image.Created | date: 'medium'}}</td>
</tr>
<tr>
<td>Parent:</td>
Expand Down Expand Up @@ -89,21 +99,22 @@ <h4>Containers created:</h4>
<legend>Tag image</legend>
<div class="form-group">
<label>Tag:</label>
<input type="text" placeholder="repo..." ng-model="tag.repo" class="form-control">
<input type="text" placeholder="repo" ng-model="tagInfo.repo" class="form-control">
<input type="text" placeholder="version" ng-model="tagInfo.version" class="form-control">
</div>
<div class="form-group">
<label class="checkbox">
<input type="checkbox" ng-model="tag.force" class="form-control"/> Force?
<input type="checkbox" ng-model="tagInfo.force" class="form-control"/> Force?
</label>
</div>
<input type="button" ng-click="updateTag()" value="Tag" class="btn btn-primary"/>
<input type="button" ng-click="addTag()" value="Add Tag" class="btn btn-primary"/>
</fieldset>
</form>
</div>

<hr/>

<div class="btn-remove">
<button class="btn btn-large btn-block btn-primary btn-danger" ng-click="remove()">Remove Image</button>
<button class="btn btn-large btn-block btn-primary btn-danger" ng-click="removeImage(id)">Remove Image</button>
</div>
</div>
51 changes: 32 additions & 19 deletions app/components/image/imageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ angular.module('image', [])
.controller('ImageController', ['$scope', '$q', '$routeParams', '$location', 'Image', 'Container', 'Messages', 'LineChart',
function ($scope, $q, $routeParams, $location, Image, Container, Messages, LineChart) {
$scope.history = [];
$scope.tag = {repo: '', force: false};
$scope.tagInfo = {repo: '', version: '', force: false};
$scope.id = '';
$scope.repoTags = [];

$scope.remove = function () {
Image.remove({id: $routeParams.id}, function (d) {
Messages.send("Image Removed", $routeParams.id);
$scope.removeImage = function (id) {
Image.remove({id: id}, function (d) {
d.forEach(function(msg){
var key = Object.keys(msg)[0];
Messages.send(key, msg[key]);
});
// If last message key is 'Deleted' then assume the image is gone and send to images page
if (d[d.length-1].Deleted) {
$location.path('/images');
} else {
$location.path('/images/' + $scope.id); // Refresh the current page.
}
}, function (e) {
$scope.error = e.data;
$('#error-message').show();
Expand All @@ -19,24 +30,30 @@ angular.module('image', [])
});
};

$scope.updateTag = function () {
var tag = $scope.tag;
Image.tag({id: $routeParams.id, repo: tag.repo, force: tag.force ? 1 : 0}, function (d) {
$scope.addTag = function () {
var tag = $scope.tagInfo;
Image.tag({
id: $routeParams.id,
repo: tag.repo,
tag: tag.version,
force: tag.force ? 1 : 0
}, function (d) {
Messages.send("Tag Added", $routeParams.id);
$location.path('/images/' + $scope.id);
}, function (e) {
$scope.error = e.data;
$('#error-message').show();
});
};

function getContainersFromImage($q, Container, tag) {
function getContainersFromImage($q, Container, imageId) {
var defer = $q.defer();

Container.query({all: 1, notruc: 1}, function (d) {
var containers = [];
for (var i = 0; i < d.length; i++) {
var c = d[i];
if (c.Image === tag) {
if (c.ImageID === imageId) {
containers.push(new ContainerViewModel(c));
}
}
Expand All @@ -48,18 +65,14 @@ angular.module('image', [])

Image.get({id: $routeParams.id}, function (d) {
$scope.image = d;
$scope.tag = d.id;
var t = $routeParams.tag;
if (t && t !== ":") {
$scope.tag = t;
var promise = getContainersFromImage($q, Container, t);
$scope.id = d.Id;
$scope.RepoTags = d.RepoTags;

promise.then(function (containers) {
LineChart.build('#containers-started-chart', containers, function (c) {
return new Date(c.Created * 1000).toLocaleDateString();
});
getContainersFromImage($q, Container, $scope.id).then(function (containers) {
LineChart.build('#containers-started-chart', containers, function (c) {
return new Date(c.Created * 1000).toLocaleDateString();
});
}
});
}, function (e) {
if (e.status === 404) {
$('.detail').hide();
Expand Down
2 changes: 1 addition & 1 deletion app/shared/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ angular.module('dockerui.services', ['ngResource'])
},
insert: {method: 'POST', params: {id: '@id', action: 'insert'}},
push: {method: 'POST', params: {id: '@id', action: 'push'}},
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo'}},
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}},
remove: {method: 'DELETE', params: {id: '@id'}, isArray: true}
});
}])
Expand Down

0 comments on commit 1dd1ce2

Please sign in to comment.