summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorckonstanski <kostcarl@isu.edu>2026-08-18 20:00:23 -0600
committerckonstanski <kostcarl@isu.edu>2026-08-18 20:00:23 -0600
commit26a106b0d9687be8448e37658887c8bc2937804e (patch)
treec13e2b04583802f7e3c407dc9a7c9f945cc15bfb
parentc3b8f1326a874ae08b394020c6279237b0413293 (diff)
notification cleanup and message marking
-rw-r--r--lisp/service/auth-service.lisp16
-rw-r--r--lisp/service/contact-us-service.lisp4
-rw-r--r--lisp/service/login-service.lisp14
-rw-r--r--lisp/service/messages-service.lisp15
-rw-r--r--lisp/service/password-service.lisp4
-rw-r--r--lisp/service/profile-service.lisp4
-rw-r--r--lisp/service/rest-service.lisp6
-rw-r--r--lisp/service/resume-service.lisp33
-rw-r--r--lisp/service/users-service.lisp36
-rw-r--r--lisp/sql/contact-pkg.lisp1
-rw-r--r--lisp/webapps/resume/clojurescript/resume/src/resume/core.clj16
-rw-r--r--lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs152
-rw-r--r--sql/functions/contact.mark_contact_us_post.sql33
13 files changed, 178 insertions, 156 deletions
diff --git a/lisp/service/auth-service.lisp b/lisp/service/auth-service.lisp
index 8450e64..0862147 100644
--- a/lisp/service/auth-service.lisp
+++ b/lisp/service/auth-service.lisp
@@ -20,15 +20,15 @@
(when (null (errormsg ,instance))
,@body)
(when (location-p ,instance)
- (setf (session-value :message) nil)
- (setf (session-value :errormsg) nil))
+ (setf (message instance) nil)
+ (setf (errormsg instance) nil))
(org-ckons-json::objects-to-json `(,,instance))))
(defmacro with-auth-raw ((instance auth-service roles) &body body)
`(let ((,instance (make-instance ',auth-service :roles ,roles)))
(when (location-p ,instance)
- (setf (session-value :message) nil)
- (setf (session-value :errormsg) nil))
+ (setf (message instance) nil)
+ (setf (errormsg instance) nil))
(when (null (errormsg ,instance))
,@body)))
@@ -36,13 +36,13 @@
`(let ((,instance (make-instance ',rest-service)))
,@body
(when (location-p ,instance)
- (setf (session-value :message) nil)
- (setf (session-value :errormsg) nil))
+ (setf (message instance) nil)
+ (setf (errormsg instance) nil))
(org-ckons-json::objects-to-json `(,,instance))))
(defmacro with-noauth-raw ((instance rest-service) &body body)
`(let ((,instance (make-instance ',rest-service)))
(when (location-p ,instance)
- (setf (session-value :message) nil)
- (setf (session-value :errormsg) nil))
+ (setf (message instance) nil)
+ (setf (errormsg instance) nil))
,@body))
diff --git a/lisp/service/contact-us-service.lisp b/lisp/service/contact-us-service.lisp
index 1e55ddb..d97d74c 100644
--- a/lisp/service/contact-us-service.lisp
+++ b/lisp/service/contact-us-service.lisp
@@ -78,10 +78,10 @@
:reply-to (mail-postmaster *webapp*)
:ssl (mail-ssl *webapp*)
:authentication (mail-authentication *webapp*))
- (setf (session-value :message) "Form submitted successfully."))
+ (setf (message instance) "Form submitted successfully."))
(error (e)
(declare (ignore e))
- (setf (session-value :errormsg) "Error submitting form.")))))))
+ (setf (errormsg instance) "Error submitting form.")))))))
(define-endpoint ("/contact-us" :method :get) () contact-us-json)
(define-endpoint ("/contact-us/view" :method :get) () contact-us-view-json)
diff --git a/lisp/service/login-service.lisp b/lisp/service/login-service.lisp
index cedc867..a4ff93c 100644
--- a/lisp/service/login-service.lisp
+++ b/lisp/service/login-service.lisp
@@ -49,19 +49,19 @@
(with-noauth (instance login-authenticate-service)
(if (or (org-ckons-core::null-or-empty-p username)
(org-ckons-core::null-or-empty-p pwd))
- (setf (session-value :errormsg) "Login failed.")
+ (setf (errormsg instance) "Login failed.")
(with-resume-database
(let* ((auth-pkg (make-instance 'auth-pkg))
(user (get-active-user-by-username-pwd auth-pkg username pwd)))
(cond (user
(set-user user)
- (setf (session-value :message) "Successfully logged in.")
- (setf (session-value :errormsg) nil))
+ (setf (message instance) "Successfully logged in.")
+ (setf (errormsg instance) nil))
(t
- (setf (session-value :message) nil)
- (setf (session-value :errormsg) "Login failed."))))))
- (setf (message instance) (session-value :message))
- (setf (errormsg instance) (session-value :errormsg))))
+ (setf (message instance) nil)
+ (setf (errormsg instance) "Login failed."))))))
+ (setf (message instance) (message instance))
+ (setf (errormsg instance) (errormsg instance))))
(define-endpoint ("/login" :method :get) () login-json)
(define-endpoint ("/login/authenticate" :method :post) (&post (username :parameter-type 'string) (pwd :parameter-type 'string)) login-authenticate-json username pwd)
diff --git a/lisp/service/messages-service.lisp b/lisp/service/messages-service.lisp
index 9690822..5c0f241 100644
--- a/lisp/service/messages-service.lisp
+++ b/lisp/service/messages-service.lisp
@@ -18,19 +18,18 @@
(setf (form instance) (make-form "messages-select-mode-form"
nil
nil
- `((:name "read" :field-type "hidden" :required "required" :value ,(session-value :messages-read))
- (:label "View Unread" :field-type "button" :onclick "on_messages_mode_clicked('unread')")
+ `((:label "View Unread" :field-type "button" :onclick "on_messages_mode_clicked('unread')")
(:label "View Read" :field-type "button" :onclick "on_messages_mode_clicked('read')"))))))
-(defclass messages/results-service (messages-service)
+(defclass messages/view-service (messages-service)
((results :initarg :results
:initform nil
:accessor results)
(location-p :initform nil))
(:documentation ""))
-(defun messages-results-json (read)
- (with-auth (instance messages/results-service "messages-view")
+(defun messages-view-json (read)
+ (with-auth (instance messages/view-service "messages-view")
(when read (setf (session-value :messages-read) read))
(with-resume-database
(let ((contact-pkg (make-instance 'contact-pkg)))
@@ -51,11 +50,11 @@
(handler-case
(let ((contact-pkg (make-instance 'contact-pkg)))
(mark-contact-us-post contact-pkg id (id (get-user)) (string= read "read"))
- (setf (session-value :message) (format nil "Message marked ~a successfully." read)))
+ (setf (message instance) (format nil "Message marked ~a successfully." read)))
(error (e)
(declare (ignore e))
- (setf (session-value :errormsg) (format nil "Error marking message ~a." read)))))))
+ (setf (errormsg instance) (format nil "Error marking message ~a." read)))))))
(define-endpoint ("/messages" :method :get) () messages-json)
-(define-endpoint ("/messages/results" :method :post) (&post (read :parameter-type 'string)) messages-results-json read)
+(define-endpoint ("/messages/view" :method :post) (&post (read :parameter-type 'string)) messages-view-json read)
(define-endpoint ("/messages/mark" :method :post) (&post (read :parameter-type 'string) (id :parameter-type 'integer)) messages-mark-json read id)
diff --git a/lisp/service/password-service.lisp b/lisp/service/password-service.lisp
index dc319a0..d9ad4bc 100644
--- a/lisp/service/password-service.lisp
+++ b/lisp/service/password-service.lisp
@@ -46,8 +46,8 @@
do (setf (slot-value user param) (symbol-value param)))
(update-password auth-pkg user)
(set-user user)
- (setf (session-value :message) "Password saved successfully."))
- (setf (session-value :errormsg) "An error occured."))))))
+ (setf (message instance) "Password saved successfully."))
+ (setf (errormsg instance) "An error occured."))))))
(define-endpoint ("/password" :method :get) () password-json)
(define-endpoint ("/password/submit" :method :post) (&post (id :parameter-type 'integer) (pwd :parameter-type 'string) (pwd2 :parameter-type 'string)) password-submit-json id pwd pwd2)
diff --git a/lisp/service/profile-service.lisp b/lisp/service/profile-service.lisp
index d2a9f05..990a9d0 100644
--- a/lisp/service/profile-service.lisp
+++ b/lisp/service/profile-service.lisp
@@ -70,8 +70,8 @@
do (setf (slot-value user param) (symbol-value param)))
(update-user auth-pkg user)
(set-user user)
- (setf (session-value :message) "Profile saved successfully."))
- (setf (session-value :errormsg) "An error occured."))))))
+ (setf (message instance) "Profile saved successfully."))
+ (setf (errormsg instance) "An error occured."))))))
(define-endpoint ("/profile" :method :get) () profile-json)
(define-endpoint ("/profile/view" :method :get) () profile-view-json)
diff --git a/lisp/service/rest-service.lisp b/lisp/service/rest-service.lisp
index 4d23031..f497245 100644
--- a/lisp/service/rest-service.lisp
+++ b/lisp/service/rest-service.lisp
@@ -20,12 +20,6 @@
(defmethod initialize-instance :after ((rest-service rest-service) &key)
(when (location-p rest-service)
- (if (message rest-service)
- (setf (session-value :message) (message rest-service))
- (setf (message rest-service) (session-value :message)))
- (if (errormsg rest-service)
- (setf (session-value :errormsg) (errormsg rest-service))
- (setf (errormsg rest-service) (session-value :errormsg)))
(when (null (location rest-service))
(setf (location rest-service) (type-to-path rest-service)))))
diff --git a/lisp/service/resume-service.lisp b/lisp/service/resume-service.lisp
index 46badc6..6a8e589 100644
--- a/lisp/service/resume-service.lisp
+++ b/lisp/service/resume-service.lisp
@@ -42,7 +42,7 @@
;; macros
-(defmacro define-resume-component ((component-s rest-args input-add-fields input-modify-fields order-by &optional view-p))
+(defmacro define-resume-component ((component-s rest-args input-add-fields input-modify-fields order-by &key view-p))
"`component-s' is a symbol that matches the component's record object
name, i.e SKILL, JOB, EDUCATION, LANGUAGE, CONTACTINFO. This will be
used all over the place. The record name equals the component name.
@@ -57,7 +57,7 @@ fields that get inserted into the add and modify forms.
needs to JOIN with other data."
(let* ((component (symbol-name component-s))
(component-lcase (string-downcase component))
- (components-s (intern (format nil "~aS" component)))
+ (component-s (intern (format nil "~a" component)))
(table (format nil "resume.~a~a" component-lcase (if view-p "_v" "")))
(arg-names (loop for arg in rest-args collect (car arg)))
(func-root-s (intern (format nil "~a-JSON" component)))
@@ -90,13 +90,11 @@ needs to JOIN with other data."
(defun ,func-add-s ()
(with-auth (instance resume/resume-component/modify-service "resume-modify")
- (with-resume-database
- (let ((resume-pkg (make-instance 'resume-pkg)))
- (setf (title instance) (format nil "~a - Add" ,component))
- (setf (form instance) (make-form ,form-add
- nil
- t
- ,input-add-fields))))))
+ (setf (title instance) (format nil "~a - Add" ,component))
+ (setf (form instance) (make-form ,form-add
+ nil
+ t
+ ,input-add-fields))))
(defun ,func-add-submit-s (,@arg-names)
(declare (special ,@arg-names))
@@ -149,11 +147,13 @@ needs to JOIN with other data."
(loop for param in (sb-introspect:function-lambda-list #',func-modify-submit-s)
do (setf (slot-value new-component param) (symbol-value param)))
(setf (user_id new-component) (id user))
- (update-record resume-pkg new-component)
- (setf (session-value :message) (format nil "~a modified successfully." ,component)))
+ (update-record-no-nulls resume-pkg new-component)
+ (setf (session-value :message) (format nil "~a modified successfully." ,component))
+ (setf (message instance) (session-value :message)))
(error (format nil "~a error" ,component))))
(error (e)
- (setf (session-value :errormsg) (format nil "Error modifying ~a. ~a" ,component e)))))))
+ (setf (session-value :errormsg) (format nil "Error modifying ~a. ~a" ,component e))
+ (setf (errormsg instance) (session-value :errormsg)))))))
(defun ,func-delete-s (id)
(with-auth (instance resume/resume-component/modify-service "resume-modify")
@@ -167,8 +167,11 @@ needs to JOIN with other data."
(if ,component-s
(progn
(delete-record resume-pkg (make-instance ',component-s :id id))
- (setf (session-value :message) (format nil "~a deleted successfully." ,component)))
- (setf (session-value :errormsg) (format nil "Error: could not delete ~a: not found." ,component)))))))
+ (setf (session-value :message) (format nil "~a deleted successfully." ,component))
+ (setf (message instance) (session-value :message)))
+ (progn
+ (setf (session-value :errormsg) (format nil "Error: could not delete ~a: not found." ,component))
+ (setf (errormsg instance) (session-value :errormsg))))))))
(define-endpoint (,(format nil "/resume/~a" component-lcase) :method :get) () ,func-root-s)
(define-endpoint (,(format nil "/resume/~a/view" component-lcase) :method :get) () ,func-view-s)
@@ -207,7 +210,7 @@ needs to JOIN with other data."
(:name "visastatus_id" :label "VISA Status" :field-type "select" :value (visastatus_id contactinfo) :options ,(visastatus-options (get-records resume-pkg (make-instance 'visastatus) "visastatus asc")) :required "required")
(:label "Modify CONTACTINFO" :field-type "button" :onclick "on_contactinfo_modify_submit_clicked()"))
"state_abbr asc, city asc, address asc"
- t))
+ :view-p t))
(define-resume-component (education
((school :parameter-type 'string) (major :parameter-type 'string) (minor :parameter-type 'string) (degree :parameter-type 'string) (progress :parameter-type 'string) (start_date :parameter-type 'string) (end_date :parameter-type 'string))
diff --git a/lisp/service/users-service.lisp b/lisp/service/users-service.lisp
index d05dfb0..4143ad3 100644
--- a/lisp/service/users-service.lisp
+++ b/lisp/service/users-service.lisp
@@ -113,9 +113,9 @@
:reply-to (mail-postmaster *webapp*)
:ssl (mail-ssl *webapp*)
:authentication (mail-authentication *webapp*))
- (setf (session-value :message) (format nil "Email sent successfully to ~a" (email registration))))
+ (setf (message instance) (format nil "Email sent successfully to ~a" (email registration))))
(error (e)
- (setf (session-value :errormsg) (format nil "Error sending email to ~a. Registration failed. ~a" (email registration) e))))))))
+ (setf (errormsg instance) (format nil "Error sending email to ~a. Registration failed. ~a" (email registration) e))))))))
(defclass users/register-service (rest-service)
((title :initarg :title
@@ -155,7 +155,7 @@
(:name "pwd2" :label "Password (again)" :field-type "password" :required "required")
(:name "phone" :label "Phone" :field-type "text")
(:label "Register" :field-type "button" :onclick "on_users_register_submit_clicked()"))))
- (setf (session-value :errormsg) "Error: invalid registration."))))))
+ (setf (errormsg instance) "Error: invalid registration."))))))
(defclass users/register/submit-service (rest-service)
((location-p :initform nil))
@@ -187,10 +187,10 @@
:user_id (id user)
:role_group_name role-group)))
(delete-registration auth-pkg hash)
- (setf (session-value :message) "Registration completed successfully."))
- (setf (session-value :errormsg) "Error while completing registration.")))
- (setf (session-value :errormsg) "Error: passwords do not match."))
- (setf (session-value :errormsg) "Error while completing registration."))))))
+ (setf (message instance) "Registration completed successfully."))
+ (setf (errormsg instance) "Error while completing registration.")))
+ (setf (errormsg instance) "Error: passwords do not match."))
+ (setf (errormsg instance) "Error while completing registration."))))))
(defclass users/modify-service (users/add-service)
()
@@ -217,7 +217,7 @@
(:name "phone" :label "Phone" :field-type "text" :value ,(phone user))
,@(role-checkboxes "users_modify" role-groups active-role-groups)
(:label "Modify User" :field-type "button" :onclick "on_users_modify_submit_clicked()"))))
- (setf (session-value :errormsg) "Error: could not modify user. Not found."))))))
+ (setf (errormsg instance) "Error: could not modify user. Not found."))))))
(defun users-modify-submit-json (id role_groups username first_name last_name email phone)
(declare (special role_groups username first_name last_name email phone))
@@ -239,8 +239,8 @@
do (insert-user-role-group auth-pkg (make-instance 'user-role
:user_id id
:role_group_name role-group)))
- (setf (session-value :message) "User saved successfully."))
- (setf (session-value :errormsg) "An error occured."))))))
+ (setf (message instance) "User saved successfully."))
+ (setf (errormsg instance) "An error occured."))))))
(defclass users/toggle-service (users/add-service)
()
@@ -253,12 +253,12 @@
(user (get-user-by-id auth-pkg id)))
(if user
(if (= (id user) (id (get-user)))
- (setf (session-value :errormsg) "Error: you may not toggle your own active state.")
+ (setf (errormsg instance) "Error: you may not toggle your own active state.")
(progn
(user-toggle-active auth-pkg user)
- (setf (session-value :errormsg) nil)
- (setf (session-value :message) "User active state toggled successfully.")))
- (setf (session-value :errormsg) "Error: could not toggle the active state of the user: not found."))))))
+ (setf (errormsg instance) nil)
+ (setf (message instance) "User active state toggled successfully.")))
+ (setf (errormsg instance) "Error: could not toggle the active state of the user: not found."))))))
(defclass users/delete-service (users/add-service)
()
@@ -271,12 +271,12 @@
(user (get-user-by-id auth-pkg id)))
(if user
(if (= (id user) (id (get-user)))
- (setf (session-value :errormsg) "Error: you may not delete yourself.")
+ (setf (errormsg instance) "Error: you may not delete yourself.")
(progn
(deactivate-user auth-pkg user)
- (setf (session-value :errormsg) nil)
- (setf (session-value :message) "User deleted successfully.")))
- (setf (session-value :errormsg) "Error: could not delete user: not found."))))))
+ (setf (errormsg instance) nil)
+ (setf (message instance) "User deleted successfully.")))
+ (setf (errormsg instance) "Error: could not delete user: not found."))))))
(define-endpoint ("/users" :method :get) () users-json)
(define-endpoint ("/users/view" :method :get) () users-view-json)
diff --git a/lisp/sql/contact-pkg.lisp b/lisp/sql/contact-pkg.lisp
index dce6384..207708c 100644
--- a/lisp/sql/contact-pkg.lisp
+++ b/lisp/sql/contact-pkg.lisp
@@ -23,6 +23,7 @@
(caar (call-pg-function contact-pkg contact-us-post)))
(defmethod mark-contact-us-post ((contact-pkg contact-pkg) contact-us-post-id user-id read-p)
+
(let ((contact-us-post (make-instance 'contact-us-post
:*table (format nil
"contact.mark_contact_us_post(~a, ~a, '~a')"
diff --git a/lisp/webapps/resume/clojurescript/resume/src/resume/core.clj b/lisp/webapps/resume/clojurescript/resume/src/resume/core.clj
index c02b686..7d61812 100644
--- a/lisp/webapps/resume/clojurescript/resume/src/resume/core.clj
+++ b/lisp/webapps/resume/clojurescript/resume/src/resume/core.clj
@@ -132,12 +132,7 @@
(for [rec# results#]
(let [tr-attributes# (atom {:id (str "tr-" ~component "-" (get rec# "id"))
:key (str "tr-" ~component "-" (get rec# "id"))})
- selected-p# (= (str (get rec# "id"))
- (str (get (get (deref ~(symbol (str component "-view-state")))
- (keyword ~component))
- "id")))]
- (when selected-p#
- (swap! tr-attributes# assoc :class "selected"))
+ td-attributes# (atom {:on-click #()})]
[:tr @tr-attributes#
(for [key# (filter #(not (str/includes? % "_id")) keys#)]
[:td (str (get rec# key#))])
@@ -150,7 +145,6 @@
(defn ~(symbol (str "handler-" component "-view")) [response#]
(let [jsonobj# (cljs.core/js->clj (js/JSON.parse response#))]
- (notifications jsonobj#)
(~(symbol (str "reset-" component "-view-state")) jsonobj#)))
(defn ~(symbol (str "render-" component "-view")) []
@@ -165,7 +159,6 @@
(defn ~(symbol (str "handler-" component "-add")) [response#]
(let [jsonobj# (cljs.core/js->clj (js/JSON.parse response#))]
- (auth-notifications jsonobj#)
(~(symbol (str "reset-" component "-add-state")) jsonobj#)
(.modal (jquery (str "#modal-" ~component "-add")))))
@@ -183,7 +176,7 @@
(defn ~(symbol (str "handler-" component "-add-submit")) [response#]
(let [jsonobj# (cljs.core/js->clj (js/JSON.parse response#))]
(auth-notifications jsonobj#)
- (on-menu-clicked ~(str "/resume/" component))))
+ (~(symbol (str "render-" component "-view")))))
(defn ~(symbol (str "render-" component "-add-submit")) []
(ajax.core/POST ~(str "/resume/" component "/add/submit")
@@ -199,7 +192,6 @@
(defn ~(symbol (str "handler-" component "-modify")) [response#]
(let [jsonobj# (cljs.core/js->clj (js/JSON.parse response#))]
- (auth-notifications jsonobj#)
(~(symbol (str "reset-" component "-modify-state")) jsonobj#)
(.modal (jquery (str "#modal-" ~component "-modify")))))
@@ -219,7 +211,7 @@
(defn ~(symbol (str "handler-" component "-modify-submit")) [response#]
(let [jsonobj# (cljs.core/js->clj (js/JSON.parse response#))]
(auth-notifications jsonobj#)
- (on-menu-clicked (str "/resume/" ~component))))
+ (~(symbol (str "render-" component "-view")))))
(defn ~(symbol (str "render-" component "-modify-submit")) []
(ajax.core/POST (str "/resume/" ~component "/modify/submit")
@@ -234,7 +226,7 @@
(defn ~(symbol (str "handler-" component "-delete")) [response#]
(let [jsonobj# (cljs.core/js->clj (js/JSON.parse response#))]
(auth-notifications jsonobj#)
- (on-menu-clicked ~(str "/resume/" component))))
+ (~(symbol (str "render-" component "-view")))))
(defn ~(symbol (str "render-" component "-delete")) [id#]
(ajax.core/DELETE (str "/resume/" ~component "/delete/" id#)
diff --git a/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs b/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs
index 967ee47..52059f7 100644
--- a/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs
+++ b/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs
@@ -24,7 +24,8 @@
(declare reset-contact-us-state)
(declare reset-contact-us-view-state)
(declare reset-messages-state)
-(declare reset-messages-results-state)
+(declare reset-messages-view-state)
+(declare reset-messages-mode-state)
(declare reset-users-state)
(declare reset-users-view-state)
(declare reset-users-add-state)
@@ -35,6 +36,7 @@
(declare markdown-to-html)
(declare reduce-checkboxes)
(declare form-fields-to-map)
+(declare clear-notifications)
(declare notifications)
(declare auth-notifications)
(declare comp-menu-main)
@@ -96,9 +98,9 @@
(declare handler-messages)
(declare render-messages)
(declare on-messages-mode-clicked)
-(declare comp-messages-results)
-(declare handler-messages-results)
-(declare render-messages-results)
+(declare comp-messages-view)
+(declare handler-messages-view)
+(declare render-messages-view)
(declare on-messages-mark)
(declare handler-messages-mark)
(declare render-messages-mark)
@@ -171,7 +173,8 @@
(def contact-us-state (r/atom {}))
(def contact-us-view-state (r/atom {}))
(def messages-state (r/atom {}))
-(def messages-results-state (r/atom {}))
+(def messages-view-state (r/atom {}))
+(def messages-mode-state (r/atom "unread"))
(def users-state (r/atom {}))
(def users-view-state (r/atom {}))
(def users-add-state (r/atom {}))
@@ -223,8 +226,11 @@
(defn reset-messages-state [jsonobj]
(reset! messages-state jsonobj))
-(defn reset-messages-results-state [jsonobj]
- (reset! messages-results-state jsonobj))
+(defn reset-messages-view-state [jsonobj]
+ (reset! messages-view-state jsonobj))
+
+(defn reset-messages-mode-state [mode]
+ (reset! messages-mode-state mode))
(defn reset-users-state [jsonobj]
(reset! users-state jsonobj))
@@ -278,6 +284,9 @@
;; notifications
+(defn clear-notifications []
+ (notifications {:message nil :errormsg nil}))
+
(defn notifications [jsonobj]
(ck-notifications/reset-message (get jsonobj "message"))
(ck-notifications/reset-errormsg (get jsonobj "errormsg")))
@@ -347,8 +356,8 @@
(defn handler-login [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (reset-login-state jsonobj)
- (notifications jsonobj)))
+ (notifications jsonobj)
+ (reset-login-state jsonobj)))
(defn render-login []
(GET "/login" {:handler handler-login}))
@@ -363,13 +372,8 @@
(defn handler-login-authenticate [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (cond (get jsonobj "errormsg")
- (goto-location "/login")
- (get jsonobj "message")
- (do
- (reset-location "/home")
- (render-home)
- (render-menu)))))
+ (cond (get jsonobj "errormsg") (goto-location "/login")
+ (get jsonobj "message") (on-menu-clicked "/home"))))
(defn render-login-authenticate []
(POST "/login/authenticate"
@@ -461,8 +465,7 @@
(defn handler-profile-view [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (reset-profile-view-state jsonobj)
- (auth-notifications jsonobj)))
+ (reset-profile-view-state jsonobj)))
(defn render-profile-view []
(GET "/profile/view" {:handler handler-profile-view}))
@@ -477,7 +480,6 @@
(defn handler-profile-modify [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (auth-notifications jsonobj)
(reset-profile-modify-state jsonobj)
(.modal (jquery "#modify-profile"))))
@@ -496,7 +498,7 @@
(defn handler-profile-modify-submit [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(auth-notifications jsonobj)
- (on-menu-clicked "/profile")))
+ (render-profile-view)))
(defn render-profile-modify-submit []
(POST "/profile/modify/submit"
@@ -513,7 +515,6 @@
(defn handler-password [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (notifications jsonobj)
(reset-password-state jsonobj)))
(defn render-password []
@@ -529,8 +530,8 @@
(defn handler-password-submit [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (auth-notifications jsonobj)
- (on-menu-clicked "/password")))
+ (notifications jsonobj)
+ (render-password)))
(defn render-password-submit []
(POST "/password/submit"
@@ -569,9 +570,9 @@
(defn handler-about-us [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
+ (notifications jsonobj)
(reset-about-us-category-state (get jsonobj "category"))
(reset-about-us-state jsonobj)
- (notifications jsonobj)
(render-about-us-view)))
(defn render-home
@@ -612,7 +613,6 @@
(defn handler-about-us-modify [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (auth-notifications jsonobj)
(reset-about-us-modify-state jsonobj)
(.modal (jquery "#modify-about-us"))))
@@ -631,8 +631,8 @@
(defn handler-about-us-modify-submit [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (reset-about-us-view-state jsonobj)
- (auth-notifications jsonobj)))
+ (auth-notifications jsonobj)
+ (render-about-us-view)))
(defn render-about-us-modify-submit []
(POST (str "/" @about-us-category-state "/modify/submit")
@@ -679,7 +679,6 @@
(defn handler-contact-us-view [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (notifications jsonobj)
(reset-contact-us-view-state jsonobj)))
(defn render-contact-us-view []
@@ -694,7 +693,7 @@
(render-contact-us-email-submit)))
(defn handler-contact-us-email-submit [response]
- (on-menu-clicked "/contact-us"))
+ (render-contact-us-view))
(defn render-contact-us-email-submit []
(POST "/contact-us/email"
@@ -708,28 +707,26 @@
[:div {:style {:display (cond (or (= @location-state "/messages")) "block" :else "none")}}
[:h3 {:style {:text-align "center"}} (get @messages-state "title")]
[:div {:dangerouslySetInnerHTML (r/unsafe-html (ck-form/template-generic-form (get @messages-state "form") (namespace ::x)))}]
- [comp-messages-results]])
+ [comp-messages-view]])
(defn handler-messages [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(notifications jsonobj)
- (reset-messages-state jsonobj)))
+ (reset-messages-state jsonobj)
+ (render-messages-view)))
(defn render-messages []
(GET "/messages" {:handler handler-messages}))
-;; messages-results
-
-(defn on-messages-mode-clicked [read]
- (dommy/set-value! (dommy/sel1 :#messages_select_mode_form-read) read)
- (render-messages-results))
+;; messages-view
-(defn comp-messages-results []
- (let [results (get @messages-results-state "results")
+(defn comp-messages-view []
+ (let [results (get @messages-view-state "results")
keys (remove (fn [x]
(not (get (first results) x)))
(keys (first results)))]
[:div
+ [:h3 {:style {:text-align "center"}} (str @messages-mode-state " messages")]
(cond (empty? results)
[:h5 {:style {:text-align "center"}} "No results found."]
:else
@@ -739,37 +736,42 @@
(for [key keys]
[:th key])
[:th
- (str "Mark " (cond (= (dommy/value (dommy/sel1 :#messages_select_mode_form-read)) "read")
+ (str "Mark " (cond (= @messages-mode-state "read")
"unread"
:else
"read"))]]]
[:tbody
(for [rec results]
- (let [onclick "void()"]
- [:tr
- (for [key keys]
- [:td {:onclick onclick} (get rec key)])
- [:td [:img {:src (str "/static/images/"
- (cond (= (dommy/value (dommy/sel1 :#messages_select_mode_form-read)) "read")
- "edit-undo.png"
- :else
- "edit-redo.png"))
- :on-click #(on-messages-mark (cond (= (dommy/value (dommy/sel1 :#messages_select_mode_form-read)) "read")
- "'unread'"
- :else
- "'read'")
- (get rec "id"))}]]]))]])]))
+ [:tr {:key (str "messages-select-mode-" (get rec "id"))}
+ (for [key keys]
+ [:td (get rec key)])
+ [:td [:img {:src (str "/static/images/"
+ (cond (= @messages-mode-state "read")
+ "edit-undo.png"
+ :else
+ "edit-redo.png"))
+ :on-click #(on-messages-mark (cond (= @messages-mode-state "read")
+ "unread"
+ :else
+ "read")
+ (get rec "id"))}]]])]])]))
-(defn handler-messages-results [response]
+(defn handler-messages-view [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (auth-notifications jsonobj)
- (reset-messages-results-state jsonobj)))
+ (reset-messages-view-state jsonobj)))
-(defn render-messages-results []
- (POST "/messages/results"
+(defn render-messages-view []
+ (POST "/messages/view"
{:format :raw
- :params (form-fields-to-map "#messages-select-mode-form :input")
- :handler handler-messages-results}))
+ :params {:read @messages-mode-state}
+ :handler handler-messages-view}))
+
+;; messages-read/unread
+
+(defn on-messages-mode-clicked [mode]
+ (clear-notifications)
+ (reset-messages-mode-state mode)
+ (render-messages-view))
;; messages-mark
@@ -779,12 +781,13 @@
(defn handler-messages-mark [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(auth-notifications jsonobj)
- (on-menu-clicked "/messages")))
+ (render-messages-view)))
(defn render-messages-mark [read id]
(POST "/messages/mark"
{:format :raw
- :params (merge (form-fields-to-map "#messages-select-mode-form :input") {"id" (str id)})
+ :params {:read read
+ :id (str id)}
:handler handler-messages-mark}))
;; users
@@ -865,12 +868,13 @@
[:th {:scope "col"} "Del"]]]
[:tbody
(for [user (get @users-view-state "users")]
- [:tr
- [:td [:img {:src (cond (get user "active")
- "/static/images/yes.png"
- :else
- "/static/images/no.png")
- :on-click #(on-users-toggle-active-clicked (get user "id"))}]]
+ [:tr {:key (str "users-view-" (get user "id"))}
+ [:td
+ [:img {:src (cond (get user "active")
+ "/static/images/yes.png"
+ :else
+ "/static/images/no.png")
+ :on-click #(on-users-toggle-active-clicked (get user "id"))}]]
[:td (get user "last_name")]
[:td (get user "first_name")]
[:td (get user "username")]
@@ -885,7 +889,6 @@
(defn handler-users-view [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (notifications jsonobj)
(reset-users-view-state jsonobj)))
(defn render-users-view []
@@ -901,7 +904,6 @@
(defn handler-users-add [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (auth-notifications jsonobj)
(reset-users-add-state jsonobj)
(.modal (jquery "#modal-users-add"))))
@@ -920,7 +922,7 @@
(defn handler-users-add-submit [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(auth-notifications jsonobj)
- (on-menu-clicked "/users")))
+ (render-users-view)))
(defn render-users-add-submit []
(POST "/users/add/submit"
@@ -964,7 +966,6 @@
(defn handler-users-register-form [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (notifications jsonobj)
(reset-users-register-form-state jsonobj)))
(defn render-users-register-form [hash]
@@ -1002,7 +1003,6 @@
(defn handler-users-modify [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
- (auth-notifications jsonobj)
(reset-users-modify-state jsonobj)
(.modal (jquery "#modal-users-modify"))))
@@ -1024,7 +1024,7 @@
(defn handler-users-modify-submit [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(auth-notifications jsonobj)
- (on-menu-clicked "/users")))
+ (render-users-view)))
(defn render-users-modify-submit []
(POST "/users/modify/submit"
@@ -1041,7 +1041,7 @@
(defn handler-users-toggle-active [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(auth-notifications jsonobj)
- (on-menu-clicked "/users")))
+ (render-users-view)))
(defn render-users-toggle-active [id]
(POST "/users/toggle-active"
@@ -1058,7 +1058,7 @@
(defn handler-users-delete [response]
(let [jsonobj (js->clj (js/JSON.parse response))]
(auth-notifications jsonobj)
- (on-menu-clicked "/users")))
+ (render-users-view)))
(defn render-users-delete [id]
(DELETE (str "/users/delete/" id)
diff --git a/sql/functions/contact.mark_contact_us_post.sql b/sql/functions/contact.mark_contact_us_post.sql
index 7bcc001..2329f26 100644
--- a/sql/functions/contact.mark_contact_us_post.sql
+++ b/sql/functions/contact.mark_contact_us_post.sql
@@ -36,3 +36,36 @@ begin
end if;
end;
$$ language plpgsql;
+
+
+
+
+do $$declare
+ l_id bigint;
+ p_contact_us_post_id int := 1;
+ p_user_id int := 1;
+ p_read_p bool := 't';
+begin
+ if(p_read_p) then
+ select id into l_id
+ from contact.contact_us_posts_read
+ where contact_us_post_id = p_contact_us_post_id
+ and user_id = p_user_id;
+
+ if(l_id is null) then
+ insert into contact.contact_us_posts_read (
+ contact_us_post_id,
+ user_id
+ ) values (
+ p_contact_us_post_id,
+ p_user_id
+ );
+ end if;
+ else
+ delete from contact.contact_us_posts_read
+ where contact_us_post_id = p_contact_us_post_id
+ and user_id = p_user_id;
+ end if;
+end$$;
+
+