Skip to content

Commit 5ffe91c

Browse files
authored
Merge pull request #1654 from KiaraGrouwstra/easy-copy-hash
front-end: easy way to copy commit hashes in front-end
2 parents 3ec0151 + eb19d97 commit 5ffe91c

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

subprojects/hydra/root/common.tt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ BLOCK renderInputs; %]
393393
<tt>[% HTML.escape(input.uri) %]</tt>
394394
[% END %]
395395
</td>
396-
<td>[% IF input.revision %][% HTML.escape(input.revision) %][% END %]</td>
396+
<td>[% IF input.revision %]<tt class="rev-copy" onclick="copyToClipboard('[% input.revision | html %]', this)" title="Click to copy">[% HTML.escape(input.revision) %]</tt>[% END %]</td>
397397
<td><tt>[% input.path | html %]</tt></td>
398398
</tr>
399399
[% END %]
@@ -423,10 +423,12 @@ BLOCK renderInputDiff; %]
423423
[% IF bi1.type == "git" %]
424424
<tr><td>
425425
<b>[% HTML.escape(bi1.name) %]</b></td><td><tt>[% INCLUDE renderDiffUri contents=(bi1.frontend_revision _ ' to ' _ bi2.frontend_revision) %]</tt>
426+
(<a class="rev-copy" href="javascript:void(0)" onclick="copyToClipboard('[% bi2.revision | html %]', this); return false;" title="Click to copy full revision: [% bi2.revision | html %]">copy</a>)
426427
</td></tr>
427428
[% ELSE %]
428429
<tr><td>
429430
<b>[% HTML.escape(bi1.name) %]</b></td><td><tt>[% INCLUDE renderDiffUri contents=(bi1.revision _ ' to ' _ bi2.revision) %]</tt>
431+
(<a class="rev-copy" href="javascript:void(0)" onclick="copyToClipboard('[% bi2.revision | html %]', this); return false;" title="Click to copy latest revision">copy</a>)
430432
</td></tr>
431433
[% END %]
432434
[% ELSIF bi1.dependency.id != bi2.dependency.id || bi1.path != bi2.path %]
@@ -466,7 +468,7 @@ BLOCK renderShortEvalInput;
466468
IF input.type == "build" || input.type == "sysbuild" %]
467469
<a [% HTML.attributes(href => c.uri_for('/build' input.get_column('dependency'))) %]>[% HTML.escape(input.get_column('dependency')) %]</a>
468470
[% ELSE %]
469-
<tt>[% input.frontend_revision | html %]</tt>
471+
<a class="rev-copy" href="javascript:void(0)" onclick="copyToClipboard('[% input.revision | html %]', this); return false;" title="Click to copy full revision: [% input.revision | html %]"><tt>[% input.frontend_revision | html %]</tt></a>
470472
[% END;
471473
END;
472474

subprojects/hydra/root/static/css/hydra.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ table.clickable-rows > tbody > tr {
5555
cursor: pointer;
5656
}
5757

58+
.rev-copy {
59+
cursor: pointer;
60+
user-select: all;
61+
}
62+
63+
a.rev-copy {
64+
color: inherit;
65+
text-decoration: underline;
66+
}
67+
5868
h2 {
5969
font-size: 150%;
6070
margin-bottom: 0em;

subprojects/hydra/root/static/js/common.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
function copyToClipboard(text, el) {
2+
navigator.clipboard.writeText(text).then(function() {
3+
var $el = $(el);
4+
var orig = $el.attr('title');
5+
$el.attr('title', 'Copied!').tooltip('dispose').tooltip('show');
6+
setTimeout(function() {
7+
$el.tooltip('dispose').attr('title', orig);
8+
}, 1200);
9+
});
10+
}
11+
112
function makeTreeCollapsible(tab) {
213
/*** Tree toggles in logfiles. ***/
314

0 commit comments

Comments
 (0)