Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
reimplemente routing custom
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-sciabarra committed Oct 18, 2020
1 parent 1835145 commit 45e91d2
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 5,994 deletions.
1 change: 1 addition & 0 deletions admin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ stop: ../iosdk/iosdk
$(MAKE) -C ../iosdk

web/public/build/bundle.js: $(wildcard web/src/*.svelte)
echo "Checking you did not forget to do source ../source-me-first"
node -v | grep v12
cd web && npm install && npm run build

Expand Down
5,826 changes: 0 additions & 5,826 deletions admin/package-lock.json

This file was deleted.

45 changes: 20 additions & 25 deletions admin/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions admin/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "svelte-app",
"version": "1.0.0",
"description": "IO-SDK Admin",
"repository": "https://github.com/pagopa/io-sdk",
"license": "Apache-2.0",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
Expand All @@ -17,7 +20,6 @@
},
"dependencies": {
"marked": "^1.1.1",
"sirv-cli": "^1.0.0",
"svelte-routing": "^1.4.2"
"sirv-cli": "^1.0.0"
}
}
56 changes: 52 additions & 4 deletions admin/web/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
<script>
import { parseURL, navigate, url } from './url.js'
import { onMount, onDestroy } from 'svelte'
import Cookiebar from './Cookiebar.svelte'
import Header from './Header.svelte'
import Body from './Body.svelte'
import Footer from './Footer.svelte'
import Cookiebar from './Cookiebar.svelte'
</script>
import Menu from "./Menu.svelte";
import Home from "./Home.svelte";
import About from "./About.svelte";
import Devel from "./Devel.svelte";
import Debug from "./Debug.svelte";
import Send from "./Send.svelte";
import Ship from "./Ship.svelte";
import Import from "./Import.svelte";
let menu = ""
let key = ""
let api = ""
onMount(() => {
[menu, key, api] = parseURL(location.href)
navigate(menu, key)
})
onDestroy(url.subscribe((href) => {
[menu, key, api] = parseURL(href)
console.log("menu=",menu, "key=", key, "api=", api)
}))
</script>

<main>
<div id="root">
<Header/>
<Body/>
<section class="row">
<Menu />
<div class="col-9 col-md-offset-1 ">
<div class="mr-1 pt-1 pb-1">
{#if menu == ""}
<Home/>
{:else if menu=="about"}
<About/>
{:else if menu=="ship"}
<Ship {api}/>
{:else if menu=="send"}
<Send {api} {key}/>
{:else if menu=="debug"}
<Debug {api} {key}/>
{:else if menu=="import"}
<Import {api} action="/util/import"/>
{:else if menu=="custom"}
<Import {api} action="/iosdk/import"/>
{:else if menu=="devel"}
<Devel {api} {key}/>
{/if}
</div>
</div>
</section>
<Cookiebar/>
<Footer/>
</div>
Expand Down
45 changes: 0 additions & 45 deletions admin/web/src/Body.svelte

This file was deleted.

10 changes: 5 additions & 5 deletions admin/web/src/Debug.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script>
import { Link } from "svelte-routing";
import { reload } from "./store";
import { onMount } from "svelte";
import Link from './Link.svelte'
const cacheUrl = "http://localhost:3280/api/v1/web/guest/util/cache?";
export let api;
const cacheUrl = api + "/util/cache?";
const scanUrl = cacheUrl + "scan="
const cleanUrl = cacheUrl + "clean="
Expand Down Expand Up @@ -80,9 +82,7 @@
{#if state.list}
<ul>
{#each state.list as key}
<li>
<Link to="debug/{window.btoa(key)}">{key}</Link>
</li>
<li><Link to="debug/{window.btoa(key)}" description={key}/></li>
{/each}
</ul>
<p>Elements Found: #{state.list.length}</p>
Expand Down
2 changes: 1 addition & 1 deletion admin/web/src/DebugData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let state = {};
const url = "http://localhost:3280/api/v1/web/guest/util/cache";
const url = api + "/util/cache";
let entry = window.atob(key);
async function cache(action, entry) {
Expand Down
24 changes: 13 additions & 11 deletions admin/web/src/Import.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<script>
export let action;
import { onDestroy, onMount } from 'svelte'
import { formData } from "./store";
import ImportForm from "./ImportForm.svelte";
import ImportData from "./ImportData.svelte";
const base = "http://localhost:3280/api/v1/web/guest/";
const url = base + action;
export let api;
export let action;
const storeURL = api + "/util/store"
const importURL = api + action;
let message = "uploading...";
let state
onMount( () => {
state = start()
})
async function start() {
formData.set({})
return fetch(url)
return fetch(importURL)
.then((res) => res.json())
.catch((err) => { return { "error": err }})
}
async function save(data) {
await fetch(base + "util/store", {
await fetch(storeURL, {
method: "POST",
body: JSON.stringify({"data":data}),
headers: { "Content-Type": "application/json" }
Expand All @@ -36,9 +41,6 @@
});
}
onMount( () => {
state = start()
})
let unsubscribe = formData.subscribe(value => {
console.log("subscribe")
Expand All @@ -58,7 +60,7 @@ onDestroy(unsubscribe)
<div>loading...</div>
{:then currState}
{#if currState.form}
<ImportForm form={currState.form} {url} />
<ImportForm form={currState.form} {api} {action} />
{:else if currState.data}
<ImportData data={state.data} />
<big><b>Import status: </b>{message}</big>
Expand Down
14 changes: 8 additions & 6 deletions admin/web/src/ImportForm.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script>
import { formData } from "./store";
export let api;
export let action;
export let form = {};
export let url;
const base = "http://localhost:3280/api/v1/web/guest";
const uploadUrl = base+"/util/upload";
const uploadURL = api+"/util/upload";
const importURL = api + action;
let loading = false;
async function parseForm() {
let submit = await fetch(uploadUrl, {
let submit = await fetch(uploadURL, {
method: "POST",
body: new FormData(document["_theForm_"])
})
Expand All @@ -23,7 +25,7 @@
// perform import
if(data) {
loading = true;
fetch(url, {
fetch(importURL, {
method: "POST",
body: JSON.stringify(data),
headers: {
Expand All @@ -45,7 +47,7 @@
}
</script>

<form name="_theForm_" action={uploadUrl} method="post" enctype="multipart/form-data">
<form name="_theForm_" action={uploadURL} method="post" enctype="multipart/form-data">
{#each form as field}
{#if field.type == 'message'}
<div class="callout">
Expand Down
Loading

0 comments on commit 45e91d2

Please sign in to comment.