Skip to content

Commit c183a14

Browse files
committed
Add search to water_budget #5, reorder team page #8,
1 parent 78dcb35 commit c183a14

File tree

2 files changed

+106
-41
lines changed

2 files changed

+106
-41
lines changed

src/routes/team/+page.svelte

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,29 @@
2727
let team_array = [];
2828
let filter_value = '';
2929
let team = data.result;
30-
team_array = team;
30+
team_array = team.reverse();
31+
team_array = team_array.sort(compare);
32+
team_array.sort(
33+
(/** @type {{ related_org: string; }} */ a, /** @type {{ related_org: string; }} */ b) =>
34+
// b.last_name.toLowerCase() - a.last_name.toLowerCase() ||
35+
36+
(b.related_org === 'GERICS') - (a.related_org === 'GERICS') ||
37+
(b.related_org === 'Uni Jena') - (a.related_org === 'Uni Jena') ||
38+
(b.related_org === 'WITS-GCI') - (a.related_org === 'WITS-GCI') ||
39+
(b.related_org === 'NUST') - (a.related_org === 'NUST') ||
40+
(b.related_org === 'Gobabeb') - (a.related_org === 'Gobabeb')
41+
);
42+
43+
function compare(a, b) {
44+
if (a.last_name < b.last_name) {
45+
return -1;
46+
}
47+
if (a.last_name > b.last_name) {
48+
return 1;
49+
}
50+
return 0;
51+
}
52+
3153
// team_array = team_array.filter((team) => team.org =="Uni Jena")
3254
3355
/**

src/routes/water_budget/+page.svelte

Lines changed: 83 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"wget --input-file 'http://127.0.0.1:8000/climate/get_climate_txt?hash=21cd9c90faad4dc19b73c8c0ae75d51a'";
3737
let wget_add_args = '-r -H -N --cut-dirs=2';
3838
39+
let type = 'water_budget';
40+
3941
// set default search type
4042
// select_search_type('collection');
4143
@@ -103,7 +105,8 @@
103105
}
104106
105107
async function fetch_foldercontent() {
106-
const custom_url = "https://leutra.geogr.uni-jena.de/backend_geoportal/climate/get_content"
108+
const custom_url =
109+
'https://leutra.geogr.uni-jena.de/backend_geoportal/climate/get_content?type=' + type;
107110
108111
try {
109112
const res = await fetch(custom_url, {
@@ -130,6 +133,14 @@
130133
console.log(error);
131134
}
132135
}
136+
let search_term = '';
137+
function filter_folder_data() {
138+
//folder_data.filter(( /** @type {(string | string[])[]} */ data) => data[0].includes(search_term));
139+
const folder_data_new = Object.values(folder_data).filter((item) =>
140+
item[0].includes(search_term)
141+
);
142+
folder_data = folder_data_new;
143+
}
133144
134145
/**
135146
* @param {{ srcElement: { value: string; checked: any; }; }} e
@@ -148,7 +159,8 @@
148159
// the response of this request is a string containing a wget request with the
149160
// mentioned hash, that should download all selected files from our server
150161
async function handle_checkbox_submit() {
151-
const custom_url = 'https://leutra.geogr.uni-jena.de/backend_geoportal/climate/select_for_wget';
162+
const custom_url =
163+
'https://leutra.geogr.uni-jena.de/backend_geoportal/climate/select_for_wget?type=' + type;
152164
let checked_boxes = [];
153165
154166
for (let i = 0; i < folder_checkbox_bools.length; i++) {
@@ -180,53 +192,84 @@
180192
}
181193
}
182194
195+
/**
196+
* @param {string} new_type
197+
*/
198+
function set_type(new_type) {
199+
if (new_type == 'water_budget') {
200+
font_bold_ind = '';
201+
font_bold_col = 'font-bold';
202+
type = new_type;
203+
} else if (new_type == 'water_budget_bias') {
204+
font_bold_col = '';
205+
font_bold_ind = 'font-bold';
206+
type = new_type;
207+
}
208+
fetch_foldercontent();
209+
}
210+
183211
// array with current geo_data['facets']['file_id']
184212
</script>
185213

186214
<!-- Backend Folder Content as checkboxes -->
215+
<div class="btn-group variant-ghost-primary [&>*+*]:border-red-500 h-6">
216+
<button
217+
type="button"
218+
class="btn variant-filled-tertiary {font_bold_col}"
219+
on:click={() => set_type('water_budget')}>Water Budget</button
220+
>
221+
<button
222+
type="button"
223+
class="btn variant-filled-tertiary {font_bold_ind}"
224+
on:click={() => set_type('water_budget_bias')}>Water Budget bias adjusted</button
225+
>
226+
</div>
227+
<div>
228+
<input
229+
class="input w-full mt-4"
230+
type="text"
231+
placeholder="Filter filenames..."
232+
bind:value={search_term}
233+
/>
234+
</div>
235+
187236
{#if folder_data != null}
188237
<div class="grid grid-cols-9">
189-
<div class="col-span-6">
190-
Filename
191-
</div>
192-
<div>
193-
Filesize
194-
</div>
195-
<div>
196-
Last modified
197-
</div>
198-
<div>
199-
Download Link
200-
</div>
238+
<div class="col-span-6">Filename</div>
239+
<div>Filesize</div>
240+
<div>Last modified</div>
241+
<div>Download Link</div>
201242
{#each Object.values(folder_data['content']) as datapoint, i}
202-
<!-- Checkbox and filename -->
203-
<div class="col-span-6">
204-
<input
205-
type="checkbox"
206-
value={i}
207-
id={'checkbox_' + i}
208-
on:change={on_folder_checkbox_change}
209-
/>
210-
&nbsp;{datapoint[0]}
211-
</div>
212-
<!-- filesize -->
213-
<div>
214-
{datapoint[1]}
215-
</div>
216-
<!-- creation date -->
217-
<div>
218-
{datapoint[2]}
219-
</div>
220-
<!-- download link -->
221-
<div>
222-
&nbsp;<a
223-
href="https://leutra.geogr.uni-jena.de/backend_geoportal/climate/get_file?name={datapoint[0]}"
224-
class="underline">download</a
225-
>
226-
</div>
243+
{#if datapoint[0].toLowerCase().includes(search_term.toLowerCase())}
244+
<!-- Checkbox and filename -->
245+
<div class="col-span-6">
246+
<input
247+
type="checkbox"
248+
value={i}
249+
id={'checkbox_' + i}
250+
on:change={on_folder_checkbox_change}
251+
/>
252+
&nbsp;{datapoint[0]}
253+
</div>
254+
<!-- filesize -->
255+
<div>
256+
{datapoint[1]}
257+
</div>
258+
<!-- creation date -->
259+
<div>
260+
{datapoint[2]}
261+
</div>
262+
<!-- download link -->
263+
<div>
264+
&nbsp;<a
265+
href="https://leutra.geogr.uni-jena.de/backend_geoportal/climate/get_file?name={datapoint[0]}&type={type}"
266+
class="underline">download</a
267+
>
268+
</div>
269+
{/if}
227270
{/each}
228271
<button class="btn variant-ghost-primary m-4" on:click|preventDefault={handle_checkbox_submit}
229-
>Submit</button
272+
>Generate wget link</button
230273
>
231274
</div>
232275
{:else}

0 commit comments

Comments
 (0)