harbor/static/resources/js/components/log/list-log.directive.js

123 lines
2.9 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.log')
.directive('listLog', listLog);
ListLogController.$inject = ['$scope','ListLogService', 'getParameterByName', '$location'];
function ListLogController($scope, ListLogService, getParameterByName, $location) {
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
var vm = this;
vm.sectionHeight = {'min-height': '579px'};
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;
vm.keywords = "";
vm.username = "";
2016-04-28 19:36:39 +02:00
2016-04-27 12:29:55 +02:00
vm.op = [];
2016-04-28 19:36:39 +02:00
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
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
};
retrieve(vm.queryParams);
$scope.$on('$locationChangeSuccess', function() {
vm.projectId = getParameterByName('project_id', $location.absUrl());
vm.queryParams = {
'beginTimestamp' : vm.beginTimestamp,
'endTimestamp' : vm.endTimestamp,
'keywords' : vm.keywords,
'projectId': vm.projectId,
'username' : vm.username
};
retrieve(vm.queryParams);
});
2016-05-01 19:46:50 +02:00
2016-04-27 12:29:55 +02:00
function search(e) {
2016-05-23 12:29:17 +02:00
if(e.op[0] === 'all') {
2016-04-28 19:36:39 +02:00
vm.queryParams.keywords = '';
2016-04-27 12:29:55 +02:00
}else {
2016-04-28 19:36:39 +02:00
vm.queryParams.keywords = e.op.join('/') ;
2016-04-27 12:29:55 +02:00
}
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-28 19:36:39 +02:00
function showAdvancedSearch() {
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;
}
function listLogFailed(e){
console.log('listLogFailed:' + e);
}
2016-04-28 19:36:39 +02:00
function toUTCSeconds(date, hour, min, sec) {
2016-05-23 12:29:17 +02:00
if(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);
var utcTime = new Date(t.getUTCFullYear(),
t.getUTCMonth(),
t.getUTCDate(),
t.getUTCHours(),
t.getUTCMinutes(),
t.getUTCSeconds());
return utcTime.getTime() / 1000;
}
}
function listLog() {
var directive = {
restrict: 'E',
templateUrl: '/static/resources/js/components/log/list-log.directive.html',
scope: {
'sectionHeight': '='
},
controller: ListLogController,
controllerAs: 'vm',
bindToController: true
2016-05-23 12:29:17 +02:00
};
return directive;
}
})();