Skip to content

Commit

Permalink
Svelte code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye authored and hahn-kev committed Oct 24, 2023
1 parent be8159a commit 977c580
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 224 deletions.
37 changes: 19 additions & 18 deletions frontend/src/lib/components/TusUpload.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import {Upload, type DetailedError} from 'tus-js-client';
import { Upload, type DetailedError } from 'tus-js-client';
import Button from '$lib/forms/Button.svelte';
import {env} from '$env/dynamic/public';
import { env } from '$env/dynamic/public';
import FormField from '$lib/forms/FormField.svelte';
import {createEventDispatcher, onDestroy} from 'svelte';
import { createEventDispatcher, onDestroy } from 'svelte';
import FormError from '$lib/forms/FormError.svelte';
import t from '$lib/i18n';
Expand All @@ -13,7 +13,7 @@
Error = 'Error',
Uploading = 'Uploading',
Paused = 'Paused',
Complete = 'Complete'
Complete = 'Complete',
}
export let endpoint: string;
Expand All @@ -22,7 +22,7 @@
export let inputLabel: string = $t('tus.select_file');
export let inputDescription: string | undefined = undefined;
const dispatch = createEventDispatcher<{
uploadComplete: { upload: Upload }
uploadComplete: { upload: Upload };
}>();
let status = UploadStatus.NoFile;
Expand All @@ -47,17 +47,16 @@
chunkSize: maxUploadChunkSizeMb * 1024 * 1024,
endpoint,
metadata: {
filetype: file.type
filetype: file.type,
},
uploadDataDuringCreation: false,
onProgress: (bytesUploaded, bytesTotal) => {
percent = bytesTotal > 0 ? bytesUploaded / bytesTotal * 100 : 0;
percent = bytesTotal > 0 ? (bytesUploaded / bytesTotal) * 100 : 0;
},
onSuccess: () => {
status = UploadStatus.Complete;
percent = 100;
if (upload)
dispatch('uploadComplete', {upload});
if (upload) dispatch('uploadComplete', { upload });
},
onError: (err) => {
status = UploadStatus.Error;
Expand All @@ -78,7 +77,7 @@
const status = err.originalResponse ? err.originalResponse.getStatus() : 0;
return navigator.onLine && (status === 409 || status == 423 || status < 400 || 499 < status);
}
},
});
percent = 0;
status = UploadStatus.Ready;
Expand Down Expand Up @@ -124,21 +123,23 @@
<div class="space-y-4">
<form>
<FormField label={inputLabel} id="tus-upload" error={fileError} description={inputDescription}>
<input id="tus-upload"
type="file"
{accept}
class="file-input file-input-bordered file-input-primary"
on:cancel|stopPropagation
on:change={fileSelected}/>
<input
id="tus-upload"
type="file"
{accept}
class="file-input file-input-bordered file-input-primary"
on:cancel|stopPropagation
on:change={fileSelected}
/>
</FormField>
<FormError error={uploadError}/>
<FormError error={uploadError} />
</form>
</div>

