diff --git a/static/ng/resources/js/components/replication/create-policy.directive.html b/static/ng/resources/js/components/replication/create-policy.directive.html index 8c0384db8..d83ff94e2 100644 --- a/static/ng/resources/js/components/replication/create-policy.directive.html +++ b/static/ng/resources/js/components/replication/create-policy.directive.html @@ -15,7 +15,7 @@
- +
Name is required.
@@ -24,7 +24,7 @@
- +
Description is required.
@@ -33,7 +33,7 @@
- +
@@ -43,13 +43,13 @@
- +
- +
Endpoint is required.
@@ -58,7 +58,7 @@
- +
Username is required.
@@ -67,7 +67,7 @@
- +
Password is required.
@@ -79,11 +79,10 @@
-
diff --git a/static/ng/resources/js/components/replication/create-policy.directive.js b/static/ng/resources/js/components/replication/create-policy.directive.js index 84e6a2035..00ab53c47 100644 --- a/static/ng/resources/js/components/replication/create-policy.directive.js +++ b/static/ng/resources/js/components/replication/create-policy.directive.js @@ -6,13 +6,58 @@ .module('harbor.replication') .directive('createPolicy', createPolicy); - function CreatePolicyController() { + CreatePolicyController.$inject = ['$scope', 'ListDestinationService', 'CreateReplicationPolicyService', '$location', 'getParameterByName']; + + function CreatePolicyController($scope, ListDestinationService, CreateReplicationPolicyService, $location, getParameterByName) { var vm = this; - vm.enabled = true; - vm.save = save; - function save(policy) { - console.log(angular.toJson(policy)); + //Since can not set value for textarea by using vm + //use $scope for instead. + $scope.replication = {}; + $scope.replication.policy = {}; + + var vm0 = $scope.replication; + var vm1 = $scope.replication.policy; + vm.projectId = getParameterByName('project_id', $location.absUrl()); + vm.prepare = prepare; + vm.prepare(); + vm.createPolicy = createPolicy; + + $scope.$watch('vm.destinations', function(current) { + if(current) { + console.log('destination:' + angular.toJson(current)); + vm0.destination = current[0]; + } + }); + + function prepare() { + vm1.name = 'name'; + vm1.description = 'test'; + vm1.enabled = true; + + ListDestinationService() + .success(listDestinationSuccess) + .error(listDestinationFailed); + } + + function createPolicy(policy) { + CreateReplicationPolicyService(policy) + .success(createReplicationPolicySuccess) + .error(createReplicationPolicyFailed); + } + + function listDestinationSuccess(data, status) { + vm.destinations = data; + } + function listDestinationFailed(data, status) { + console.log('Failed list destination:' + data); + } + function createReplicationPolicySuccess(data, status) { + console.log('Successful create replication policy.'); + vm.clearUp(); + } + function createReplicationPolicyFailed(data, status) { + console.log('Failed create replication policy.'); } } @@ -20,13 +65,38 @@ var directive = { 'restrict': 'E', 'templateUrl': '/static/ng/resources/js/components/replication/create-policy.directive.html', - 'scope': true, - 'replace': true, + 'scope': { + 'reload': '&' + }, + 'link': link, 'controller': CreatePolicyController, 'controllerAs': 'vm', 'bindToController': true }; return directive; + + function link(scope, element, attr, ctrl) { + ctrl.save = save; + ctrl.clearUp = clearUp; + function save(form) { + console.log(angular.toJson(form)); + var postPayload = { + 'projectId': Number(ctrl.projectId), + 'targetId': form.destination.id, + 'name': form.policy.name, + 'enabled': form.policy.enabled ? 1 : 0, + 'description': form.policy.description, + 'cron_str': '', + 'start_time': '' + }; + ctrl.createPolicy(postPayload, clearUp); + } + + function clearUp() { + element.find('#createPolicyModal').modal('hide'); + ctrl.reload(); + } + } } })(); \ No newline at end of file diff --git a/static/ng/resources/js/components/replication/list-replication.directive.html b/static/ng/resources/js/components/replication/list-replication.directive.html index 115c051cc..a67f04ecd 100644 --- a/static/ng/resources/js/components/replication/list-replication.directive.html +++ b/static/ng/resources/js/components/replication/list-replication.directive.html @@ -8,7 +8,7 @@
- +
@@ -26,7 +26,7 @@

No replication policies, add new replication policy.

- + //r.name// //r.description// //r.destination// diff --git a/static/ng/resources/js/components/system-management/destination.directive.html b/static/ng/resources/js/components/system-management/destination.directive.html index 408a582ca..ecb0e2e5f 100644 --- a/static/ng/resources/js/components/system-management/destination.directive.html +++ b/static/ng/resources/js/components/system-management/destination.directive.html @@ -25,7 +25,7 @@ //r.name// - //r.url// + //r.endpoint// //r.creation_time// diff --git a/static/ng/resources/js/services/destination/services.create-destination.js b/static/ng/resources/js/services/destination/services.create-destination.js index 571a4fb40..524672a8a 100644 --- a/static/ng/resources/js/services/destination/services.create-destination.js +++ b/static/ng/resources/js/services/destination/services.create-destination.js @@ -14,7 +14,7 @@ return $http .post('/api/targets', { 'name': name, - 'url': endpoint, + 'endpoint': endpoint, 'username': username, 'password': password }); diff --git a/static/ng/resources/js/services/replication-policy/services.create-replication-policy.js b/static/ng/resources/js/services/replication-policy/services.create-replication-policy.js index 3f89a2d89..826d96b50 100644 --- a/static/ng/resources/js/services/replication-policy/services.create-replication-policy.js +++ b/static/ng/resources/js/services/replication-policy/services.create-replication-policy.js @@ -9,7 +9,7 @@ CreateReplicationPolicyService.$inject = ['$http']; function CreateReplicationPolicyService($http) { - return createReplicaitonPolicy; + return createReplicationPolicy; function createReplicationPolicy(policy) { return $http diff --git a/views/ng/sections/header-include.htm b/views/ng/sections/header-include.htm index c1087a5d6..91f0511ea 100644 --- a/views/ng/sections/header-include.htm +++ b/views/ng/sections/header-include.htm @@ -137,6 +137,7 @@ +