Skip to content

Commit f0f314b

Browse files
committed
Prototype of an asset reference viewer
Based on statamic/ideas#1412
1 parent 372d48c commit f0f314b

6 files changed

Lines changed: 566 additions & 3 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<template>
2+
<div v-if="!isLoaded" class="flex items-center justify-center">
3+
<ui-button @click="loadReferences" :text="__('View Usage')" variant="filled" size="sm" />
4+
</div>
5+
<div v-else>
6+
<Listing
7+
:url="url"
8+
:columns="columns"
9+
:per-page="5"
10+
:show-pagination-totals="false"
11+
:show-pagination-page-links="false"
12+
:show-pagination-per-page-selector="false"
13+
:allow-search="false"
14+
:allow-customizing-columns="false"
15+
>
16+
<template #initializing>
17+
<div class="flex flex-col gap-[8px] justify-between py-1 px-5">
18+
<ui-skeleton class="h-[18px] w-full" />
19+
<ui-skeleton class="h-[18px] w-full" />
20+
<ui-skeleton class="h-[18px] w-full" />
21+
</div>
22+
</template>
23+
<template #default="{ items }">
24+
<ui-description v-if="items?.length" :text="__('In Use')" class="mb-3" />
25+
<table v-if="items?.length" class="w-full [&_td]:px-0.75 [&_td]:py-1 [&_td]:text-sm">
26+
<ListingTableHead sr-only />
27+
<ListingTableBody class="divide-y divide-gray-200 dark:divide-gray-700">
28+
<template #cell-title="{ row: entry }">
29+
<div class="flex items-center gap-2">
30+
<StatusIndicator :status="entry.status" />
31+
<Link :href="entry.edit_url" class="line-clamp-1 overflow-hidden text-ellipsis">{{ entry.title }}</Link>
32+
</div>
33+
</template>
34+
<template #cell-collection="{ row: entry }">
35+
<div class="text-end">
36+
<ui-badge :text="entry.collection?.title" size="sm" />
37+
</div>
38+
</template>
39+
</ListingTableBody>
40+
</table>
41+
<ui-subheading v-else class="text-center h-full flex items-center justify-center py-4">
42+
{{ __('This asset is not being used anywhere.') }}
43+
</ui-subheading>
44+
</template>
45+
</Listing>
46+
</div>
47+
</template>
48+
49+
<script>
50+
import {
51+
StatusIndicator,
52+
Listing,
53+
ListingTableHead,
54+
ListingTableBody,
55+
} from '@/components/ui';
56+
import { Link } from '@inertiajs/vue3';
57+
58+
export default {
59+
components: {
60+
StatusIndicator,
61+
Listing,
62+
ListingTableHead,
63+
ListingTableBody,
64+
Link,
65+
},
66+
67+
props: {
68+
assetId: {
69+
type: String,
70+
required: true,
71+
},
72+
},
73+
74+
data() {
75+
return {
76+
isLoaded: false,
77+
};
78+
},
79+
80+
computed: {
81+
url() {
82+
return cp_url(`assets/${utf8btoa(this.assetId)}/references`);
83+
},
84+
85+
columns() {
86+
return [
87+
{ label: 'Title', field: 'title', visible: true },
88+
{ label: 'Collection name', field: 'collection', visible: true },
89+
];
90+
},
91+
},
92+
93+
methods: {
94+
loadReferences() {
95+
this.isLoaded = true;
96+
},
97+
},
98+
};
99+
</script>

resources/js/components/assets/Editor/Editor.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@
136136
</div>
137137

138138
<PublishTabs />
139+
<div class="px-2">
140+
<AssetReferences v-if="asset" :asset-id="asset.id" />
141+
</div>
139142
</div>
140143
</PublishContainer>
141144
</div>
@@ -183,6 +186,7 @@
183186
<script>
184187
import FocalPointEditor from './FocalPointEditor.vue';
185188
import PdfViewer from './PdfViewer.vue';
189+
import AssetReferences from '../AssetReferences.vue';
186190
import { pick, flatten } from 'lodash-es';
187191
import {
188192
Dropdown,
@@ -205,6 +209,7 @@ export default {
205209
ItemActions,
206210
FocalPointEditor,
207211
PdfViewer,
212+
AssetReferences,
208213
PublishContainer,
209214
PublishTabs,
210215
Icon,

routes/cp.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
Route::post('assets-fieldtype', [FieldtypeController::class, 'index']);
264264
Route::resource('assets', AssetsController::class)->parameters(['assets' => 'encoded_asset'])->except('destroy');
265265
Route::get('assets/{encoded_asset}/download', [AssetsController::class, 'download'])->name('assets.download');
266+
Route::get('assets/{encoded_asset}/references', [AssetsController::class, 'references'])->name('assets.references');
266267
Route::get('thumbnails/{encoded_asset}/{size?}/{orientation?}', [ThumbnailController::class, 'show'])->name('assets.thumbnails.show');
267268
Route::get('svgs/{encoded_asset}', [SvgController::class, 'show'])->name('assets.svgs.show');
268269
Route::get('pdfs/{encoded_asset}', [PdfController::class, 'show'])->name('assets.pdfs.show');

0 commit comments

Comments
 (0)