Add revision component to job details

This commit is contained in:
Marliana Lara
2017-07-06 14:14:47 -04:00
parent 3cc522de8f
commit 3d5f7057c3
5 changed files with 68 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
function atTruncateLink (scope, el, attr, ctrl) { function atTruncateLink (scope, el, attr, ctrl) {
let truncateController = ctrl; let truncateController = ctrl;
let string = attr.atTruncate; let string = attr.string;
let maxlength = attr.maxlength; let maxlength = attr.maxlength;
truncateController.init(scope, string, maxlength); truncateController.init(scope, string, maxlength);
@@ -8,36 +8,73 @@ function atTruncateLink (scope, el, attr, ctrl) {
function AtTruncateController ($filter) { function AtTruncateController ($filter) {
let vm = this; let vm = this;
vm.toolTipContent = 'Copy full revision to clipboard.';
let string, let maxlength;
maxlength;
vm.init = (scope, _string_, _maxlength_) => { vm.init = (scope, _string_, _maxlength_) => {
string = _string_; vm.string = _string_;
maxlength = _maxlength_; maxlength = _maxlength_;
vm.truncatedString = $filter('limitTo')(string, maxlength, 0); vm.truncatedString = $filter('limitTo')(vm.string, maxlength, 0);
} }
vm.copy = function() {
vm.toolTipContent = 'Copied to clipboard.';
let textArea = document.createElement("textarea");
// Place in top-left corner of screen regardless of scroll position.
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
// Ensure it has a small width and height. Setting to 1px / 1em
// doesn't work as this gives a negative w/h on some browsers.
textArea.style.width = '2em';
textArea.style.height = '2em';
// We don't need padding, reducing the size if it does flash render.
textArea.style.padding = 0;
// Clean up any borders.
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
// Avoid flash of white box if rendered for any reason.
textArea.style.background = 'transparent';
textArea.value = vm.string;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
};
} }
function atTruncate($filter) { function atTruncate($filter, pathService) {
return { return {
restrict: 'EA', restrict: 'EA',
replace: true, replace: true,
transclude: true, transclude: true,
template: '<span>{{vm.truncatedString}}</span>', templateUrl: pathService.getPartialPath('components/truncate/truncate'),
controller: AtTruncateController, controller: AtTruncateController,
controllerAs: 'vm', controllerAs: 'vm',
link: atTruncateLink, link: atTruncateLink,
scope: { scope: {
maxLength: '@' maxLength: '@',
string: '@'
} }
} }
} }
atTruncate.$inject = [ atTruncate.$inject = [
'$filter' '$filter',
'PathService'
]; ];
export default atTruncate; export default atTruncate;

View File

@@ -0,0 +1,9 @@
<div class="RevisionHash">
<div class="RevisionHash-tag">
<span class="RevisionHash-name">{{vm.truncatedString}}</span>
</div>
<div class="RevisionHash-copy" aw-tool-tip="vm.toolTipContent" data-tip-watch="vm.toolTipContent"
data-placement="top" ng-click="vm.copy()">
<i class="fa fa-clone"></i>
</div>
</div>

View File

@@ -247,9 +247,8 @@
<label class="JobResults-resultRowLabel"> <label class="JobResults-resultRowLabel">
Revision Revision
</label> </label>
<div class="JobResults-resultRowText JobResults-resultRowText--revision"> <at-truncate string="{{job.scm_revision}}" maxLength="7" class="JobResults-resultRowText JobResults-resultRowText--revision">
{{ job.scm_revision }} </at-truncate>
</div>
</div> </div>
<!-- PLAYBOOK DETAIL --> <!-- PLAYBOOK DETAIL -->

View File

@@ -94,14 +94,16 @@ export default ['$scope', '$rootScope', '$log', 'Rest', 'Alert',
} }
$scope.$on('copied', function(e) { $scope.$on('copied', function(e) {
$scope.projects.map( (project) => { // $scope.projects.map( (project) => {
if (project.id === e.targetScope.project.id) { // if (project.id === e.targetScope.project.id) {
project.tooltipContent = 'Copied to clipboard.'; // project.tooltipContent = 'Copied to clipboard.';
} // }
else { // else {
project.tooltipContent = "Copy full revision to clipboard."; // project.tooltipContent = "Copy full revision to clipboard.";
} // }
}); // });
console.log('copied hi there');
console.log(e);
}); });
$scope.reloadList = function(){ $scope.reloadList = function(){

View File

@@ -525,7 +525,7 @@ angular.module('GeneratorHelpers', [systemStatus.name])
Attr(field, 'columnClass') : ""; Attr(field, 'columnClass') : "";
html += ` html += `
<td ${classList}> <td ${classList}>
<revisions class=\"RevisionHash\"></revisions> <at-truncate string="{{project.scm_revision}}" maxLength="7"></at-truncate>
</td>`; </td>`;
} else if (field.type === 'badgeCount') { } else if (field.type === 'badgeCount') {
html = BadgeCount(params); html = BadgeCount(params);