Char skill edit not saved (#36)
* Skill edit was not saved * show warning when skill name is to be edited in char_skills
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
<!-- Submenu Content -->
|
||||
<!-- <div class="character-aspect"> -->
|
||||
<component :is="currentView" :character="character" :isOwner="isOwner" @character-updated="refreshCharacter"/>
|
||||
<component :is="currentView" :character="character" :isOwner="isOwner" @character-updated="refreshCharacter" @character-data-updated="updateCharacterData"/>
|
||||
<!-- </div> -->
|
||||
|
||||
<!-- Submenu -->
|
||||
@@ -156,6 +156,12 @@ export default {
|
||||
alert('Fehler beim Aktualisieren der Charakterdaten: ' + (error.response?.data?.error || error.message));
|
||||
}
|
||||
},
|
||||
|
||||
updateCharacterData(updatedData) {
|
||||
// Update character data directly without reloading from server
|
||||
this.character = updatedData;
|
||||
console.log('Character data updated directly from response');
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -55,6 +55,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Warning message when editing skill name -->
|
||||
<div v-if="showNameEditWarning" class="warning-message">
|
||||
<span class="warning-icon">⚠️</span>
|
||||
<span class="warning-text">
|
||||
{{ $t('characters.datasheet.editnamewarning') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<table class="cd-table">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -384,6 +393,29 @@
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
.warning-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 12px 16px;
|
||||
margin: 10px 0;
|
||||
background-color: #fff3cd;
|
||||
border: 1px solid #ffc107;
|
||||
border-radius: 6px;
|
||||
color: #856404;
|
||||
animation: slideIn 0.3s ease;
|
||||
}
|
||||
|
||||
.warning-icon {
|
||||
font-size: 1.2rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.warning-text {
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
@@ -431,6 +463,7 @@ export default {
|
||||
editingSkillId: null,
|
||||
editingField: null,
|
||||
editValue: '',
|
||||
showNameEditWarning: false,
|
||||
|
||||
isLoading: false
|
||||
};
|
||||
@@ -752,6 +785,11 @@ export default {
|
||||
this.editingField = field;
|
||||
this.editValue = skill[field] || '';
|
||||
|
||||
// Show warning when editing skill name
|
||||
if (field === 'name') {
|
||||
this.showNameEditWarning = true;
|
||||
}
|
||||
|
||||
this.$nextTick(() => {
|
||||
const input = this.$refs.editInput;
|
||||
if (input) {
|
||||
@@ -779,19 +817,50 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
// Update local character object
|
||||
skill[field] = newValue;
|
||||
// Find and update the original skill in character.fertigkeiten or character.waffenfertigkeiten
|
||||
let originalSkillFound = false;
|
||||
|
||||
// Check in fertigkeiten
|
||||
if (this.character.fertigkeiten) {
|
||||
const originalSkill = this.character.fertigkeiten.find(s => s.name === skill.name);
|
||||
if (originalSkill) {
|
||||
originalSkill[field] = newValue;
|
||||
originalSkillFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check in waffenfertigkeiten if not found in fertigkeiten
|
||||
if (!originalSkillFound && this.character.waffenfertigkeiten) {
|
||||
const originalWeaponSkill = this.character.waffenfertigkeiten.find(s => s.name === skill.name);
|
||||
if (originalWeaponSkill) {
|
||||
originalWeaponSkill[field] = newValue;
|
||||
originalSkillFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!originalSkillFound) {
|
||||
console.warn('Original skill not found in character data:', skill.name);
|
||||
alert('Warnung: Originalfertigkeit nicht gefunden.');
|
||||
this.cancelEditSkill();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Save to backend
|
||||
await API.put(`/api/characters/${this.character.id}`, this.character);
|
||||
const response = await API.put(`/api/characters/${this.character.id}`, this.character);
|
||||
|
||||
console.log('Skill updated successfully:', skill.name, field, newValue);
|
||||
|
||||
// Update the parent component with the response data
|
||||
// The backend now returns the full FeChar with categorizedskills
|
||||
this.$emit('character-data-updated', response.data);
|
||||
|
||||
this.$emit('character-updated');
|
||||
this.cancelEditSkill();
|
||||
} catch (error) {
|
||||
console.error('Failed to update skill:', error);
|
||||
alert('Fehler beim Speichern: ' + (error.response?.data?.error || error.message));
|
||||
this.cancelEditSkill();
|
||||
// Revert changes on error by reloading
|
||||
this.$emit('character-updated');
|
||||
}
|
||||
},
|
||||
|
||||
@@ -799,6 +868,7 @@ export default {
|
||||
this.editingSkillId = null;
|
||||
this.editingField = null;
|
||||
this.editValue = '';
|
||||
this.showNameEditWarning = false;
|
||||
},
|
||||
|
||||
isEditingSkill(skill, field) {
|
||||
|
||||
@@ -563,7 +563,8 @@ export default {
|
||||
bRollTooltip: 'B würfeln: 1d6 + Modifikator je nach Rasse'
|
||||
},
|
||||
datasheet: {
|
||||
editHelp: 'Doppelklicken auf ein Feld, um es zu bearbeiten.'
|
||||
editHelp: 'Doppelklicken auf ein Feld, um es zu bearbeiten.',
|
||||
editnamewarning: 'Wenn der Name der Fertigkeit geändert wird kann diese nicht mehr nach den Regeln verbessert werden. Auch beim Export können Boni und andere Werte fehlen!'
|
||||
}
|
||||
},
|
||||
audit: {
|
||||
|
||||
@@ -559,7 +559,8 @@ export default {
|
||||
bRollTooltip: 'Roll B: 1d6 + modifier based on race'
|
||||
},
|
||||
datasheet: {
|
||||
editHelp: 'Click twice on a field to edit it.'
|
||||
editHelp: 'Click twice on a field to edit it.',
|
||||
editnamewarning: 'If the name of the skill is changed, it can no longer be improved according to the rules. Also, bonuses and other values may be missing when exporting!'
|
||||
}
|
||||
},
|
||||
audit: {
|
||||
|
||||
Reference in New Issue
Block a user