Skip to content

Commit d205cd5

Browse files
authored
Merge pull request #382 from jnywong/copy-error
Add `copy error to clipboard` button
2 parents ab7fccf + 55ea4b7 commit d205cd5

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

nbgitpuller/static/js/gitsyncview.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FitAddon } from 'xterm-addon-fit';
44
import { WebLinksAddon } from 'xterm-addon-web-links';
55

66
export class GitSyncView{
7-
constructor(termSelector, progressSelector, termToggleSelector, recoverySelector) {
7+
constructor(termSelector, progressSelector, termToggleSelector, containerErrorSelector, copyErrorSelector) {
88
// Class that encapsulates view rendering as much as possible
99
this.term = new Terminal({
1010
convertEol: true
@@ -18,7 +18,8 @@ export class GitSyncView{
1818

1919
this.termToggle = document.querySelector(termToggleSelector);
2020
this.termElement = document.querySelector(termSelector);
21-
this.recovery = document.querySelector(recoverySelector);
21+
this.containerError = document.querySelector(containerErrorSelector);
22+
this.copyError = document.querySelector(copyErrorSelector);
2223

2324
this.termToggle.onclick = () => this.setTerminalVisibility(!this.visible)
2425
}
@@ -64,9 +65,18 @@ export class GitSyncView{
6465
}
6566
}
6667

67-
setRecoveryLink(isError) {
68+
setContainerError(isError, errorText='') {
6869
if (isError) {
69-
this.recovery.classList.toggle('hidden', !visible);
70+
this.containerError.classList.toggle('hidden', !this.visible);
71+
}
72+
const button = this.copyError;
73+
button.onclick = async () => {
74+
try {
75+
await navigator.clipboard.writeText(errorText);
76+
button.innerHTML = 'Error message copied!';
77+
} catch (err) {
78+
console.error('Failed to copy error text: ', err);
79+
}
7080
}
7181
}
7282
}

nbgitpuller/static/js/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const gsv = new GitSyncView(
2929
'#status-details',
3030
'#status-panel-title',
3131
'#status-panel-toggle',
32-
'#recovery-link'
32+
'#container-error',
33+
'#copy-error-button',
3334
);
3435

3536
gs.addHandler('syncing', function(data) {
@@ -46,10 +47,14 @@ gs.addHandler('error', function(data) {
4647
gsv.setProgressValue(100);
4748
gsv.setProgressText('Error: ' + data.message);
4849
gsv.setProgressError(true);
49-
gsv.setRecoveryLink(true);
5050
gsv.setTerminalVisibility(true);
5151
if (data.output) {
52-
gsv.term.write(data.output);
52+
const errorText= `Repository: ${gs.repo}\nBranch: ${gs.branch}\nRedirect URL: ${gs.redirectUrl}\n\n${data.output}\n`;
53+
gsv.term.write(errorText);
54+
gsv.setContainerError(
55+
true,
56+
errorText
57+
);
5358
}
5459
});
5560
gs.start();

nbgitpuller/templates/status.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{% endblock %}
1313

1414
{% block site %}
15-
<div class="container"">
15+
<div class="container">
1616
<div class="page-header">
1717
Synchronizing <a href="{{ repo }}">git repository</a> before sending you to <strong>{{ path }}...</strong>
1818
</div>
@@ -30,8 +30,15 @@
3030
<div id="status-details"></div>
3131
</div>
3232
</div>
33-
<div id="recovery-link" class="hidden">
34-
<a class="btn btn-warning" href="{{ base_url }}" aria-label="Go to the Jupyter server without synchronizing content">Proceed to server without synchronizing</a>
33+
<div id="container-error" class="container hidden">
34+
<div class="row">
35+
<div id="recovery-link" class="col-xs-6 pull-left">
36+
<a class="btn btn-warning" href="{{ base_url }}" aria-label="Go to the Jupyter server without synchronizing content">Proceed to server without synchronizing</a>
37+
</div>
38+
<div id="copy-error" class="col-xs-6 pull-right text-right">
39+
<button class="btn btn-danger" id="copy-error-button" aria-label="Copy error details to clipboard">Copy error to clipboard</button>
40+
</div>
41+
</div>
3542
</div>
3643
</div>
3744
{% endblock %}
@@ -74,5 +81,12 @@
7481
width: 100%;
7582
color: black;
7683
}
84+
85+
#container-error {
86+
margin-right: 0px;
87+
padding-left: 0px;
88+
padding-right: 30px;
89+
}
90+
7791
</style>
7892
{% endblock %}

0 commit comments

Comments
 (0)