Skip to content

Commit 2e9c606

Browse files
committed
Merge branch 'main' of github.com:ironArray/Caterva2
2 parents d4e1f4a + c7926f7 commit 2e9c606

6 files changed

Lines changed: 67 additions & 124 deletions

File tree

caterva2/client.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, client, name):
7777
['ds-sc-attr.b2nd', 'lung-jpeg2000_10x.b2nd', 'tomo-guess-test.b2nd']
7878
"""
7979
self.client = client
80-
urlbase, name = _format_paths(client.urlbase, name)
80+
_, name = _format_paths(client.urlbase, name)
8181
self.name = name
8282

8383
@property
@@ -934,7 +934,6 @@ def get_roots(self):
934934
>>> roots_dict['b2tests']
935935
{'name': 'b2tests'}
936936
"""
937-
urlbase, _ = _format_paths(self.urlbase)
938937
return self._get(f"{self.urlbase}/api/roots", auth_cookie=self.cookie, timeout=self.timeout)
939938

940939
def get(self, path):
@@ -999,7 +998,7 @@ def get_list(self, path):
999998
>>> client.get_list('example')[:3]
1000999
['README.md', 'dir1/ds-2d.b2nd', 'dir1/ds-3d.b2nd']
10011000
"""
1002-
urlbase, path = _format_paths(self.urlbase, path)
1001+
_, path = _format_paths(self.urlbase, path)
10031002
return self._get(f"{self.urlbase}/api/list/{path}", auth_cookie=self.cookie, timeout=self.timeout)
10041003

10051004
def get_info(self, path):
@@ -1029,7 +1028,7 @@ def get_info(self, path):
10291028
"""
10301029
if isinstance(path, (Dataset, File)):
10311030
path = path.path
1032-
urlbase, path = _format_paths(self.urlbase, path)
1031+
_, path = _format_paths(self.urlbase, path)
10331032
return self._get(f"{self.urlbase}/api/info/{path}", auth_cookie=self.cookie, timeout=self.timeout)
10341033

