2022-07-07 05:19:05 +08:00
|
|
|
<script>
|
|
|
|
import CommonHelper from "@/utils/CommonHelper";
|
|
|
|
import tooltip from "@/actions/tooltip";
|
|
|
|
import IdLabel from "@/components/base/IdLabel.svelte";
|
|
|
|
import FormattedDate from "@/components/base/FormattedDate.svelte";
|
|
|
|
import RecordFilePreview from "@/components/records/RecordFilePreview.svelte";
|
|
|
|
|
|
|
|
export let record;
|
|
|
|
export let field;
|
2022-09-29 02:55:18 +08:00
|
|
|
|
|
|
|
// rough text cut to avoid rendering large chunk of texts
|
|
|
|
function cutText(text) {
|
|
|
|
text = text || "";
|
|
|
|
return text.length > 200 ? text.substring(0, 200) : text;
|
|
|
|
}
|
2022-07-07 05:19:05 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<td class="col-type-{field.type} col-field-{field.name}">
|
|
|
|
{#if CommonHelper.isEmpty(record[field.name])}
|
|
|
|
<span class="txt-hint">N/A</span>
|
|
|
|
{:else if field.type === "bool"}
|
|
|
|
<span class="txt">{record[field.name] ? "True" : "False"}</span>
|
2022-12-31 16:07:20 +08:00
|
|
|
{:else if field.type === "number"}
|
|
|
|
<span class="txt">{record[field.name]}</span>
|
2022-07-07 05:19:05 +08:00
|
|
|
{:else if field.type === "url"}
|
|
|
|
<a
|
|
|
|
class="txt-ellipsis"
|
|
|
|
href={record[field.name]}
|
|
|
|
target="_blank"
|
2022-10-30 16:28:14 +08:00
|
|
|
rel="noopener noreferrer"
|
2022-07-07 05:19:05 +08:00
|
|
|
use:tooltip={"Open in new tab"}
|
|
|
|
on:click|stopPropagation
|
|
|
|
>
|
|
|
|
{record[field.name]}
|
|
|
|
</a>
|
|
|
|
{:else if field.type === "date"}
|
|
|
|
<FormattedDate date={record[field.name]} />
|
|
|
|
{:else if field.type === "json"}
|
2022-09-29 02:55:18 +08:00
|
|
|
<span class="txt txt-ellipsis">
|
|
|
|
{cutText(JSON.stringify(record[field.name]))}
|
|
|
|
</span>
|
2022-07-07 05:19:05 +08:00
|
|
|
{:else if field.type === "select"}
|
|
|
|
<div class="inline-flex">
|
2022-10-05 03:42:51 +08:00
|
|
|
{#each CommonHelper.toArray(record[field.name]) as item, i (i + item)}
|
2022-07-07 05:19:05 +08:00
|
|
|
<span class="label">{item}</span>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{:else if field.type === "relation" || field.type === "user"}
|
|
|
|
<div class="inline-flex">
|
2022-10-30 16:28:14 +08:00
|
|
|
{#each CommonHelper.toArray(record[field.name]).slice(0, 20) as item, i (i + item)}
|
2022-07-07 05:19:05 +08:00
|
|
|
<IdLabel id={item} />
|
|
|
|
{/each}
|
2022-10-30 16:28:14 +08:00
|
|
|
{#if CommonHelper.toArray(record[field.name]).length > 20}
|
|
|
|
...
|
|
|
|
{/if}
|
2022-07-07 05:19:05 +08:00
|
|
|
</div>
|
|
|
|
{:else if field.type === "file"}
|
|
|
|
<div class="inline-flex">
|
2022-10-05 03:42:51 +08:00
|
|
|
{#each CommonHelper.toArray(record[field.name]) as filename, i (i + filename)}
|
2022-07-18 05:16:09 +08:00
|
|
|
<figure class="thumb thumb-sm">
|
2022-07-07 05:19:05 +08:00
|
|
|
<RecordFilePreview {record} {filename} />
|
|
|
|
</figure>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{:else}
|
2022-09-29 02:55:18 +08:00
|
|
|
<span class="txt txt-ellipsis" title={cutText(record[field.name])}>
|
|
|
|
{cutText(record[field.name])}
|
2022-07-07 05:19:05 +08:00
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</td>
|