From a7eb3240bf04e5272f03b8d260f7d961c0d9e32e Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Mon, 26 Sep 2022 01:01:18 +0100 Subject: [PATCH] add optional parameter to set-alert function in utils package. This is so I can define what type of alert message I want the server to send... and include the cat images I found. --- src/utils.lisp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utils.lisp b/src/utils.lisp index 54a629e..c4bf195 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -76,11 +76,25 @@ name. Just specify it in this function's `REQUEST-VALUE' argument." (string= request-value (car item))) collect item)) -(defun set-alert (message) +(defun set-alert (message &optional alert-type) "Sets the alert `MESSAGE' stored in session, provide info. to users. The intention is store a `MESSAGE' across a redirect during a HTTP POST request." - (setf (gethash :alert ningle:*session*) message)) + (cond ((string= "error" alert-type) + (setf (gethash :alert ningle:*session*) + (build-alert-string alert-type "vomit-cat.png" message))) + ((string= "success" alert-type) + (setf (gethash :alert ningle:*session*) + (build-alert-string alert-type "disco-cat.png" message))) + (t (setf (gethash :alert ningle:*session*) message)))) + +(defun build-alert-string (alt-text src-image message) + (format nil + "

\"~a\"~a

" + alt-text + alt-text + src-image + message)) (defun get-alert () "Get alert message from session data."