-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement rudimentary asset viewer capabilities
- Loading branch information
Showing
6 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script> | ||
import NotImplemented from "../utils/NotImplemented.svelte"; | ||
export let asset; | ||
// Importing all the implememented viewers. | ||
import ImageViewer from "../viewer/ImageViewer.svelte"; | ||
import VideoViewer from "../viewer/VideoViewer.svelte"; | ||
// Mapping the "class" names from the data to a Svelte component | ||
// implementing the respective viewer. | ||
const componentMapping = { | ||
"audio": VideoViewer, | ||
"image": ImageViewer, | ||
"video": VideoViewer, | ||
}; | ||
</script> | ||
|
||
{#if asset.class in componentMapping} | ||
<svelte:component this={componentMapping[asset.class]} asset={asset} /> | ||
{:else} | ||
<NotImplemented message="Asset type '{asset.class}' not implemented" /> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script> | ||
import { fieldData, findSchemaColumn, hasReverseSubData, hasSubData, linkedSubData, reverseLinkedSubData } from "../../lib/easydbHelpers"; | ||
import { Carousel, Pagination } from "flowbite-svelte"; | ||
import AssetDispatch from "./AssetDispatch.svelte"; | ||
export let fields; | ||
export let table; | ||
export let data; | ||
function findAssets(fields, table, data) { | ||
let ret = []; | ||
for (const field of fields) { | ||
if (field.kind === "field") { | ||
if (findSchemaColumn(table, field).type === "eas") { | ||
ret = ret.concat(fieldData(data, table, field)); | ||
} | ||
} | ||
if (field.kind === "linked-table") { | ||
if (hasSubData(data, table, field)) { | ||
for (const subdata of linkedSubData(data, table, field)) { | ||
ret = ret.concat(findAssets(field.mask.fields, field.other_table_name_hint, subdata)); | ||
} | ||
} | ||
} | ||
if (field.kind === "reverse-linked-table") { | ||
if (hasReverseSubData(data, table, field)) { | ||
for (const subdata of reverseLinkedSubData(data, table, field)) { | ||
ret = ret.concat(findAssets(field.mask.fields, field.other_table_name_hint, subdata)); | ||
} | ||
} | ||
} | ||
} | ||
return ret; | ||
} | ||
function getCarouselImages(assets) { | ||
return assets.map((asset) => { return {src: asset.versions.preview.url}}); | ||
} | ||
const assets = findAssets(fields, table, data); | ||
console.log(assets); | ||
</script> | ||
|
||
<!-- If there are no assets, no viewer is shown --> | ||
{#if assets.length > 0} | ||
<!-- If all assets are images, we show them as a carousel, as we have this | ||
component readily available from flowbite svelte --> | ||
{#if assets.every((asset) => asset.class === "image") } | ||
<Carousel images={getCarouselImages(assets)} imgClass="object-contain" class="bg-gray-200" let:Controls> | ||
<Controls /> | ||
</Carousel> | ||
{:else} | ||
<!-- In this case we construct our own carousel-like thing with pagination --> | ||
{#if assets.length > 1} | ||
Pagination | ||
<!-- <Pagination /> --> | ||
{/if} | ||
{#each assets as asset} | ||
<AssetDispatch asset={asset} /> | ||
{/each} | ||
{/if} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!-- NB: This component is used much less than you would expect, because | ||
datasets that do only have image assets are displayed using the | ||
Carousel component from Flowbite Svelte. Only in the case of mixing | ||
image and non-image assets this is used to display images. --> | ||
<script> | ||
import { Img } from "flowbite-svelte"; | ||
export let asset; | ||
</script> | ||
|
||
<Img src={asset.versions.preview.url} alt={asset.original_filename} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
import { Video } from "flowbite-svelte"; | ||
export let asset; | ||
</script> | ||
|
||
<Video src={asset.versions.original.url} controls /> |