2022-07-07 05:19:05 +08:00
|
|
|
<script>
|
|
|
|
import CommonHelper from "@/utils/CommonHelper";
|
|
|
|
import tooltip from "@/actions/tooltip";
|
|
|
|
import FormattedDate from "@/components/base/FormattedDate.svelte";
|
2023-01-24 03:57:35 +08:00
|
|
|
import IdLabel from "@/components/base/IdLabel.svelte";
|
2023-01-10 03:41:27 +08:00
|
|
|
import RecordFileThumb from "@/components/records/RecordFileThumb.svelte";
|
2023-01-24 03:57:35 +08:00
|
|
|
import RecordInfo from "@/components/records/RecordInfo.svelte";
|
2022-07-07 05:19:05 +08:00
|
|
|
|
|
|
|
export let record;
|
|
|
|
export let field;
|
|
|
|
</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
|
|
|
|
>
|
2023-01-24 03:57:35 +08:00
|
|
|
{CommonHelper.truncate(record[field.name])}
|
2022-07-07 05:19:05 +08:00
|
|
|
</a>
|
2023-01-17 19:31:48 +08:00
|
|
|
{:else if field.type === "editor"}
|
2023-01-24 03:57:35 +08:00
|
|
|
<span class="txt">
|
|
|
|
{CommonHelper.truncate(CommonHelper.plainText(record[field.name]), 300, true)}
|
2023-01-17 19:31:48 +08:00
|
|
|
</span>
|
2022-07-07 05:19:05 +08:00
|
|
|
{: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">
|
2023-01-24 03:57:35 +08:00
|
|
|
{CommonHelper.truncate(JSON.stringify(record[field.name]))}
|
2022-09-29 02:55:18 +08:00
|
|
|
</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"}
|
2023-01-24 03:57:35 +08:00
|
|
|
{@const relations = CommonHelper.toArray(record[field.name])}
|
|
|
|
{@const expanded = CommonHelper.toArray(record.expand[field.name])}
|
2022-07-07 05:19:05 +08:00
|
|
|
<div class="inline-flex">
|
2023-01-24 03:57:35 +08:00
|
|
|
{#if expanded.length}
|
|
|
|
{#each expanded.slice(0, 20) as item, i (i + item)}
|
|
|
|
<span class="label">
|
|
|
|
<RecordInfo record={item} displayFields={field.options?.displayFields} />
|
|
|
|
</span>
|
|
|
|
{/each}
|
|
|
|
{:else}
|
|
|
|
{#each relations.slice(0, 20) as item, i (i + item)}
|
|
|
|
<IdLabel id={item} />
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
{#if relations.length > 20}
|
2022-10-30 16:28:14 +08:00
|
|
|
...
|
|
|
|
{/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)}
|
2023-01-10 03:41:27 +08:00
|
|
|
<RecordFileThumb {record} {filename} size="sm" />
|
2022-07-07 05:19:05 +08:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{:else}
|
2023-01-24 03:57:35 +08:00
|
|
|
<span class="txt txt-ellipsis" title={CommonHelper.truncate(record[field.name])}>
|
|
|
|
{CommonHelper.truncate(record[field.name])}
|
2022-07-07 05:19:05 +08:00
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</td>
|
2023-01-11 04:20:52 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.filename {
|
|
|
|
max-width: 200px;
|
|
|
|
}
|
|
|
|
</style>
|