10351034
def fetch(self, path, slice_=None):
@@ -1159,7 +1158,7 @@ def get_chunk(self, path, nchunk):
11591158
"""
11601159
if isinstance(path, Dataset):
11611160
path = path.path
1162-
urlbase, path = _format_paths(self.urlbase, path)
1161+
_, path = _format_paths(self.urlbase, path)
11631162
data = self._xget(
11641163
f"{self.urlbase}/api/chunk/{path}",
11651164
{"nchunk": nchunk},
@@ -1433,7 +1432,7 @@ def unfold(self, remotepath):
14331432
"""
14341433
if isinstance(remotepath, File):
14351434
remotepath = remotepath.path
1436-
urlbase, path = _format_paths(self.urlbase, remotepath)
1435+
_, path = _format_paths(self.urlbase, remotepath)
14371436
result = self._post(
14381437
f"{self.urlbase}/api/unfold/{path}", auth_cookie=self.cookie, timeout=self.timeout
14391438
)
@@ -1471,7 +1470,7 @@ def remove(self, path):
14711470
"""
14721471
if isinstance(path, File):
14731472
path = path.path
1474-
urlbase, path = _format_paths(self.urlbase, path)
1473+
_, path = _format_paths(self.urlbase, path)
14751474
result = self._post(
14761475
f"{self.urlbase}/api/remove/{path}", auth_cookie=self.cookie, timeout=self.timeout
14771476
)
@@ -1510,7 +1509,6 @@ def move(self, src, dst):
15101509
"""
15111510
if isinstance(src, File):
15121511
src = src.path
1513-
urlbase, _ = _format_paths(self.urlbase)
15141512
result = self._post(
15151513
f"{self.urlbase}/api/move/",
15161514
{"src": str(src), "dst": str(dst)},
@@ -1556,7 +1554,6 @@ def copy(self, src, dst):
15561554
"""
15571555
if isinstance(src, File):
15581556
src = src.path
1559-
urlbase, _ = _format_paths(self.urlbase)
15601557
result = self._post(
15611558
f"{self.urlbase}/api/copy/",
15621559
{"src": str(src), "dst": str(dst)},
@@ -1591,7 +1588,7 @@ def _upload_lazyarr(self, remotepath, expression, compute=False):
15911588
Object: Dataset
15921589
Pointer to server-hosted lazy dataset.
15931590
"""
1594-
urlbase, remotepath = _format_paths(self.urlbase, remotepath)
1591+
_, remotepath = _format_paths(self.urlbase, remotepath)
15951592
operands = expression.operands if hasattr(expression, "operands") else expression.inputs_dict
15961593
if operands is not None:
15971594
operands = {k: str(v) for k, v in operands.items()}
@@ -1658,7 +1655,6 @@ def adduser(self, newuser, password=None, superuser=False):
16581655
>>> f"User added: username='{username}' password='foo' superuser=False" == message
16591656
True
16601657
"""
1661-
urlbase, _ = _format_paths(self.urlbase)
16621658
return self._post(
16631659
f"{self.urlbase}/api/adduser/",
16641660
{"username": newuser, "password": password, "superuser": superuser},
@@ -1691,7 +1687,6 @@ def deluser(self, user):
16911687
>>> message == f"User deleted: {username}"
16921688
True
16931689
"""
1694-
urlbase, _ = _format_paths(self.urlbase)
16951690
return self._get(f"{self.urlbase}/api/deluser/{user}", auth_cookie=self.cookie)
16961691

16971692
def listusers(self, username=None):
@@ -1729,6 +1724,5 @@ def listusers(self, username=None):
17291724
>>> superuser_info[0]['is_superuser']
17301725
True
17311726
"""
1732-
urlbase, _ = _format_paths(self.urlbase)
17331727
url = f"{self.urlbase}/api/listusers/" + (f"?username={username}" if username else "")
17341728
return self._get(url, auth_cookie=self.cookie)

caterva2/services/plugins/image/templates/display.html

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,3 @@
1414
<a href="{{ href }}" target="blank_" id="image-original">{{ width }} x {{ height }} (original size)</a>
1515
<br>
1616
<img src="{{ href }}&width=512" id="display-image" onload="stopSpinner()">
17-
18-
<script>
19-
function updateURL(src, options) {
20-
const url = new URL(src);
21-
for (const [key, value] of Object.entries(options)) {
22-
url.searchParams.set(key, value);
23-
}
24-
return url.toString();
25-
}
26-
27-
function updateImage(options) {
28-
let img = document.getElementById('display-image');
29-
document.getElementById('image-spinner').classList.add('htmx-request');
30-
img.src = updateURL(img.src, options);
31-
}
32-
33-
function update_i(input) {
34-
const options = {i: input.value};
35-
updateImage(options);
36-
37-
let link = document.getElementById('image-original');
38-
if (link) {
39-
link.href = updateURL(link.href, options);
40-
}
41-
}
42-
43-
function update_ndim(select) {
44-
// Update image URL
45-
const option = select.selectedOptions[0];
46-
const options = {ndim: option.value, i: 0};
47-
updateImage(options);
48-
49-
// Update max of input element
50-
const size = option.getAttribute('data-size');
51-
const input = document.querySelector('input[name="i"]');
52-
input.setAttribute('max', size - 1);
53-
input.value = 0;
54-
55-
// Update link to original size image
56-
let link = document.getElementById('image-original');
57-
if (link) {
58-
link.href = updateURL(link.href, options);
59-
const [h, w] = [...select.options].filter(opt => !opt.selected).map(opt => opt.dataset.size);
60-
link.textContent = `${w} x ${h} (original size)`;
61-
}
62-
}
63-
64-
function stopSpinner() {
65-
const spinner = document.getElementById('image-spinner');
66-
if (spinner) {
67-
spinner.classList.remove('htmx-request');
68-
}
69-
}
70-
</script>

caterva2/services/plugins/tomography/templates/display.html

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,11 @@
66
</select>
77
<input class="form-control w-auto" type="number" min="0" max="{{ shape.0 - 1}}" name="i" value="0"
88
hx-on:change="update_i(this)">
9-
{% with id="tomography-spinner" %}
9+
{% with id="image-spinner" %}
1010
{% include 'includes/loading.html' %}
1111
{% endwith %}
1212
</div>
1313

1414
<a href="{{ href }}" target="blank_" id="image-original">{{ width }} x {{ height }} (original size)</a>
1515
<br>
1616
<img src="{{ href }}&width=512" id="display-image" onload="stopSpinner()">
17-
18-
<script>
19-
function updateURL(src, options) {
20-
const url = new URL(src);
21-
for (const [key, value] of Object.entries(options)) {
22-
url.searchParams.set(key, value);
23-
}
24-
return url.toString();
25-
}
26-
27-
function updateImage(options) {
28-
let img = document.getElementById('display-image');
29-
document.getElementById('tomography-spinner').classList.add('htmx-request');
30-
img.src = updateURL(img.src, options);
31-
}
32-
33-
function update_i(input) {
34-
const options = {i: input.value};
35-
updateImage(options);
36-
37-
let link = document.getElementById('image-original');
38-
if (link) {
39-
link.href = updateURL(link.href, options);
40-
}
41-
}
42-
43-
function update_ndim(select) {
44-
// Update image URL
45-
const option = select.selectedOptions[0];
46-
const options = {ndim: option.value, i: 0};
47-
updateImage(options);
48-
49-
// Update max of input element
50-
const size = option.getAttribute('data-size');
51-
const input = document.querySelector('input[name="i"]');
52-
input.setAttribute('max', size - 1);
53-
input.value = 0;
54-
55-
// Update link to original size image
56-
let link = document.getElementById('image-original');
57-
if (link) {
58-
link.href = updateURL(link.href, options);
59-
const [h, w] = [...select.options].filter(opt => !opt.selected).map(opt => opt.dataset.size);
60-
link.textContent = `${w} x ${h} (original size)`;
61-
}
62-
}
63-
64-
function stopSpinner() {
65-
const spinner = document.getElementById('tomography-spinner');
66-
if (spinner) {
67-
spinner.classList.remove('htmx-request');
68-
}
69-
}
70-
</script>

caterva2/services/static/build/main-BBYmTrE7.js renamed to caterva2/services/static/build/main-BWQxJoNB.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

caterva2/services/static/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"src/main.js": {
3-
"file": "main-BBYmTrE7.js",
3+
"file": "main-BWQxJoNB.js",
44
"name": "main",
55
"src": "src/main.js",
66
"isEntry": true,

src/main.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,59 @@ function resetForm(ev, form) {
199199
btn.onclick = null;
200200
}
201201

202+
function _updateURL(src, options) {
203+
const url = new URL(src);
204+
for (const [key, value] of Object.entries(options)) {
205+
url.searchParams.set(key, value);
206+
}
207+
return url.toString();
208+
}
209+
210+
function _updateImage(options) {
211+
let img = document.getElementById('display-image');
212+
document.getElementById('image-spinner').classList.add('htmx-request');
213+
img.src = _updateURL(img.src, options);
214+
}
215+
216+
function update_i(input) {
217+
const options = {i: input.value};
218+
_updateImage(options);
219+
220+
let link = document.getElementById('image-original');
221+
if (link) {
222+
link.href = _updateURL(link.href, options);
223+
}
224+
}
225+
226+
function update_ndim(select) {
227+
// Update image URL
228+
const option = select.selectedOptions[0];
229+
const options = {ndim: option.value, i: 0};
230+
_updateImage(options);
231+
232+
// Update max of input element
233+
const size = option.getAttribute('data-size');
234+
const input = document.querySelector('input[name="i"]');
235+
input.setAttribute('max', size - 1);
236+
input.value = 0;
237+
238+
// Update link to original size image
239+
let link = document.getElementById('image-original');
240+
if (link) {
241+
link.href = _updateURL(link.href, options);
242+
const [h, w] = [...select.options].filter(opt => !opt.selected).map(opt => opt.dataset.size);
243+
link.textContent = `${w} x ${h} (original size)`;
244+
}
245+
}
246+
247+
function stopSpinner() {
248+
const spinner = document.getElementById('image-spinner');
249+
if (spinner) {
250+
spinner.classList.remove('htmx-request');
251+
}
252+
}
253+
254+
202255
window.activate = activate;
203256
window.clearContent = clearContent;
204257
window.openTab = openTab;
@@ -209,4 +262,8 @@ window.submitFormAsJSON = submitFormAsJSON;
209262
window.handleSubmit = handleSubmit;
210263
window.resetForm = resetForm;
211264

265+
window.update_i = update_i;
266+
window.update_ndim = update_ndim;
267+
window.stopSpinner = stopSpinner;
268+
212269
export {bootstrap};

0 commit comments

Comments
 (0)