Skip to content

Commit

Permalink
Merge pull request #5394 from parthaa/crud-ui
Browse files Browse the repository at this point in the history
Fixes #10040 - UI Bindings to CRUD rpm-ostree
  • Loading branch information
parthaa committed Aug 18, 2015
2 parents 727126e + ab73aa3 commit 0e1d89e
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 30 deletions.
13 changes: 2 additions & 11 deletions app/lib/actions/katello/repository/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ class Update < Actions::EntryAction
def plan(repository, repo_params)
action_subject repository
ostree_branches = repo_params.delete(:ostree_branches)
if ostree_branches
# remove the ostree_branches not in this list
repository.ostree_branches.keep_if do |branch|
ostree_branches.include?(branch.name)
end

# add the new ostree_branches
(ostree_branches - repository.ostree_branch_names).each do |ref|
repository.ostree_branches.create!(:name => ref)
end
end
repository.update_ostree_branches!(ostree_branches) if ostree_branches
repository = repository.reload
repository.update_attributes!(repo_params)

if (::Katello.config.use_cp && ::Katello.config.use_pulp) && repository.library_instance?
Expand Down
29 changes: 29 additions & 0 deletions app/models/katello/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,37 @@ def ostree_branch_names
self.ostree_branches.map(&:name)
end

def update_ostree_branches!(branch_names)
check_duplicate_branch_names(branch_names)

# remove the ostree_branches not in this list
self.ostree_branches.each do |branch|
branch.destroy unless branch_names.include?(branch.name)
end

# add the new ostree_branches
(branch_names - self.ostree_branch_names).each do |ref|
self.ostree_branches.create!(:name => ref)
end
end

protected

def check_duplicate_branch_names(branch_names)
dupe_branch_checker = Hash.new
dupe_branch_checker.default = 0
branch_names.each do |branch|
dupe_branch_checker[branch] += 1
end

duplicate_branch_names = dupe_branch_checker.select { |_, value| value > 1 }.keys

unless duplicate_branch_names.empty?
fail ::Katello::Errors::ConflictException,
_("Duplicate branches specified - %{branches}") % { branches: duplicate_branch_names.join(", ")}
end
end

