Skip to content

Commit

Permalink
#724 - show upload errors on page
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlocker8 committed Jan 14, 2023
1 parent 1aecff3 commit 7387129
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import de.deadlocker8.budgetmaster.categories.CategoryService;
import de.deadlocker8.budgetmaster.categories.CategoryType;
import de.deadlocker8.budgetmaster.controller.BaseController;
import de.deadlocker8.budgetmaster.services.DateFormatStyle;
import de.deadlocker8.budgetmaster.services.HelpersService;
import de.deadlocker8.budgetmaster.settings.SettingsService;
import de.deadlocker8.budgetmaster.transactions.csvimport.*;
import de.deadlocker8.budgetmaster.utils.Mappings;
import de.deadlocker8.budgetmaster.utils.WebRequestUtils;
import de.deadlocker8.budgetmaster.utils.notification.Notification;
import de.deadlocker8.budgetmaster.utils.notification.NotificationType;
import de.thecodelabs.utils.util.Localization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -53,7 +55,6 @@ private RequestAttributeNames()
public static final String CSV_ROWS = "csvRows";
public static final String CSV_TRANSACTIONS = "csvTransactions";
public static final String ERROR_UPLOAD = "errorUpload";
public static final String ERROR_UPLOAD_FILE = "errorUploadFile";
public static final String ERRORS_COLUMN_SETTINGS = "errorsColumnSettings";

}
Expand Down Expand Up @@ -98,7 +99,9 @@ public String upload(WebRequest request,
{
if(csvImport.file().isEmpty())
{
return ReturnValues.REDIRECT_CANCEL;
removeAllAttributes(request);
WebRequestUtils.putNotification(request, new Notification(Localization.getString("transactions.import.error.upload.empty"), NotificationType.ERROR));
return ReturnValues.REDIRECT_IMPORT;
}

if(!csvImport.isValidSeparator())
Expand Down Expand Up @@ -132,8 +135,7 @@ public String upload(WebRequest request,
{
LOGGER.error("CSV upload failed", e);

// TODO: show in html
request.setAttribute(RequestAttributeNames.ERROR_UPLOAD_FILE, e.getMessage(), RequestAttributes.SCOPE_SESSION);
WebRequestUtils.putNotification(request, new Notification(Localization.getString("transactions.import.error.upload", e.getMessage()), NotificationType.ERROR));
}
return ReturnValues.REDIRECT_IMPORT;
}
Expand Down Expand Up @@ -294,7 +296,6 @@ private void removeAllAttributes(WebRequest request)
request.removeAttribute(RequestAttributeNames.CSV_ROWS, RequestAttributes.SCOPE_SESSION);
request.removeAttribute(RequestAttributeNames.CSV_TRANSACTIONS, RequestAttributes.SCOPE_SESSION);
request.removeAttribute(RequestAttributeNames.ERROR_UPLOAD, RequestAttributes.SCOPE_SESSION);
request.removeAttribute(RequestAttributeNames.ERROR_UPLOAD_FILE, RequestAttributes.SCOPE_SESSION);
request.removeAttribute(RequestAttributeNames.ERRORS_COLUMN_SETTINGS, RequestAttributes.SCOPE_SESSION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ info.text.update=Es ist ein Update für BudgetMaster verfügbar<br><br>Installie
info.title.backup.reminder=Zeit für ein Backup
info.text.backup.reminder=Schon mal über ein Backup nachgedacht?<br>Du solltest deine BudgetMaster Datenbank regelmäßig sichern.<br>Dies geht besonders einfach in den Einstellungen.<br>Du kannst auch ein automatisches Backup konfigurieren.<br><br>(Du wilst diese Erinnerung nicht jeden Monat sehen? Dann deaktiviere die Backuperinnerung in den Einstellungen.)
info.button.backup.reminder=Zu den Einstellungen
notification.settings.saved=Einstellungen gespeichert
notification.settings.security.saved=Passwort gespeichert
notification.settings.security.warning=Passwort entspricht bereits gespeicherten Passwort
notification.settings.security.error=Fehler beim Speichern des Passworts
Expand Down Expand Up @@ -381,6 +380,8 @@ transactions.import.status.pending=ausstehend
transactions.import.status.imported=importiert
transactions.import.status.skipped=übersprungen
transactions.import.actions=Aktionen
transactions.import.error.upload=Fehler beim Hochladen: {0}
transactions.import.error.upload.empty=Ungültige leere Datei
transactions.import.error.column=Zugeordnete Spalten in Zeile {0} (Zählung beginnt relativ zu Anzahl übersprungener Zeilen) nicht gefunden: {1}
transactions.import.error.parse.amount=Fehler beim Parsen des Betrags in Zeile {0} (Zählung beginnt relativ zu Anzahl übersprungener Zeilen)
transactions.import.error.parse.date=Fehler beim Parsen des Datums in Zeile {0} (Zählung beginnt relativ zu Anzahl übersprungener Zeilen)<br>Wert "{1}" kann nicht mit Pattern "{2}" geparst werden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ info.text.update=An update for BudgetMaster is available<br><br>Installed: v{0}<
info.title.backup.reminder=Time for a backup
info.text.backup.reminder=Have you ever thought about a backup?<br>You should back up your BudgetMaster database regularly.<br>This can be done on the settings page.<br>You can also enable an automatic backup.<br><br>(You don''t want to see this reminder every month? Disable the backup reminder in the settings.)
info.button.backup.reminder=To the settings
notification.settings.saved=Settings saved
notification.settings.security.saved=Password saved
notification.settings.security.warning=Password equals already saved password
notification.settings.security.error=Error saving password
Expand Down Expand Up @@ -380,6 +379,8 @@ transactions.import.status.pending=pending
transactions.import.status.imported=imported
transactions.import.status.skipped=skipped
transactions.import.actions=Actions
transactions.import.error.upload=Upload error: {0}
transactions.import.error.upload.empty=Invalid empty file
transactions.import.error.column=Associated columns not found in row {0} (counting starts relative to the number of skipped rows): {1}
transactions.import.error.parse.amount=Error parsing the amount in line {0} (counting starts relative to number of skipped lines)
transactions.import.error.parse.date=Error parsing the date in line {0} (counting starts relative to number of skipped lines)<br>Value "{1}" could not be parsed with pattern "{2}".
Expand Down

0 comments on commit 7387129

Please sign in to comment.