Fix issue #35: Dragonroll frontend: item modifications
All checks were successful
Test / test (push) Successful in 2s
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -26,7 +26,6 @@ const sidebarCollapsed = ref(false);
|
||||
const activeSection = ref('notes');
|
||||
const isDragOverSidebar = ref(false);
|
||||
const expandedFolderIds = ref([]);
|
||||
const expandedEntryIds = ref([]);
|
||||
const nestedNoteListRef = ref(null);
|
||||
let entryRefreshInterval;
|
||||
|
||||
@@ -287,12 +286,6 @@ function showEntryMenu(entry, entityType) {
|
||||
ShowContextMenu(menuItems);
|
||||
}
|
||||
|
||||
function toggleEntryDetails(entryId) {
|
||||
expandedEntryIds.value = expandedEntryIds.value.includes(entryId)
|
||||
? expandedEntryIds.value.filter((id) => id !== entryId)
|
||||
: [...expandedEntryIds.value, entryId];
|
||||
}
|
||||
|
||||
async function openCharacterSheet(actor) {
|
||||
const existingWindowId = GetFirstWindowId('character_sheet');
|
||||
if (existingWindowId !== undefined) {
|
||||
@@ -302,6 +295,16 @@ async function openCharacterSheet(actor) {
|
||||
CreateWindow('character_sheet', { actor });
|
||||
}
|
||||
|
||||
// Clicking an item opens its window, like a character does with its sheet.
|
||||
async function openItemSheet(item) {
|
||||
const existingWindowId = GetFirstWindowId('item_sheet');
|
||||
if (existingWindowId !== undefined) {
|
||||
ClearWindow({ id: existingWindowId });
|
||||
await nextTick();
|
||||
}
|
||||
CreateWindow('item_sheet', { item });
|
||||
}
|
||||
|
||||
// Maps are anchored on the note container instead of opening a window: the notes that were open
|
||||
// stay open, and the sidebar's notes/maps buttons switch between the two.
|
||||
function openMapViewer(map) {
|
||||
@@ -498,17 +501,12 @@ onBeforeUnmount(() => {
|
||||
<div v-if="loadingEntries" class="sidebar-state">{{ t('campaigns.states.loading') }}</div>
|
||||
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
|
||||
<div v-else-if="items.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-items') }}</div>
|
||||
<div v-for="item in items" :key="item._id" class="entity-entry" role="button" tabindex="0" :aria-expanded="expandedEntryIds.includes(item._id)" @click="toggleEntryDetails(item._id)" @keydown.enter="toggleEntryDetails(item._id)" @keydown.space.prevent="toggleEntryDetails(item._id)" @contextmenu.prevent="showEntryMenu(item, 'item')">
|
||||
<div v-for="item in items" :key="item._id" class="entity-entry" role="button" tabindex="0" @click="openItemSheet(item)" @keydown.enter="openItemSheet(item)" @keydown.space.prevent="openItemSheet(item)" @contextmenu.prevent="showEntryMenu(item, 'item')">
|
||||
<span class="entity-entry-name-row">
|
||||
<span class="entity-entry-name">{{ item.name }}</span>
|
||||
<span v-if="item.foundryItemId" class="entity-entry-sync">{{ t('campaigns.synced') }}</span>
|
||||
</span>
|
||||
<span class="entity-entry-meta">{{ itemSummary(item) }}</span>
|
||||
<template v-if="expandedEntryIds.includes(item._id)">
|
||||
<span v-if="item.weight !== undefined" class="entity-entry-description">{{ item.weight }} lb</span>
|
||||
<span v-if="item.properties" class="entity-entry-description">{{ item.properties }}</span>
|
||||
<span v-if="item.description" class="entity-entry-description">{{ item.description }}</span>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
213
frontend/app/components/windows/ItemSheetWindow.vue
Normal file
213
frontend/app/components/windows/ItemSheetWindow.vue
Normal file
@@ -0,0 +1,213 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { SetupHandle, SetSize, ResetPosition, ClearWindow, Top } from '@/services/Windows';
|
||||
import WindowHandle from './partials/WindowHandle.vue';
|
||||
import Server, { getBaseUrl } from '~/services/Server';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const id = props.data.id;
|
||||
const itemId = props.data.item?._id;
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
const error = ref('');
|
||||
const uploadingIcon = ref(false);
|
||||
const applyingFoundryIcon = ref(false);
|
||||
const photoInput = ref(null);
|
||||
const { t } = useI18n();
|
||||
|
||||
function normalizeItem(item) {
|
||||
return {
|
||||
name: item?.name ?? '',
|
||||
category: item?.category ?? 'adventuring-gear',
|
||||
rarity: item?.rarity ?? 'common',
|
||||
quantity: Number(item?.quantity ?? 1),
|
||||
weight: item?.weight ?? '',
|
||||
properties: item?.properties ?? '',
|
||||
description: item?.description ?? '',
|
||||
image: item?.image ?? '',
|
||||
foundryItemId: item?.foundryItemId ?? '',
|
||||
foundryImage: item?.foundryImage ?? ''
|
||||
};
|
||||
}
|
||||
|
||||
const form = ref(normalizeItem(props.data.item));
|
||||
|
||||
onMounted(() => {
|
||||
Top(wrapper);
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, { width: 460, height: 560 });
|
||||
ResetPosition(id, 'center');
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => ClearWindow({ type: 'item_sheet' }));
|
||||
|
||||
// The sidebar keeps this entry fresh (Foundry sync lands in the background);
|
||||
// follow along unless the window is mid-icon-upload.
|
||||
function handleItemSync({ entityType, entry }) {
|
||||
if (entityType !== 'item' || entry?._id !== itemId || uploadingIcon.value) return;
|
||||
form.value = normalizeItem(entry);
|
||||
}
|
||||
|
||||
onMounted(() => emitter.on('campaign-entry-updated', handleItemSync));
|
||||
onBeforeUnmount(() => emitter.off('campaign-entry-updated', handleItemSync));
|
||||
|
||||
const imageUrl = computed(() => {
|
||||
if (!form.value.image) return '';
|
||||
return /^(https?:|data:|\/\/)/i.test(form.value.image)
|
||||
? form.value.image
|
||||
: `${getBaseUrl()}/public/${form.value.image}`;
|
||||
});
|
||||
|
||||
const canUseFoundryIcon = computed(() => Boolean(form.value.foundryImage) && form.value.foundryImage !== form.value.image);
|
||||
|
||||
async function updateItem(payload) {
|
||||
const response = await Server().post('/item/update', { id: itemId, ...payload });
|
||||
if (response.data.status !== 'ok') return false;
|
||||
form.value = normalizeItem(response.data.item);
|
||||
emitter.emit('campaign-entry-updated', { entityType: 'item', entry: response.data.item });
|
||||
return true;
|
||||
}
|
||||
|
||||
function pickIcon() {
|
||||
photoInput.value?.click();
|
||||
}
|
||||
|
||||
async function onIconSelected(event) {
|
||||
const file = event.target.files?.[0];
|
||||
event.target.value = '';
|
||||
if (!file || uploadingIcon.value) return;
|
||||
uploadingIcon.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('image', file);
|
||||
const response = await Server().post(`/item/upload-image?item=${itemId}`, formData, {
|
||||
headers: { "Content-Type": "multipart/form-data" }
|
||||
});
|
||||
if (response.data.status !== 'ok') {
|
||||
error.value = t('campaigns.item.sheet.upload-error');
|
||||
return;
|
||||
}
|
||||
form.value = normalizeItem(response.data.item);
|
||||
emitter.emit('campaign-entry-updated', { entityType: 'item', entry: response.data.item });
|
||||
} catch (requestError) {
|
||||
error.value = t('campaigns.item.sheet.upload-error');
|
||||
} finally {
|
||||
uploadingIcon.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// "Fetch from Foundry's icons": the module keeps the world's own icon on the
|
||||
// item, so this just switches back to it.
|
||||
async function useFoundryIcon() {
|
||||
if (!canUseFoundryIcon.value || applyingFoundryIcon.value) return;
|
||||
applyingFoundryIcon.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const done = await updateItem({ image: form.value.foundryImage });
|
||||
if (!done) error.value = t('campaigns.item.sheet.save-error');
|
||||
} catch (requestError) {
|
||||
error.value = t('campaigns.item.sheet.save-error');
|
||||
} finally {
|
||||
applyingFoundryIcon.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeIcon() {
|
||||
if (!form.value.image) return;
|
||||
error.value = '';
|
||||
try {
|
||||
const done = await updateItem({ image: '' });
|
||||
if (!done) error.value = t('campaigns.item.sheet.save-error');
|
||||
} catch (requestError) {
|
||||
error.value = t('campaigns.item.sheet.save-error');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper item-window" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle" />
|
||||
<div class="item-body">
|
||||
<header class="item-hero">
|
||||
<div class="item-icon" :class="{ empty: !form.image }">
|
||||
<img v-if="form.image" :src="imageUrl" :alt="$t('campaigns.item.sheet.icon')">
|
||||
<span v-else aria-hidden="true">{{ form.name.slice(0, 1).toUpperCase() }}</span>
|
||||
</div>
|
||||
<div class="item-identity">
|
||||
<h1>{{ form.name }}</h1>
|
||||
<div class="item-tags">
|
||||
<span class="item-tag">{{ $t(`campaigns.item.categories.${form.category}`) }}</span>
|
||||
<span class="item-tag">{{ $t(`campaigns.item.rarities.${form.rarity}`) }}</span>
|
||||
<span v-if="form.foundryItemId" class="item-tag synced">{{ $t('campaigns.synced') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="error" class="item-error">{{ error }}</div>
|
||||
|
||||
<div class="icon-controls">
|
||||
<button class="sheet-button" type="button" :disabled="uploadingIcon" @click="pickIcon">
|
||||
{{ uploadingIcon
|
||||
? $t('campaigns.item.sheet.uploading')
|
||||
: (form.image ? $t('campaigns.item.sheet.change-icon') : $t('campaigns.item.sheet.choose-icon')) }}
|
||||
</button>
|
||||
<button v-if="canUseFoundryIcon" class="sheet-button secondary" type="button" :disabled="applyingFoundryIcon" @click="useFoundryIcon">
|
||||
{{ $t('campaigns.item.sheet.foundry-icon') }}
|
||||
</button>
|
||||
<button v-if="form.image" class="sheet-button secondary" type="button" :disabled="uploadingIcon" :aria-label="$t('campaigns.item.sheet.remove-icon')" @click="removeIcon">×</button>
|
||||
<input ref="photoInput" class="photo-input" type="file" accept="image/*" @change="onIconSelected">
|
||||
</div>
|
||||
|
||||
<dl class="item-facts">
|
||||
<div class="item-fact">
|
||||
<dt>{{ $t('campaigns.item.quantity') }}</dt>
|
||||
<dd>{{ form.quantity }}</dd>
|
||||
</div>
|
||||
<div v-if="form.weight !== '' && form.weight !== undefined" class="item-fact">
|
||||
<dt>{{ $t('campaigns.item.weight') }}</dt>
|
||||
<dd>{{ Number(form.weight).toFixed(1) }} lb</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<section v-if="form.properties" class="item-section">
|
||||
<h2>{{ $t('campaigns.item.properties') }}</h2>
|
||||
<p class="item-copy">{{ form.properties }}</p>
|
||||
</section>
|
||||
|
||||
<section class="item-section">
|
||||
<h2>{{ $t('campaigns.fields.description') }}</h2>
|
||||
<p class="item-copy">{{ form.description || $t('campaigns.item.sheet.no-description') }}</p>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.item-window { min-width: 0; min-height: 0; }
|
||||
.item-body { width: 100%; min-height: 0; flex: 1; overflow: auto; padding: 14px 16px 16px; box-sizing: border-box; }
|
||||
.item-hero { display: flex; align-items: center; gap: 13px; padding: 2px 2px 13px; margin-bottom: 11px; border-bottom: 1px solid var(--color-border); }
|
||||
.item-icon { width: 64px; height: 64px; flex: 0 0 64px; display: grid; place-items: center; overflow: hidden; border-radius: 10px; border: 1px solid var(--color-border); background: var(--color-background-soft); color: var(--color-link); font: 30px MrEavesRemake; }
|
||||
.item-icon.empty { border-style: dashed; }
|
||||
.item-icon img { width: 100%; height: 100%; object-fit: contain; }
|
||||
.item-identity { min-width: 0; }
|
||||
.item-identity h1 { margin: 0 0 6px; font: 24px MrEavesRemake; overflow-wrap: anywhere; }
|
||||
.item-tags { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
|
||||
.item-tag { padding: 3px 9px; border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-background-soft); font-size: 12px; opacity: .9; }
|
||||
.item-tag.synced { font-size: 10px; letter-spacing: .04em; text-transform: uppercase; opacity: .6; }
|
||||
.item-error { padding: 7px 10px; margin-bottom: 10px; border-radius: 6px; color: var(--color-red); background: var(--color-background-soft); font-size: 12px; }
|
||||
.icon-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-bottom: 13px; }
|
||||
.sheet-button { border: 1px solid var(--color-border); border-radius: 7px; padding: 7px 12px; background: var(--color-background-soft); color: var(--color-text); cursor: pointer; white-space: nowrap; font-size: 13px; }
|
||||
.sheet-button:hover { background: var(--color-button-hover); }
|
||||
.sheet-button:disabled { opacity: .55; cursor: wait; }
|
||||
.photo-input { display: none; }
|
||||
.item-facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 13px; }
|
||||
.item-fact { flex: 1 1 120px; min-width: 0; padding: 9px 11px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); }
|
||||
.item-fact dt { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; opacity: .72; }
|
||||
.item-fact dd { margin: 3px 0 0; font: 17px MrEavesRemake; }
|
||||
.item-section { padding: 11px 13px; margin: 0 0 10px; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-light); }
|
||||
.item-section h2 { margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--color-border); font: 15px MrEavesRemake; letter-spacing: .03em; }
|
||||
.item-copy { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; opacity: .85; }
|
||||
</style>
|
||||
@@ -71,6 +71,12 @@ const defWindows = {
|
||||
close: () => ClearWindow({type: 'character_sheet'}),
|
||||
movable: true
|
||||
},
|
||||
item_sheet: {
|
||||
title: 'windows.item-sheet',
|
||||
component: () => import('~/components/windows/ItemSheetWindow.vue'),
|
||||
close: () => ClearWindow({type: 'item_sheet'}),
|
||||
movable: true
|
||||
},
|
||||
create_map: {
|
||||
title: 'windows.create-map',
|
||||
component: () => import('~/components/windows/CreateMapWindow.vue'),
|
||||
|
||||
@@ -62,6 +62,12 @@
|
||||
"new": "Objecte nou", "edit": "Edita l'objecte", "foundry-sync-note": "Els canvis en aquest objecte també s'apliquen al món del Foundry vinculat.",
|
||||
"category": "Categoria", "rarity": "Raresa", "quantity": "Quantitat",
|
||||
"quantity-short": "Quant.", "weight": "Pes (lb)", "properties": "Propietats", "properties-placeholder": "Per exemple, versàtil, subtil",
|
||||
"sheet": {
|
||||
"icon": "Icona de l'objecte", "choose-icon": "Tria la teva pròpia icona", "change-icon": "Canvia la icona",
|
||||
"uploading": "Pujant...", "upload-error": "No s'ha pogut pujar aquesta icona.",
|
||||
"foundry-icon": "Fes servir la icona del Foundry", "remove-icon": "Treu la icona", "save-error": "No s'ha pogut desar aquest objecte.",
|
||||
"no-description": "Sense descripció afegida."
|
||||
},
|
||||
"categories": {
|
||||
"weapon": "Arma", "armor": "Armadura", "shield": "Escut", "adventuring-gear": "Equip d'aventura",
|
||||
"magic-item": "Objecte màgic", "consumable": "Consumible", "tool": "Eina", "treasure": "Tresor", "other": "Altre"
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
"create-campaign": "Crear campanya",
|
||||
"create-map": "Crear mapa",
|
||||
"map-viewer": "Mapa",
|
||||
"pinned-note": "Nota fixada"
|
||||
"pinned-note": "Nota fixada",
|
||||
"item-sheet": "Objecte"
|
||||
}
|
||||
|
||||
@@ -66,6 +66,12 @@
|
||||
"new": "New item", "edit": "Edit item", "foundry-sync-note": "Changes to this item are also applied in the linked Foundry world.",
|
||||
"category": "Category", "rarity": "Rarity", "quantity": "Quantity",
|
||||
"quantity-short": "Qty", "weight": "Weight (lb)", "properties": "Properties", "properties-placeholder": "For example, versatile, finesse",
|
||||
"sheet": {
|
||||
"icon": "Item icon", "choose-icon": "Choose your own icon", "change-icon": "Change icon",
|
||||
"uploading": "Uploading...", "upload-error": "Unable to upload this icon.",
|
||||
"foundry-icon": "Use Foundry icon", "remove-icon": "Remove icon", "save-error": "Unable to save this item.",
|
||||
"no-description": "No description added."
|
||||
},
|
||||
"categories": {
|
||||
"weapon": "Weapon", "armor": "Armor", "shield": "Shield", "adventuring-gear": "Adventuring gear",
|
||||
"magic-item": "Magic item", "consumable": "Consumable", "tool": "Tool", "treasure": "Treasure", "other": "Other"
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
"create-campaign": "Create Campaign",
|
||||
"create-map": "Create Map",
|
||||
"map-viewer": "Map",
|
||||
"pinned-note": "Pinned note"
|
||||
"pinned-note": "Pinned note",
|
||||
"item-sheet": "Item"
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@
|
||||
"new": "Nuevo objeto", "edit": "Editar objeto", "foundry-sync-note": "Los cambios en este objeto también se aplican al mundo de Foundry vinculado.",
|
||||
"category": "Categoría", "rarity": "Rareza", "quantity": "Cantidad",
|
||||
"quantity-short": "Cant.", "weight": "Peso (lb)", "properties": "Propiedades", "properties-placeholder": "Por ejemplo, versátil, sutil",
|
||||
"sheet": {
|
||||
"icon": "Icono del objeto", "choose-icon": "Elegir tu propio icono", "change-icon": "Cambiar icono",
|
||||
"uploading": "Subiendo...", "upload-error": "No se pudo subir este icono.",
|
||||
"foundry-icon": "Usar el icono de Foundry", "remove-icon": "Quitar el icono", "save-error": "No se pudo guardar este objeto.",
|
||||
"no-description": "Sin descripción añadida."
|
||||
},
|
||||
"categories": {
|
||||
"weapon": "Arma", "armor": "Armadura", "shield": "Escudo", "adventuring-gear": "Equipo de aventura",
|
||||
"magic-item": "Objeto mágico", "consumable": "Consumible", "tool": "Herramienta", "treasure": "Tesoro", "other": "Otro"
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
"create-campaign": "Crear campanya",
|
||||
"create-map": "Crear mapa",
|
||||
"map-viewer": "Mapa",
|
||||
"pinned-note": "Nota fijada"
|
||||
"pinned-note": "Nota fijada",
|
||||
"item-sheet": "Objeto"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user