<div class="mt-6 flex items-center gap-6">
<Button style="btn-success" disabled={status > UploadStatus.Ready} on:click={startUpload}>{uploadLabel}</Button>
<div class="flex-1">
<p class="label label-text py-0">{$t('tus.upload_progress')}</p>
<progress class="progress progress-success" class:progress-error={uploadError} value={percent} max="100"/>
<progress class="progress progress-success" class:progress-error={uploadError} value={percent} max="100" />
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import MoreSettings from '$lib/components/MoreSettings.svelte';
import { AdminContent, Page } from '$lib/layout';
import SvelteMarkdown from 'svelte-markdown';
import {ProjectMigrationStatus, ResetStatus} from '$lib/gql/generated/graphql';
import {onMount} from 'svelte';
import { ProjectMigrationStatus, ResetStatus } from '$lib/gql/generated/graphql';
import { onMount } from 'svelte';
import Button from '$lib/forms/Button.svelte';
import Icon from '$lib/icons/Icon.svelte';
Expand Down Expand Up @@ -64,7 +64,7 @@
let resetProjectModal: ResetProjectModal;
async function resetProject(): Promise<void> {
await resetProjectModal.open(_project.code, _project.resetStatus)
await resetProjectModal.open(_project.code, _project.resetStatus);
}
let removeUserModal: DeleteModal;
Expand Down Expand Up @@ -139,13 +139,13 @@
[ProjectMigrationStatus.Migrating]: 'Migrating',
[ProjectMigrationStatus.Unknown]: 'Unknown',
[ProjectMigrationStatus.PrivateRedmine]: 'Not Migrated (private)',
[ProjectMigrationStatus.PublicRedmine]: 'Not Migrated (public)',
[ProjectMigrationStatus.PublicRedmine]: 'Not Migrated (public)',
} satisfies Record<ProjectMigrationStatus, string>;
onMount(() => {
migrationStatus = project?.migrationStatus ?? ProjectMigrationStatus.Unknown;
if (migrationStatus === ProjectMigrationStatus.Migrating) {
void watchMigrationStatus();
}
migrationStatus = project?.migrationStatus ?? ProjectMigrationStatus.Unknown;
if (migrationStatus === ProjectMigrationStatus.Migrating) {
void watchMigrationStatus();
}
});
async function watchMigrationStatus(): Promise<void> {
Expand Down Expand Up @@ -176,55 +176,59 @@
<div class="space-y-2 space-x-1">
<div class="float-right mt-1 sm:mt-2 md:mt-1">
{#if migrationStatus !== ProjectMigrationStatus.Migrating}
<Dropdown>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label bind:this={getProjectDropdownTrigger} tabindex="-1" class="btn btn-sm md:btn-md btn-success">
{$t('project_page.get_project.label')}
<span class="i-mdi-dots-vertical text-2xl" />
</label>
<div slot="content" class="card w-[calc(100vw-1rem)] sm:max-w-[35rem]">
<div class="card-body max-sm:p-4">
<div class="prose">
<SvelteMarkdown
source={$t('project_page.get_project.instructions', {type: _project.type, code: data.code, name: _project.name})}>
</SvelteMarkdown>
</div>
<AdminContent>
<FormField label={$t('project_page.get_project.send_receive_url')}>
<div class="join">
<input
value={projectHgUrl}
class="input input-bordered join-item w-full focus:input-success"
readonly
/>
<div
class="join-item tooltip-open"
class:tooltip={copiedToClipboard}
data-tip={$t('clipboard.copied')}
>
{#if copiedToClipboard}
<IconButton disabled icon="i-mdi-check" style="btn-outline btn-success" />
{:else}
<IconButton
loading={copyingToClipboard}
icon="i-mdi-content-copy"
style="btn-outline"
on:click={copyProjectUrlToClipboard}
/>
{/if}
</div>
</div>
</FormField>
</AdminContent>
<Dropdown>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label bind:this={getProjectDropdownTrigger} tabindex="-1" class="btn btn-sm md:btn-md btn-success">
{$t('project_page.get_project.label')}
<span class="i-mdi-dots-vertical text-2xl" />
</label>
<div slot="content" class="card w-[calc(100vw-1rem)] sm:max-w-[35rem]">
<div class="card-body max-sm:p-4">
<div class="prose">
<SvelteMarkdown
source={$t('project_page.get_project.instructions', {
type: _project.type,
code: data.code,
name: _project.name,
})}
/>
</div>
<AdminContent>
<FormField label={$t('project_page.get_project.send_receive_url')}>
<div class="join">
<input
value={projectHgUrl}
class="input input-bordered join-item w-full focus:input-success"
readonly
/>
<div
class="join-item tooltip-open"
class:tooltip={copiedToClipboard}
data-tip={$t('clipboard.copied')}
>
{#if copiedToClipboard}
<IconButton disabled icon="i-mdi-check" style="btn-outline btn-success" />
{:else}
<IconButton
loading={copyingToClipboard}
icon="i-mdi-content-copy"
style="btn-outline"
on:click={copyProjectUrlToClipboard}
/>
{/if}
</div>
</div>
</FormField>
</AdminContent>
</div>
</Dropdown>
</div>
</Dropdown>
{/if}
{#if migrationStatus === ProjectMigrationStatus.PublicRedmine || migrationStatus === ProjectMigrationStatus.PrivateRedmine}
<AdminContent>
<Button on:click={migrateProject}>
Migrate Project
<Icon icon="i-mdi-source-branch-sync"/>
<Icon icon="i-mdi-source-branch-sync" />
</Button>
</AdminContent>
{/if}
Expand All @@ -241,21 +245,25 @@
</span>
</div>
<BadgeList>
<ProjectTypeBadge type={project.type}/>
<ProjectTypeBadge type={project.type} />
<Badge>
<FormatRetentionPolicy policy={project.retentionPolicy}/>
<FormatRetentionPolicy policy={project.retentionPolicy} />
</Badge>
{#if migrationStatus === ProjectMigrationStatus.Migrating}
<Badge><span class="loading loading-spinner loading-xs"></span> Migrating</Badge>
<Badge><span class="loading loading-spinner loading-xs" /> Migrating</Badge>
{:else}
<Badge>{migrationStatusTable[migrationStatus]}</Badge>
{/if}
{#if project.resetStatus === ResetStatus.InProgress}
<button class:tooltip={isAdmin(user)} data-tip={$t('project_page.reset_project_modal.click_to_continue')}
disabled={!isAdmin(user)} on:click={resetProject}>
<button
class:tooltip={isAdmin(user)}
data-tip={$t('project_page.reset_project_modal.click_to_continue')}
disabled={!isAdmin(user)}
on:click={resetProject}
>
<Badge type="badge-warning">
{$t('project_page.reset_project_modal.reset_in_progress')}
<span class="i-mdi-warning text-xl mb-[-2px]"/>
<span class="i-mdi-warning text-xl mb-[-2px]" />
</Badge>
</button>
{/if}
Expand Down Expand Up @@ -294,12 +302,11 @@

<BadgeList>
{#each project.users as member}
{@const canManageMember = canManage && (member.user.id !== userId || isAdmin(user))}
{@const canManageMember = canManage && (member.user.id !== userId || isAdmin(user))}
<Dropdown disabled={!canManageMember}>
<MemberBadge
member={{ name: member.user.name, role: member.role }}
canManage={canManageMember}
/>
canManage={canManageMember} />
<ul slot="content" class="menu">
<li>
<button on:click={() => changeMemberRole(member)}>
Expand Down Expand Up @@ -357,9 +364,9 @@
{$t('delete_project_modal.submit')}<TrashIcon />
</button>
<AdminContent>
<button class="btn btn-accent" on:click={resetProject}>
{$t('project_page.reset_project_modal.submit')}<CircleArrowIcon />
</button>
<button class="btn btn-accent" on:click={resetProject}>
{$t('project_page.reset_project_modal.submit')}<CircleArrowIcon />
</button>
<ResetProjectModal bind:this={resetProjectModal} />
</AdminContent>
</MoreSettings>
Expand Down
Loading

0 comments on commit 977c580

Please sign in to comment.