Skip to content
Snippets Groups Projects
Commit 12f37326 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#583 - show feedback after deleting of a category

parent ff8305a7
Branches
Tags
No related merge requests found
......@@ -3,15 +3,17 @@ package de.deadlocker8.budgetmaster.categories;
import de.deadlocker8.budgetmaster.controller.BaseController;
import de.deadlocker8.budgetmaster.services.HelpersService;
import de.deadlocker8.budgetmaster.settings.SettingsService;
import de.deadlocker8.budgetmaster.utils.Colors;
import de.deadlocker8.budgetmaster.utils.Mappings;
import de.deadlocker8.budgetmaster.utils.ResourceNotFoundException;
import de.deadlocker8.budgetmaster.utils.*;
import de.deadlocker8.budgetmaster.utils.notification.Notification;
import de.deadlocker8.budgetmaster.utils.notification.NotificationType;
import de.thecodelabs.utils.util.ColorUtilsNonJavaFX;
import de.thecodelabs.utils.util.Localization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.WebRequest;
import java.util.List;
import java.util.Optional;
......@@ -65,11 +67,21 @@ public class CategoryController extends BaseController
}
@PostMapping(value = "/{ID}/delete")
public String deleteCategory(@PathVariable("ID") Integer ID, @ModelAttribute("DestinationCategory") DestinationCategory destinationCategory)
public String deleteCategory(WebRequest request, @PathVariable("ID") Integer ID, @ModelAttribute("DestinationCategory") DestinationCategory destinationCategory)
{
if(categoryService.isDeletable(ID))
{
final Optional<Category> categoryOptional = categoryService.findById(ID);
if(categoryOptional.isPresent())
{
final Category categoryToDelete = categoryOptional.get();
categoryService.deleteCategory(ID, destinationCategory.getCategory());
WebRequestUtils.putNotification(request, new Notification(Localization.getString("notification.category.delete.success", categoryToDelete.getName()), NotificationType.SUCCESS));
}
}
else
{
WebRequestUtils.putNotification(request, new Notification(Localization.getString("notification.category.delete.not.deletable", String.valueOf(ID)), NotificationType.ERROR));
}
return "redirect:/categories";
......@@ -83,6 +95,7 @@ public class CategoryController extends BaseController
Category emptyCategory = new Category(null, ColorUtilsNonJavaFX.toRGBHexWithoutOpacity(Colors.CATEGORIES_LIGHT_GREY).toLowerCase(), CategoryType.CUSTOM);
model.addAttribute("category", emptyCategory);
model.addAttribute("settings", settingsService.getSettings());
return "categories/newCategory";
}
......
......@@ -99,6 +99,9 @@ info.title.category.delete=Kategorie löschen
info.text.category.delete=Möchtest du die Kategorie "{0}" wirklich unwiderruflich löschen?
info.title.category.delete.move=Verschieben nach
info.text.category.delete.move=In welche Kategorie sollen alle veknüpften Buchungen verschoben werden?
notification.category.delete.success=Die Kategorie "{0}" wurde erfolgreich gelöscht.
notification.category.delete.not.deletable=Die Kategorie mit der ID "{0}" ist nicht löschbar!
info.title.account.delete=Konto löschen
info.text.account.delete=Möchtest du das Konto "{0}" wirklich unwiderruflich löschen?<br>Hinweis: Diesem Konto sind {1} Buchungen zugeordnet. Beim Löschen des Kontos werden diese ebenfalls gelöscht!
info.button.account.delete=Konto und Buchungen löschen
......
......@@ -99,6 +99,9 @@ info.title.category.delete=Delete Category
info.text.category.delete=Do you really want to delete the category "{0}"? This can''t be undone.
info.title.category.delete.move=Move to
info.text.category.delete.move=In which category should all related transactions be moved?
notification.category.delete.success=Successfully deleted category "{0}".
notification.category.delete.not.deletable=The category with id "{0}" is undeletable.
info.title.account.delete=Delete Account
info.text.account.delete=Do you really want to delete the account "{0}"? This can''t be undone.<br>Note: There are {1} transactions associated with this account. Deleting this account will delete all releated transactions too!
info.button.account.delete=Delete Account and Transactions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment