Skip to content

Commit

Permalink
Add selectFolder button and functionality
Browse files Browse the repository at this point in the history
Adds a button to the UI to select folders and adds them to a list
  • Loading branch information
phwissmann committed Aug 27, 2024
1 parent a23b38b commit 8ad405d
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 5 deletions.
7 changes: 6 additions & 1 deletion openem-ingestor/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"openem-ingestor/backend"

"github.com/wailsapp/wails/v2/pkg/runtime"
)
Expand Down Expand Up @@ -37,5 +38,9 @@ func (a *App) startup(ctx context.Context) {
}

func (a *App) SelectFolder() {

folder, err := backend.SelectFolder(a.ctx)
if err != nil {
return
}
println(folder.Folder)
}
32 changes: 32 additions & 0 deletions openem-ingestor/backend/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package backend

import (
"context"

"github.com/google/uuid"
"github.com/wailsapp/wails/v2/pkg/runtime"
)

type DatasetFolder struct {
Id uuid.UUID
Folder string
Cancel context.CancelFunc
}

// Select a folder using a native menu
func SelectFolder(context context.Context) (DatasetFolder, error) {
dialogOptions := runtime.OpenDialogOptions{
}

folder, err := runtime.OpenDirectoryDialog(context, dialogOptions)
if err != nil || folder == "" {
return DatasetFolder{}, err
}

id := uuid.New()

runtime.EventsEmit(context, "folder-added", id, folder)

selected_folder := DatasetFolder{Folder: folder, Id: id}
return selected_folder, nil
}
31 changes: 29 additions & 2 deletions openem-ingestor/frontend/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
<script lang="ts">
import logo from "./assets/images/logo-wide-1024x317.png";
// import { SelectFolder } from "../wailsjs/go/main/App.js";
import { SelectFolder } from "../wailsjs/go/main/App.js";
import { EventsOn } from "../wailsjs/runtime/runtime";
import List from "./List.svelte";
import ListElement from "./ListElement.svelte";
function selectFolder(): void {}
function selectFolder(): void {
SelectFolder();
}
let items = {};
function newItem(id: string, folder: string): string {
items[id] = {
id: id,
value: folder,
status: "Selected",
progress: 0,
component: ListElement,
};
return id;
}
EventsOn("folder-added", (id, folder) => {
newItem(id, folder);
});
</script>

<main>
<img alt="OpenEM logo" id="logo" src={logo} />
<button class="btn" on:click={selectFolder}>Select Folder</button>
<div>
<div id="upload-list">
<List {items} />
</div>
</div>
</main>

<style>
Expand Down
25 changes: 25 additions & 0 deletions openem-ingestor/frontend/src/List.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script>
export let items;
</script>

<h3>Selected Folders:</h3>
<div style="overflow-y: scroll; height:400px;">
<ul>
{#each Object.entries(items) as [id, item]}
<li>
<svelte:component this={item.component} {...item} />
</li>
{/each}
</ul>
</div>

<style>
ul {
list-style-type: none;
}
li {
display: block;
flex: 0 1 auto; /* Default */
list-style-type: none;
}
</style>
30 changes: 30 additions & 0 deletions openem-ingestor/frontend/src/ListElement.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
export let id;
export let value;
export let status;
export let progress;
</script>

<div class="listitem">
<div class="path">
{value}
</div>
<div>
{status}
</div>
<div>
{progress} %
</div>
</div>

<style>
.listitem {
display: grid;
grid-template-columns: 5fr 2fr 2fr;
grid-template-rows: auto;
padding-right: 30px;
}
.path {
text-align: left;
}
</style>
6 changes: 4 additions & 2 deletions openem-ingestor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ go 1.21

toolchain go1.22.1

require github.com/wailsapp/wails/v2 v2.9.1
require (
github.com/google/uuid v1.3.0
github.com/wailsapp/wails/v2 v2.9.1
)

require (
github.com/bep/debounce v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
Expand Down

0 comments on commit 8ad405d

Please sign in to comment.