mirror of
https://github.com/SqrtMinusOne/biome.git
synced 2025-12-10 14:35:13 +03:00
biome-query: finally proper dynamic layout
This commit is contained in:
parent
d18723e76d
commit
648cb287f6
2 changed files with 96 additions and 25 deletions
118
biome-query.el
118
biome-query.el
|
|
@ -29,6 +29,11 @@
|
||||||
(require 'compat)
|
(require 'compat)
|
||||||
(require 'transient)
|
(require 'transient)
|
||||||
|
|
||||||
|
(defcustom biome-query-max-fields-in-row 20
|
||||||
|
"Maximum number of fields in a row."
|
||||||
|
:type 'integer
|
||||||
|
:group 'biome)
|
||||||
|
|
||||||
(defconst biome-query-groups '("daily" "hourly" "minutely_15" "hourly")
|
(defconst biome-query-groups '("daily" "hourly" "minutely_15" "hourly")
|
||||||
"Name of groups.
|
"Name of groups.
|
||||||
|
|
||||||
|
|
@ -99,6 +104,7 @@ It is an alist with the following keys:
|
||||||
(mapcar (lambda (it) (if (listp it) (nreverse it) (list it))))
|
(mapcar (lambda (it) (if (listp it) (nreverse it) (list it))))
|
||||||
(seq-sort-by
|
(seq-sort-by
|
||||||
(lambda (it)
|
(lambda (it)
|
||||||
|
;; TODO better weight function
|
||||||
(cl-loop for take in it
|
(cl-loop for take in it
|
||||||
for seq in sequences
|
for seq in sequences
|
||||||
if (= 2 (length seq)) sum 1
|
if (= 2 (length seq)) sum 1
|
||||||
|
|
@ -153,35 +159,97 @@ NAMES is a list of strings."
|
||||||
do (puthash name key keys-by-name)))
|
do (puthash name key keys-by-name)))
|
||||||
keys-by-name))
|
keys-by-name))
|
||||||
|
|
||||||
(setq my/test (mapcar (lambda (l) (alist-get :name l))
|
(defun biome-query--section-fields-children (fields keys)
|
||||||
(car (alist-get :fields (nth 1 (alist-get :sections (cdar biome-api-data)))))))
|
"Get transient laoyut for FIELDS.
|
||||||
(setq my/test2
|
|
||||||
(cl-loop for key being the hash-key of (biome-query--unique-keys my/test)
|
|
||||||
using (hash-values name)
|
|
||||||
collect (cons key name)))
|
|
||||||
|
|
||||||
(defun biome-query--section-children (section)
|
FIELDS is a list of fields as defined in `biome-api-parse--page'.
|
||||||
(let ((sections (alist-get :sections section))
|
KEYS is the result of `biome-query--unique-keys'."
|
||||||
(fields (alist-get :fields section))
|
(when fields
|
||||||
(keys (make-hash-table :test 'equal))
|
`(["Fields"
|
||||||
res)
|
:class transient-columns
|
||||||
(cl-loop for section in sections
|
,@(thread-last
|
||||||
do (puthash (alist-get :name section) section keys))
|
fields
|
||||||
))
|
(seq-map-indexed
|
||||||
|
(lambda (field idx) (cons field (/ idx biome-query-max-fields-in-row))))
|
||||||
|
(seq-group-by #'cdr)
|
||||||
|
(mapcar (lambda (group)
|
||||||
|
(apply #'vector
|
||||||
|
(mapcar
|
||||||
|
(lambda (el)
|
||||||
|
(let* ((field (car el))
|
||||||
|
(name (alist-get :name (cdr field))))
|
||||||
|
;; TODO
|
||||||
|
(list (gethash name keys) name #'transient-quit-one)))
|
||||||
|
(cdr group))))))])))
|
||||||
|
|
||||||
(transient-define-prefix biome-query--root-section (section)
|
(defun biome-query--section-sections-children (sections keys parents)
|
||||||
"Render transient for root SECTION.
|
"Get transient layout for SECTIONS.
|
||||||
|
|
||||||
|
SECTIONS is a list of sections as defined in `biome-api-parse--page'.
|
||||||
|
KEYS is the result of `biome-query--unique-keys'. PARENTS is a
|
||||||
|
list of parent sections."
|
||||||
|
(when sections
|
||||||
|
`(["Sections"
|
||||||
|
:class transient-row
|
||||||
|
,@(mapcar
|
||||||
|
(lambda (section)
|
||||||
|
`(,(gethash (alist-get :name section) keys)
|
||||||
|
,(alist-get :name section)
|
||||||
|
(lambda ()
|
||||||
|
(interactive)
|
||||||
|
(biome-query--section ',section ',parents))
|
||||||
|
:transient transient--do-replace))
|
||||||
|
sections)])))
|
||||||
|
|
||||||
|
(defun biome-query--section-layout (section parents)
|
||||||
|
"Get transient layout for SECTION.
|
||||||
|
|
||||||
|
SECTION is a form as defined by `biome-api-parse--page'. PARENTS
|
||||||
|
is a list of parent sections."
|
||||||
|
(let* ((sections (or (alist-get :children section)
|
||||||
|
(alist-get :sections section)))
|
||||||
|
(fields (alist-get :fields section))
|
||||||
|
(keys (biome-query--unique-keys
|
||||||
|
(append
|
||||||
|
(mapcar (lambda (s) (alist-get :name s)) sections)
|
||||||
|
(mapcar (lambda (s) (alist-get :name (cdr s))) fields)))))
|
||||||
|
(append
|
||||||
|
(biome-query--section-fields-children fields keys)
|
||||||
|
(biome-query--section-sections-children sections keys (cons section parents)))))
|
||||||
|
|
||||||
|
(defun biome-query--transient-prepare-layout (name suffixes)
|
||||||
|
"Prepare dynamic transient layout for NAME.
|
||||||
|
|
||||||
|
SUFFIXES is a list of suffix definitions."
|
||||||
|
(thread-last
|
||||||
|
suffixes
|
||||||
|
(cl-mapcan (lambda (s) (transient--parse-child 'tsc-dynamic-layout s)))
|
||||||
|
(mapcar #'eval)
|
||||||
|
(put name 'transient--layout)))
|
||||||
|
|
||||||
|
(transient-define-prefix biome-query--section (section &optional parents)
|
||||||
|
"Render transient for SECTION.
|
||||||
|
|
||||||
SECTION is a form as defined in `biome-api-parse--page'."
|
SECTION is a form as defined in `biome-api-parse--page'."
|
||||||
[:description
|
|
||||||
(lambda () (alist-get :name (oref transient--prefix scope)))
|
|
||||||
(biome-query--transient-report-infix)]
|
|
||||||
["Actions"
|
|
||||||
:class transient-row
|
|
||||||
("q" "Up" transient-quit-one)
|
|
||||||
("Q" "Quit" transient-quit-all)]
|
|
||||||
(interactive (list nil))
|
(interactive (list nil))
|
||||||
(transient-setup 'biome-query--section nil nil :scope section))
|
(unwind-protect
|
||||||
|
(progn
|
||||||
|
(setq my/test section)
|
||||||
|
(biome-query--prepare-layout
|
||||||
|
'biome-query--section
|
||||||
|
(append
|
||||||
|
'([:description
|
||||||
|
(lambda () (alist-get :name (car (oref transient--prefix scope))))
|
||||||
|
(biome-query--transient-report-infix)])
|
||||||
|
(biome-query--section-layout section parents)
|
||||||
|
'(["Actions"
|
||||||
|
:class transient-row
|
||||||
|
("q" "Up" transient-quit-one)
|
||||||
|
("Q" "Quit" transient-quit-all)])))
|
||||||
|
(transient-setup 'biome-query--section nil nil :scope
|
||||||
|
`((:section . ,section)
|
||||||
|
(:parents . ,parents))))
|
||||||
|
(put 'biome-query-section 'transient--layout nil)))
|
||||||
|
|
||||||
(transient-define-prefix biome-query ()
|
(transient-define-prefix biome-query ()
|
||||||
["Open Meteo Data"
|
["Open Meteo Data"
|
||||||
|
|
@ -201,7 +269,7 @@ SECTION is a form as defined in `biome-api-parse--page'."
|
||||||
'((:name . ,name)
|
'((:name . ,name)
|
||||||
(:kind . nil)
|
(:kind . nil)
|
||||||
(:parameters . nil))))
|
(:parameters . nil))))
|
||||||
(biome-query--root-section ',params))
|
(biome-query--section ',params))
|
||||||
:transient transient--do-replace))))]
|
:transient transient--do-replace))))]
|
||||||
["Actions"
|
["Actions"
|
||||||
("q" "Quit" transient-quit-one)])
|
("q" "Quit" transient-quit-one)])
|
||||||
|
|
|
||||||
3
biome.el
3
biome.el
|
|
@ -28,6 +28,9 @@
|
||||||
;; TODO
|
;; TODO
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
(defgroup biome nil
|
||||||
|
"Bountiful Interface to Open Meteo for Emacs."
|
||||||
|
:group 'applications)
|
||||||
|
|
||||||
(provide 'biome)
|
(provide 'biome)
|
||||||
;;; biome.el ends here
|
;;; biome.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue