Files
lucent-laravel/front/js/svelte/records/PreviewCard.svelte
T

102 lines
2.8 KiB
Svelte
Raw Normal View History

2023-10-02 23:10:49 +03:00
<script>
import Icon from "../common/Icon.svelte";
2024-03-25 21:26:21 +02:00
import {getContext, createEventDispatcher} from "svelte";
import {previewTitle} from "./Preview";
2023-10-02 23:10:49 +03:00
import Status from "./Status.svelte";
2024-03-25 21:26:21 +02:00
import Preview from "../newPreview/Preview.svelte";
import EdgeData from "./form/references/EdgeData.svelte";
2023-10-02 23:10:49 +03:00
const dispatch = createEventDispatcher();
const channel = getContext("channel");
export let record;
2024-03-25 21:26:21 +02:00
export let field;
export let edge;
export let editable = false;
2023-10-02 23:10:49 +03:00
export let classes = "";
export let hasDelete = false;
2024-03-25 21:26:21 +02:00
let edgeData;
2023-10-04 13:32:30 +03:00
let schema = channel.schemas.find((aschema) => aschema.name === record.schema);
2024-03-25 21:26:21 +02:00
let cardTitle = previewTitle(record);
2023-10-02 23:10:49 +03:00
function remove(e) {
e.preventDefault();
dispatch("remove", record.id);
}
2024-03-25 21:26:21 +02:00
function edit(e) {
e.preventDefault();
edgeData.openEdit();
}
2023-10-02 23:10:49 +03:00
</script>
<div
2024-03-25 21:26:21 +02:00
class="card mb-2 bg-light {classes}"
style="border-color:{schema.color ?? '#ccc'}; border-width: 1px;"
2023-10-02 23:10:49 +03:00
>
2024-03-25 21:26:21 +02:00
<div class="card-body">
<Preview {record} type="card"/>
{#if editable}
<EdgeData bind:this={edgeData} {field} {edge}/>
2023-10-02 23:10:49 +03:00
{/if}
2024-03-25 21:26:21 +02:00
<!-- <div class="overflow-hidden">-->
<!-- <a-->
<!-- class="title-link m-0 fs-5 text-decoration-none text-dark d-block"-->
<!-- href="{channel.lucentUrl}/records/{record.id}"-->
<!-- title={cardTitle}-->
<!-- >-->
<!-- {cardTitle}-->
<!-- </a>-->
<!-- <small class="text-muted">-->
<!-- {schema.label}-->
<!-- </small>-->
<!-- <small class="text-muted">-->
<!-- {#if record.status === "draft"}-->
<!-- <Status status={record.status} />-->
<!-- {/if}-->
<!-- </small>-->
<!-- </div>-->
2023-10-02 23:10:49 +03:00
</div>
{#if hasDelete}
2024-03-25 21:26:21 +02:00
<div class="position-absolute d-flex end-0" style="top:5px">
{#if editable}
<button
class="trash-button text-dark btn btn-sm btn-link"
on:click={edit}
>
<Icon icon="pencil"/>
</button>
{/if}
2023-10-02 23:10:49 +03:00
<button
2024-03-25 21:26:21 +02:00
class="trash-button text-dark btn btn-sm btn-link"
on:click={remove}
>
<Icon icon="trash-can"/>
2023-10-02 23:10:49 +03:00
</button>
2024-03-25 21:26:21 +02:00
2023-10-02 23:10:49 +03:00
</div>
{/if}
</div>
<style>
2023-10-13 21:06:23 +03:00
2023-10-02 23:10:49 +03:00
.card .trash-button {
display: none;
}
2024-03-25 21:26:21 +02:00
2023-10-02 23:10:49 +03:00
.card:hover .trash-button {
display: block;
}
2024-03-25 21:26:21 +02:00
2023-10-02 23:10:49 +03:00
.title-link {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>