Foundry and discord bot
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m51s
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m51s
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import ContentManager from './components/managers/ContentManager.vue';
|
||||
import ToastManager from './components/managers/ToastManager.vue';
|
||||
import WindowManager from './components/managers/WindowManager.vue';
|
||||
import DiscordAuthorize from './components/views/DiscordAuthorize.vue';
|
||||
|
||||
import { CreateWindow } from '@/services/Windows'
|
||||
import { GetUser, HasAdmin } from './services/User';
|
||||
@@ -11,6 +12,11 @@ import { useCampaignService } from './services/Campaign';
|
||||
|
||||
const { RestoreCampaign } = useCampaignService();
|
||||
|
||||
// El bot de Discord enllaça amb aquesta pantalla; no és part de l'aplicació i no ha d'arrencar
|
||||
// les finestres normals.
|
||||
const requestUrl = useRequestURL();
|
||||
const isDiscordAuthorize = computed(() => requestUrl.pathname.replace(/\/+$/, '') === '/discord/authorize');
|
||||
|
||||
async function start(){
|
||||
if(GetUser()){
|
||||
const restoredCampaign = await RestoreCampaign();
|
||||
@@ -40,12 +46,15 @@ useHead({
|
||||
onMounted(() => {
|
||||
setupTheme();
|
||||
setTheme('dark');
|
||||
start();
|
||||
if(!isDiscordAuthorize.value){
|
||||
start();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="viewer">
|
||||
<DiscordAuthorize v-if="isDiscordAuthorize"></DiscordAuthorize>
|
||||
<div v-else class="viewer">
|
||||
<ToastManager></ToastManager>
|
||||
<TooltipManager></TooltipManager>
|
||||
<ContextMenuManager></ContextMenuManager>
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
<script setup>
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { AddSound } from '../../services/Sound';
|
||||
import { useCampaignService } from '~/services/Campaign';
|
||||
import { ClearWindow } from '~/services/Windows';
|
||||
import { ClearWindow, CreateChildWindow, GetFirstWindowId } from '~/services/Windows';
|
||||
const { SetCampaign } = useCampaignService();
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const data = props.data;
|
||||
|
||||
const title = ref("");
|
||||
const title = computed(() => data.name);
|
||||
const campaignStyle = computed(() => data.color
|
||||
? { background: `linear-gradient(90deg, ${data.color}, ${data.color}44)` }
|
||||
: {});
|
||||
|
||||
const container = ref(null);
|
||||
|
||||
onMounted(() => {
|
||||
title.value = data.name;
|
||||
if (data.color && container.value) {
|
||||
container.value.style.background = `linear-gradient(90deg, ${data.color}, ${data.color}44)`;
|
||||
}
|
||||
|
||||
AddSound(container.value)
|
||||
});
|
||||
|
||||
@@ -27,11 +25,16 @@ function ViewCampaign(){
|
||||
SetCampaign(data);
|
||||
ClearWindow({type: "main_menu"});
|
||||
}
|
||||
|
||||
function OpenSettings(){
|
||||
ClearWindow({type: 'campaign_settings'});
|
||||
CreateChildWindow(GetFirstWindowId('main_menu'), 'campaign_settings', { campaign: data });
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<template>
|
||||
<div class="campaign-entry-container" ref="container">
|
||||
<div class="campaign-entry-container" ref="container" :style="campaignStyle">
|
||||
<div class="main-campaign-entry-container-inner">
|
||||
<img class="campaign-icon" src="/img/def-avatar.jpg" draggable="false">
|
||||
<div class="campaign-info">
|
||||
@@ -39,6 +42,7 @@ function ViewCampaign(){
|
||||
</div>
|
||||
|
||||
<div class="campaign-user-actions">
|
||||
<button class="btn-primary button-small sound-click" v-on:click.prevent="OpenSettings">{{ $t('main-menu.settings') }}</button>
|
||||
<button class="btn-primary button-small sound-click" v-on:click.prevent="ViewCampaign">{{ $t('general.open')}}</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -81,5 +85,7 @@ function ViewCampaign(){
|
||||
|
||||
.campaign-user-actions {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,28 +1,43 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { useCampaignService } from '~/services/Campaign.js';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
import Server from '~/services/Server';
|
||||
import { CreateWindow } from '~/services/Windows';
|
||||
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
|
||||
import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu';
|
||||
import NestedNoteList from './NestedNoteList.vue';
|
||||
|
||||
const { Campaign } = useCampaignService();
|
||||
const { t } = useI18n();
|
||||
const notes = ref([]);
|
||||
const folders = ref([]);
|
||||
const actors = ref([]);
|
||||
const items = ref([]);
|
||||
const loadingNotes = ref(false);
|
||||
const loadingEntries = ref(false);
|
||||
const notesError = ref('');
|
||||
const entriesError = ref('');
|
||||
const sidebarCollapsed = ref(false);
|
||||
const activeSection = ref('notes');
|
||||
const isDragOverSidebar = ref(false);
|
||||
const expandedFolderIds = ref([]);
|
||||
const expandedEntryIds = ref([]);
|
||||
const nestedNoteListRef = ref(null);
|
||||
let actorRefreshInterval;
|
||||
|
||||
async function handleSidebarDrop(event) {
|
||||
if (activeSection.value !== 'notes') return;
|
||||
const noteKey = event.dataTransfer.getData('text/plain');
|
||||
if (!noteKey) return;
|
||||
try {
|
||||
await Server().post('/note/update', { id: noteKey, folder: null });
|
||||
fetchCampaignNotes();
|
||||
if (nestedNoteListRef.value) {
|
||||
nestedNoteListRef.value.clearCacheAndReloadExpanded();
|
||||
} else {
|
||||
fetchCampaignNotes();
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
@@ -58,7 +73,13 @@ function handleNoteCreated(note) {
|
||||
};
|
||||
|
||||
notes.value = notes.value.filter((currentNote) => currentNote.key !== createdNote.key);
|
||||
notes.value.unshift(createdNote);
|
||||
|
||||
// Notes created inside a folder are added by NestedNoteList's own cache handler
|
||||
const noteFolderId = note.folder?._id ?? note.folder ?? null;
|
||||
if (!noteFolderId) {
|
||||
notes.value.unshift(createdNote);
|
||||
}
|
||||
|
||||
openNote(createdNote);
|
||||
}
|
||||
|
||||
@@ -70,6 +91,32 @@ function handleNoteRenamed(data) {
|
||||
emitter.emit('title-updated', { key: data.key, title: data.title });
|
||||
}
|
||||
|
||||
function handleNoteDeleted(noteKey) {
|
||||
notes.value = notes.value.filter(n => n.key !== noteKey);
|
||||
}
|
||||
|
||||
function handleFolderSaved() {
|
||||
fetchCampaignNotes();
|
||||
}
|
||||
|
||||
function handleFolderDeleted(folderId) {
|
||||
expandedFolderIds.value = expandedFolderIds.value.filter((id) => id !== folderId);
|
||||
}
|
||||
|
||||
function handleCampaignEntryCreated({ entityType, entry }) {
|
||||
if (!entry || (entry.campaign && String(entry.campaign) !== String(campaignId.value))) return;
|
||||
const list = entityType === 'actor' ? actors : items;
|
||||
list.value = [...list.value.filter((current) => current._id !== entry._id), entry]
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
function handleCampaignEntryUpdated({ entityType, entry }) {
|
||||
if (!entry) return;
|
||||
const list = entityType === 'actor' ? actors : items;
|
||||
list.value = list.value.map((current) => current._id === entry._id ? entry : current)
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
|
||||
const campaignId = computed(() => {
|
||||
return Campaign.value?._id ?? Campaign.value?.id ?? null;
|
||||
});
|
||||
@@ -111,24 +158,97 @@ async function fetchCampaignNotes() {
|
||||
}
|
||||
}
|
||||
|
||||
async function createNote() {
|
||||
async function fetchCampaignEntries(entityType = activeSection.value, silent = false) {
|
||||
if (!campaignId.value || !['actors', 'items'].includes(entityType)) return;
|
||||
if (!silent) {
|
||||
loadingEntries.value = true;
|
||||
entriesError.value = '';
|
||||
}
|
||||
try {
|
||||
const collection = entityType === 'actors' ? 'actor' : 'item';
|
||||
const response = await Server().get(`/${collection}/list`, { params: { campaign: campaignId.value } });
|
||||
if (response.data.status !== 'ok') {
|
||||
if (!silent) entriesError.value = response.data.msg ?? t('campaigns.errors.load');
|
||||
return;
|
||||
}
|
||||
if (entityType === 'actors') {
|
||||
const previousById = new Map(actors.value.map((actor) => [actor._id, actor]));
|
||||
actors.value = response.data.actors;
|
||||
for (const actor of actors.value) {
|
||||
const previous = previousById.get(actor._id);
|
||||
if (previous && JSON.stringify(previous) !== JSON.stringify(actor)) {
|
||||
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: actor });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items.value = response.data.items;
|
||||
}
|
||||
} catch (error) {
|
||||
if (!silent) entriesError.value = t('campaigns.errors.load');
|
||||
} finally {
|
||||
if (!silent) loadingEntries.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function selectSection(section) {
|
||||
activeSection.value = section;
|
||||
if (section === 'actors' || section === 'items') fetchCampaignEntries(section);
|
||||
}
|
||||
|
||||
function createEntry(entityType) {
|
||||
if (!campaignId.value) return;
|
||||
CreateWindow('create_campaign_entry', { entityType, campaign: campaignId.value });
|
||||
}
|
||||
|
||||
function entrySummary(actor) {
|
||||
const bits = [t(`campaigns.actor.types.${actor.type}`)];
|
||||
if (actor.species) bits.push(actor.species);
|
||||
if (actor.className) bits.push(actor.className);
|
||||
if (actor.level) bits.push(`${t('campaigns.actor.level-short')} ${actor.level}`);
|
||||
if (actor.challengeRating) bits.push(`${t('campaigns.actor.cr-short')} ${actor.challengeRating}`);
|
||||
return bits.join(' · ');
|
||||
}
|
||||
|
||||
function itemSummary(item) {
|
||||
return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`;
|
||||
}
|
||||
|
||||
function showEntryMenu(entry, entityType) {
|
||||
const collection = entityType === 'actor' ? 'actor' : 'item';
|
||||
ShowContextMenu([{
|
||||
name: t('campaigns.actions.delete'),
|
||||
icon: '/icons/iconoir/regular/trash.svg',
|
||||
action: async () => {
|
||||
try {
|
||||
const response = await Server().post(`/${collection}/delete`, { id: entry._id });
|
||||
if (response.data.status === 'ok') {
|
||||
if (entityType === 'actor') actors.value = actors.value.filter((actor) => actor._id !== entry._id);
|
||||
else items.value = items.value.filter((item) => item._id !== entry._id);
|
||||
}
|
||||
} catch (error) {} finally { HideContextMenu(); }
|
||||
}
|
||||
}]);
|
||||
}
|
||||
|
||||
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) {
|
||||
ClearWindow({ id: existingWindowId });
|
||||
await nextTick();
|
||||
}
|
||||
CreateWindow('character_sheet', { actor });
|
||||
}
|
||||
|
||||
function createNote() {
|
||||
if (!Campaign.value) return;
|
||||
|
||||
const cid = Campaign.value?._id;
|
||||
|
||||
try {
|
||||
const response = await Server().post('/note/create', {
|
||||
title: 'New note',
|
||||
content: '',
|
||||
campaign: cid
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok') return;
|
||||
|
||||
emitter.emit('note-created', response.data.note);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
CreateWindow('new_note', { campaign: campaignId.value });
|
||||
}
|
||||
|
||||
function createFolder() {
|
||||
@@ -143,18 +263,46 @@ const rootNotes = computed(() => notes.value.filter(n => !n._folder));
|
||||
|
||||
watch(campaignId, (newVal) => {
|
||||
if (newVal) {
|
||||
actors.value = [];
|
||||
items.value = [];
|
||||
fetchCampaignNotes();
|
||||
if (activeSection.value === 'actors' || activeSection.value === 'items') fetchCampaignEntries(activeSection.value);
|
||||
} else {
|
||||
notes.value = [];
|
||||
folders.value = [];
|
||||
actors.value = [];
|
||||
items.value = [];
|
||||
notesError.value = '';
|
||||
entriesError.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
emitter.on('note-created', handleNoteCreated);
|
||||
emitter.on('note-renamed', handleNoteRenamed);
|
||||
emitter.on('delete-note', handleNoteDeleted);
|
||||
emitter.on('folder-saved', handleFolderSaved);
|
||||
emitter.on('folder-deleted', handleFolderDeleted);
|
||||
emitter.on('campaign-entry-created', handleCampaignEntryCreated);
|
||||
emitter.on('campaign-entry-updated', handleCampaignEntryUpdated);
|
||||
|
||||
if (campaignId.value) {
|
||||
fetchCampaignNotes();
|
||||
}
|
||||
actorRefreshInterval = setInterval(() => {
|
||||
if (activeSection.value === 'actors' && campaignId.value) fetchCampaignEntries('actors', true);
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearInterval(actorRefreshInterval);
|
||||
emitter.off('note-created', handleNoteCreated);
|
||||
emitter.off('note-renamed', handleNoteRenamed);
|
||||
emitter.off('delete-note', handleNoteDeleted);
|
||||
emitter.off('folder-saved', handleFolderSaved);
|
||||
emitter.off('folder-deleted', handleFolderDeleted);
|
||||
emitter.off('campaign-entry-created', handleCampaignEntryCreated);
|
||||
emitter.off('campaign-entry-updated', handleCampaignEntryUpdated);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -166,9 +314,9 @@ onMounted(() => {
|
||||
type="button"
|
||||
@click="toggleSidebar"
|
||||
:aria-expanded="(!sidebarCollapsed).toString()"
|
||||
aria-controls="campaign-notes-list"
|
||||
:title="sidebarCollapsed ? 'Expand notes' : 'Collapse notes'"
|
||||
:aria-label="sidebarCollapsed ? 'Expand notes' : 'Collapse notes'"
|
||||
aria-controls="campaign-section-list"
|
||||
:title="sidebarCollapsed ? t('campaigns.actions.expand-sidebar') : t('campaigns.actions.collapse-sidebar')"
|
||||
:aria-label="sidebarCollapsed ? t('campaigns.actions.expand-sidebar') : t('campaigns.actions.collapse-sidebar')"
|
||||
>
|
||||
<img
|
||||
class="sidebar-action-icon"
|
||||
@@ -180,72 +328,100 @@ onMounted(() => {
|
||||
|
||||
<button
|
||||
class="sidebar-action"
|
||||
type="button"
|
||||
@click="createNote"
|
||||
:disabled="!Campaign"
|
||||
title="New note"
|
||||
aria-label="New note"
|
||||
:class="{ selected: activeSection === 'notes' }"
|
||||
type="button" @click="selectSection('notes')"
|
||||
:title="t('campaigns.sections.notes')" :aria-label="t('campaigns.sections.notes')"
|
||||
:aria-pressed="(activeSection === 'notes').toString()"
|
||||
>
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/book.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="sidebar-action"
|
||||
type="button"
|
||||
@click="createFolder"
|
||||
:disabled="!Campaign"
|
||||
title="New folder"
|
||||
aria-label="New folder"
|
||||
:class="{ selected: activeSection === 'actors' }"
|
||||
type="button" @click="selectSection('actors')"
|
||||
:title="t('campaigns.sections.actors')" :aria-label="t('campaigns.sections.actors')"
|
||||
:aria-pressed="(activeSection === 'actors').toString()"
|
||||
>
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/folder.svg" alt="" aria-hidden="true">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/user.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="sidebar-action"
|
||||
type="button"
|
||||
@click="fetchCampaignNotes"
|
||||
:disabled="!Campaign || loadingNotes"
|
||||
title="Refresh notes"
|
||||
aria-label="Refresh notes"
|
||||
:class="{ selected: activeSection === 'items' }"
|
||||
type="button" @click="selectSection('items')"
|
||||
:title="t('campaigns.sections.items')" :aria-label="t('campaigns.sections.items')"
|
||||
:aria-pressed="(activeSection === 'items').toString()"
|
||||
>
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/box.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<aside class="notes-sidebar" :class="{ collapsed: sidebarCollapsed }">
|
||||
<div class="sidebar-header">
|
||||
<div class="sidebar-copy">
|
||||
<span class="sidebar-eyebrow">Campaign</span>
|
||||
<strong class="sidebar-title">Notes</strong>
|
||||
<span class="sidebar-eyebrow">{{ t('campaigns.sidebar-label') }}</span>
|
||||
<strong class="sidebar-title">{{ t(`campaigns.sections.${activeSection}`) }}</strong>
|
||||
</div>
|
||||
<div class="sidebar-header-actions">
|
||||
<template v-if="activeSection === 'notes'">
|
||||
<button class="sidebar-action" type="button" @click="createNote" :disabled="!Campaign" :title="t('campaigns.actions.new-note')" :aria-label="t('campaigns.actions.new-note')">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
<button class="sidebar-action" type="button" @click="createFolder" :disabled="!Campaign" :title="t('campaigns.actions.new-folder')" :aria-label="t('campaigns.actions.new-folder')">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/folder.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
<button class="sidebar-action" type="button" @click="fetchCampaignNotes" :disabled="!Campaign || loadingNotes" :title="t('campaigns.actions.refresh')" :aria-label="t('campaigns.actions.refresh')">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<button class="sidebar-action" type="button" @click="createEntry(activeSection === 'actors' ? 'actor' : 'item')" :disabled="!Campaign" :title="t('campaigns.actions.create', { section: t(`campaigns.sections.${activeSection}`).toLowerCase() })" :aria-label="t('campaigns.actions.create', { section: t(`campaigns.sections.${activeSection}`).toLowerCase() })">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
<button class="sidebar-action" type="button" @click="fetchCampaignEntries(activeSection)" :disabled="!Campaign || loadingEntries" :title="t('campaigns.actions.refresh')" :aria-label="t('campaigns.actions.refresh')">
|
||||
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sidebar-list-drop-wrap" :class="{ 'drag-over': isDragOverSidebar }" id="campaign-notes-list" @dragenter.self="isDragOverSidebar = true" @dragleave.self="isDragOverSidebar = false" @dragover.prevent @drop.stop="handleSidebarDrop">
|
||||
<div v-if="loadingNotes" class="sidebar-state">
|
||||
Loading notes...
|
||||
</div>
|
||||
<div class="sidebar-list-drop-wrap" :class="{ 'drag-over': activeSection === 'notes' && isDragOverSidebar }" id="campaign-section-list" @dragenter.self="isDragOverSidebar = true" @dragleave.self="isDragOverSidebar = false" @dragover.prevent @drop.stop="handleSidebarDrop">
|
||||
<template v-if="activeSection === 'notes'">
|
||||
<div v-if="loadingNotes" class="sidebar-state">{{ t('campaigns.states.loading-notes') }}</div>
|
||||
<div v-else-if="notesError" class="sidebar-state error">{{ notesError }}</div>
|
||||
<div v-else-if="folders.length === 0 && notes.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-notes') }}</div>
|
||||
<NestedNoteList v-else ref="nestedNoteListRef"
|
||||
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :campaign-id="campaignId"
|
||||
:expanded-folder-ids="expandedFolderIds" @open-note="openNote"
|
||||
@reload-notes="fetchCampaignNotes" @toggle-expanded-folder="toggleExpandedFolder" />
|
||||
</template>
|
||||
|
||||
<div v-else-if="notesError" class="sidebar-state error">
|
||||
{{ notesError }}
|
||||
</div>
|
||||
<template v-else-if="activeSection === 'actors'">
|
||||
<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="actors.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-actors') }}</div>
|
||||
<div v-for="actor in actors" :key="actor._id" class="entity-entry" role="button" tabindex="0" @click="openCharacterSheet(actor)" @keydown.enter="openCharacterSheet(actor)" @keydown.space.prevent="openCharacterSheet(actor)" @contextmenu.prevent="showEntryMenu(actor, 'actor')">
|
||||
<span class="entity-entry-name">{{ actor.name }}</span>
|
||||
<span class="entity-entry-meta">{{ entrySummary(actor) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-else-if="folders.length === 0 && notes.length === 0" class="sidebar-state">
|
||||
No notes in this campaign yet.
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<NestedNoteList ref="nestedNoteListRef"
|
||||
:parent-folder-id="null"
|
||||
:folders="folders"
|
||||
:notes="rootNotes"
|
||||
:campaign-id="campaignId"
|
||||
:expanded-folder-ids="expandedFolderIds"
|
||||
@open-note="openNote"
|
||||
@reload-notes="fetchCampaignNotes"
|
||||
@toggle-expanded-folder="toggleExpandedFolder"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
<template v-else>
|
||||
<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')">
|
||||
<span class="entity-entry-name">{{ item.name }}</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>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
@@ -258,8 +434,8 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
.sidebar-actions {
|
||||
width: 32px;
|
||||
min-width: 32px;
|
||||
width: 46px;
|
||||
min-width: 46px;
|
||||
padding: 8px 6px;
|
||||
border-right: 1px solid var(--color-border);
|
||||
background-color: var(--color-background-light);
|
||||
@@ -284,6 +460,11 @@ onMounted(() => {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.sidebar-action.selected {
|
||||
background: var(--color-button-hover);
|
||||
border-color: var(--color-link);
|
||||
}
|
||||
|
||||
.sidebar-action:hover {
|
||||
background: var(--color-button-hover);
|
||||
}
|
||||
@@ -322,11 +503,16 @@ onMounted(() => {
|
||||
box-sizing: border-box;
|
||||
padding: 12px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.sidebar-header-actions { display: flex; align-items: center; gap: 4px; }
|
||||
.sidebar-header-actions .sidebar-action { width: 30px; height: 30px; }
|
||||
.sidebar-header-actions .sidebar-action-icon { width: 16px; height: 16px; }
|
||||
|
||||
.sidebar-copy {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -374,6 +560,17 @@ onMounted(() => {
|
||||
color: #9e2a2b;
|
||||
}
|
||||
|
||||
.entity-entry {
|
||||
width: 100%; padding: 9px 10px; border: 1px solid transparent; border-radius: 8px;
|
||||
background: transparent; color: var(--color-text); text-align: left; display: flex; flex-direction: column;
|
||||
gap: 3px; cursor: pointer;
|
||||
}
|
||||
.entity-entry:hover { border-color: var(--color-border); background: var(--color-background-soft); }
|
||||
.entity-entry:focus-visible { outline: 1px solid var(--color-link); }
|
||||
.entity-entry-name { font-weight: bold; }
|
||||
.entity-entry-meta, .entity-entry-description { font-size: 12px; opacity: 0.72; }
|
||||
.entity-entry-description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.notes-sidebar {
|
||||
width: 220px;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
import { ref, onBeforeUnmount, onMounted, watch } from 'vue';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
import Server from '~/services/Server';
|
||||
import { CreateWindow } from '~/services/Windows';
|
||||
@@ -40,8 +40,54 @@ watch(
|
||||
|
||||
onMounted(() => {
|
||||
loadExpandedFolders();
|
||||
emitter.on('note-created', handleNoteCreated);
|
||||
emitter.on('note-renamed', handleNoteRenamed);
|
||||
emitter.on('delete-note', handleNoteDeleted);
|
||||
emitter.on('folder-saved', handleFolderSaved);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
emitter.off('note-created', handleNoteCreated);
|
||||
emitter.off('note-renamed', handleNoteRenamed);
|
||||
emitter.off('delete-note', handleNoteDeleted);
|
||||
emitter.off('folder-saved', handleFolderSaved);
|
||||
});
|
||||
|
||||
// Keep this instance's folder content cache in sync with changes made anywhere in the app.
|
||||
// The cache entry for a folder only lives on the instance that renders it, so every
|
||||
// instance listens and updates whichever entries it owns.
|
||||
function handleNoteCreated(note) {
|
||||
if (!note) return;
|
||||
const folderId = note.folder?._id ?? note.folder ?? null;
|
||||
const entry = folderId ? folderContentCache.value[folderId] : null;
|
||||
if (entry) {
|
||||
entry.notes.unshift({ key: note._id, title: note.title, text: note.content || '' });
|
||||
}
|
||||
}
|
||||
|
||||
function handleNoteRenamed(data) {
|
||||
if (!data) return;
|
||||
for (const entry of Object.values(folderContentCache.value)) {
|
||||
const note = entry.notes.find((n) => n.key === data.key);
|
||||
if (note) note.title = data.title;
|
||||
}
|
||||
}
|
||||
|
||||
function handleNoteDeleted(noteKey) {
|
||||
for (const entry of Object.values(folderContentCache.value)) {
|
||||
entry.notes = entry.notes.filter((n) => n.key !== noteKey);
|
||||
}
|
||||
}
|
||||
|
||||
function handleFolderSaved(folder) {
|
||||
const folderId = folder?._id ?? folder?.id;
|
||||
if (!folderId) return;
|
||||
for (const entry of Object.values(folderContentCache.value)) {
|
||||
const subfolder = entry.subfolders.find((f) => (f._id ?? f.id) === folderId);
|
||||
if (subfolder) subfolder.name = folder.name;
|
||||
}
|
||||
}
|
||||
|
||||
function loadFolderContents(folderId) {
|
||||
if (loadingFolders.has(folderId)) return;
|
||||
loadingFolders.add(folderId);
|
||||
@@ -86,7 +132,7 @@ async function handleDropNoteOnFolder(folderId, event) {
|
||||
|
||||
try {
|
||||
await Server().post('/note/update', { id: noteKey, folder: folderId });
|
||||
emit('reload-notes');
|
||||
clearCacheAndReloadExpanded();
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
@@ -98,29 +144,23 @@ async function handleDropNoteOnRoot(event) {
|
||||
|
||||
try {
|
||||
await Server().post('/note/update', { id: noteKey, folder: null });
|
||||
emit('reload-notes');
|
||||
clearCacheAndReloadExpanded();
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// Called on reload — clears cache so expanded folders refetch fresh content
|
||||
// Called on reload — clears cache and refetches what this instance is responsible for,
|
||||
// then bubbles the reload up so ancestors (and eventually the sidebar) refresh too
|
||||
function clearCacheAndReloadExpanded() {
|
||||
const folderIdsToReLoad = [];
|
||||
if (props.level === 0) {
|
||||
for (const id of props.expandedFolderIds) {
|
||||
if (folderContentCache.value[id]) folderIdsToReLoad.push(id);
|
||||
delete folderContentCache.value[id];
|
||||
}
|
||||
} else if (props.parentFolderId && folderContentCache.value[props.parentFolderId]) {
|
||||
folderIdsToReLoad.push(props.parentFolderId);
|
||||
delete folderContentCache.value[props.parentFolderId];
|
||||
}
|
||||
const loadedIds = Object.keys(folderContentCache.value);
|
||||
|
||||
// Force reactivity by creating a new object
|
||||
folderContentCache.value = {};
|
||||
|
||||
for (const id of folderIdsToReLoad) {
|
||||
for (const id of loadedIds) {
|
||||
loadFolderContents(id);
|
||||
}
|
||||
|
||||
emit('reload-notes');
|
||||
}
|
||||
|
||||
// Exposed to parent components
|
||||
@@ -180,7 +220,7 @@ function renameNote(note) { CreateWindow('rename_note', { title: note.title, key
|
||||
async function deleteNote(note) {
|
||||
try {
|
||||
const response = await Server().post('/note/delete', { id: note.key });
|
||||
if (response.data.status === 'ok') { emit('reload-notes'); emitter.emit('delete-note', note.key); }
|
||||
if (response.data.status === 'ok') emitter.emit('delete-note', note.key);
|
||||
} catch (error) {} finally {
|
||||
HideContextMenu();
|
||||
}
|
||||
@@ -190,7 +230,10 @@ function renameFolder(folderId, name) { CreateWindow('new_folder', { folderId, c
|
||||
|
||||
async function deleteFolder(folderId) {
|
||||
const response = await Server().post('/folder/delete', { id: folderId });
|
||||
if (response.data.status === 'ok') emit('reload-notes');
|
||||
if (response.data.status === 'ok') {
|
||||
emitter.emit('folder-deleted', folderId);
|
||||
clearCacheAndReloadExpanded();
|
||||
}
|
||||
HideContextMenu();
|
||||
}
|
||||
|
||||
@@ -198,16 +241,13 @@ async function moveNoteToFolder(note, folderId) {
|
||||
try {
|
||||
const response = await Server().post('/note/update', { id: note.key, folder: folderId || null });
|
||||
if (response.data.status !== 'ok') return;
|
||||
emit('reload-notes');
|
||||
clearCacheAndReloadExpanded();
|
||||
} catch (e) {}
|
||||
HideContextMenu();
|
||||
}
|
||||
|
||||
async function createNoteInFolder(folderId) {
|
||||
try {
|
||||
const response = await Server().post('/note/create', { title: 'New note', content: '', campaign: props.campaignId, folder: folderId });
|
||||
if (response.data.status === 'ok') emit('reload-notes');
|
||||
} catch (e) {}
|
||||
function createNoteInFolder(folderId) {
|
||||
CreateWindow('new_note', { campaign: props.campaignId, folder: folderId });
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -251,10 +291,6 @@ async function createNoteInFolder(folderId) {
|
||||
@reload-notes="clearCacheAndReloadExpanded"
|
||||
@toggle-expanded-folder="toggleExpanded"
|
||||
/>
|
||||
|
||||
<div v-if="expandedFolderIds.includes(folder._id) && folderContentCache[folder._id] !== undefined && (getFolderNotes(folder._id).length === 0 && getFolderSubfolders(folder._id).length === 0)" class="sidebar-state">
|
||||
Empty folder
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
<script setup>
|
||||
import TopSearchBar from './topbar/TopSearchBar.vue';
|
||||
import { useCampaignService } from '~/services/Campaign.js';
|
||||
import { ClearWindow, CreateWindow } from '~/services/Windows';
|
||||
|
||||
const campaignName = computed(() => {
|
||||
return 'Campaign';
|
||||
});
|
||||
const { Campaign } = useCampaignService();
|
||||
const campaignName = computed(() => Campaign.value?.name || 'Campaign');
|
||||
|
||||
function OpenCampaignSettings() {
|
||||
if (!Campaign.value) return;
|
||||
ClearWindow({ type: 'campaign_settings' });
|
||||
CreateWindow('campaign_settings', { campaign: Campaign.value });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -18,7 +24,11 @@ const campaignName = computed(() => {
|
||||
<div class="center">
|
||||
<TopSearchBar></TopSearchBar>
|
||||
</div>
|
||||
<div class="right"></div>
|
||||
<div class="right">
|
||||
<button class="btn-primary settings-button sound-click" type="button" @click="OpenCampaignSettings">
|
||||
{{ $t('main-menu.settings') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -40,16 +50,25 @@ const campaignName = computed(() => {
|
||||
left: 6px;
|
||||
}
|
||||
|
||||
.left, .right {
|
||||
.left {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding-right: 10px;
|
||||
justify-content: flex-end;
|
||||
flex: 1;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.settings-button {
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.top-bar-title {
|
||||
|
||||
@@ -5,6 +5,7 @@ import PlusIcon from 'pixelarticons/svg/plus.svg'
|
||||
import NoteSearchResult from './SearchResult.vue';
|
||||
import Server from '~/services/Server';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
import { CreateWindow } from '~/services/Windows';
|
||||
import { register, search as searchActions, execute as executeAction } from '~/services/ActionRegistry';
|
||||
import { useCampaignService } from '~/services/Campaign.js';
|
||||
|
||||
@@ -41,20 +42,10 @@ function registerCreateNoteAction() {
|
||||
id: 'create_note',
|
||||
label: 'New note',
|
||||
description: 'Create a new note in the current campaign',
|
||||
execute: async () => {
|
||||
execute: () => {
|
||||
if (!Campaign.value) return;
|
||||
const campaignId = Campaign.value?._id ?? Campaign.value?.id;
|
||||
try {
|
||||
const response = await Server().post('/note/create', {
|
||||
title: 'New note',
|
||||
content: '',
|
||||
campaign: campaignId
|
||||
});
|
||||
if (response.data.status !== 'ok') return;
|
||||
emitter.emit('note-created', response.data.note);
|
||||
} catch (err) {
|
||||
console.error('[ActionRegistry] Failed to create note:', err);
|
||||
}
|
||||
CreateWindow('new_note', { campaign: campaignId });
|
||||
}
|
||||
};
|
||||
register(action);
|
||||
|
||||
260
frontend/app/components/views/DiscordAuthorize.vue
Normal file
260
frontend/app/components/views/DiscordAuthorize.vue
Normal file
@@ -0,0 +1,260 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import Server from '~/services/Server';
|
||||
import { GetUser, SetUser } from '~/services/User';
|
||||
import { AddSound } from '~/services/Sound';
|
||||
import Spinner from '../partials/Spinner.vue';
|
||||
|
||||
// Pantalla autònoma que el bot obre des de Discord: l'usuari s'identifica aquí
|
||||
// i autoritza el servidor de Discord que s'ha rebut per la URL.
|
||||
useHead({ title: 'Connect Dragonroll to Discord' });
|
||||
|
||||
const card = ref(null);
|
||||
|
||||
const code = ref('');
|
||||
const guildName = ref('');
|
||||
const discordUserName = ref('');
|
||||
const signedInAs = ref('');
|
||||
const connectedGuild = ref('');
|
||||
|
||||
// 'checking' | 'login' | 'approve' | 'connected' | 'error'
|
||||
const status = ref('checking');
|
||||
const messageKey = ref('');
|
||||
|
||||
const username = ref('');
|
||||
const password = ref('');
|
||||
const busy = ref(false);
|
||||
|
||||
function readCode() {
|
||||
const hash = new URLSearchParams(window.location.hash.slice(1));
|
||||
const search = new URLSearchParams(window.location.search);
|
||||
return hash.get('code') || search.get('code') || '';
|
||||
}
|
||||
|
||||
function ShowError(key) {
|
||||
messageKey.value = key;
|
||||
}
|
||||
|
||||
function PrepareApproval() {
|
||||
const user = GetUser();
|
||||
if (!user) {
|
||||
status.value = 'login';
|
||||
messageKey.value = '';
|
||||
return;
|
||||
}
|
||||
signedInAs.value = user.username || user.name || user.email || 'Dragonroll';
|
||||
status.value = 'approve';
|
||||
messageKey.value = '';
|
||||
}
|
||||
|
||||
async function LoadRequest() {
|
||||
const response = await Server().post('/discord/link/details', { code: code.value });
|
||||
const details = response.data;
|
||||
if (details.status !== 'ok') {
|
||||
status.value = 'error';
|
||||
ShowError('discord.errors.link-expired');
|
||||
return;
|
||||
}
|
||||
|
||||
guildName.value = details.guildName;
|
||||
discordUserName.value = details.discordUserName;
|
||||
PrepareApproval();
|
||||
}
|
||||
|
||||
async function SignIn() {
|
||||
busy.value = true;
|
||||
messageKey.value = '';
|
||||
try {
|
||||
const response = await Server().post('/user/login', {
|
||||
usermail: username.value,
|
||||
password: password.value
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok' || !response.data.token) {
|
||||
ShowError(response.data.msg || 'discord.errors.sign-in-failed');
|
||||
return;
|
||||
}
|
||||
|
||||
// El token passa al servei d'usuari perquè el client el reutilitzi en autoritzar.
|
||||
SetUser(response.data.token);
|
||||
password.value = '';
|
||||
PrepareApproval();
|
||||
} catch {
|
||||
ShowError('discord.errors.sign-in-failed');
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function Authorize() {
|
||||
busy.value = true;
|
||||
try {
|
||||
const response = await Server().post('/discord/link/complete', { code: code.value });
|
||||
|
||||
if (response.data.status !== 'ok') {
|
||||
status.value = 'error';
|
||||
ShowError('discord.errors.link-expired');
|
||||
return;
|
||||
}
|
||||
|
||||
connectedGuild.value = response.data.guildName;
|
||||
status.value = 'connected';
|
||||
messageKey.value = '';
|
||||
// El codi ja s'ha fet servir, treu-lo de la barra d'adreces.
|
||||
window.history.replaceState(null, '', window.location.pathname);
|
||||
} catch (error) {
|
||||
if (error?.response?.status === 401) {
|
||||
status.value = 'login';
|
||||
ShowError('discord.errors.session-expired');
|
||||
return;
|
||||
}
|
||||
status.value = 'error';
|
||||
ShowError('discord.errors.link-expired');
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
AddSound(card.value);
|
||||
code.value = readCode();
|
||||
|
||||
if (!code.value) {
|
||||
status.value = 'error';
|
||||
ShowError('discord.errors.missing-code');
|
||||
return;
|
||||
}
|
||||
|
||||
LoadRequest().catch(() => {
|
||||
status.value = 'error';
|
||||
ShowError('discord.errors.internal');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="discord-authorize">
|
||||
<main class="authorize-card" ref="card">
|
||||
<h1>{{ $t('discord.title') }}</h1>
|
||||
|
||||
<p v-if="guildName" class="summary">
|
||||
{{ $t('discord.summary', { guild: guildName, user: discordUserName }) }}
|
||||
</p>
|
||||
<p v-else-if="status !== 'error'" class="summary">
|
||||
<Spinner v-if="status === 'checking'"></Spinner>
|
||||
<span v-else>{{ $t('discord.checking') }}</span>
|
||||
</p>
|
||||
|
||||
<form v-if="status === 'login'" v-on:submit.prevent="SignIn">
|
||||
<p>{{ $t('discord.sign-in-lead') }}</p>
|
||||
<div class="form-field">
|
||||
<label for="discord-authorize-usermail">{{ $t('login.username') }}</label>
|
||||
<input
|
||||
id="discord-authorize-usermail"
|
||||
type="text"
|
||||
:placeholder="$t('login.username-placeholder')"
|
||||
name="usermail"
|
||||
autocomplete="username"
|
||||
v-model="username"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label for="discord-authorize-password">{{ $t('login.password') }}</label>
|
||||
<input
|
||||
id="discord-authorize-password"
|
||||
type="password"
|
||||
name="password"
|
||||
autocomplete="current-password"
|
||||
v-model="password"
|
||||
required
|
||||
>
|
||||
</div>
|
||||
<button class="btn-primary sound-click" type="submit" :disabled="busy">
|
||||
<Spinner v-if="busy"></Spinner>
|
||||
<span v-else>{{ $t('login.log-in') }}</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<section v-if="status === 'approve'">
|
||||
<p>{{ $t('discord.signed-in-as', { user: signedInAs }) }}</p>
|
||||
<p class="hint">{{ $t('discord.next-step') }}</p>
|
||||
<p class="hint">{{ $t('discord.replace-warning') }}</p>
|
||||
<button class="btn-primary sound-click" type="button" :disabled="busy" v-on:click="Authorize">
|
||||
<Spinner v-if="busy"></Spinner>
|
||||
<span v-else>{{ $t('discord.approve') }}</span>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section v-if="status === 'connected'">
|
||||
<p class="success">{{ $t('discord.connected', { guild: connectedGuild }) }}</p>
|
||||
<p class="hint">{{ $t('discord.next-step') }}</p>
|
||||
</section>
|
||||
|
||||
<p v-if="messageKey" class="error" role="status">
|
||||
{{ $t(messageKey) }}
|
||||
</p>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.discord-authorize {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
padding: 24px;
|
||||
box-sizing: border-box;
|
||||
background-color: var(--color-background);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.authorize-card {
|
||||
width: min(100%, 460px);
|
||||
padding: 28px;
|
||||
box-sizing: border-box;
|
||||
background-color: var(--color-window-background);
|
||||
border: 1px solid var(--color-window-border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 24px var(--color-window-shadow);
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.authorize-card h1 {
|
||||
margin-top: 0;
|
||||
font-family: 'MrEavesRemake', serif;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.authorize-card p {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.summary {
|
||||
color: var(--color-gray);
|
||||
}
|
||||
|
||||
form,
|
||||
section {
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: var(--color-gray);
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: var(--color-green);
|
||||
}
|
||||
|
||||
.error {
|
||||
color: var(--color-red);
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
356
frontend/app/components/windows/CampaignSettingsWindow.vue
Normal file
356
frontend/app/components/windows/CampaignSettingsWindow.vue
Normal file
@@ -0,0 +1,356 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import WindowHandle from './partials/WindowHandle.vue';
|
||||
import Tabs from '../layouts/Tabs.vue';
|
||||
import { SetupHandle, SetSize, ResetPosition, Top, SetResizable, SetMinSize } from '@/services/Windows';
|
||||
import Server from '~/services/Server';
|
||||
import { DisplayToast } from '~/services/Toaster';
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const data = props.data;
|
||||
const campaign = data.campaign;
|
||||
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
const saving = ref(false);
|
||||
const name = ref(campaign.name || '');
|
||||
const color = ref(campaign.color || '#6b6b6b');
|
||||
const settings = ref(campaign.settings && typeof campaign.settings === 'object' ? campaign.settings : {});
|
||||
const foundryUrl = ref(settings.value.integrations?.foundryUrl || '');
|
||||
const pairingCode = ref('');
|
||||
const requestId = ref('');
|
||||
const linking = ref(false);
|
||||
const id = data.id;
|
||||
let statusPoll;
|
||||
let checkingStatus = false;
|
||||
|
||||
const rows = [
|
||||
{ id: 'basic', value: 'campaigns.settings.tabs.basic' },
|
||||
{ id: 'integrations', value: 'campaigns.settings.tabs.integrations' }
|
||||
];
|
||||
|
||||
onMounted(() => {
|
||||
Top(wrapper);
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, { width: 560, height: 430 });
|
||||
ResetPosition(id, 'center');
|
||||
SetResizable(id, true);
|
||||
SetMinSize(id, { width: 440, height: 340 });
|
||||
ResumePendingFoundryLink();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearInterval(statusPoll);
|
||||
});
|
||||
|
||||
function ApplyCampaignUpdate(updatedCampaign) {
|
||||
Object.assign(campaign, updatedCampaign);
|
||||
settings.value = updatedCampaign.settings || {};
|
||||
foundryUrl.value = settings.value.integrations?.foundryUrl || foundryUrl.value;
|
||||
}
|
||||
|
||||
function validFoundryUrl(value) {
|
||||
if (!value.trim()) return true;
|
||||
try {
|
||||
const url = new URL(value.trim());
|
||||
return url.protocol === 'http:' || url.protocol === 'https:';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function SaveSettings() {
|
||||
if (!name.value.trim()) {
|
||||
DisplayToast('red', $t('campaigns.settings.errors.name-required'), 3000);
|
||||
return;
|
||||
}
|
||||
if (!validFoundryUrl(foundryUrl.value)) {
|
||||
DisplayToast('red', $t('campaigns.settings.errors.invalid-foundry-url'), 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
const updatedSettings = {
|
||||
...settings.value,
|
||||
integrations: {
|
||||
...(settings.value.integrations || {}),
|
||||
foundryUrl: foundryUrl.value.trim()
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await Server().post('/campaign/update', {
|
||||
id: campaign._id,
|
||||
name: name.value.trim(),
|
||||
color: color.value,
|
||||
settings: updatedSettings
|
||||
});
|
||||
|
||||
if (response.data.status !== 'ok') {
|
||||
DisplayToast('red', $t(response.data.msg || 'errors.internal'), 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyCampaignUpdate(response.data.campaign);
|
||||
DisplayToast('green', $t('campaigns.settings.saved'), 3000);
|
||||
} catch {
|
||||
DisplayToast('red', $t('errors.internal'), 3000);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function StartFoundryLink() {
|
||||
linking.value = true;
|
||||
try {
|
||||
const response = await Server().post('/campaign/foundry-link/start', { campaignId: campaign._id });
|
||||
if (response.data.status !== 'ok') {
|
||||
DisplayToast('red', $t(response.data.msg || 'errors.internal'), 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
pairingCode.value = response.data.code;
|
||||
requestId.value = response.data.requestId;
|
||||
clearInterval(statusPoll);
|
||||
statusPoll = setInterval(CheckFoundryLinkStatus, 2500);
|
||||
} catch {
|
||||
DisplayToast('red', $t('errors.internal'), 3000);
|
||||
} finally {
|
||||
linking.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// The pairing code lives server-side until it expires, so re-attach to it when
|
||||
// the window opens again after a reload, restart or closing the window.
|
||||
async function ResumePendingFoundryLink() {
|
||||
try {
|
||||
const response = await Server().get(`/campaign/foundry-link/pending?campaignId=${campaign._id}`);
|
||||
if (response.data.status !== 'ok' || !response.data.request) return;
|
||||
|
||||
pairingCode.value = response.data.request.code || '';
|
||||
requestId.value = response.data.request.requestId;
|
||||
clearInterval(statusPoll);
|
||||
statusPoll = setInterval(CheckFoundryLinkStatus, 2500);
|
||||
} catch {
|
||||
// Showing the stored pairing code is best-effort; ignore resume failures.
|
||||
}
|
||||
}
|
||||
|
||||
async function CheckFoundryLinkStatus() {
|
||||
if (!requestId.value || checkingStatus) return;
|
||||
checkingStatus = true;
|
||||
try {
|
||||
const response = await Server().get(`/campaign/foundry-link/status/${requestId.value}`);
|
||||
if (response.data.status !== 'ok' || response.data.state === 'expired') {
|
||||
clearInterval(statusPoll);
|
||||
pairingCode.value = '';
|
||||
requestId.value = '';
|
||||
const error = response.data.state === 'expired'
|
||||
? 'campaigns.settings.errors.link-expired'
|
||||
: response.data.msg || 'campaigns.settings.errors.link-expired';
|
||||
DisplayToast('red', $t(error), 3000);
|
||||
return;
|
||||
}
|
||||
if (response.data.state === 'complete') {
|
||||
ApplyCampaignUpdate(response.data.campaign);
|
||||
clearInterval(statusPoll);
|
||||
pairingCode.value = '';
|
||||
requestId.value = '';
|
||||
DisplayToast('green', $t('campaigns.settings.linked'), 3000);
|
||||
}
|
||||
} catch {
|
||||
// Keep polling while the Foundry module completes the pairing.
|
||||
} finally {
|
||||
checkingStatus = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function UnlinkFoundry() {
|
||||
linking.value = true;
|
||||
try {
|
||||
const response = await Server().post('/campaign/foundry-unlink', { campaignId: campaign._id });
|
||||
if (response.data.status !== 'ok') {
|
||||
DisplayToast('red', $t(response.data.msg || 'errors.internal'), 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
ApplyCampaignUpdate(response.data.campaign);
|
||||
DisplayToast('green', $t('campaigns.settings.unlinked'), 3000);
|
||||
} catch {
|
||||
DisplayToast('red', $t('errors.internal'), 3000);
|
||||
} finally {
|
||||
linking.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function CopyPairingCode() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(pairingCode.value);
|
||||
DisplayToast('green', $t('campaigns.settings.code-copied'), 2000);
|
||||
} catch {
|
||||
DisplayToast('red', $t('campaigns.settings.errors.copy-code'), 3000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle"></WindowHandle>
|
||||
|
||||
<div class="settings-body">
|
||||
<Tabs :rows="rows">
|
||||
<template #basic>
|
||||
<div class="settings-fields">
|
||||
<label class="field">
|
||||
<span>{{ $t('campaigns.settings.name') }}</span>
|
||||
<input v-model="name" type="text" maxlength="120" autocomplete="off">
|
||||
</label>
|
||||
<label class="field color-field">
|
||||
<span>{{ $t('campaigns.settings.color') }}</span>
|
||||
<input v-model="color" type="color">
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
<template #integrations>
|
||||
<div class="settings-fields">
|
||||
<div class="world-link">
|
||||
<div v-if="campaign.foundryWorldId" class="linked-world">
|
||||
<strong>{{ campaign.foundryWorldTitle || campaign.foundryWorldId }}</strong>
|
||||
<span v-if="campaign.foundrySystem">{{ campaign.foundrySystem }}</span>
|
||||
<button class="btn-primary sound-click" type="button" :disabled="linking" @click="UnlinkFoundry">
|
||||
{{ $t('campaigns.settings.unlink-foundry') }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-else class="help-text standalone">{{ $t('campaigns.settings.no-foundry-world') }}</p>
|
||||
|
||||
<button class="btn-primary sound-click" type="button" :disabled="linking" @click="StartFoundryLink">
|
||||
{{ $t('campaigns.settings.start-foundry-link') }}
|
||||
</button>
|
||||
<p class="help-text standalone">{{ $t('campaigns.settings.start-foundry-link-help') }}</p>
|
||||
<div v-if="pairingCode" class="pairing-code">
|
||||
<code>{{ pairingCode }}</code>
|
||||
<button class="btn-primary sound-click" type="button" @click="CopyPairingCode">
|
||||
{{ $t('campaigns.settings.copy-code') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="field">
|
||||
<span>{{ $t('campaigns.settings.foundry-url') }}</span>
|
||||
<input
|
||||
v-model="foundryUrl"
|
||||
type="url"
|
||||
placeholder="https://foundry.example.com"
|
||||
autocomplete="url"
|
||||
>
|
||||
</label>
|
||||
<p class="help-text">{{ $t('campaigns.settings.foundry-url-help') }}</p>
|
||||
</div>
|
||||
</template>
|
||||
</Tabs>
|
||||
<div class="actions">
|
||||
<button class="btn-primary sound-click" type="button" :disabled="saving" @click="SaveSettings">
|
||||
{{ saving ? $t('campaigns.settings.saving') : $t('general.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.window-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.settings-body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.settings-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-background-soft);
|
||||
color: var(--color-text);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.color-field input {
|
||||
width: 72px;
|
||||
height: 38px;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
.help-text {
|
||||
margin: -10px 22px 0;
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.help-text.standalone {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.world-link {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding-bottom: 14px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.linked-world {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.linked-world span {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.pairing-code {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.pairing-code code {
|
||||
user-select: text;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 12px 18px;
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
</style>
|
||||
399
frontend/app/components/windows/CharacterSheetWindow.vue
Normal file
399
frontend/app/components/windows/CharacterSheetWindow.vue
Normal file
@@ -0,0 +1,399 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
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';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const id = props.data.id;
|
||||
const actorId = props.data.actor?._id;
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
const editing = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const original = ref(null);
|
||||
const photoInput = ref(null);
|
||||
const uploadingPhoto = ref(false);
|
||||
const { t } = useI18n();
|
||||
|
||||
const abilityStats = [
|
||||
{ key: 'str', label: 'STR' }, { key: 'dex', label: 'DEX' }, { key: 'con', label: 'CON' },
|
||||
{ key: 'int', label: 'INT' }, { key: 'wis', label: 'WIS' }, { key: 'cha', label: 'CHA' }
|
||||
];
|
||||
|
||||
function normalizeActor(actor) {
|
||||
return {
|
||||
name: actor?.name ?? '',
|
||||
species: actor?.species ?? '',
|
||||
className: actor?.className ?? '',
|
||||
subclass: actor?.subclass ?? '',
|
||||
level: Number(actor?.level ?? 1),
|
||||
abilityScores: Object.fromEntries(abilityStats.map(({ key }) => [key, Number(actor?.abilityScores?.[key] ?? 10)])),
|
||||
armorClass: Number(actor?.armorClass ?? 10),
|
||||
speed: Number(actor?.speed ?? 30),
|
||||
proficiencies: actor?.proficiencies ?? '',
|
||||
inventory: (actor?.inventory ?? []).map((item) => ({
|
||||
name: item.name ?? '', quantity: Number(item.quantity ?? 1), weight: Number(item.weight ?? 0)
|
||||
})),
|
||||
traits: actor?.traits ?? '',
|
||||
spells: actor?.spells ?? '',
|
||||
image: actor?.image ?? ''
|
||||
};
|
||||
}
|
||||
|
||||
const form = ref(normalizeActor(props.data.actor));
|
||||
original.value = normalizeActor(props.data.actor);
|
||||
|
||||
onMounted(() => {
|
||||
Top(wrapper);
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, {
|
||||
width: Math.max(320, Math.min(900, window.innerWidth - 24)),
|
||||
height: Math.max(360, Math.min(700, window.innerHeight - 32))
|
||||
});
|
||||
ResetPosition(id, 'center');
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => ClearWindow({ type: 'character_sheet' }));
|
||||
|
||||
function handleActorSync({ entityType, entry }) {
|
||||
if (entityType !== 'actor' || entry?._id !== actorId || editing.value) return;
|
||||
form.value = normalizeActor(entry);
|
||||
original.value = normalizeActor(entry);
|
||||
}
|
||||
|
||||
onMounted(() => emitter.on('campaign-entry-updated', handleActorSync));
|
||||
onBeforeUnmount(() => emitter.off('campaign-entry-updated', handleActorSync));
|
||||
|
||||
const proficiencyBonus = computed(() => Math.ceil(form.value.level / 4) + 1);
|
||||
const carryingCapacity = computed(() => form.value.abilityScores.str * 15);
|
||||
const carriedWeight = computed(() => form.value.inventory.reduce((total, item) => total + (Number(item.quantity) || 0) * (Number(item.weight) || 0), 0));
|
||||
const carryPercent = computed(() => Math.min(100, carryingCapacity.value ? (carriedWeight.value / carryingCapacity.value) * 100 : 0));
|
||||
|
||||
function abilityModifier(score) {
|
||||
const modifier = Math.floor((Number(score) - 10) / 2);
|
||||
return modifier >= 0 ? `+${modifier}` : String(modifier);
|
||||
}
|
||||
|
||||
const imageUrl = computed(() => {
|
||||
if (!form.value.image) return '';
|
||||
return /^(https?:|data:|\/\/)/i.test(form.value.image)
|
||||
? form.value.image
|
||||
: `${getBaseUrl()}/public/${form.value.image}`;
|
||||
});
|
||||
|
||||
function pickPhoto() {
|
||||
photoInput.value?.click();
|
||||
}
|
||||
|
||||
async function onPhotoSelected(event) {
|
||||
const file = event.target.files?.[0];
|
||||
event.target.value = '';
|
||||
if (!file || uploadingPhoto.value) return;
|
||||
uploadingPhoto.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('image', file);
|
||||
const response = await Server().post(`/actor/upload-image?actor=${actorId}`, formData, {
|
||||
headers: { "Content-Type": "multipart/form-data" }
|
||||
});
|
||||
if (response.data.status !== 'ok') {
|
||||
error.value = t('campaigns.character-sheet.photo-error');
|
||||
return;
|
||||
}
|
||||
// La foto es desa immediatament: manté original intacte perquè cancel·lar no la perdi
|
||||
form.value.image = response.data.actor?.image ?? form.value.image;
|
||||
original.value.image = form.value.image;
|
||||
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: response.data.actor });
|
||||
} catch (requestError) {
|
||||
error.value = t('campaigns.character-sheet.photo-error');
|
||||
} finally {
|
||||
uploadingPhoto.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function removePhoto() {
|
||||
form.value.image = '';
|
||||
}
|
||||
|
||||
function startEditing() {
|
||||
editing.value = true;
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
function cancelEditing() {
|
||||
form.value = normalizeActor(original.value);
|
||||
editing.value = false;
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
function addInventoryItem() {
|
||||
form.value.inventory.push({ name: '', quantity: 1, weight: 0 });
|
||||
}
|
||||
|
||||
function removeInventoryItem(index) {
|
||||
form.value.inventory.splice(index, 1);
|
||||
}
|
||||
|
||||
async function saveSheet() {
|
||||
if (!form.value.name.trim() || saving.value) return;
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload = {
|
||||
id: actorId,
|
||||
...form.value,
|
||||
inventory: form.value.inventory.filter((item) => item.name.trim())
|
||||
};
|
||||
const response = await Server().post('/actor/update', payload);
|
||||
if (response.data.status !== 'ok') {
|
||||
error.value = t('campaigns.character-sheet.save-error');
|
||||
return;
|
||||
}
|
||||
original.value = normalizeActor(response.data.actor);
|
||||
form.value = normalizeActor(response.data.actor);
|
||||
editing.value = false;
|
||||
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: response.data.actor });
|
||||
} catch (requestError) {
|
||||
error.value = t('campaigns.character-sheet.save-error');
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper sheet-window" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle" />
|
||||
<div class="sheet-body">
|
||||
<header class="sheet-hero">
|
||||
<div class="character-mark" aria-hidden="true">{{ form.name.slice(0, 1).toUpperCase() }}</div>
|
||||
<div class="character-identity">
|
||||
<input v-if="editing" v-model="form.name" class="character-name-input" required :aria-label="$t('campaigns.character-sheet.name')">
|
||||
<h1 v-else>{{ form.name }}</h1>
|
||||
<div class="identity-fields">
|
||||
<label v-if="editing" class="identity-field">
|
||||
<span>{{ $t('campaigns.character-sheet.class') }}</span><input v-model="form.className">
|
||||
</label>
|
||||
<span v-else class="identity-tag">{{ form.className || $t('campaigns.character-sheet.unset-class') }}</span>
|
||||
<label v-if="editing" class="identity-field">
|
||||
<span>{{ $t('campaigns.character-sheet.subclass') }}</span><input v-model="form.subclass">
|
||||
</label>
|
||||
<span v-else-if="form.subclass" class="identity-tag">{{ form.subclass }}</span>
|
||||
<label v-if="editing" class="identity-field level-field">
|
||||
<span>{{ $t('campaigns.character-sheet.level') }}</span><input v-model.number="form.level" type="number" min="1" max="20">
|
||||
</label>
|
||||
<span v-else class="identity-tag">{{ $t('campaigns.character-sheet.level') }} {{ form.level }}</span>
|
||||
<label v-if="editing" class="identity-field">
|
||||
<span>{{ $t('campaigns.character-sheet.species') }}</span><input v-model="form.species">
|
||||
</label>
|
||||
<span v-else class="identity-tag">{{ form.species || $t('campaigns.character-sheet.unset-species') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sheet-actions">
|
||||
<button v-if="!editing" class="sheet-button" type="button" @click="startEditing">{{ $t('campaigns.character-sheet.edit') }}</button>
|
||||
<template v-else>
|
||||
<button class="sheet-button secondary" type="button" @click="cancelEditing">{{ $t('campaigns.character-sheet.cancel') }}</button>
|
||||
<button class="sheet-button primary" type="button" :disabled="saving" @click="saveSheet">
|
||||
{{ saving ? $t('campaigns.character-sheet.saving') : $t('campaigns.character-sheet.save') }}
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div v-if="error" class="sheet-error">{{ error }}</div>
|
||||
|
||||
<main class="sheet-grid">
|
||||
<div v-if="form.image || editing" class="sheet-portrait" :class="{ empty: !form.image }">
|
||||
<img v-if="form.image" :src="imageUrl" :alt="$t('campaigns.character-sheet.photo')">
|
||||
<button v-if="editing && !form.image" class="portrait-upload" type="button" :disabled="uploadingPhoto" @click="pickPhoto">
|
||||
{{ uploadingPhoto ? $t('campaigns.character-sheet.uploading-photo') : $t('campaigns.character-sheet.upload-photo') }}
|
||||
</button>
|
||||
<div v-if="editing && form.image" class="portrait-controls">
|
||||
<button type="button" :disabled="uploadingPhoto" @click="pickPhoto">
|
||||
{{ uploadingPhoto ? $t('campaigns.character-sheet.uploading-photo') : $t('campaigns.character-sheet.change-photo') }}
|
||||
</button>
|
||||
<button type="button" :disabled="uploadingPhoto" :aria-label="$t('campaigns.character-sheet.remove-photo')" @click="removePhoto">×</button>
|
||||
</div>
|
||||
<input ref="photoInput" class="photo-input" type="file" accept="image/*" @change="onPhotoSelected">
|
||||
</div>
|
||||
|
||||
<section class="sheet-panel abilities-panel">
|
||||
<h2>{{ $t('campaigns.character-sheet.ability-scores') }}</h2>
|
||||
<div class="ability-grid">
|
||||
<div v-for="stat in abilityStats" :key="stat.key" class="ability-card">
|
||||
<span class="ability-label">{{ stat.label }}</span>
|
||||
<input v-if="editing" v-model.number="form.abilityScores[stat.key]" type="number" min="1" max="30" :aria-label="stat.label">
|
||||
<strong v-else class="ability-score">{{ form.abilityScores[stat.key] }}</strong>
|
||||
<span class="ability-modifier">{{ abilityModifier(form.abilityScores[stat.key]) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="proficiency-badge">
|
||||
<span>{{ $t('campaigns.character-sheet.proficiency-bonus') }}</span>
|
||||
<strong>+{{ proficiencyBonus }}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="sheet-panel combat-panel">
|
||||
<h2>{{ $t('campaigns.character-sheet.combat') }}</h2>
|
||||
<div class="combat-stats">
|
||||
<div class="combat-stat">
|
||||
<span>{{ $t('campaigns.character-sheet.armor-class') }}</span>
|
||||
<input v-if="editing" v-model.number="form.armorClass" type="number" min="0">
|
||||
<strong v-else>{{ form.armorClass }}</strong>
|
||||
</div>
|
||||
<div class="combat-stat">
|
||||
<span>{{ $t('campaigns.character-sheet.speed') }}</span>
|
||||
<label v-if="editing" class="number-with-unit"><input v-model.number="form.speed" type="number" min="0"><small>ft</small></label>
|
||||
<strong v-else>{{ form.speed }} <small>ft</small></strong>
|
||||
</div>
|
||||
</div>
|
||||
<h3>{{ $t('campaigns.character-sheet.proficiencies') }}</h3>
|
||||
<textarea v-if="editing" v-model="form.proficiencies" rows="5" :placeholder="$t('campaigns.character-sheet.proficiencies-placeholder')" />
|
||||
<p v-else class="sheet-copy">{{ form.proficiencies || $t('campaigns.character-sheet.empty-proficiencies') }}</p>
|
||||
</section>
|
||||
|
||||
<section class="sheet-panel traits-panel">
|
||||
<h2>{{ $t('campaigns.character-sheet.traits') }}</h2>
|
||||
<textarea v-if="editing" v-model="form.traits" rows="5" :placeholder="$t('campaigns.character-sheet.traits-placeholder')" />
|
||||
<p v-else class="sheet-copy">{{ form.traits || $t('campaigns.character-sheet.empty-traits') }}</p>
|
||||
</section>
|
||||
|
||||
<section class="sheet-panel spells-panel">
|
||||
<h2>{{ $t('campaigns.character-sheet.spells') }}</h2>
|
||||
<textarea v-if="editing" v-model="form.spells" rows="5" :placeholder="$t('campaigns.character-sheet.spells-placeholder')" />
|
||||
<p v-else class="sheet-copy">{{ form.spells || $t('campaigns.character-sheet.empty-spells') }}</p>
|
||||
</section>
|
||||
|
||||
<section class="sheet-panel inventory-panel">
|
||||
<div class="panel-title-row">
|
||||
<h2>{{ $t('campaigns.character-sheet.inventory') }}</h2>
|
||||
<button v-if="editing" class="sheet-button secondary compact" type="button" @click="addInventoryItem">{{ $t('campaigns.character-sheet.add-item') }}</button>
|
||||
</div>
|
||||
<div class="weight-summary">
|
||||
<span>{{ $t('campaigns.character-sheet.carried-weight') }}</span>
|
||||
<strong>{{ carriedWeight.toFixed(1) }} / {{ carryingCapacity }} lb</strong>
|
||||
</div>
|
||||
<div class="weight-track"><div class="weight-fill" :style="{ width: `${carryPercent}%` }" /></div>
|
||||
<div class="inventory-table-wrap">
|
||||
<table class="inventory-table">
|
||||
<thead><tr>
|
||||
<th>{{ $t('campaigns.character-sheet.item-name') }}</th>
|
||||
<th>{{ $t('campaigns.character-sheet.quantity') }}</th>
|
||||
<th>{{ $t('campaigns.character-sheet.weight-each') }}</th>
|
||||
<th>{{ $t('campaigns.character-sheet.total-weight') }}</th>
|
||||
<th v-if="editing"><span class="sr-only">{{ $t('campaigns.character-sheet.actions') }}</span></th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in form.inventory" :key="index">
|
||||
<td><input v-if="editing" v-model="item.name" :aria-label="$t('campaigns.character-sheet.item-name')"><span v-else>{{ item.name }}</span></td>
|
||||
<td><input v-if="editing" v-model.number="item.quantity" type="number" min="1" :aria-label="$t('campaigns.character-sheet.quantity')"><span v-else>{{ item.quantity }}</span></td>
|
||||
<td><input v-if="editing" v-model.number="item.weight" type="number" min="0" step="0.1" :aria-label="$t('campaigns.character-sheet.weight-each')"><span v-else>{{ Number(item.weight).toFixed(1) }} lb</span></td>
|
||||
<td>{{ ((Number(item.quantity) || 0) * (Number(item.weight) || 0)).toFixed(1) }} lb</td>
|
||||
<td v-if="editing"><button class="remove-item" type="button" @click="removeInventoryItem(index)">×</button></td>
|
||||
</tr>
|
||||
<tr v-if="form.inventory.length === 0"><td :colspan="editing ? 5 : 4" class="empty-inventory">{{ $t('campaigns.character-sheet.empty-inventory') }}</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.sheet-window { min-width: 0; min-height: 0; }
|
||||
.sheet-body { width: 100%; min-height: 0; flex: 1; overflow: auto; padding: 16px; box-sizing: border-box; }
|
||||
.sheet-hero { display: flex; align-items: center; gap: 14px; padding: 4px 2px 16px; margin-bottom: 12px; border-bottom: 1px solid var(--color-border); }
|
||||
.character-mark { width: 56px; height: 56px; flex: 0 0 56px; display: grid; place-items: center; border-radius: 12px; background: var(--color-background-soft); color: var(--color-link); border: 1px solid var(--color-border); font: 28px MrEavesRemake; }
|
||||
.character-identity { flex: 1; min-width: 0; }
|
||||
.character-identity h1 { margin: 0 0 7px; font: 28px MrEavesRemake; overflow-wrap: anywhere; }
|
||||
.character-name-input { width: min(100%, 440px); font-size: 24px !important; font-family: MrEavesRemake !important; }
|
||||
.identity-fields { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
|
||||
.identity-tag { padding: 4px 9px; border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-background-soft); font-size: 12px; opacity: .9; }
|
||||
.identity-field { display: flex; align-items: center; gap: 5px; font-size: 11px; opacity: .8; }
|
||||
.identity-field input { width: 106px; }
|
||||
.identity-field.level-field input { width: 58px; }
|
||||
.sheet-actions { display: flex; align-items: center; gap: 7px; }
|
||||
.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; }
|
||||
.sheet-button:hover { background: var(--color-button-hover); }
|
||||
.sheet-button.primary { background: var(--color-link); color: var(--color-background); border-color: var(--color-link); }
|
||||
.sheet-button:disabled { opacity: .55; cursor: wait; }
|
||||
.sheet-button.compact { padding: 5px 9px; font-size: 12px; }
|
||||
.sheet-grid { display: grid; grid-template-columns: minmax(200px, 34%) minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto auto auto; gap: 11px; align-items: start; }
|
||||
.sheet-panel { min-width: 0; padding: 13px; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-light); box-shadow: 0 3px 12px var(--color-window-shadow); }
|
||||
.sheet-panel h2 { margin: 0 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--color-border); font: 17px MrEavesRemake; letter-spacing: .03em; }
|
||||
.sheet-panel h3 { margin: 13px 0 7px; font: 14px MrEavesRemake; }
|
||||
.sheet-portrait { grid-column: 1; grid-row: 1 / -1; position: relative; overflow: hidden; border: 1px solid var(--color-border); border-radius: 10px; background: var(--color-background-soft); }
|
||||
.sheet-portrait.empty { display: grid; place-items: center; min-height: 220px; border-style: dashed; }
|
||||
.sheet-portrait img { display: block; width: 100%; height: auto; }
|
||||
.portrait-upload { border: 0; padding: 8px 10px; background: transparent; color: var(--color-link); font-size: 12px; cursor: pointer; }
|
||||
.portrait-controls { position: absolute; inset: auto 0 0 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 7px; background: var(--color-background-soft); border-top: 1px solid var(--color-border); }
|
||||
.portrait-controls button { border: 1px solid var(--color-border); border-radius: 6px; padding: 4px 9px; background: var(--color-background-light); color: var(--color-text); font-size: 11px; cursor: pointer; }
|
||||
.portrait-controls button:last-child { flex: 0 0 auto; padding: 3px 8px; font-size: 15px; line-height: 1; }
|
||||
.portrait-controls button:hover { background: var(--color-button-hover); }
|
||||
.portrait-controls button:disabled { opacity: .55; cursor: wait; }
|
||||
.photo-input { display: none; }
|
||||
.abilities-panel { grid-column: 2 / -1; grid-row: 1; }
|
||||
.combat-panel { grid-column: 2; grid-row: 2; }
|
||||
.traits-panel { grid-column: 3; grid-row: 2; }
|
||||
.spells-panel { grid-column: 2 / -1; grid-row: 3; }
|
||||
.ability-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
|
||||
.ability-card { min-height: 83px; padding: 8px 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); }
|
||||
.ability-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; opacity: .75; }
|
||||
.ability-score { font: 25px MrEavesRemake; }
|
||||
.ability-modifier { min-width: 33px; text-align: center; padding: 2px 5px; border-radius: 999px; background: var(--color-background); font-size: 12px; }
|
||||
.ability-card input { width: 55px; text-align: center; font-size: 21px; }
|
||||
.proficiency-badge { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; padding: 8px; border-radius: 8px; background: var(--color-background-soft); font-size: 12px; }
|
||||
.proficiency-badge strong { font-size: 15px; color: var(--color-link); }
|
||||
.combat-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
||||
.combat-stat { min-height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-background-soft); }
|
||||
.combat-stat > span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; opacity: .72; }
|
||||
.combat-stat > strong { font: 25px MrEavesRemake; }
|
||||
.combat-stat small { font-size: 11px; opacity: .7; }
|
||||
.number-with-unit { display: flex; align-items: center; gap: 4px; }
|
||||
.number-with-unit input { width: 57px; }
|
||||
.sheet-copy { min-height: 74px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; opacity: .85; }
|
||||
input, textarea { box-sizing: border-box; max-width: 100%; padding: 6px 7px; border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-background-soft); color: var(--color-text); font: inherit; }
|
||||
input:focus, textarea:focus { outline: none; border-color: var(--color-link); }
|
||||
textarea { resize: vertical; width: 100%; min-height: 88px; font-size: 12px; }
|
||||
.traits-panel, .spells-panel { min-height: 175px; }
|
||||
.panel-title-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
|
||||
.panel-title-row h2 { flex: 1; }
|
||||
.weight-summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 1px 0 7px; font-size: 12px; }
|
||||
.weight-summary strong { white-space: nowrap; }
|
||||
.weight-track { height: 5px; margin-bottom: 10px; overflow: hidden; border-radius: 999px; background: var(--color-background-soft); }
|
||||
.weight-fill { height: 100%; border-radius: inherit; background: var(--color-link); transition: width .2s ease; }
|
||||
.inventory-panel { grid-column: 2 / -1; grid-row: 4; }
|
||||
.inventory-table-wrap { overflow-x: auto; }
|
||||
.inventory-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
||||
.inventory-table th { padding: 6px 7px; text-align: left; font-weight: 600; opacity: .7; }
|
||||
.inventory-table td { padding: 5px 7px; border-top: 1px solid var(--color-border); }
|
||||
.inventory-table td input { width: 100%; min-width: 54px; }
|
||||
.inventory-table td:first-child input { min-width: 100px; }
|
||||
.inventory-table th:not(:first-child), .inventory-table td:not(:first-child) { text-align: center; }
|
||||
.empty-inventory { text-align: center !important; opacity: .65; }
|
||||
.remove-item { width: 24px; height: 24px; border: 0; border-radius: 5px; background: transparent; color: var(--color-text); font-size: 20px; cursor: pointer; }
|
||||
.remove-item:hover { background: var(--color-button-hover); }
|
||||
.sheet-error { padding: 7px 10px; margin-bottom: 10px; border-radius: 6px; color: var(--color-red); background: var(--color-background-soft); font-size: 12px; }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
||||
@media (max-width: 760px) {
|
||||
.sheet-grid { grid-template-columns: 1fr 1fr; grid-template-rows: none; }
|
||||
.sheet-portrait { grid-column: 1 / -1; grid-row: auto; }
|
||||
.abilities-panel { grid-column: 1 / -1; grid-row: auto; }
|
||||
.combat-panel, .traits-panel { grid-column: auto; grid-row: auto; }
|
||||
.spells-panel, .inventory-panel { grid-column: 1 / -1; grid-row: auto; }
|
||||
}
|
||||
@media (max-width: 520px) {
|
||||
.sheet-body { padding: 10px; }
|
||||
.sheet-hero { align-items: flex-start; flex-wrap: wrap; }
|
||||
.sheet-actions { margin-left: auto; }
|
||||
.sheet-grid { grid-template-columns: 1fr; }
|
||||
.ability-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
}
|
||||
</style>
|
||||
135
frontend/app/components/windows/CreateCampaignEntryWindow.vue
Normal file
135
frontend/app/components/windows/CreateCampaignEntryWindow.vue
Normal file
@@ -0,0 +1,135 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { SetupHandle, SetSize, ResetPosition, ClearWindow } from '@/services/Windows';
|
||||
import WindowHandle from './partials/WindowHandle.vue';
|
||||
import Server from '~/services/Server';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const data = props.data;
|
||||
const id = data.id;
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
const saving = ref(false);
|
||||
const form = ref({
|
||||
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
|
||||
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
|
||||
});
|
||||
|
||||
const isActor = data.entityType === 'actor';
|
||||
const endpoint = isActor ? '/actor/create' : '/item/create';
|
||||
|
||||
onMounted(() => {
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, isActor ? { width: 420, height: 220 } : { width: 500, height: 560 });
|
||||
ResetPosition(id, 'center');
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => ClearWindow({ type: 'create_campaign_entry' }));
|
||||
|
||||
async function saveEntry() {
|
||||
if (!form.value.name.trim() || saving.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const payload = { name: form.value.name.trim(), campaign: data.campaign };
|
||||
if (!isActor) {
|
||||
for (const field of ['category', 'rarity', 'quantity', 'weight', 'properties', 'description']) {
|
||||
payload[field] = form.value[field];
|
||||
}
|
||||
}
|
||||
const response = await Server().post(endpoint, payload);
|
||||
if (response.data.status === 'ok') {
|
||||
emitter.emit('campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
|
||||
ClearWindow({ id });
|
||||
}
|
||||
} catch (error) {
|
||||
// Keep the form open so the user can retry.
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle" />
|
||||
<div class="body">
|
||||
<h3>{{ $t(isActor ? 'campaigns.actor.new' : 'campaigns.item.new') }}</h3>
|
||||
<form @submit.prevent="saveEntry">
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.fields.name') }}</span>
|
||||
<input v-model="form.name" required autofocus autocomplete="off">
|
||||
</label>
|
||||
|
||||
<template v-if="!isActor">
|
||||
<div class="form-grid">
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.item.category') }}</span>
|
||||
<select v-model="form.category">
|
||||
<option value="weapon">{{ $t('campaigns.item.categories.weapon') }}</option>
|
||||
<option value="armor">{{ $t('campaigns.item.categories.armor') }}</option>
|
||||
<option value="shield">{{ $t('campaigns.item.categories.shield') }}</option>
|
||||
<option value="adventuring-gear">{{ $t('campaigns.item.categories.adventuring-gear') }}</option>
|
||||
<option value="magic-item">{{ $t('campaigns.item.categories.magic-item') }}</option>
|
||||
<option value="consumable">{{ $t('campaigns.item.categories.consumable') }}</option>
|
||||
<option value="tool">{{ $t('campaigns.item.categories.tool') }}</option>
|
||||
<option value="treasure">{{ $t('campaigns.item.categories.treasure') }}</option>
|
||||
<option value="other">{{ $t('campaigns.item.categories.other') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.item.rarity') }}</span>
|
||||
<select v-model="form.rarity">
|
||||
<option value="common">{{ $t('campaigns.item.rarities.common') }}</option>
|
||||
<option value="uncommon">{{ $t('campaigns.item.rarities.uncommon') }}</option>
|
||||
<option value="rare">{{ $t('campaigns.item.rarities.rare') }}</option>
|
||||
<option value="very-rare">{{ $t('campaigns.item.rarities.very-rare') }}</option>
|
||||
<option value="legendary">{{ $t('campaigns.item.rarities.legendary') }}</option>
|
||||
<option value="artifact">{{ $t('campaigns.item.rarities.artifact') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.item.quantity') }}</span>
|
||||
<input v-model.number="form.quantity" type="number" min="1" required>
|
||||
</label>
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.item.weight') }}</span>
|
||||
<input v-model="form.weight" type="number" min="0" step="0.1">
|
||||
</label>
|
||||
</div>
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.item.properties') }}</span>
|
||||
<input v-model="form.properties" :placeholder="$t('campaigns.item.properties-placeholder')">
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<label v-if="!isActor" class="form-field">
|
||||
<span>{{ $t('campaigns.fields.description') }}</span>
|
||||
<textarea v-model="form.description" rows="3" />
|
||||
</label>
|
||||
<div class="form-actions">
|
||||
<button class="btn-primary sound-click" type="submit" :disabled="saving">
|
||||
{{ saving ? $t('campaigns.actions.saving') : $t('campaigns.actions.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.window-wrapper { display: flex; align-items: center; flex-direction: column; }
|
||||
.body { width: 100%; padding: 10px 18px 16px; overflow-y: auto; }
|
||||
h3 { margin: 0 0 12px; font-family: MrEavesRemake; }
|
||||
form { display: flex; flex-direction: column; gap: 10px; }
|
||||
.form-field { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
|
||||
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
input, select, textarea {
|
||||
box-sizing: border-box; width: 100%; padding: 7px 8px; border: 1px solid var(--color-border);
|
||||
border-radius: 6px; background: var(--color-background-soft); color: var(--color-text); font: inherit;
|
||||
}
|
||||
textarea { resize: vertical; }
|
||||
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-link); }
|
||||
.form-actions { display: flex; justify-content: center; margin-top: 2px; }
|
||||
.form-actions button { width: 100%; max-width: 220px; }
|
||||
</style>
|
||||
129
frontend/app/components/windows/NewNoteWindow.vue
Normal file
129
frontend/app/components/windows/NewNoteWindow.vue
Normal file
@@ -0,0 +1,129 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { SetupHandle, SetSize, ResetPosition, ClearWindow } from '@/services/Windows';
|
||||
import WindowHandle from './partials/WindowHandle.vue';
|
||||
import Server from '~/services/Server';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
|
||||
const props = defineProps(['data']);
|
||||
const data = props.data;
|
||||
|
||||
let id = data.id;
|
||||
|
||||
const newName = ref('');
|
||||
|
||||
onMounted(() => {
|
||||
SetupHandle(id, handle);
|
||||
SetSize(id, { width: 420, height: 200 });
|
||||
ResetPosition(id, 'center');
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
ClearWindow({ type: 'new_note' });
|
||||
});
|
||||
|
||||
function confirmCreate() {
|
||||
if (!newName.value.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Server().post('/note/create', {
|
||||
title: newName.value.trim(),
|
||||
content: '',
|
||||
campaign: data.campaign,
|
||||
folder: data.folder ?? null
|
||||
}).then((response) => {
|
||||
if (response.data.status !== 'ok') {
|
||||
return;
|
||||
}
|
||||
emitter.emit('note-created', response.data.note);
|
||||
ClearWindow({ id });
|
||||
}).catch(() => {});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle"></WindowHandle>
|
||||
|
||||
<div class="body">
|
||||
<h3>New Note</h3>
|
||||
<form v-on:submit.prevent="confirmCreate">
|
||||
<div class="form-field">
|
||||
<input
|
||||
type="text"
|
||||
v-model="newName"
|
||||
placeholder="Note title"
|
||||
autofocus
|
||||
autocomplete="off"
|
||||
>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn-primary sound-click" type="submit">Create</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.window-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.body {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0 0 10px 10px;
|
||||
font-family: MrEavesRemake;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.form-field > * {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-background-soft);
|
||||
color: var(--color-text);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-accent);
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.form-actions button {
|
||||
width: 100%;
|
||||
max-width: 200px;
|
||||
}
|
||||
</style>
|
||||
@@ -35,6 +35,12 @@ const defWindows = {
|
||||
close: () => ClearWindow({type: 'create_campaign'}),
|
||||
movable: true
|
||||
},
|
||||
campaign_settings: {
|
||||
title: 'campaigns.settings.title',
|
||||
component: () => import('~/components/windows/CampaignSettingsWindow.vue'),
|
||||
close: () => ClearWindow({type: 'campaign_settings'}),
|
||||
movable: true
|
||||
},
|
||||
rename_note: {
|
||||
title: "Rename Note",
|
||||
component: () => import('~/components/windows/RenameNoteWindow.vue'),
|
||||
@@ -46,6 +52,24 @@ const defWindows = {
|
||||
component: () => import('~/components/windows/NewFolderWindow.vue'),
|
||||
close: () => ClearWindow({type: 'new_folder'}),
|
||||
movable: true
|
||||
},
|
||||
new_note: {
|
||||
title: "New Note",
|
||||
component: () => import('~/components/windows/NewNoteWindow.vue'),
|
||||
close: () => ClearWindow({type: 'new_note'}),
|
||||
movable: true
|
||||
},
|
||||
create_campaign_entry: {
|
||||
title: 'campaigns.create-entry',
|
||||
component: () => import('~/components/windows/CreateCampaignEntryWindow.vue'),
|
||||
close: () => ClearWindow({type: 'create_campaign_entry'}),
|
||||
movable: true
|
||||
},
|
||||
character_sheet: {
|
||||
title: 'campaigns.character-sheet.title',
|
||||
component: () => import('~/components/windows/CharacterSheetWindow.vue'),
|
||||
close: () => ClearWindow({type: 'character_sheet'}),
|
||||
movable: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user