2015-03-13 22:34:28 +00:00
|
|
|
/**
|
|
|
|
* An element which displays the builds panel for a repository view.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('repoPanelBuilds', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/repo-view/repo-panel-builds.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: false,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'repository': '=repository',
|
2015-05-06 22:16:03 +00:00
|
|
|
'builds': '=builds',
|
|
|
|
'isEnabled': '=isEnabled'
|
2015-03-13 22:34:28 +00:00
|
|
|
},
|
2015-03-18 20:26:27 +00:00
|
|
|
controller: function($scope, $element, $filter, $routeParams, ApiService, TriggerService, UserService) {
|
2015-03-13 22:34:28 +00:00
|
|
|
var orderBy = $filter('orderBy');
|
|
|
|
|
|
|
|
$scope.TriggerService = TriggerService;
|
|
|
|
|
2015-03-18 20:26:27 +00:00
|
|
|
UserService.updateUserIn($scope);
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
$scope.options = {
|
|
|
|
'filter': 'recent',
|
|
|
|
'reverse': false,
|
|
|
|
'predicate': 'started_datetime'
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.currentFilter = null;
|
|
|
|
|
|
|
|
$scope.currentStartTrigger = null;
|
|
|
|
|
|
|
|
$scope.showBuildDialogCounter = 0;
|
|
|
|
$scope.showTriggerStartDialogCounter = 0;
|
|
|
|
|
2015-04-16 18:58:25 +00:00
|
|
|
$scope.triggerCredentialsModalTrigger = null;
|
|
|
|
$scope.triggerCredentialsModalCounter = 0;
|
2015-04-14 18:11:02 +00:00
|
|
|
|
2015-07-14 09:39:49 +00:00
|
|
|
$scope.feedback = null;
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
var updateBuilds = function() {
|
|
|
|
if (!$scope.allBuilds) { return; }
|
|
|
|
|
|
|
|
var unordered = $scope.allBuilds.map(function(build_info) {
|
|
|
|
var commit_sha = null;
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
if (build_info.trigger_metadata) {
|
2015-06-02 19:43:55 +00:00
|
|
|
commit_sha = TriggerService.getCommitSHA(build_info.trigger_metadata);
|
2015-03-13 22:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $.extend(build_info, {
|
|
|
|
'started_datetime': (new Date(build_info.started)).valueOf() * (-1),
|
2015-04-30 19:33:19 +00:00
|
|
|
'building_tags': build_info.tags || [],
|
2015-03-13 22:34:28 +00:00
|
|
|
'commit_sha': commit_sha
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.fullBuilds = orderBy(unordered, $scope.options.predicate, $scope.options.reverse);
|
|
|
|
};
|
|
|
|
|
2015-04-30 17:01:40 +00:00
|
|
|
var loadBuilds = function(opt_forcerefresh) {
|
2015-05-06 22:16:03 +00:00
|
|
|
if (!$scope.builds || !$scope.repository || !$scope.options.filter || !$scope.isEnabled) {
|
2015-03-13 22:34:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: We only refresh if the filter has changed.
|
|
|
|
var filter = $scope.options.filter;
|
2015-04-30 17:01:40 +00:00
|
|
|
if ($scope.buildsResource && filter == $scope.currentFilter && !opt_forcerefresh) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-13 22:34:28 +00:00
|
|
|
|
|
|
|
var since = null;
|
2015-03-23 19:44:17 +00:00
|
|
|
var limit = 10;
|
2015-03-13 22:34:28 +00:00
|
|
|
|
2015-03-18 15:59:22 +00:00
|
|
|
if ($scope.options.filter == '48hour') {
|
2015-03-13 22:34:28 +00:00
|
|
|
since = Math.floor(moment().subtract(2, 'days').valueOf() / 1000);
|
2015-03-23 19:44:17 +00:00
|
|
|
limit = 100;
|
2015-03-18 15:59:22 +00:00
|
|
|
} else if ($scope.options.filter == '30day') {
|
2015-03-13 22:34:28 +00:00
|
|
|
since = Math.floor(moment().subtract(30, 'days').valueOf() / 1000);
|
2015-03-23 19:44:17 +00:00
|
|
|
limit = 100;
|
2015-03-13 22:34:28 +00:00
|
|
|
} else {
|
|
|
|
since = null;
|
2015-03-23 19:44:17 +00:00
|
|
|
limit = 10;
|
2015-03-13 22:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
2015-03-23 19:44:17 +00:00
|
|
|
'limit': limit,
|
2015-03-13 22:34:28 +00:00
|
|
|
'since': since
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.buildsResource = ApiService.getRepoBuildsAsResource(params).get(function(resp) {
|
|
|
|
$scope.allBuilds = resp.builds;
|
|
|
|
$scope.currentFilter = filter;
|
|
|
|
updateBuilds();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var buildsChanged = function() {
|
|
|
|
if (!$scope.allBuilds) {
|
|
|
|
loadBuilds();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-06 22:16:03 +00:00
|
|
|
if (!$scope.builds || !$scope.repository || !$scope.isEnabled) {
|
2015-03-13 22:34:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace any build records with updated records from the server.
|
2015-04-30 17:01:40 +00:00
|
|
|
var requireReload = false;
|
2015-03-13 22:34:28 +00:00
|
|
|
$scope.builds.map(function(build) {
|
2015-04-30 17:01:40 +00:00
|
|
|
var found = false;
|
2015-03-13 22:34:28 +00:00
|
|
|
for (var i = 0; i < $scope.allBuilds.length; ++i) {
|
|
|
|
var current = $scope.allBuilds[i];
|
|
|
|
if (current.id == build.id && current.phase != build.phase) {
|
|
|
|
$scope.allBuilds[i] = build;
|
2015-04-30 17:01:40 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
2015-03-13 22:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 17:01:40 +00:00
|
|
|
|
|
|
|
// If the build was not found, then a new build has started. Reload
|
|
|
|
// the builds list.
|
|
|
|
if (!found) {
|
|
|
|
requireReload = true;
|
|
|
|
}
|
2015-03-13 22:34:28 +00:00
|
|
|
});
|
|
|
|
|
2015-04-30 17:01:40 +00:00
|
|
|
if (requireReload) {
|
|
|
|
loadBuilds(/* force refresh */true);
|
|
|
|
} else {
|
|
|
|
updateBuilds();
|
|
|
|
}
|
2015-03-13 22:34:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var loadBuildTriggers = function() {
|
2015-05-06 22:16:03 +00:00
|
|
|
if (!$scope.repository || !$scope.repository.can_admin || !$scope.isEnabled) { return; }
|
2015-03-13 22:34:28 +00:00
|
|
|
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.triggersResource = ApiService.listBuildTriggersAsResource(params).get(function(resp) {
|
|
|
|
$scope.triggers = resp.triggers;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('repository', loadBuildTriggers);
|
|
|
|
$scope.$watch('repository', loadBuilds);
|
|
|
|
|
2015-05-06 22:16:03 +00:00
|
|
|
$scope.$watch('isEnabled', loadBuildTriggers);
|
|
|
|
$scope.$watch('isEnabled', loadBuilds);
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
$scope.$watch('builds', buildsChanged);
|
|
|
|
|
|
|
|
$scope.$watch('options.filter', loadBuilds);
|
|
|
|
$scope.$watch('options.predicate', updateBuilds);
|
|
|
|
$scope.$watch('options.reverse', updateBuilds);
|
|
|
|
|
|
|
|
$scope.tablePredicateClass = function(name, predicate, reverse) {
|
|
|
|
if (name != predicate) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'current ' + (reverse ? 'reversed' : '');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.orderBy = function(predicate) {
|
|
|
|
if (predicate == $scope.options.predicate) {
|
|
|
|
$scope.options.reverse = !$scope.options.reverse;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.options.reverse = false;
|
|
|
|
$scope.options.predicate = predicate;
|
|
|
|
};
|
|
|
|
|
2015-04-16 18:58:25 +00:00
|
|
|
$scope.showTriggerCredentialsModal = function(trigger) {
|
|
|
|
$scope.triggerCredentialsModalTrigger = trigger;
|
|
|
|
$scope.triggerCredentialsModalCounter++;
|
2015-04-14 18:11:02 +00:00
|
|
|
};
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
$scope.askDeleteTrigger = function(trigger) {
|
|
|
|
$scope.deleteTriggerInfo = {
|
|
|
|
'trigger': trigger
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.askRunTrigger = function(trigger) {
|
2016-09-09 20:54:46 +00:00
|
|
|
if (!trigger.can_invoke) {
|
|
|
|
bootbox.alert('You do not have permission to manually invoke this trigger');
|
2015-03-18 20:26:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:28 +00:00
|
|
|
$scope.currentStartTrigger = trigger;
|
|
|
|
$scope.showTriggerStartDialogCounter++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteTrigger = function(trigger, opt_callback) {
|
|
|
|
if (!trigger) { return; }
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
|
|
|
'trigger_uuid': trigger.id
|
|
|
|
};
|
|
|
|
|
|
|
|
var errorHandler = ApiService.errorDisplay('Could not delete build trigger', function() {
|
|
|
|
opt_callback && opt_callback(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
ApiService.deleteBuildTrigger(null, params).then(function(resp) {
|
|
|
|
$scope.triggers.splice($scope.triggers.indexOf(trigger), 1);
|
|
|
|
opt_callback && opt_callback(true);
|
|
|
|
}, errorHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showNewBuildDialog = function() {
|
|
|
|
$scope.showBuildDialogCounter++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.handleBuildStarted = function(build) {
|
2015-05-26 17:49:58 +00:00
|
|
|
if ($scope.allBuilds) {
|
2015-05-06 22:27:04 +00:00
|
|
|
$scope.allBuilds.push(build);
|
|
|
|
}
|
2015-03-13 22:34:28 +00:00
|
|
|
updateBuilds();
|
2015-07-14 09:39:49 +00:00
|
|
|
|
|
|
|
$scope.feedback = {
|
|
|
|
'kind': 'info',
|
|
|
|
'message': 'Build {buildid} started',
|
|
|
|
'data': {
|
|
|
|
'buildid': build.id
|
|
|
|
}
|
|
|
|
};
|
2015-03-13 22:34:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|
|
|
|
|