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-04-17 17:53:26 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.log')
|
|
|
|
.directive('listLog', listLog);
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
ListLogController.$inject = ['$scope','ListLogService', 'getParameterByName', '$location', '$filter', 'trFilter'];
|
2016-04-17 17:53:26 +02:00
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
function ListLogController($scope, ListLogService, getParameterByName, $location, $filter, trFilter) {
|
2016-06-26 06:56:58 +02:00
|
|
|
|
2016-06-28 01:58:38 +02:00
|
|
|
$scope.subsTabPane = 30;
|
2016-06-26 06:56:58 +02:00
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
var vm = this;
|
2016-06-28 07:12:25 +02:00
|
|
|
|
|
|
|
vm.sectionHeight = {'min-height': '579px'};
|
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.isOpen = false;
|
2016-04-28 19:36:39 +02:00
|
|
|
|
2016-04-27 12:29:55 +02:00
|
|
|
vm.beginTimestamp = 0;
|
|
|
|
vm.endTimestamp = 0;
|
2016-07-05 03:06:36 +02:00
|
|
|
vm.keywords = '';
|
|
|
|
vm.username = '';
|
2016-04-28 19:36:39 +02:00
|
|
|
|
2016-04-27 12:29:55 +02:00
|
|
|
vm.op = [];
|
2016-07-04 13:09:19 +02:00
|
|
|
vm.opOthers = true;
|
|
|
|
|
2016-04-27 12:29:55 +02:00
|
|
|
vm.search = search;
|
2016-04-28 19:36:39 +02:00
|
|
|
vm.showAdvancedSearch = showAdvancedSearch;
|
2016-04-27 12:29:55 +02:00
|
|
|
|
2016-05-31 12:49:16 +02:00
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
2016-05-01 19:46:50 +02:00
|
|
|
vm.queryParams = {
|
|
|
|
'beginTimestamp' : vm.beginTimestamp,
|
|
|
|
'endTimestamp' : vm.endTimestamp,
|
|
|
|
'keywords' : vm.keywords,
|
|
|
|
'projectId': vm.projectId,
|
|
|
|
'username' : vm.username
|
|
|
|
};
|
2016-07-06 01:57:09 +02:00
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
retrieve(vm.queryParams);
|
2016-06-01 08:01:35 +02:00
|
|
|
|
|
|
|
$scope.$on('$locationChangeSuccess', function() {
|
2016-07-05 10:12:20 +02:00
|
|
|
|
|
|
|
if(vm.publicity) {
|
|
|
|
vm.target = 'repositories';
|
|
|
|
}
|
|
|
|
|
2016-06-01 08:01:35 +02:00
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
|
|
|
vm.queryParams = {
|
|
|
|
'beginTimestamp' : vm.beginTimestamp,
|
|
|
|
'endTimestamp' : vm.endTimestamp,
|
|
|
|
'keywords' : vm.keywords,
|
|
|
|
'projectId': vm.projectId,
|
|
|
|
'username' : vm.username
|
|
|
|
};
|
2016-07-05 03:06:36 +02:00
|
|
|
vm.username = '';
|
2016-06-01 08:01:35 +02:00
|
|
|
retrieve(vm.queryParams);
|
|
|
|
});
|
2016-07-02 12:20:31 +02:00
|
|
|
|
2016-04-27 12:29:55 +02:00
|
|
|
function search(e) {
|
2016-07-05 03:06:36 +02:00
|
|
|
|
2016-05-23 12:29:17 +02:00
|
|
|
if(e.op[0] === 'all') {
|
2016-07-05 03:06:36 +02:00
|
|
|
e.op = ['create', 'pull', 'push', 'delete'];
|
|
|
|
}
|
|
|
|
if(vm.opOthers && $.trim(vm.others) !== '') {
|
|
|
|
e.op.push(vm.others);
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.queryParams.keywords = e.op.join('/');
|
2016-04-28 19:36:39 +02:00
|
|
|
vm.queryParams.username = e.username;
|
2016-04-27 12:29:55 +02:00
|
|
|
|
2016-04-28 19:36:39 +02:00
|
|
|
vm.queryParams.beginTimestamp = toUTCSeconds(vm.fromDate, 0, 0, 0);
|
|
|
|
vm.queryParams.endTimestamp = toUTCSeconds(vm.toDate, 23, 59, 59);
|
|
|
|
|
|
|
|
retrieve(vm.queryParams);
|
2016-04-27 12:29:55 +02:00
|
|
|
}
|
2016-04-17 17:53:26 +02:00
|
|
|
|
2016-04-28 19:36:39 +02:00
|
|
|
function showAdvancedSearch() {
|
2016-04-22 18:49:52 +02:00
|
|
|
if(vm.isOpen){
|
|
|
|
vm.isOpen = false;
|
|
|
|
}else{
|
|
|
|
vm.isOpen = true;
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 12:29:55 +02:00
|
|
|
|
|
|
|
function retrieve(queryParams) {
|
|
|
|
ListLogService(queryParams)
|
|
|
|
.then(listLogComplete)
|
|
|
|
.catch(listLogFailed);
|
|
|
|
}
|
2016-04-28 19:36:39 +02:00
|
|
|
|
2016-04-27 12:29:55 +02:00
|
|
|
function listLogComplete(response) {
|
|
|
|
vm.logs = response.data;
|
2016-07-04 11:09:45 +02:00
|
|
|
|
|
|
|
vm.queryParams = {
|
|
|
|
'beginTimestamp' : 0,
|
|
|
|
'endTimestamp' : 0,
|
|
|
|
'keywords' : '',
|
|
|
|
'projectId': vm.projectId,
|
|
|
|
'username' : ''
|
|
|
|
};
|
|
|
|
vm.op = ['all'];
|
|
|
|
vm.fromDate = '';
|
|
|
|
vm.toDate = '';
|
|
|
|
vm.others = '';
|
2016-07-04 13:09:19 +02:00
|
|
|
vm.opOthers = true;
|
2016-07-02 12:20:31 +02:00
|
|
|
vm.isOpen = false;
|
2016-04-27 12:29:55 +02:00
|
|
|
}
|
2016-07-01 12:37:17 +02:00
|
|
|
function listLogFailed(response){
|
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
2016-07-04 06:34:34 +02:00
|
|
|
$scope.$emit('modalMessage', $filter('tr')('failed_to_get_log') + response);
|
2016-07-01 12:37:17 +02:00
|
|
|
$scope.$emit('raiseError', true);
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to get log:' + response);
|
2016-04-27 12:29:55 +02:00
|
|
|
}
|
2016-04-28 19:36:39 +02:00
|
|
|
|
2016-06-14 08:54:00 +02:00
|
|
|
function toUTCSeconds(date, hour, min, sec) {
|
2016-06-30 10:31:53 +02:00
|
|
|
if(!angular.isDefined(date) || date === '') {
|
2016-04-28 19:36:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-28 19:36:39 +02:00
|
|
|
}
|
|
|
|
|
2016-04-17 17:53:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function listLog() {
|
|
|
|
var directive = {
|
2016-07-11 10:11:54 +02:00
|
|
|
'restrict': 'E',
|
|
|
|
'templateUrl': '/static/resources/js/components/log/list-log.directive.html',
|
|
|
|
'scope': {
|
2016-07-05 10:12:20 +02:00
|
|
|
'sectionHeight': '=',
|
|
|
|
'target': '=',
|
|
|
|
'publicity': '='
|
2016-06-28 07:12:25 +02:00
|
|
|
},
|
2016-07-11 10:11:54 +02:00
|
|
|
'link': link,
|
|
|
|
'controller': ListLogController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
2016-05-23 12:29:17 +02:00
|
|
|
};
|
2016-04-17 17:53:26 +02:00
|
|
|
|
|
|
|
return directive;
|
2016-07-11 10:11:54 +02:00
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
element.find('#txtSearchInput').on('keydown', function(e) {
|
|
|
|
if($(this).is(':focus') && e.keyCode === 13) {
|
|
|
|
ctrl.search({'op': ctrl.op, 'username': ctrl.username});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-17 17:53:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|