Skip to content

Commit

Permalink
Added view, working on edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Izaakwltn committed May 7, 2022
1 parent 120cc26 commit 162887a
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 38 deletions.
26 changes: 18 additions & 8 deletions backup-of-receipts.lisp
Original file line number Diff line number Diff line change
@@ -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"
))
1 change: 1 addition & 0 deletions bart.asd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:components ((:file "package")
(:file "lexing")
(:file "browse")
(:file "view")
(:file "new")
(:file "check-out")
(:file "help")
Expand Down
65 changes: 65 additions & 0 deletions bart/edit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

4 changes: 3 additions & 1 deletion bart/package.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
;;;;bart/package.lisp

(defpackage #:bart
(:use #:cl #:bartleby))
(:use #:cl #:bartleby)

(:export #:bart))
41 changes: 41 additions & 0 deletions bart/view.lisp
Original file line number Diff line number Diff line change
@@ -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)))
13 changes: 13 additions & 0 deletions bart/view.lisp~
Original file line number Diff line number Diff line change
@@ -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)))
3 changes: 2 additions & 1 deletion bartleby.asd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 24 additions & 12 deletions search.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions sort.lisp
Original file line number Diff line number Diff line change
@@ -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)))))
12 changes: 12 additions & 0 deletions sort.lisp~
Original file line number Diff line number Diff line change
@@ -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)))))
16 changes: 0 additions & 16 deletions system-generics.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;;;------------------------------------------------------------------------
Expand Down

0 comments on commit 162887a

Please sign in to comment.