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:
@@ -147,7 +147,17 @@ func UpdateCharacter(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, character)
|
// Reload character to get updated data
|
||||||
|
var updatedCharacter models.Char
|
||||||
|
err = updatedCharacter.FirstID(id)
|
||||||
|
if err != nil {
|
||||||
|
respondWithError(c, http.StatusInternalServerError, "Failed to reload character")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return as FeChar with categorized skills
|
||||||
|
feChar := ToFeChar(&updatedCharacter)
|
||||||
|
c.JSON(http.StatusOK, feChar)
|
||||||
}
|
}
|
||||||
func DeleteCharacter(c *gin.Context) {
|
func DeleteCharacter(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<!-- Submenu Content -->
|
<!-- Submenu Content -->
|
||||||
<!-- <div class="character-aspect"> -->
|
<!-- <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> -->
|
<!-- </div> -->
|
||||||
|
|
||||||
<!-- Submenu -->
|
<!-- Submenu -->
|
||||||
@@ -156,6 +156,12 @@ export default {
|
|||||||
alert('Fehler beim Aktualisieren der Charakterdaten: ' + (error.response?.data?.error || error.message));
|
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>
|
</script>
|
||||||
@@ -55,6 +55,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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">
|
<table class="cd-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -384,6 +393,29 @@
|
|||||||
transform: translateX(0);
|
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>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -431,6 +463,7 @@ export default {
|
|||||||
editingSkillId: null,
|
editingSkillId: null,
|
||||||
editingField: null,
|
editingField: null,
|
||||||
editValue: '',
|
editValue: '',
|
||||||
|
showNameEditWarning: false,
|
||||||
|
|
||||||
isLoading: false
|
isLoading: false
|
||||||
};
|
};
|
||||||
@@ -752,6 +785,11 @@ export default {
|
|||||||
this.editingField = field;
|
this.editingField = field;
|
||||||
this.editValue = skill[field] || '';
|
this.editValue = skill[field] || '';
|
||||||
|
|
||||||
|
// Show warning when editing skill name
|
||||||
|
if (field === 'name') {
|
||||||
|
this.showNameEditWarning = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const input = this.$refs.editInput;
|
const input = this.$refs.editInput;
|
||||||
if (input) {
|
if (input) {
|
||||||
@@ -779,19 +817,50 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update local character object
|
// Find and update the original skill in character.fertigkeiten or character.waffenfertigkeiten
|
||||||
skill[field] = newValue;
|
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 {
|
try {
|
||||||
// Save to backend
|
// 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();
|
this.cancelEditSkill();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to update skill:', error);
|
console.error('Failed to update skill:', error);
|
||||||
alert('Fehler beim Speichern: ' + (error.response?.data?.error || error.message));
|
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.editingSkillId = null;
|
||||||
this.editingField = null;
|
this.editingField = null;
|
||||||
this.editValue = '';
|
this.editValue = '';
|
||||||
|
this.showNameEditWarning = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
isEditingSkill(skill, field) {
|
isEditingSkill(skill, field) {
|
||||||
|
|||||||
@@ -563,7 +563,8 @@ export default {
|
|||||||
bRollTooltip: 'B würfeln: 1d6 + Modifikator je nach Rasse'
|
bRollTooltip: 'B würfeln: 1d6 + Modifikator je nach Rasse'
|
||||||
},
|
},
|
||||||
datasheet: {
|
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: {
|
audit: {
|
||||||
|
|||||||
@@ -559,7 +559,8 @@ export default {
|
|||||||
bRollTooltip: 'Roll B: 1d6 + modifier based on race'
|
bRollTooltip: 'Roll B: 1d6 + modifier based on race'
|
||||||
},
|
},
|
||||||
datasheet: {
|
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: {
|
audit: {
|
||||||
|
|||||||
Reference in New Issue
Block a user