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:
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>
|
||||
Reference in New Issue
Block a user