Skip to content

Commit

Permalink
feat: mark and batch actions in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
d12frosted committed Nov 1, 2024
1 parent 3d75f59 commit a2b8ce9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Fix average score calculation using =amean= strategy.
- Use =vulpea-select-multiple-from= when selecting grapes to avoid repetition.
- Move =volume= property from bottle to wine entry.
- Mark and batch actions in UI.

** v0.4.0

Expand Down
64 changes: 50 additions & 14 deletions vino-inv.el
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ duplicates."
(suppress-keymap map)
(define-key map "q" #'vino-inv-ui-quit)
(define-key map "g" #'vino-inv-ui-update)
(define-key map "m" #'vino-inv-ui-mark)
(define-key map "u" #'vino-inv-ui-unmark)
(define-key map (kbd "el") #'vino-inv-ui-edit-location)
(define-key map (kbd "ep") #'vino-inv-ui-edit-price)
(define-key map (kbd "ed") #'vino-inv-ui-edit-date)
Expand Down Expand Up @@ -714,22 +716,24 @@ If OTHER-WINDOW, visit the NOTE in another window."
(defun vino-inv-ui-edit-location ()
"Edit location of the bottle at point."
(interactive)
(let ((bottle-id (vino-inv-ui-get-bottle-id))
(location-id (vino-inv-location-id (vino-inv-ui-read-location)))
(let ((location-id (vino-inv-location-id (vino-inv-ui-read-location)))
(db (vino-inv-db))
(date (format-time-string "%Y-%m-%d")))
(emacsql-with-transaction db
(emacsql db [:update bottle
:set (= location-id $s2)
:where (= bottle-id $s1)]
bottle-id location-id)
(emacsql db
[:insert :into transaction [bottle-id
transaction-type
transaction-date
destination-location-id]
:values $v1]
`([,bottle-id move ,date ,location-id])))
(vino-inv-ui-dispatch-action
(lambda (bottle)
(let ((bottle-id (vino-inv-bottle-id bottle)))
(emacsql-with-transaction db
(emacsql db [:update bottle
:set (= location-id $s2)
:where (= bottle-id $s1)]
bottle-id location-id)
(emacsql db
[:insert :into transaction [bottle-id
transaction-type
transaction-date
destination-location-id]
:values $v1]
`([,bottle-id move ,date ,location-id]))))))
(vino-inv-ui-update)))

(defun vino-inv-ui-edit-price ()
Expand Down Expand Up @@ -814,5 +818,37 @@ If OTHER-WINDOW, visit the NOTE in another window."
bottle-id comment)
(vino-inv-ui-update)))

(defun vino-inv-ui-mark ()
"Mark entry at point."
(interactive)
(tabulated-list-put-tag "*" t))

(defun vino-inv-ui-unmark ()
"Mark entry at point."
(interactive)
(tabulated-list-put-tag " " t))

(defun vino-inv-ui-dispatch-action (fn)
"Execute action FN over bottle under point or marked bottles.
If there are marked bottles, FN is executed sequentially on each marked
bottle. Otherwise FN is executed on bottled under point.
FN is called with `vino-inv-bottle' as its only argument."
(let (print-list bottle cmd)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(setq cmd (char-after))
(when (eq cmd ?\*)
;; This is the key PKG-DESC.
(setq bottle (tabulated-list-get-id))
(push bottle print-list))
(forward-line)))
(-each (->> (or (--map (string-to-number (nth 1 (s-split ":" it))) print-list)
(list (vino-inv-ui-get-bottle-id)))
(-map #'vino-inv-get-bottle))
fn)))

(provide 'vino-inv)
;;; vino-inv.el ends here

0 comments on commit a2b8ce9

Please sign in to comment.