mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 09:08:26 +01:00
update for creation of policy and destinations.
This commit is contained in:
parent
3b2b0d8849
commit
7ae5b39407
@ -19,27 +19,30 @@
|
||||
|
||||
var vm0 = $scope.replication.policy;
|
||||
var vm1 = $scope.replication.destination;
|
||||
|
||||
|
||||
vm.selectDestination = selectDestination;
|
||||
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
||||
|
||||
$scope.$on('$locationChangeSuccess', function() {
|
||||
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
||||
});
|
||||
|
||||
vm.addNew = addNew;
|
||||
vm.edit = edit;
|
||||
vm.prepareDestination = prepareDestination;
|
||||
vm.createPolicy = createPolicy;
|
||||
vm.updatePolicy = updatePolicy;
|
||||
vm.create = create;
|
||||
vm.update = update;
|
||||
vm.pingDestination = pingDestination;
|
||||
|
||||
$scope.$watch('vm.destinations', function(current) {
|
||||
if(current) {
|
||||
console.log('destination:' + angular.toJson(current));
|
||||
vm1.selection = current[0];
|
||||
vm1.endpoint = vm1.selection.endpoint;
|
||||
vm1.username = vm1.selection.username;
|
||||
vm1.password = vm1.selection.password;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$scope.$watch('vm.action+","+vm.policyId', function(current) {
|
||||
if(current) {
|
||||
console.log('Current action for replication policy:' + current);
|
||||
@ -48,9 +51,11 @@
|
||||
vm.policyId = Number(parts[1]);
|
||||
switch(parts[0]) {
|
||||
case 'ADD_NEW':
|
||||
vm.addNew(); break;
|
||||
vm.addNew();
|
||||
break;
|
||||
case 'EDIT':
|
||||
vm.edit(vm.policyId); break;
|
||||
vm.edit(vm.policyId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -68,7 +73,7 @@
|
||||
.error(listDestinationFailed);
|
||||
}
|
||||
|
||||
function addNew() {
|
||||
function addNew() {
|
||||
vm0.name = '';
|
||||
vm0.description = '';
|
||||
vm0.enabled = true;
|
||||
@ -81,13 +86,13 @@
|
||||
.error(listReplicationPolicyFailed);
|
||||
}
|
||||
|
||||
function createPolicy(policy) {
|
||||
function create(policy) {
|
||||
CreateReplicationPolicyService(policy)
|
||||
.success(createReplicationPolicySuccess)
|
||||
.error(createReplicationPolicyFailed);
|
||||
}
|
||||
|
||||
function updatePolicy(policy) {
|
||||
function update(policy) {
|
||||
console.log('Update policy ID:' + vm.policyId);
|
||||
UpdateReplicationPolicyService(vm.policyId, policy)
|
||||
.success(updateReplicationPolicySuccess)
|
||||
@ -119,7 +124,7 @@
|
||||
}
|
||||
|
||||
function listDestinationSuccess(data, status) {
|
||||
vm.destinations = data;
|
||||
vm.destinations = data || [];
|
||||
}
|
||||
function listDestinationFailed(data, status) {
|
||||
console.log('Failed list destination:' + data);
|
||||
@ -136,12 +141,17 @@
|
||||
}
|
||||
function createReplicationPolicySuccess(data, status) {
|
||||
console.log('Successful create replication policy.');
|
||||
vm.reload();
|
||||
}
|
||||
function createReplicationPolicyFailed(data, status) {
|
||||
if(status === 409) {
|
||||
alert('Policy name already exists.');
|
||||
}
|
||||
console.log('Failed create replication policy.');
|
||||
}
|
||||
function updateReplicationPolicySuccess(data, status) {
|
||||
console.log('Successful update replication policy.');
|
||||
vm.reload();
|
||||
}
|
||||
function updateReplicationPolicyFailed(data, status) {
|
||||
console.log('Failed update replication policy.');
|
||||
@ -177,16 +187,17 @@
|
||||
};
|
||||
return directive;
|
||||
|
||||
function link(scope, element, attr, ctrl) {
|
||||
|
||||
element.find('#createPolicyModal').on('shown.bs.modal', function() {
|
||||
function link(scope, element, attr, ctrl) {
|
||||
|
||||
element.find('#createPolicyModal').on('show.bs.modal', function() {
|
||||
ctrl.prepareDestination();
|
||||
scope.form.$setPristine();
|
||||
});
|
||||
scope.form.$setUntouched();
|
||||
});
|
||||
|
||||
ctrl.save = save;
|
||||
|
||||
function save(form) {
|
||||
console.log(angular.toJson(form));
|
||||
var postPayload = {
|
||||
'projectId': Number(ctrl.projectId),
|
||||
'targetId': form.destination.selection.id,
|
||||
@ -198,14 +209,14 @@
|
||||
};
|
||||
switch(ctrl.action) {
|
||||
case 'ADD_NEW':
|
||||
ctrl.createPolicy(postPayload); break;
|
||||
ctrl.create(postPayload);
|
||||
break;
|
||||
case 'EDIT':
|
||||
ctrl.updatePolicy(postPayload); break;
|
||||
ctrl.update(postPayload);
|
||||
break;
|
||||
}
|
||||
element.find('#createPolicyModal').modal('hide');
|
||||
ctrl.reload();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
vm.update = update;
|
||||
vm.pingDestination = pingDestination;
|
||||
|
||||
$scope.$watch('vm.action + "," + vm.targetId', function(current) {
|
||||
$scope.$watch('vm.action+","+vm.targetId', function(current) {
|
||||
if(current) {
|
||||
var parts = current.split(',');
|
||||
vm.action = parts[0];
|
||||
@ -62,6 +62,9 @@
|
||||
}
|
||||
|
||||
function createDestinationFailed(data, status) {
|
||||
if(status === 409) {
|
||||
alert('Destination already exists.');
|
||||
}
|
||||
console.log('Failed create destination:' + data);
|
||||
}
|
||||
|
||||
@ -105,7 +108,6 @@
|
||||
'username': vm0.username,
|
||||
'password': vm0.password
|
||||
};
|
||||
console.log('Ping target:' + angular.toJson(target));
|
||||
PingDestinationService(target)
|
||||
.success(pingDestinationSuccess)
|
||||
.error(pingDestinationFailed);
|
||||
@ -136,24 +138,24 @@
|
||||
|
||||
function link(scope, element, attrs, ctrl) {
|
||||
|
||||
element.find('#createDestinationModal').on('hidden.bs.modal', function() {
|
||||
scope.form.$setPristine();
|
||||
element.find('#createDestinationModal').on('show.bs.modal', function() {
|
||||
scope.form.$setPristine();
|
||||
scope.form.$setUntouched();
|
||||
});
|
||||
|
||||
ctrl.save = save;
|
||||
|
||||
function save(destination) {
|
||||
if(destination) {
|
||||
console.log('destination:' + angular.toJson(destination));
|
||||
if(destination) {
|
||||
switch(ctrl.action) {
|
||||
case 'ADD_NEW':
|
||||
ctrl.create(destination);
|
||||
break;
|
||||
case 'EDIT':
|
||||
ctrl.update(destination);
|
||||
break;
|
||||
}
|
||||
element.find('#createDestinationModal').modal('hide');
|
||||
ctrl.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user