-
+
Endpoint is required.
@@ -58,7 +58,7 @@
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 @@