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

97 lines
2.6 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";
2024-04-03 16:25:59 +03:00
import {previewEdgeTitle, 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;
2024-03-30 13:42:38 +02:00
export let edge = null;
2024-03-25 21:26:21 +02:00
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>
2024-03-26 01:58:05 +02:00
<div class="d-flex gap-2">
{#if editable}
<div
class="card mb-2 bg-light w-50 "
style="border-color:{schema.color ?? '#ccc'}; border-width: 1px;"
>
<div class="card-body">
2024-04-03 16:25:59 +03:00
<span class="text-muted d-block">Relation Data</span>
{previewEdgeTitle(edge)}
2024-03-26 01:58:05 +02:00
<div class="position-absolute d-flex end-0" style="top:5px">
<button
class="trash-button text-dark btn btn-sm btn-link"
on:click={edit}
>
<Icon icon="pencil"/>
</button>
</div>
</div>
</div>
2023-10-02 23:10:49 +03:00
2024-03-30 13:42:38 +02:00
<EdgeData bind:this={edgeData} {record} {field} bind:edge/>
2024-03-26 01:58:05 +02:00
{/if}
2023-10-02 23:10:49 +03:00
2024-03-26 01:58:05 +02:00
<div
class="card mb-2 bg-light w-100 {classes}"
style="border-color:{schema.color ?? '#ccc'}; border-width: 1px;"
>
<div class="card-body">
<Preview {record} type="card"/>
</div>
{#if hasDelete}
<div class="position-absolute d-flex end-0" style="top:5px">
2023-10-02 23:10:49 +03:00
2024-03-25 21:26:21 +02:00
<button
class="trash-button text-dark btn btn-sm btn-link"
2024-03-26 01:58:05 +02:00
on:click={remove}
2024-03-25 21:26:21 +02:00
>
2024-03-26 01:58:05 +02:00
<Icon icon="trash-can"/>
2024-03-25 21:26:21 +02:00
</button>
2024-03-26 01:58:05 +02:00
</div>
{/if}
</div>
2023-10-02 23:10:49 +03:00
</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>