2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2016-06-07 10:49:38 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.replication')
|
2016-06-29 11:14:00 +02:00
|
|
|
.directive('listReplication', listReplication)
|
|
|
|
.factory('jobStatus', jobStatus);
|
|
|
|
|
|
|
|
jobStatus.inject = ['$filter', 'trFilter'];
|
|
|
|
function jobStatus($filter, trFilter) {
|
|
|
|
return function() {
|
|
|
|
return [
|
|
|
|
{'key': 'all' , 'value': $filter('tr')('all')},
|
|
|
|
{'key': 'pending', 'value': $filter('tr')('pending')},
|
|
|
|
{'key': 'running', 'value': $filter('tr')('running')},
|
|
|
|
{'key': 'error' , 'value': $filter('tr')('error')},
|
2016-07-06 01:57:09 +02:00
|
|
|
{'key': 'retrying', 'value': $filter('tr')('retrying')},
|
2016-06-29 11:14:00 +02:00
|
|
|
{'key': 'stopped', 'value': $filter('tr')('stopped')},
|
|
|
|
{'key': 'finished', 'value':$filter('tr')('finished')},
|
|
|
|
{'key': 'canceled', 'value': $filter('tr')('canceled')}
|
|
|
|
];
|
2016-07-11 12:38:51 +02:00
|
|
|
};
|
2016-06-29 11:14:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ListReplicationController.$inject = ['$scope', 'getParameterByName', '$location', 'ListReplicationPolicyService', 'ToggleReplicationPolicyService', 'ListReplicationJobService', '$window', '$filter', 'trFilter', 'jobStatus'];
|
2016-06-07 10:49:38 +02:00
|
|
|
|
2016-06-29 11:14:00 +02:00
|
|
|
function ListReplicationController($scope, getParameterByName, $location, ListReplicationPolicyService, ToggleReplicationPolicyService, ListReplicationJobService, $window, $filter, trFilter, jobStatus) {
|
2016-06-07 10:49:38 +02:00
|
|
|
var vm = this;
|
|
|
|
|
2016-07-14 10:53:25 +02:00
|
|
|
vm.sectionHeight = {'min-height': '1260px'};
|
2016-07-06 01:57:09 +02:00
|
|
|
|
2016-06-15 11:46:23 +02:00
|
|
|
$scope.$on('$locationChangeSuccess', function() {
|
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
|
|
|
vm.retrievePolicy();
|
|
|
|
});
|
2016-06-07 10:49:38 +02:00
|
|
|
|
|
|
|
vm.addReplication = addReplication;
|
2016-06-13 12:12:46 +02:00
|
|
|
vm.editReplication = editReplication;
|
|
|
|
|
2016-06-16 11:36:06 +02:00
|
|
|
vm.searchReplicationPolicy = searchReplicationPolicy;
|
|
|
|
vm.searchReplicationJob = searchReplicationJob;
|
2016-07-03 06:10:42 +02:00
|
|
|
vm.refreshReplicationJob = refreshReplicationJob;
|
2016-06-15 11:46:23 +02:00
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
vm.retrievePolicy = retrievePolicy;
|
|
|
|
vm.retrieveJob = retrieveJob;
|
2016-07-06 14:22:45 +02:00
|
|
|
|
|
|
|
vm.confirmToTogglePolicy = confirmToTogglePolicy;
|
2016-06-13 12:12:46 +02:00
|
|
|
vm.togglePolicy = togglePolicy;
|
2016-06-16 11:36:06 +02:00
|
|
|
|
|
|
|
vm.downloadLog = downloadLog;
|
2016-06-14 12:47:32 +02:00
|
|
|
|
2016-06-13 12:12:46 +02:00
|
|
|
vm.last = false;
|
2016-06-16 11:36:06 +02:00
|
|
|
|
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
2016-06-07 10:49:38 +02:00
|
|
|
vm.retrievePolicy();
|
2016-06-30 09:57:00 +02:00
|
|
|
|
2016-06-29 11:14:00 +02:00
|
|
|
vm.jobStatus = jobStatus;
|
|
|
|
vm.currentStatus = vm.jobStatus()[0];
|
|
|
|
|
2016-06-30 10:31:53 +02:00
|
|
|
vm.pickUp = pickUp;
|
|
|
|
|
2016-07-03 06:10:42 +02:00
|
|
|
vm.searchJobTIP = false;
|
|
|
|
vm.refreshJobTIP = false;
|
2016-07-06 01:57:09 +02:00
|
|
|
|
2016-06-16 11:36:06 +02:00
|
|
|
function searchReplicationPolicy() {
|
2016-06-15 11:46:23 +02:00
|
|
|
vm.retrievePolicy();
|
|
|
|
}
|
|
|
|
|
2016-06-16 11:36:06 +02:00
|
|
|
function searchReplicationJob() {
|
|
|
|
if(vm.lastPolicyId !== -1) {
|
2016-07-03 06:10:42 +02:00
|
|
|
vm.searchJobTIP = true;
|
2016-06-16 11:36:06 +02:00
|
|
|
vm.retrieveJob(vm.lastPolicyId);
|
|
|
|
}
|
|
|
|
}
|
2016-07-03 06:10:42 +02:00
|
|
|
|
|
|
|
function refreshReplicationJob() {
|
|
|
|
if(vm.lastPolicyId !== -1) {
|
|
|
|
vm.refreshJobTIP = true;
|
|
|
|
vm.retrieveJob(vm.lastPolicyId);
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 11:36:06 +02:00
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
function retrievePolicy() {
|
2016-06-15 11:46:23 +02:00
|
|
|
ListReplicationPolicyService('', vm.projectId, vm.replicationPolicyName)
|
2016-06-07 10:49:38 +02:00
|
|
|
.success(listReplicationPolicySuccess)
|
|
|
|
.error(listReplicationPolicyFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function retrieveJob(policyId) {
|
2016-06-29 11:14:00 +02:00
|
|
|
var status = (vm.currentStatus.key === 'all' ? '' : vm.currentStatus.key);
|
2016-06-30 10:31:53 +02:00
|
|
|
ListReplicationJobService(policyId, vm.replicationJobName, status, toUTCSeconds(vm.fromDate, 0, 0, 0), toUTCSeconds(vm.toDate, 23, 59, 59))
|
2016-06-07 10:49:38 +02:00
|
|
|
.success(listReplicationJobSuccess)
|
|
|
|
.error(listReplicationJobFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function listReplicationPolicySuccess(data, status) {
|
2016-06-17 06:14:41 +02:00
|
|
|
vm.replicationJobs = [];
|
2016-06-07 10:49:38 +02:00
|
|
|
vm.replicationPolicies = data || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
function listReplicationPolicyFailed(data, status) {
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to list replication policy:' + data);
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function listReplicationJobSuccess(data, status) {
|
|
|
|
vm.replicationJobs = data || [];
|
2016-07-06 01:57:09 +02:00
|
|
|
var alertInfo = {
|
|
|
|
'show': false,
|
|
|
|
'message': ''
|
|
|
|
};
|
2016-06-29 11:14:00 +02:00
|
|
|
angular.forEach(vm.replicationJobs, function(item) {
|
|
|
|
for(var key in item) {
|
2016-07-06 01:57:09 +02:00
|
|
|
var value = item[key];
|
|
|
|
if(key === 'status' && (value === 'error' || value === 'retrying')) {
|
|
|
|
alertInfo.show = true;
|
|
|
|
alertInfo.message = $filter('tr')('alert_job_contains_error');
|
|
|
|
}
|
2016-06-29 11:14:00 +02:00
|
|
|
switch(key) {
|
|
|
|
case 'operation':
|
|
|
|
case 'status':
|
|
|
|
item[key] = $filter('tr')(value);
|
2016-07-11 12:38:51 +02:00
|
|
|
break;
|
2016-06-29 11:14:00 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-07-06 01:57:09 +02:00
|
|
|
|
|
|
|
$scope.$emit('raiseAlert', alertInfo);
|
2016-07-03 06:10:42 +02:00
|
|
|
vm.searchJobTIP = false;
|
|
|
|
vm.refreshJobTIP = false;
|
2016-07-11 12:38:51 +02:00
|
|
|
}
|
2016-06-07 10:49:38 +02:00
|
|
|
|
|
|
|
function listReplicationJobFailed(data, status) {
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to list replication job:' + data);
|
2016-07-03 06:10:42 +02:00
|
|
|
vm.searchJobTIP = false;
|
|
|
|
vm.refreshJobTIP = false;
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addReplication() {
|
2016-06-22 05:26:28 +02:00
|
|
|
vm.modalTitle = $filter('tr')('add_new_policy', []);
|
2016-06-13 12:12:46 +02:00
|
|
|
vm.action = 'ADD_NEW';
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
|
2016-06-13 12:12:46 +02:00
|
|
|
function editReplication(policyId) {
|
|
|
|
vm.policyId = policyId;
|
2016-06-22 05:26:28 +02:00
|
|
|
vm.modalTitle = $filter('tr')('edit_policy', []);
|
2016-06-13 12:12:46 +02:00
|
|
|
vm.action = 'EDIT';
|
2016-06-14 12:47:32 +02:00
|
|
|
|
2016-06-13 12:12:46 +02:00
|
|
|
console.log('Selected policy ID:' + vm.policyId);
|
|
|
|
}
|
2016-07-06 14:22:45 +02:00
|
|
|
|
|
|
|
function confirmToTogglePolicy(policyId, enabled, name) {
|
|
|
|
vm.policyId = policyId;
|
|
|
|
vm.enabled = enabled;
|
|
|
|
|
2016-07-07 05:51:03 +02:00
|
|
|
var status = $filter('tr')(vm.enabled === 1 ? 'enable':'disable');
|
2016-07-06 14:22:45 +02:00
|
|
|
|
2016-07-07 11:11:40 +02:00
|
|
|
var title;
|
|
|
|
var message;
|
|
|
|
if(enabled === 1){
|
|
|
|
title = $filter('tr')('confirm_to_toggle_enabled_policy_title');
|
|
|
|
message = $filter('tr')('confirm_to_toggle_enabled_policy');
|
|
|
|
}else{
|
|
|
|
title = $filter('tr')('confirm_to_toggle_disabled_policy_title');
|
|
|
|
message = $filter('tr')('confirm_to_toggle_disabled_policy');
|
|
|
|
}
|
|
|
|
$scope.$emit('modalTitle', title);
|
|
|
|
$scope.$emit('modalMessage', message);
|
2016-07-06 14:22:45 +02:00
|
|
|
|
|
|
|
var emitInfo = {
|
|
|
|
'contentType': 'text/html',
|
|
|
|
'confirmOnly': false,
|
|
|
|
'action': vm.togglePolicy
|
2016-07-11 12:38:51 +02:00
|
|
|
};
|
2016-07-06 14:22:45 +02:00
|
|
|
|
|
|
|
$scope.$emit('raiseInfo', emitInfo);
|
|
|
|
}
|
2016-06-14 12:47:32 +02:00
|
|
|
|
2016-07-06 14:22:45 +02:00
|
|
|
function togglePolicy() {
|
|
|
|
ToggleReplicationPolicyService(vm.policyId, vm.enabled)
|
2016-06-13 12:12:46 +02:00
|
|
|
.success(toggleReplicationPolicySuccess)
|
|
|
|
.error(toggleReplicationPolicyFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleReplicationPolicySuccess(data, status) {
|
|
|
|
console.log('Successful toggle replication policy.');
|
|
|
|
vm.retrievePolicy();
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleReplicationPolicyFailed(data, status) {
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to toggle replication policy.');
|
2016-06-13 12:12:46 +02:00
|
|
|
}
|
2016-06-14 12:47:32 +02:00
|
|
|
|
2016-06-16 11:36:06 +02:00
|
|
|
function downloadLog(policyId) {
|
|
|
|
$window.open('/api/jobs/replication/' + policyId + '/log', '_blank');
|
|
|
|
}
|
2016-06-30 10:31:53 +02:00
|
|
|
|
|
|
|
function pickUp(e) {
|
|
|
|
switch(e.key){
|
|
|
|
case 'fromDate':
|
|
|
|
vm.fromDate = e.value;
|
|
|
|
break;
|
|
|
|
case 'toDate':
|
|
|
|
vm.toDate = e.value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$scope.$apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
function toUTCSeconds(date, hour, min, sec) {
|
|
|
|
if(!angular.isDefined(date) || date === '') {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
var t = new Date(date);
|
|
|
|
t.setHours(hour);
|
|
|
|
t.setMinutes(min);
|
|
|
|
t.setSeconds(sec);
|
2016-07-04 11:09:45 +02:00
|
|
|
return t.getTime() / 1000;
|
2016-06-30 10:31:53 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
|
2016-07-06 19:12:20 +02:00
|
|
|
function listReplication($timeout, I18nService) {
|
2016-06-07 10:49:38 +02:00
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/replication/list-replication.directive.html',
|
2016-06-28 07:12:25 +02:00
|
|
|
'scope': {
|
|
|
|
'sectionHeight': '='
|
|
|
|
},
|
2016-06-07 10:49:38 +02:00
|
|
|
'link': link,
|
|
|
|
'controller': ListReplicationController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
2016-07-07 18:03:32 +02:00
|
|
|
|
2016-07-14 14:43:58 +02:00
|
|
|
|
|
|
|
var uponPaneHeight = element.find('#upon-pane').height();
|
|
|
|
var downPaneHeight = element.find('#down-pane').height();
|
|
|
|
|
|
|
|
var uponTableHeight = element.find('#upon-pane .table-body-container').height();
|
|
|
|
var downTableHeight = element.find('#down-pane .table-body-container').height();
|
|
|
|
|
|
|
|
var handleHeight = element.find('.split-handle').height() + element.find('.split-handle').offset().top + element.find('.well').height() - 24;
|
|
|
|
|
|
|
|
var maxDownPaneHeight = 760;
|
|
|
|
|
|
|
|
element.find('.split-handle').on('mousedown', mousedownHandler);
|
|
|
|
|
|
|
|
function mousedownHandler(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$(document).on('mousemove', mousemoveHandler);
|
|
|
|
$(document).on('mouseup', mouseupHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
function mousemoveHandler(e) {
|
|
|
|
|
|
|
|
var incrementHeight = $('.container-fluid').scrollTop() + e.pageY;
|
|
|
|
|
|
|
|
if(element.find('#down-pane').height() <= maxDownPaneHeight) {
|
|
|
|
element.find('#upon-pane').css({'height' : (uponPaneHeight - (handleHeight - incrementHeight)) + 'px'});
|
|
|
|
element.find('#down-pane').css({'height' : (downPaneHeight + (handleHeight - incrementHeight)) + 'px'});
|
|
|
|
element.find('#upon-pane .table-body-container').css({'height': (uponTableHeight - (handleHeight - incrementHeight)) + 'px'});
|
|
|
|
element.find('#down-pane .table-body-container').css({'height': (downTableHeight + (handleHeight - incrementHeight)) + 'px'});
|
|
|
|
}else{
|
|
|
|
element.find('#down-pane').css({'height' : (maxDownPaneHeight) + 'px'});
|
|
|
|
$(document).off('mousemove');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mouseupHandler(e) {
|
|
|
|
$(document).off('mousedown');
|
|
|
|
$(document).off('mousemove');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-13 12:12:46 +02:00
|
|
|
ctrl.lastPolicyId = -1;
|
2016-06-07 10:49:38 +02:00
|
|
|
|
2016-06-13 06:10:45 +02:00
|
|
|
scope.$watch('vm.replicationPolicies', function(current) {
|
2016-06-07 10:49:38 +02:00
|
|
|
$timeout(function(){
|
2016-06-15 11:46:23 +02:00
|
|
|
if(current) {
|
|
|
|
if(current.length > 0) {
|
|
|
|
element.find('#upon-pane table>tbody>tr').on('click', trClickHandler);
|
|
|
|
if(ctrl.lastPolicyId === -1) {
|
|
|
|
element.find('#upon-pane table>tbody>tr:eq(0)').trigger('click');
|
|
|
|
}else{
|
|
|
|
element.find('#upon-pane table>tbody>tr').filter('[policy_id="' + ctrl.lastPolicyId + '"]').trigger('click');
|
|
|
|
}
|
2016-06-13 12:12:46 +02:00
|
|
|
}else{
|
2016-06-15 12:17:04 +02:00
|
|
|
element
|
|
|
|
.find('#upon-pane table>tbody>tr')
|
|
|
|
.css({'background-color': '#FFFFFF'})
|
|
|
|
.css({'color': '#000'});
|
2016-06-13 12:12:46 +02:00
|
|
|
}
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-06-16 11:36:06 +02:00
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
function trClickHandler(e) {
|
|
|
|
element
|
|
|
|
.find('#upon-pane table>tbody>tr')
|
|
|
|
.css({'background-color': '#FFFFFF'})
|
2016-06-27 06:24:06 +02:00
|
|
|
.css({'color': '#000'})
|
|
|
|
.css({'cursor': 'default'});
|
2016-06-13 12:12:46 +02:00
|
|
|
element
|
|
|
|
.find('#upon-pane table>tbody>tr a')
|
|
|
|
.css({'color': '#337ab7'});
|
2016-06-07 10:49:38 +02:00
|
|
|
$(this)
|
|
|
|
.css({'background-color': '#057ac9'})
|
|
|
|
.css({'color': '#fff'});
|
2016-06-13 12:12:46 +02:00
|
|
|
$('a', this)
|
|
|
|
.css({'color': '#fff'});
|
2016-06-07 10:49:38 +02:00
|
|
|
ctrl.retrieveJob($(this).attr('policy_id'));
|
2016-06-13 12:12:46 +02:00
|
|
|
ctrl.lastPolicyId = $(this).attr('policy_id');
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
2016-06-29 11:14:00 +02:00
|
|
|
|
|
|
|
element.find('.datetimepicker').datetimepicker({
|
2016-07-06 19:12:20 +02:00
|
|
|
locale: I18nService().getCurrentLanguage(),
|
2016-06-29 11:14:00 +02:00
|
|
|
ignoreReadonly: true,
|
|
|
|
format: 'L',
|
|
|
|
showClear: true
|
|
|
|
});
|
|
|
|
element.find('#fromDatePicker').on('blur', function(){
|
|
|
|
ctrl.pickUp({'key': 'fromDate', 'value': $(this).val()});
|
|
|
|
});
|
|
|
|
element.find('#toDatePicker').on('blur', function(){
|
|
|
|
ctrl.pickUp({'key': 'toDate', 'value': $(this).val()});
|
|
|
|
});
|
2016-07-11 10:11:54 +02:00
|
|
|
|
|
|
|
element.find('#txtSearchPolicyInput').on('keydown', function(e) {
|
|
|
|
if($(this).is(':focus') && e.keyCode === 13) {
|
|
|
|
ctrl.searchReplicationPolicy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
element.find('#txtSearchJobInput').on('keydown', function(e) {
|
|
|
|
if($(this).is(':focus') && e.keyCode === 13) {
|
|
|
|
ctrl.searchReplicationJob();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 12:38:51 +02:00
|
|
|
})();
|