Skip to content

Commit

Permalink
added button to update water_budget folder geofranzi/geoportal#72
Browse files Browse the repository at this point in the history
  • Loading branch information
FlatErikk committed Nov 7, 2024
1 parent 4e6ede3 commit 5710f39
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 28 deletions.
34 changes: 34 additions & 0 deletions src/lib/fetch_folder_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,37 @@ export async function _fetch_foldercontent_by_type(type, convertable = false) {

return result;
}

/**
* @param {string | undefined} [type]
*/
export async function _fetch_foldercontent_force_update(type, convertable = false) {
var helper = API_URL + '/climate/get_content?type=' + type;
if (convertable) {
helper += '&convertable=true';
}

// set the force_update parameter
helper += '&force_update=true';

const custom_url = helper;

const res = await fetch(custom_url, {
method: 'GET'
});

let result = [];
if (!res.ok) {
var msg = await res.text();
throw new Error(`${res.status} ${res.statusText}\nReason: ${msg}`);
}

result = await res.json();

// sort array
result['content'].sort();

// console.log('folder_data', result['content']);

return result;
}
70 changes: 42 additions & 28 deletions src/routes/water_budget/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<script lang="ts">
import { onMount } from 'svelte';
import { API_URL } from '../../app.config';
import { _fetch_foldercontent_by_type } from '$lib/fetch_folder_content';
import {
_fetch_foldercontent_by_type,
_fetch_foldercontent_force_update
} from '$lib/fetch_folder_content';
import { browser } from '$app/environment';
import { tempresult_selection } from '../store/tempresult_store';
import { goto } from '$app/navigation';
Expand Down Expand Up @@ -85,7 +88,7 @@
});
onMount(() => {
refresh_foldercontent();
refresh_foldercontent(false);
});
async function send_query() {
Expand Down Expand Up @@ -125,9 +128,9 @@
}
}
async function generate_dat(filename: string){
var api_dat = API_URL+ '/climate/generate_dat_file?name=' + filename + '&type=' + foldertype
console.log(api_dat)
async function generate_dat(filename: string) {
var api_dat = API_URL + '/climate/generate_dat_file?name=' + filename + '&type=' + foldertype;
console.log(api_dat);
const res = await fetch(api_dat, {
method: 'GET'
});
Expand Down Expand Up @@ -299,12 +302,16 @@
cat_folder_data = categories;
}
async function refresh_foldercontent() {
async function refresh_foldercontent(force_update = false) {
folder_data = {};
// only_convertable false fetches all files
try {
var result = await _fetch_foldercontent_by_type(foldertype, false);
if (force_update) {
var result = await _fetch_foldercontent_force_update(foldertype, false);
} else {
var result = await _fetch_foldercontent_by_type(foldertype, false);
}
folder_data = result.content;
set_cat_folder_data();
Expand Down Expand Up @@ -334,7 +341,15 @@
<FolderTree />
</div>
</div>
<FoldertypeChooser bind:foldertype on:foldertype_changed={refresh_foldercontent} />
<FoldertypeChooser bind:foldertype on:foldertype_changed={() => refresh_foldercontent(false)} />
<div>
<button
class="w-[120px] h-[30px] flex-center variant-filled-tertiary hover:bg-tertiary-900 rounded-md"
on:click={() => refresh_foldercontent(true)}
>
Force Update
</button>
</div>
<div class="flex gap-4 mt-2 p-2">
<div>
<button
Expand Down Expand Up @@ -481,35 +496,34 @@
</a>
</button>
{#if folder_data[file_obj.index]['dat_exists']}
<button
class="mr-1 max-h-[33px] p-1 flex items-center justify-center variant-filled-tertiary hover:bg-tertiary-900 rounded-md"
>
<a
href="{API_URL}/climate/get_temp_file?name={folder_data[
file_obj.index
]['filename']}&type={foldertype}&filetype=dat"
class="flex"
>
<SquareCaretDown />
<div class="ml-1 flex place-items-center justify-items-center">
.dat
</div>
</a>
</button>
<button
class="mr-1 max-h-[33px] p-1 flex items-center justify-center variant-filled-tertiary hover:bg-tertiary-900 rounded-md"
>
<a
href="{API_URL}/climate/get_temp_file?name={folder_data[
file_obj.index
]['filename']}&type={foldertype}&filetype=dat"
class="flex"
>
<SquareCaretDown />
<div class="ml-1 flex place-items-center justify-items-center">
.dat
</div>
</a>
</button>
{:else}
<button
class="mr-1 max-h-[3px] p-1 flex items-center justify-center bg-fuchsia-700 hover:bg-fuchsia-900 rounded-md"
on:click={() =>generate_dat(folder_data[
file_obj.index
]['filename'])}
on:click={() =>
generate_dat(folder_data[file_obj.index]['filename'])}
>
<!-- <a
<!-- <a
href="{API_URL}/climate/generate_dat_file?name={folder_data[
file_obj.index
][0]}&type={foldertype}"
class="flex"
> -->

<!-- </a> -->
</button>
{/if}
Expand Down

0 comments on commit 5710f39

Please sign in to comment.