From 08f020244bb13fbd4c8a86d3624e84033baea7ee Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Mon, 17 Jul 2023 14:59:56 +0100 Subject: [PATCH] feat: deploy to cloud & export to self-hosted --- src/lib/components/migrationBox.svelte | 6 +- .../console/(migration-wizard)/step1.svelte | 136 ++++++++++++------ .../console/(migration-wizard)/wizard.svelte | 23 +-- .../organization-[organization]/+layout.ts | 17 +-- .../settings/migrations/+page.svelte | 24 ++-- 5 files changed, 130 insertions(+), 76 deletions(-) diff --git a/src/lib/components/migrationBox.svelte b/src/lib/components/migrationBox.svelte index a4c4e0b12..0fc0acfb4 100644 --- a/src/lib/components/migrationBox.svelte +++ b/src/lib/components/migrationBox.svelte @@ -39,11 +39,11 @@ { done: 0, processing: 0 } as TotalCounter ); - console.log({ statusCounters, totalCounter }); - - return Math.round( + const res = Math.round( (totalCounter.done / (totalCounter.done + totalCounter.processing)) * 100 ); + + return Number.isNaN(res) ? 0 : res; })(); const fetchMigrations = debounce(async () => { diff --git a/src/routes/console/(migration-wizard)/step1.svelte b/src/routes/console/(migration-wizard)/step1.svelte index 735d5e312..b19d6b08b 100644 --- a/src/routes/console/(migration-wizard)/step1.svelte +++ b/src/routes/console/(migration-wizard)/step1.svelte @@ -3,62 +3,112 @@ import { InputSelect } from '$lib/elements/forms'; import InputText from '$lib/elements/forms/inputText.svelte'; import { WizardStep } from '$lib/layout'; - import type { Models } from '@appwrite.io/console'; + import { Query, type Models, ID } from '@appwrite.io/console'; import { selectedProject } from '.'; + import { sdk } from '$lib/stores/sdk'; - const projects = $page.data.allProjects as Models.ProjectList; - const hasProjects = projects.total > 0; + const organizations = $page.data.organizations + .teams as Models.TeamList['teams']; + let selectedOrg = organizations.length ? organizations[0].$id : null; + + let projects = [] as Models.ProjectList['projects']; + $: hasProjects = projects.length > 0; + let loadingProjects = false; let projectType = 'existing'; + let newProjName = ''; + + async function getProjects(orgId: string | null) { + if (!orgId) { + projects = []; + } else { + loadingProjects = true; + projects = await sdk.forConsole.projects + .list([Query.equal('teamId', orgId), Query.orderDesc('$createdAt')]) + .then((res) => res.projects); + projectType = projects.length ? 'existing' : 'new'; + loadingProjects = false; + } + } + + $: { + getProjects(selectedOrg); + } + + const beforeSubmit = async () => { + if (projectType === 'existing') return; + const project = await sdk.forConsole.projects.create(ID.unique(), newProjName, selectedOrg); + selectedProject.set(project.$id); + }; - + {hasProjects ? 'Select project' : 'Create project'} -
-
- - -
-
- - -
-
-
- {#if projectType === 'existing'} +
+ {#if organizations.length > 1} ({ + id="organization" + bind:value={selectedOrg} + label="Select organization" + options={organizations.map((p) => ({ label: p.name, value: p.$id - }))} /> - {:else} - + }))} + disabled={loadingProjects} /> + {/if} + + {#if selectedOrg && !loadingProjects} + {#if projects.length} +
+
+ + +
+
+ + +
+
+ {/if} + +
+ {#if projectType === 'existing'} + ({ + label: p.name, + value: p.$id + }))} /> + {:else} + + {/if} +
{/if}
diff --git a/src/routes/console/(migration-wizard)/wizard.svelte b/src/routes/console/(migration-wizard)/wizard.svelte index 707816690..c52629d92 100644 --- a/src/routes/console/(migration-wizard)/wizard.svelte +++ b/src/routes/console/(migration-wizard)/wizard.svelte @@ -1,15 +1,15 @@