def assert_deletable
if self.environment.try(:library?) && self.content_view.default?
if self.environment.organization.being_deleted?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ angular.module('Bastion.products').config(['$stateProvider', function ($statePro
permission: 'view_products',
collapsed: true,
templateUrl: 'repositories/details/views/repository-manage-docker-images.html'
})
.state('products.details.repositories.manage-ostree-branches', {
url: '/repositories/:repositoryId/content/ostree_branches',
permission: 'view_products',
collapsed: true,
controller: 'RepositoryManageOstreeBranchesController',
templateUrl: 'repositories/details/views/repository-manage-ostree-branches.html'
});

$stateProvider.state('products.details.tasks', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* @ngdoc object
* @name Bastion.repositories.controller:RepositoryManageContentController
*
* @requires $scope
* @requires translate
* @requires Repository
*
* @description
* Provides the functionality for the repository details pane.
*/
angular.module('Bastion.repositories').controller('RepositoryManageOstreeBranchesController',
['$scope', 'translate', 'Repository',
function ($scope, translate, Repository) {

function resetBranches() {
$scope.branch = {
editMode: false,
working: false
};
}

function saveBranches(branches, success, errors) {
var successfulUpdate, erroredUpdate;
successfulUpdate = function (repository) {
$scope.successMessages = [translate('Repository Branches Updated.')];
$scope.wrap(repository);
if (success) {
success(repository);
}
};

erroredUpdate = function (response) {
_.each(response.data.errors, function (errorMessage) {
$scope.errorMessages.push(translate("An error occurred saving the Repository: ") + errorMessage);
});
if (errors) {
errors(response);
}
};

$scope.repository["ostree_branches"] = branches;
$scope.repository.$update(successfulUpdate, erroredUpdate);
}

$scope.wrap = function (repository) {
var branches = repository["ostree_branches"];
if (angular.isUndefined(branches)) {
branches = [];
}
$scope.branchObjects = _.map(branches, function (branch) {
return {name: branch};
});
};

resetBranches();
$scope.repository = Repository.get({id: $scope.$stateParams.repositoryId});

$scope.repository.$promise.then($scope.wrap);

$scope.removeBranches = function () {
var branches,
branchObjectsToRemove = _.reject($scope.branchObjects, function (branch) {
return branch.selected;
});

branches = _.map(branchObjectsToRemove, function (branchObj) {
return branchObj.name;
});

saveBranches(branches);
};

$scope.backupPrevious = function (currentBranch) {
currentBranch.previous = {};
angular.copy(currentBranch, currentBranch.previous);
};

$scope.restorePrevious = function (currentBranch) {
angular.copy(currentBranch.previous, currentBranch);
currentBranch.previous = {};
};

$scope.isValid = function (currentBranch) {
return !_.isEmpty(currentBranch.name);
};

$scope.addBranch = function (currentBranch) {
var branches = [currentBranch.name], success, error;
_.each($scope.branchObjects, function (branchObj) {
branches.push(branchObj.name);
});

success = function () {
resetBranches();
};
error = function () {
resetBranches();
};

saveBranches(branches, success, error);
};

$scope.updateBranch = function (currentBranch) {
var success,
error,
branches = _.map($scope.branchObjects, function (branchObj) {
return branchObj.name;
});

// Need access to the original branch
success = function () {
currentBranch.previous = {};
currentBranch.editMode = false;
currentBranch.working = false;
};

error = function () {
currentBranch.working = false;
};

saveBranches(branches, success, error);
};

$scope.getSelectedBranches = function () {
return _.select($scope.branchObjects, function (branch) {
return branch.selected;
});
};

$scope.selectAll = function (val) {
_.each($scope.branchObjects, function (branch) {
branch.selected = val;
});
};
}]
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</a>

<div class="fr">

<button class="btn btn-default"
ui-sref="products.details.repositories.manage-content.packages({productId: product.id, repositoryId: repository.id})"
ng-hide="repository.content_type !== 'yum' || product.readonly">
Expand All @@ -27,6 +26,12 @@
<span translate>Manage Docker Images</span>
</button>

<button class="btn btn-default"
ui-sref="products.details.repositories.manage-ostree-branches({productId: product.id, repositoryId: repository.id})"
ng-hide="repository.content_type !== 'ostree' || product.readonly">
<span translate>Manage Branches</span>
</button>

<button class="btn btn-default"
ng-click="syncRepository(repository); working = true"
ng-hide="!repository.url || denied('sync_products', product)"
Expand All @@ -39,7 +44,7 @@
<div data-block="modal-header" translate>Remove Repository "{{ repository.name }}"?</div>
<div data-block="modal-body" translate>Are you sure you want to remove repository "{{ repository.name }}"?</div>
</div>

<span ng-switch="getRepoNonDeletableReason(repository, product)">
<i class="fa fa-question-sign" ng-switch-when="permissions"
tooltip="{{ 'You cannot remove this repository because you do not have permission.' | translate }}"
Expand Down Expand Up @@ -229,34 +234,60 @@ <h4 translate>Content Counts</h4>
</a>
</td>
</tr>
<tr ng-show="repository.content_type == 'yum'">
<tr ng-show="repository.content_type === 'yum'">
<td translate>Package Groups</td>
<td class="align-center">{{ repository.content_counts.package_group || 0 }}</td>
</tr>
<tr ng-show="repository.content_type == 'puppet'">
<tr ng-show="repository.content_type === 'puppet'">
<td translate>Puppet Modules</td>
<td class="align-center">
<a ui-sref="products.details.repositories.manage-content.puppet-modules({productId: product.id, repositoryId: repository.id})">
{{ repository.content_counts.puppet_module || 0 }}
</a>
</td>
</tr>
<tr ng-show="repository.content_type == 'docker'">
<tr ng-show="repository.content_type === 'docker'">
<td translate>Docker Images</td>
<td class="align-center">{{ repository.content_counts.docker_image || 0 }}</td>
</tr>
<tr ng-show="repository.content_type == 'docker'">
<tr ng-show="repository.content_type === 'docker'">
<td translate>Docker Tags</td>
<td class="align-center">{{ repository.content_counts.docker_tag || 0 }}</td>
</tr>
<tr ng-show="repository.content_type === 'ostree'">
<td translate>OSTree Units</td>
<td class="align-center">{{ repository.content_counts.ostree || 0 }}</td>
</tr>
</tbody>
</table>

<div class="divider" ng-if="repository.content_type === 'ostree'"/>
</section>

<section ng-if="repository.content_type === 'ostree'">
<table class="table table-striped">
<thead>
<tr>
<th translate>Branches</th>
</tr>
</thead>

<tbody>
<tr ng-if ="repository.ostree_branches === undefined || repository.ostree_branches.length === 0">
<td translate> No Branches </td>
</tr>

<tr ng-repeat="branch in repository.ostree_branches" row-select="branch">
<td>{{ branch }}</td>
</tr>
</tbody>
</table>
</section>

<section class="well" ng-if="permitted('edit_products', product) && !product.redhat">
<h5 translate ng-show="repository.content_type == 'puppet'">Upload Puppet Module</h5>
<h5 translate ng-show="repository.content_type == 'yum'">Upload Package</h5>
<h5 translate ng-show="repository.content_type == 'docker'">Upload Docker Image</h5>
<section class="well" ng-if="permitted('edit_products', product) && !product.redhat && repository.content_type !== 'ostree'">
<h5 translate ng-show="repository.content_type === 'puppet'">Upload Puppet Module</h5>
<h5 translate ng-show="repository.content_type === 'yum'">Upload Package</h5>
<h5 translate ng-show="repository.content_type === 'docker'">Upload Docker Image</h5>

<div bst-alerts success-messages="uploadSuccessMessages" error-messages="uploadErrorMessages"></div>

Expand Down
Loading

0 comments on commit 0e1d89e

Please sign in to comment.