Skip to content

Commit

Permalink
Mostly working uploader, final upload needs completion WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jmetz committed Oct 22, 2023
1 parent bf6b129 commit d28d95e
Show file tree
Hide file tree
Showing 26 changed files with 2,170 additions and 213 deletions.
544 changes: 521 additions & 23 deletions uploader/package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion uploader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.30.0",
"jszip": "^3.10.1",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.10.1",
"socket.io-client": "^4.7.2",
"svelte": "^4.0.5",
"svelte-check": "^3.4.3",
"svelte-loading-spinners": "^0.3.4",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vite-plugin-iso-import": "^1.0.0",
"vitest": "^0.32.2",
"webpack": "^5.89.0"
},
"type": "module",
"dependencies": {
"svelte-file-dropzone": "^2.0.2"
"imjoy-core": "^0.14.4",
"spdx-license-list": "^6.7.0",
"svelte-file-dropzone": "^2.0.2",
"svelte-json-tree": "^2.2.0",
"svelte-tags-input": "^5.0.0"
}
}
9 changes: 7 additions & 2 deletions uploader/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<main class="wrapper">
<div style="display: contents">%sveltekit.body%</div>
</body>
</main>
</body>
</html>
12 changes: 0 additions & 12 deletions uploader/src/components/Edit.svelte

This file was deleted.

111 changes: 111 additions & 0 deletions uploader/src/components/HyphaUploader/Add.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<script>
import { Diamonds } from 'svelte-loading-spinners';
import Dropzone from "svelte-file-dropzone/Dropzone.svelte";
import JSZip from "jszip";
import yaml from "js-yaml";
import { createEventDispatcher } from 'svelte';
export let zip_package;
export let rdf;
let rdf_text;
let files = [];
let file_info = [];
let processing = false;
const dispatch = createEventDispatcher();
function completed_step() {
dispatch('done', {});
}
async function read_model(rdf_text){
rdf = yaml.load(rdf_text);
console.log('RDF:');
console.log(rdf);
completed_step();
}
async function handle_files_select(e){
const regex_zip = /\.zip$/gi
const regex_rdf = /(rdf\.yml|rdf\.yaml)$/gi
const { acceptedFiles } = e.detail;
files = acceptedFiles;
if(files.length !== 1){
console.error(`File-count not supported: ${files.length}`);
return
}
let file = files[0];
if(file.name.search(regex_zip) !== -1){
zip_package = await JSZip.loadAsync(file);
console.log(zip_package);
// Obtain the RDF file
let file_names = Object.keys(zip_package.files);
let candidates = file_names.filter((file) => file.search(regex_rdf) !== -1)
console.log(file_names);
console.log(candidates);
if(candidates.length === 0){
console.error("Unable to find any RDF files in Zip");
file_info = [
"Invalid Zip file: no RDF file found!",
"Entries in zip file:",
...Object.keys(zip_package.files)
];
return
}
const rdf_file = zip_package.files[candidates[0]];
rdf_text = await rdf_file.async("string");
file_info = [
`Zip file: ${file.name}`,
`with ${Object.keys(zip_package.files).length} entries`,
`And RDF file: ${rdf_file.name}`];
}else if (file.name.search(regex_rdf) !== -1){
file_info = [`RDF file given: ${file.name}`];
rdf_text = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (event) => {resolve(event.target.result);};
reader.onerror = reject;
reader.readAsText(file);
});
}else{
file_info = ["Invalid file given"];
return
}
read_model(rdf_text);
}
</script>

<h1>Add model information</h1>

