From 162887a47bc6096b825ccd644f5215677c13cc25 Mon Sep 17 00:00:00 2001 From: Izaak Walton Date: Sat, 7 May 2022 13:03:38 -0600 Subject: [PATCH] Added view, working on edit --- backup-of-receipts.lisp | 26 ++++++++++++----- bart.asd | 1 + bart/edit.lisp | 65 +++++++++++++++++++++++++++++++++++++++++ bart/package.lisp | 4 ++- bart/view.lisp | 41 ++++++++++++++++++++++++++ bart/view.lisp~ | 13 +++++++++ bartleby.asd | 3 +- search.lisp | 36 +++++++++++++++-------- sort.lisp | 25 ++++++++++++++++ sort.lisp~ | 12 ++++++++ system-generics.lisp | 16 ---------- 11 files changed, 204 insertions(+), 38 deletions(-) create mode 100644 bart/view.lisp create mode 100644 bart/view.lisp~ create mode 100644 sort.lisp create mode 100644 sort.lisp~ diff --git a/backup-of-receipts.lisp b/backup-of-receipts.lisp index ee033b6..ac8c8ed 100644 --- a/backup-of-receipts.lisp +++ b/backup-of-receipts.lisp @@ -1,10 +1,20 @@ ;;;;receipts (in-package :bartleby) -(load-saved-item (make-receipt (make-appointment 10008 (quote (1001)) (quote (2001)) 0 (date-time (date 4 27 2022) (set-time 10 30)) 30 "violin") 20003 0 30 0 "violin")) - -(load-saved-item (make-receipt (make-appointment 10006 (quote (1001)) (quote (2001)) 0 (date-time (date 4 20 2022) (set-time 10 30)) 30 "violin") 20004 4 45 -15 "violin")) - -(load-saved-item (make-receipt (make-appointment 10004 (quote (1001)) (quote (2001)) 0 (date-time (date 4 13 2022) (set-time 10 30)) 30 "violin") 20005 1 0 0 "violin")) - -(load-saved-item (make-receipt (make-appointment 10003 (quote (1001)) (quote (2001)) 0 (date-time (date 4 6 2022) (set-time 10 30)) 30 "violin") 20006 2 0 30 "violin")) - +(load-saved-item (make-receipt (make-appointment 10010 (quote (1001)) (quote (2001)) 0 (date-time (date 5 4 2022) (set-time 10 30)) 30 "violin") 20001 4 45 -15 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10008 (quote (1001)) (quote (2001)) 0 (date-time (date 4 27 2022) (set-time 10 30)) 30 "violin") 20003 0 30 0 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10008 (quote (1001)) (quote (2001)) 0 (date-time (date 4 27 2022) (set-time 10 30)) 30 "violin") 20003 0 30 0 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10006 (quote (1001)) (quote (2001)) 0 (date-time (date 4 20 2022) (set-time 10 30)) 30 "violin") 20004 4 45 -15 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10006 (quote (1001)) (quote (2001)) 0 (date-time (date 4 20 2022) (set-time 10 30)) 30 "violin") 20004 4 45 -15 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10004 (quote (1001)) (quote (2001)) 0 (date-time (date 4 13 2022) (set-time 10 30)) 30 "violin") 20005 1 0 0 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10004 (quote (1001)) (quote (2001)) 0 (date-time (date 4 13 2022) (set-time 10 30)) 30 "violin") 20005 1 0 0 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10003 (quote (1001)) (quote (2001)) 0 (date-time (date 4 6 2022) (set-time 10 30)) 30 "violin") 20006 2 0 30 "violin" +)) +(load-saved-item (make-receipt (make-appointment 10003 (quote (1001)) (quote (2001)) 0 (date-time (date 4 6 2022) (set-time 10 30)) 30 "violin") 20006 2 0 30 "violin" +)) diff --git a/bart.asd b/bart.asd index 852d7aa..b8869d9 100644 --- a/bart.asd +++ b/bart.asd @@ -12,6 +12,7 @@ :components ((:file "package") (:file "lexing") (:file "browse") + (:file "view") (:file "new") (:file "check-out") (:file "help") diff --git a/bart/edit.lisp b/bart/edit.lisp index 2a91a66..04a3339 100644 --- a/bart/edit.lisp +++ b/bart/edit.lisp @@ -5,3 +5,68 @@ ;;;;editing interface +(defvar *edit-commands* '(("first" #'edit-first-name) + ("last" #'edit-last-name) + ("id" #'edit-id) + ("credits" #'edit-credits) + ("phone" #'edit-phone) + ("email" #'edit-email) + ("address" #'edit-address);;;;maybe add later + ("notes" #'edit-notes) + ("hourly" #'edit-hourly) + ("capacity" #'edit-capacity) + ("name" #'edit-name) + ("date" #'edit-date) + ("time" #'edit-time) + ("date-time" #'edit-date-time))) + +(defgeneric edit-first-name (object first-name) + (:documentation "Prompt for editing the first name of an object")) + +(defmethod edit-first-name ((client bartleby:client)) + (bartleby:change-first-name client (prompt-read "New First Name"))) + +(defmethod edit-first-name ((employee bartleby:employee)) + (bartleby:change-first-name employee (prompt-read "New First Name"))) + +(defmethod edit-last-name ((client bartleby:client)) + (bartleby:change-last-name client (prompt-read "New Last Name"))) + +(defmethod edit-last-name ((employee bartleby:employee)) + (bartleby:change-last-name employee (prompt-read "New Last Name"))) + +(defgeneric edit-prompt (object) + (:documentation "A prompt for editing a given object")) + +(defmethod edit-prompt ((client bartleby:client)) + (write-line "What would you like to edit?") + (funcall + (second + (find-if #'(lambda (x) + (string-equal (first x) + (prompt-read "first, last, id, phone, email, credits, or notes"))) + *edit-commands)) + client)) + +(defmethod edit-prompt ((employee bartleby:employee)) + (write-line "What would you like to edit?") + (funcall + (second + (find-if #'(lambda (x) + (string-equal (first x) + (prompt-read "first, last, id, phone, email, or hourly"))) + *edit-commands)) + employee)) + + +(defun edit-id-prompt () + (write-line "Please enter a client, employee, or appointment ID.") + (edit (parse-integer (prompt-read "ID")))) + +(defun edit (&optional id) + (if id + (edit-prompt (bartleby::id-search (if (numberp id) + id + (parse-integer id)))) + (edit-id-prompt))) + diff --git a/bart/package.lisp b/bart/package.lisp index 75db7b3..a92e31b 100644 --- a/bart/package.lisp +++ b/bart/package.lisp @@ -1,4 +1,6 @@ ;;;;bart/package.lisp (defpackage #:bart - (:use #:cl #:bartleby)) + (:use #:cl #:bartleby) + + (:export #:bart)) diff --git a/bart/view.lisp b/bart/view.lisp new file mode 100644 index 0000000..6628432 --- /dev/null +++ b/bart/view.lisp @@ -0,0 +1,41 @@ +;;;;bart/view.lisp +;;;; + +(in-package :bart) + +(defgeneric view-print (object) + (:documentation "Prints an object for viewing")) + +(defmethod view-print ((client bartleby:client)) + (format nil "~a ~a, ID: ~a~%~a~%~a~%Credits: ~a~%Notes: ~a~%" + (bartleby::first-name client) + (bartleby::last-name client) + (bartleby::id client) + (bartleby::phone client) + (bartleby::email client) + (bartleby::credit-minutes client) + (bartleby::notes client))) + +(defmethod view-print ((employee bartleby:employee)) + (format nil "~a ~a, ID: ~a~%~a~%~a~%Hourly Rate: ~a~%" + (bartleby::first-name employee) + (bartleby::last-name employee) + (bartleby::id employee) + (bartleby::phone employee) + (bartleby::email employee) + (bartleby::hourly-rate employee))) + +(defmethod view-print ((appointment bartleby:appointment)) + (format nil "~a" + appointment)) + +(defun view-prompt () + (write-line "Please enter a client, employee, or appointment ID.") + (view (parse-integer (prompt-read "ID")))) + +(defun view (&optional id) + (if id + (format t "~a" (view-print (bartleby::id-search (if (numberp id) + id + (parse-integer id))))) + (view-prompt))) diff --git a/bart/view.lisp~ b/bart/view.lisp~ new file mode 100644 index 0000000..4cb7ed0 --- /dev/null +++ b/bart/view.lisp~ @@ -0,0 +1,13 @@ +;;;;bart/view.lisp +;;;; + +(in-package :bart) + +(defun view-prompt () + (write-line "Please enter a client, employee, or appointment ID.") + (view (prompt-read "ID"))) + +(defun view (&optional id) + (if id + (browse-print (bartleby::id-search id)) + (view-prompt))) diff --git a/bartleby.asd b/bartleby.asd index 6c5f340..89254fe 100644 --- a/bartleby.asd +++ b/bartleby.asd @@ -9,10 +9,11 @@ :serial t :components ((:file "package") (:file "system-generics") + (:file "sort") (:file "backup") (:file "time") (:file "dates") - ;(:file "calendar") + ;(:file "calendar") ;;;;maybe later (:file "contact") (:file "clients") (:file "rooms") diff --git a/search.lisp b/search.lisp index c659133..4516ac0 100644 --- a/search.lisp +++ b/search.lisp @@ -9,18 +9,30 @@ ;;;one option- parse search input, ;;;;if one of the words is "client" "employee" or "appointment" it will only search one of those categories -(defun parse-query (input) - "Parses a search query into words." - (loop :with parsed := nil - :with current-word := "" - - :for i :from 1 :to (length input) - :if (string-equal (subseq input (- i 1) i) " ") - :do (progn (setq parsed (cons current-word parsed)) - (setq current-word "")) - :else - :do (setq current-word (concatenate 'string current-word (subseq input (- i 1) i))) - :finally (return (reverse parsed)))) +(defun id-search (id) + (cond ((client-id-search id) + (client-id-search id)) + ((employee-id-search id) + (employee-id-search id)) + ((appointment-id-search id) + (appointment-id-search id)) + (t nil))) + + + + +;(defun parse-query (input) + ; "Parses a search query into words." + ;(loop :with parsed := nil +; :with current-word := "" +; +; :for i :from 1 :to (length input) +; :if (string-equal (subseq input (- i 1) i) " ") +; :do (progn (setq parsed (cons current-word parsed)) +; (setq current-word "")) +; :else +; :do (setq current-word (concatenate 'string current-word (subseq input (- i 1) i))) +; :finally (return (reverse parsed)))) (defun client-search (input) ;taken as string diff --git a/sort.lisp b/sort.lisp new file mode 100644 index 0000000..baa22e8 --- /dev/null +++ b/sort.lisp @@ -0,0 +1,25 @@ +;;;;sort.lisp +;;;; + +(in-package :bartleby) + +;;;;------------------------------------------------------------------------ +;;;; +;;;;------------------------------------------------------------------------ + +(defun first-name-sort (object-list) + (sort (copy-list object-list) #'(lambda (o1 o2) + (string< (first-name o1) (first-name o2))))) + +(defun last-name-sort (object-list) + (sort (copy-list object-list) #'(lambda (o1 o2) + (string< (last-name o1) (last-name o2))))) + +(defun id-sort (object-list) + (sort (copy-list object-list) #'(lambda (o1 o2) + (< (id o1) (id o2))))) + +;;;;maybe date-time/date/time sorting +(defun date-time-sort (object-list) + (sort (copy-list object-list) #'(lambda (o1 o2) + (later-date-time-p (dt o1) (dt 02))))) diff --git a/sort.lisp~ b/sort.lisp~ new file mode 100644 index 0000000..5772f56 --- /dev/null +++ b/sort.lisp~ @@ -0,0 +1,12 @@ +;;;;sort.lisp +;;;; + +(in-package :bartleby) + +;;;;------------------------------------------------------------------------ +;;;; +;;;;------------------------------------------------------------------------ + +(defun first-name-sort (object-list) + (sort (copy-list object-list) #'(lambda (o1 o2) + (string> (first-name o1) (first-name o2))))) diff --git a/system-generics.lisp b/system-generics.lisp index 2e2bfa6..cd3bfd1 100644 --- a/system-generics.lisp +++ b/system-generics.lisp @@ -4,22 +4,6 @@ (in-package :bartleby) -;;;;------------------------------------------------------------------------ -;;;;Sorting -;;;;------------------------------------------------------------------------ - -(defun sort-by-first-name (object-list) - (sort object-list #'(lambda (o1 o2) - (string< (first-name o1) (first-name o2))))) - -(defun sort-by-last-name (object-list) - (sort object-list #'(lambda (o1 o2) - (string< (last-name o1) (last-name o2))))) - -(defun sort-by-id (object-list) - (sort object-list #'(lambda (o1 o2) - (< (id o1) (id o2))))) - ;;;;------------------------------------------------------------------------ ;;;;Changing attributes ;;;;------------------------------------------------------------------------