This commit is contained in:
j3d1 2026-08-22 23:29:02 +02:00
parent 3299c97392
commit de7d9426be
10 changed files with 259 additions and 99 deletions

View file

@ -40,7 +40,7 @@
<a :href="`/inventory/${item.id}/delete`" @click.prevent="deleteInventoryItem(item)">
<b-icon-trash></b-icon-trash>
</a>
<router-link :to="shortIdLink(item)">
<router-link v-if="shortIdLink(item)" :to="shortIdLink(item)">
<b-icon-link></b-icon-link>
</router-link>
</td>
@ -73,7 +73,8 @@
<router-link :to="`/inventory/${item.id}/edit`"
class="btn btn-primary btn-sm">Edit
</router-link>
<router-link :to="shortIdLink(item)" class="btn btn-secondary btn-sm">
<router-link v-if="shortIdLink(item)" :to="shortIdLink(item)"
class="btn btn-secondary btn-sm">
<b-icon-link></b-icon-link>
</router-link>
</div>
@ -100,7 +101,7 @@ import {mapActions, mapGetters, mapMutations, mapState} from "vuex";
import * as BIcons from "bootstrap-icons-vue";
import BaseLayout from "@/components/BaseLayout.vue";
import AuthenticatedImage from "../components/AuthenticatedImage.vue";
import {encodeShortId, serializeShortId} from "@/short-id";
import {shortenedRoute} from "@/router";
export default {
name: "Inventory",
@ -115,11 +116,11 @@ export default {
...BIcons
},
computed: {
...mapGetters(["inventory_items", "loaded_items"]),
...mapGetters(["inventory_items", "loaded_items", "identityIdByHandle", "groupIdByHandle"]),
...mapState(["user", "storage_locations"]),
},
methods: {
...mapActions(["fetchInventoryItems", "deleteInventoryItem", "fetchStorageLocations"]),
...mapActions(["fetchInventoryItems", "deleteInventoryItem", "fetchStorageLocations", "fetchIdMap"]),
only_images(files) {
return files.filter(file => file.mime_type.startsWith("image/"));
},
@ -128,16 +129,20 @@ export default {
return loc ? loc.path : null
},
shortIdLink(item) {
// owner_identity_id is a placeholder until the backend exposes a KnownIdentity pk
// per item (see docs/handles-and-shortids.md) - it doesn't decode to a
// meaningful owner yet.
const ints = serializeShortId({kind: 'item', owner_identity_id: 0, item_local_id: item.id});
return '/' + encodeShortId(ints);
if (item.owner_group) {
const owner_group_id = this.groupIdByHandle[item.owner_group]
if (owner_group_id === undefined) return null
return shortenedRoute({kind: 'group_item', owner_group_id, item_local_id: item.id})
}
const owner_identity_id = this.identityIdByHandle[item.owner]
if (owner_identity_id === undefined) return null
return shortenedRoute({kind: 'item', owner_identity_id, item_local_id: item.id})
},
},
async mounted() {
await this.fetchInventoryItems()
await this.fetchStorageLocations()
await this.fetchIdMap()
}
}
</script>

View file

@ -19,6 +19,13 @@
</ul>
</div>
</div>
<div class="card">
<div class="card-header">Expanded</div>
<div class="card-body">
<router-link v-if="expandedRoute" :to="expandedRoute">{{ expandedRoute }}</router-link>
<span v-else>No page exists for kind '{{ deserialized.kind }}'</span>
</div>
</div>
<div class="card">
<div class="card-header">Examples</div>
<table class="table table-striped mb-0">
@ -56,14 +63,16 @@
<script>
import BaseLayout from '@/components/BaseLayout.vue';
import {decodeShortId, deserializeShortId, encodeShortId, serializeShortId} from '@/short-id';
import {expandedRoute as buildExpandedRoute} from '@/router';
const EXAMPLES = [
{kind: 'item', owner_identity_id: 7, item_local_id: 42},
{kind: 'group', group_id: 11},
{kind: 'group_item', owner_group_id: 5, item_local_id: 42},
{kind: 'file', file_id: 123},
{kind: 'storage_location', owner_identity_id: 3, storage_location_id: 1000},
{kind: 'category', category_id: 5},
{kind: 'workflow', owner_identity_id: 2, workflow_id: 9},
{kind: 'group', group_id: 11},
{kind: 'file', file_id: 123},
];
// Debug-only display helper, kept out of short-id.js's production library: mirrors its bit-packing
@ -130,6 +139,9 @@ export default {
const {kind, ...fields} = this.deserialized;
return fields;
},
expandedRoute() {
return buildExpandedRoute(this.deserialized);
},
examples() {
return EXAMPLES.map(named => {
const {kind, ...fields} = named;