From 88f85eb8112339f70a1823fcd8b467ef79569cdf Mon Sep 17 00:00:00 2001 From: "A. Diamond" Date: Thu, 7 Dec 2023 15:56:35 -0500 Subject: [PATCH] Show flash message on object save and delete --- TODO.md | 2 +- server/controllers/app_settings_controller.go | 3 +++ server/controllers/bagit_profiles_controller.go | 1 + server/controllers/cookies.go | 2 +- server/controllers/jobs_controller.go | 2 +- server/controllers/remote_repositories_controller.go | 3 ++- server/controllers/settings_controller.go | 1 + server/controllers/storage_services_controller.go | 4 +++- server/controllers/workflows_controller.go | 3 ++- 9 files changed, 15 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index c43722d..6b82c47 100644 --- a/TODO.md +++ b/TODO.md @@ -32,7 +32,7 @@ - [ ] Implement upload-only jobs. - [ ] Context-sensitive help - [x] Autofill other properties on job package page (e.g. if profile only allows tar, autoselect tar as serialization format) -- [ ] Show flash confirmation message on successful save and delete +- [x] Show flash confirmation message on successful save and delete - [ ] BUG - Job Metadata page won't load if packaging format is not BagIt ## Later diff --git a/server/controllers/app_settings_controller.go b/server/controllers/app_settings_controller.go index 5b64e0b..ea2fd64 100644 --- a/server/controllers/app_settings_controller.go +++ b/server/controllers/app_settings_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "fmt" "net/http" "github.com/APTrust/dart-runner/core" @@ -20,6 +21,7 @@ func AppSettingDelete(c *gin.Context) { AbortWithErrorHTML(c, http.StatusInternalServerError, err) return } + SetFlashCookie(c, fmt.Sprintf("Deleted app setting %s", request.QueryResult.AppSetting())) c.Redirect(http.StatusFound, "/app_settings") } @@ -74,5 +76,6 @@ func AppSettingSave(c *gin.Context) { c.HTML(http.StatusBadRequest, "app_setting/form.html", data) return } + SetFlashCookie(c, fmt.Sprintf("Saved setting %s", setting.Name)) c.Redirect(http.StatusFound, "/app_settings") } diff --git a/server/controllers/bagit_profiles_controller.go b/server/controllers/bagit_profiles_controller.go index c071626..fe3fff0 100644 --- a/server/controllers/bagit_profiles_controller.go +++ b/server/controllers/bagit_profiles_controller.go @@ -55,6 +55,7 @@ func BagItProfileDelete(c *gin.Context) { "status": "OK", "location": "/profiles", } + SetFlashCookie(c, fmt.Sprintf("Deleted BagIt Profile %s", result.BagItProfile().Name)) c.JSON(http.StatusOK, data) } diff --git a/server/controllers/cookies.go b/server/controllers/cookies.go index a5f723e..45616a2 100644 --- a/server/controllers/cookies.go +++ b/server/controllers/cookies.go @@ -6,7 +6,7 @@ import ( ) func SetFlashCookie(c *gin.Context, message string) { - c.SetCookie(constants.FlashCookieName, message, 5, "/", "localhost", false, false) + c.SetCookie(constants.FlashCookieName, message, 2, "/", "localhost", false, false) } func GetFlashCookie(c *gin.Context) string { diff --git a/server/controllers/jobs_controller.go b/server/controllers/jobs_controller.go index f40d9dc..508daf1 100644 --- a/server/controllers/jobs_controller.go +++ b/server/controllers/jobs_controller.go @@ -33,7 +33,7 @@ func JobDelete(c *gin.Context) { AbortWithErrorHTML(c, http.StatusInternalServerError, deletionErr) return } - SetFlashCookie(c, fmt.Sprintf("Job %s was deleted.", result.Job().Name())) + SetFlashCookie(c, fmt.Sprintf("Deleted job %s.", result.Job().Name())) c.Redirect(http.StatusFound, "/jobs") } diff --git a/server/controllers/remote_repositories_controller.go b/server/controllers/remote_repositories_controller.go index f5a668e..b4f3f7a 100644 --- a/server/controllers/remote_repositories_controller.go +++ b/server/controllers/remote_repositories_controller.go @@ -21,8 +21,8 @@ func RemoteRepositoryDelete(c *gin.Context) { AbortWithErrorHTML(c, http.StatusInternalServerError, err) return } + SetFlashCookie(c, fmt.Sprintf("Deleted remote repo %s", request.QueryResult.RemoteRepository().Name)) c.Redirect(http.StatusFound, "/remote_repositories") - } // GET /remote_repositories/edit/:id @@ -78,6 +78,7 @@ func RemoteRepositorySave(c *gin.Context) { c.HTML(http.StatusBadRequest, "remote_repository/form.html", data) return } + SetFlashCookie(c, "Remote repo settings saved.") c.Redirect(http.StatusFound, "/remote_repositories") } diff --git a/server/controllers/settings_controller.go b/server/controllers/settings_controller.go index b2ef848..c96e73d 100644 --- a/server/controllers/settings_controller.go +++ b/server/controllers/settings_controller.go @@ -106,6 +106,7 @@ func SettingsExportDelete(c *gin.Context) { AbortWithErrorHTML(c, http.StatusInternalServerError, err) return } + SetFlashCookie(c, fmt.Sprintf("Deleted settings %s", exportSettings.Name)) c.Redirect(http.StatusFound, "/settings/export") } diff --git a/server/controllers/storage_services_controller.go b/server/controllers/storage_services_controller.go index 5451ec5..4e0d7ad 100644 --- a/server/controllers/storage_services_controller.go +++ b/server/controllers/storage_services_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "fmt" "net/http" "github.com/APTrust/dart-runner/core" @@ -20,8 +21,8 @@ func StorageServiceDelete(c *gin.Context) { AbortWithErrorHTML(c, http.StatusInternalServerError, err) return } + SetFlashCookie(c, fmt.Sprintf("Deleted storage service %s", request.QueryResult.StorageService().Name)) c.Redirect(http.StatusFound, "/storage_services") - } // GET /storage_services/edit/:id @@ -77,6 +78,7 @@ func StorageServiceSave(c *gin.Context) { c.HTML(http.StatusBadRequest, "storage_service/form.html", data) return } + SetFlashCookie(c, fmt.Sprintf("Saved storage service %s", ss.Name)) c.Redirect(http.StatusFound, "/storage_services") } diff --git a/server/controllers/workflows_controller.go b/server/controllers/workflows_controller.go index dbb1b85..2482921 100644 --- a/server/controllers/workflows_controller.go +++ b/server/controllers/workflows_controller.go @@ -75,6 +75,7 @@ func WorkflowDelete(c *gin.Context) { AbortWithErrorHTML(c, http.StatusNotFound, err) return } + SetFlashCookie(c, fmt.Sprintf("Deleted workflow %s", result.Workflow().Name)) c.Redirect(http.StatusFound, "/workflows") } @@ -126,8 +127,8 @@ func WorkflowSave(c *gin.Context) { c.HTML(http.StatusBadRequest, "workflow/form.html", data) return } + SetFlashCookie(c, fmt.Sprintf("Saved workflow %s", workflow.Name)) c.Redirect(http.StatusFound, "/workflows") - } // GET /workflows/export/:id