Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

Commit fb1d74d

Browse files
author
Paul Korzhyk
committed
UI to change default Dgraph Alpha URL
1 parent 09f5899 commit fb1d74d

File tree

5 files changed

+61
-39
lines changed

5 files changed

+61
-39
lines changed

published/js/runnable.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ var cm;
7676
serverLatencyInfo,
7777
networkLatency
7878
) {
79-
var isModal = $runnable.parents("#runnable-modal").length > 0;
80-
81-
var totalServerLatency = getTotalServerLatencyInMS(serverLatencyInfo);
82-
var networkOnlyLatency = Math.round(networkLatency - totalServerLatency);
79+
const totalServerLatency = getTotalServerLatencyInMS(serverLatencyInfo);
80+
const networkOnlyLatency = Math.round(networkLatency - totalServerLatency);
8381

8482
$runnable.find(".latency-info").removeClass("hidden");
8583
$runnable.find(".server-latency .number").text(serverLatencyInfo.total);

themes/hugo-tutorials/layouts/partials/runnable.html

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,37 @@
6666
</div>
6767
</div>
6868

69-
<div class="modal fade runnable-url-modal" id="runnable-url-modal" tabindex="-1" role="dialog"
69+
<style>
70+
.modal.show {
71+
display: block;
72+
opacity: 1;
73+
background-color: rgba(0,0,0,0.3);
74+
}
75+
</style>
76+
<div class="modal fade runnable-url-modal" tabindex="-1" role="dialog"
7077
aria-labelledby="runnable-url-modal-label" aria-hidden="true">
7178
<div class="modal-dialog modal-md" role="document">
7279
<div class="modal-content">
7380
<div class="modal-header">
74-
<h5 class="modal-title" id="runnable-url-modal-label">Change Dgraph Alpha URLs</h5>
81+
<h5 class="modal-title" id="runnable-url-modal-label">Change Dgraph Alpha URL</h5>
7582
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
7683
<span aria-hidden="true">&times;</span>
7784
</button>
7885
</div>
7986
<div class="modal-body">
8087
<div class="container-fluid">
8188
<form>
82-
<table class="table table-striped">
83-
<thead class="thead-dark">
84-
<tr>
85-
<th scope="col">Type</th>
86-
<th scope="col" class="col-11">URL</th>
87-
</tr>
88-
</thead>
89-
<tbody>
90-
<tr>
91-
<th scope="row" class="align-middle py-1">Alter</th>
92-
<td class="py-1">
93-
<input type="text" class="form-control" data-module="runnable-url" data-path-type="alter"
94-
data-default="http://127.0.0.1:8080/alter" placeholder="http://127.0.0.1:8080/alter">
95-
</td>
96-
</tr>
97-
</tbody>
98-
</table>
89+
<div class="form-group">
90+
<label for="inputDgraphUrl">Dgraph Alpha Address</label>
91+
<input type="text" class="form-control" id="inputDgraphUrl" placeholder="http://localhost:8080">
92+
<!-- <small id="serverStatus" class="form-text text-muted">Server status goes hear.</small> -->
93+
</div>
9994
</form>
10095
</div>
10196
</div>
10297
<div class="modal-footer">
103-
<button type="button" id="load-defaults" class="code-btn">Load Defaults</button>
104-
<button type="button" class="code-btn" data-dismiss="modal">Close</button>
105-
<button type="button" id="save" class="code-btn primary" data-dismiss="modal">Save</button>
98+
<button type="button" class="code-btn" data-action="default-url">Reset to Default</button>
99+
<button type="button" class="code-btn" data-action="apply">Apply</button>
106100
</div>
107101
</div>
108102
</div>

themes/hugo-tutorials/layouts/partials/topbar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
position: fixed;
4040
z-index: 1;
4141
left: 40vw;
42-
right: 10vw;
42+
right: 100px;
4343
top: 5px;
4444
border-radius: 8px;
4545
box-shadow: -2px 2px 6px 0px rgba(0,0,0,0.75);
@@ -56,7 +56,7 @@
5656
<strong>{{ $.Site.Params.thisRelease }}</strong>.
5757
Latest stable release is
5858
<strong>{{ $.Site.Params.latestRelease }}</strong>.
59-
<a href="/" class="btn btn-primary btn-small">Go to
59+
<a href="/" class="btn btn-primary">Go to
6060
<strong>
6161
Dgraph {{ $.Site.Params.latestRelease }}
6262
</strong>

themes/hugo-tutorials/static/js/build/dgraph-tour.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

themes/hugo-tutorials/static/js/runnable.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,36 @@ import '../css/runnable.css';
77

88
import javascript from 'codemirror/mode/javascript/javascript';
99

10-
// cm stores reference to the codemirror for the page
11-
var cm;
10+
// Stores reference to the codemirror for the page
11+
let codeMirror;
12+
13+
// Key in localStorage of the server URL string.
14+
const SERVER_ADDR = 'tourDgraphAddr';
15+
16+
let serverAddress = localStorage.getItem(SERVER_ADDR) || "http://localhost:8080";
17+
18+
changeServerAddress(serverAddress);
19+
20+
function changeServerAddress(newAddr) {
21+
serverAddress = newAddr;
22+
localStorage.setItem(SERVER_ADDR, newAddr);
23+
$('.runnable .pane-title .url').text(newAddr);
24+
$('input#inputDgraphUrl').val(newAddr);
25+
}
1226

1327
function initCodeMirror($runnable) {
1428
$runnable.find(".CodeMirror").remove();
1529

1630
var editableEl = $runnable.find(".query-content-editable")[0];
17-
cm = CodeMirror.fromTextArea(editableEl, {
31+
codeMirror = CodeMirror.fromTextArea(editableEl, {
1832
lineNumbers: true,
1933
autoCloseBrackets: true,
2034
lineWrapping: true,
2135
autofocus: false,
2236
tabSize: 2
2337
});
2438

25-
cm.on("change", function(c) {
39+
codeMirror.on("change", function(c) {
2640
var val = c.doc.getValue();
2741
$runnable.attr("data-current", val);
2842
c.save();
@@ -84,7 +98,6 @@ function updateLatencyInformation(
8498
serverLatencyInfo,
8599
networkLatency
86100
) {
87-
const isModal = $runnable.parents('#runnable-modal').length > 0;
88101
serverLatencyInfo.total_ns = Object.values(serverLatencyInfo).reduce((x, y) => x + y, 0);
89102

90103
const totalServerLatency = serverLatencyInfo.total_ns / 1e6;
@@ -130,10 +143,10 @@ $(document).on('click', '.runnable [data-action="run"]', async function(e) {
130143
$currentRunnable.find(".output-container").removeClass("empty error");
131144
codeEl.text("Waiting for the server response...");
132145

133-
var startTime = new Date().getTime();
146+
const startTime = Date.now();
134147

135148
const method = endpoint.substring(1);
136-
const stub = new dgraph.DgraphClientStub("http://localhost:8080")
149+
const stub = new dgraph.DgraphClientStub(serverAddress)
137150
const client = new dgraph.DgraphClient(stub)
138151
client.setDebugMode(true)
139152
// TODO: this should be done once per URL, but good enough for now.
@@ -191,6 +204,24 @@ $(document).on('click', '.runnable [data-action="run"]', async function(e) {
191204
}
192205
});
193206

207+
$(document).on('click', '.runnable a.btn-change', async function(e) {
208+
e.preventDefault();
209+
$('.runnable-url-modal.modal').addClass('show');
210+
})
211+
212+
$(document).on('click', '.runnable-url-modal button[data-dismiss="modal"]', async function(e) {
213+
$('.runnable-url-modal.modal').removeClass('show');
214+
})
215+
216+
$(document).on('click', '.runnable-url-modal button[data-action=apply]', async function(e) {
217+
$('.runnable-url-modal.modal').removeClass('show');
218+
changeServerAddress($('input#inputDgraphUrl').val())
219+
})
220+
221+
$(document).on('click', '.runnable-url-modal button[data-action=default-url]', async function(e) {
222+
changeServerAddress("http://localhost:8080")
223+
})
224+
194225
// Refresh code
195226
$(document).on("click", '.runnable [data-action="reset"]', function(e) {
196227
var $runnable = $(this).closest(".runnable");
@@ -209,8 +240,7 @@ $(document).on("click", '.runnable [data-action="reset"]', function(e) {
209240
}, 80);
210241
});
211242

212-
$(document).on("click", ".runnable-content.runnable-code", () => cm.focus());
213-
243+
$(document).on("click", ".runnable-content.runnable-code", () => codeMirror.focus());
214244

215245
// Initialize runnables
216246
$(".runnable").each(function() {

0 commit comments

Comments
 (0)