{#if processing}
Reading model... <Diamonds />
<button on:click={completed_step()}>Next</button>
{:else}
Please upload your model zip file here

<Dropzone on:drop={handle_files_select} multiple={false}>
{#if files.length === 0}
Click here or drop files
{:else}
{#each file_info as line}
{line}<br>
{/each}
{/if}

</Dropzone>
<!--input bind:files id="zip-file-upload" type="file" /-->

<!--
{#if files.length > 0}
<button on:click={read_model}>Upload</button>
{/if}
-->
{/if}

23 changes: 23 additions & 0 deletions uploader/src/components/HyphaUploader/Edit.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script>
import { createEventDispatcher } from 'svelte';
import EditForm from './EditForm/index.svelte';
import Validate from './Validate.svelte';
export let rdf;
export let zip_package;
export let api;
const dispatch = createEventDispatcher();
function completed_step() {
dispatch('done', {});
}
</script>

<h2>Edit your submission</h2>

<EditForm bind:rdf bind:zip_package/>

<Validate {rdf} on:done={completed_step} {api}/>

<button on:click={completed_step}>Next</button>
137 changes: 137 additions & 0 deletions uploader/src/components/HyphaUploader/EditForm/AuthorsInput.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<script>
export let authors =[];
export let error;
export let affiliation=false;
export let orcid=false;
export let email=false;
export let github=false;
function delete_author_at_index(index){
authors.splice(index, 1);
authors = authors;
}
</script>

<div>

{#each authors as author, index}
<input
type="text"
placeholder="Full Name (required)"
bind:value={author.name}
maxlength="1000"
/>
{#if affiliation}
<input
type="text"
placeholder="Affiliation (optional)"
bind:value={author.affiliation}
maxlength="100"
/>
{/if}
{#if orcid}
<input
type="text"
placeholder="ORCID (optional)"
bind:value={author.orchid}
maxlength="100"
/>
{/if}
{#if email}
<input
type="text"
placeholder="Email (optional)"
bind:value={author.orchid}
maxlength="100"
/>
{/if}
{#if github}
<input
type="text"
placeholder="Github username (required)"
bind:value={author.github_user}
maxlength="100"
/>
{/if}
<button
class="button button-outline"
on:click={()=> delete_author_at_index(index)}>Delete</button>
{/each}

<br>
<button
class="button"
on:click={()=> {authors = [...authors, {}]}}>Add</button>

<!--
<div class="control">
<div v-for="(author, i) in value" :key="i">
<b-field>
<b-input
@input="commitValue"
type="text"
placeholder="Full Name (required)"
v-model="author.name"
maxlength="1000"
>
</b-input>
<b-input
@input="commitValue"
type="text"
v-if="item.options.includes('affiliation')"
placeholder="Affiliation (optional)"
v-model="author.affiliation"
maxlength="100"
>
</b-input>
<b-input
@input="commitValue"
type="text"
v-if="item.options.includes('orcid')"
placeholder="ORCID (optional)"
v-model="author.orcid"
maxlength="1000"
>
</b-input>
<b-input
@input="commitValue"
type="text"
v-if="item.options.includes('github_user')"
placeholder="Github User (required)"
v-model="author.github_user"
maxlength="100"
>
</b-input>
<b-input
@input="commitValue"
type="text"
v-if="item.options.includes('email')"
placeholder="Email (optional)"
v-model="author.email"
maxlength="1000"
>
</b-input>
<b-button
v-if="value.length > 1"
style="text-transform:none;"
class="button"
icon-left="delete"
@click="removeAuthor(author)"
></b-button>
<b-button
v-if="
i === value.length - 1 && !(!author.name || author.name === '')
"
style="text-transform:none;"
class="button"
icon-left="plus"
@click="addNewAuthor"
></b-button>
</b-field>
</div>
-->
{#if error }
<p class="help is-danger">{error }</p>
{/if}
</div>
21 changes: 21 additions & 0 deletions uploader/src/components/HyphaUploader/EditForm/FileEntry.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script charset="utf-8">
export let name
export let handleClick = () => {};
</script>

<style type="text/css" media="screen">
.button{
padding-right:0rem
}
.button-small {
font-size: .8rem;
height: 2.8rem;
line-height: 2.8rem;
padding: 0 1.5rem;
}
</style>

<div class="button button-outline">
{name}
<div class="button button-small" on:click={handleClick}>❌</div>
</div>
24 changes: 24 additions & 0 deletions uploader/src/components/HyphaUploader/EditForm/Files.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script charset="utf-8">
import Dropzone from "svelte-file-dropzone/Dropzone.svelte";
import FileEntry from './FileEntry.svelte';
export let files = [];
export let handle_files_select = () => {};
export let remove_file = () => {};
</script>


<style type="text/css" media="screen">
.dropzone{
flex-direction: row;
}
</style>

<Dropzone containerStyles="flex-direction:row;flex-wrap:wrap;" containerClasses="dropzone" on:drop={handle_files_select} multiple={true}>
{#if files.length === 0}
Click here or drop files
{:else}
{#each files as name, index}
<FileEntry handleClick={(e)=>{remove_file(e, name, index)}} {name}/>
{/each}
{/if}
</Dropzone>
Loading

0 comments on commit d28d95e

Please sign in to comment.