bugpile-controller.el 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ;;;; bugpile-controller -- elnode handlers and such for handling web
  2. ;;;; POST/GET requests
  3. ;;;; Requirements
  4. (require 'iorg-controller)
  5. ;;;; Variables
  6. ;;; Consts
  7. ;;; Vars
  8. ;;; Customs
  9. ;;;; Functions
  10. ;;; Function Declarations
  11. ;;; Helper Functions
  12. ;;; Public Functions (interactive)
  13. ;;; Public Functions (non-interactive)
  14. (defun bugpile-controller-dispatcher-handler (httpcon)
  15. "Dispatch requests to the Bugpile application."
  16. (elnode-log-access "bugpile-controller" httpcon)
  17. (message "dispatcher elnode-params: %s, %s, %s"
  18. (elnode-http-params httpcon)
  19. (elnode-http-pathinfo httpcon)
  20. (elnode-http-query httpcon))
  21. (elnode-dispatcher httpcon
  22. (iorg-projects-get-project-urls "bugpile")))
  23. (defun bugpile-controller-index-handler (httpcon)
  24. "Serve the start-page of the Bugpile application"
  25. (elnode-log-access "bugpile-controller" httpcon)
  26. (message "index elnode-params: %s"
  27. (elnode-http-params httpcon))
  28. (elnode-send-file httpcon
  29. (iorg-controller--org-to-html
  30. (concat
  31. (iorg-projects-get-project-info
  32. "bugpile" :view)
  33. "bugpile-view-index.org"))))
  34. (defun bugpile-controller-open-new-task-handler (httpcon)
  35. "Serve a form page for a new task and process user input."
  36. (elnode-log-access "bugpile-controller" httpcon)
  37. (message "open-new-task elnode-params: %s"
  38. (elnode-http-params httpcon))
  39. ;; (elnode-send-file httpcon
  40. ;; (iorg-controller--org-to-html
  41. ;; (concat
  42. ;; (iorg-projects-get-project-info
  43. ;; "bugpile" :view)
  44. ;; "bugpile-index.org"))))
  45. )
  46. (defun bugpile-controller-show-task-handler (httpcon)
  47. "Serve a page with edit button that shows an existing task."
  48. (elnode-log-access "bugpile-controller" httpcon)
  49. (message "show-task elnode-params: %s"
  50. (elnode-http-params httpcon))
  51. (org-id-goto "e704e837-62f8-485d-8532-9ca0b6a04ad0")
  52. (org-update-all-dblocks)
  53. (elnode-send-file httpcon
  54. (iorg-controller--org-to-html
  55. (concat
  56. (iorg-projects-get-project-info
  57. "bugpile" :view)
  58. "bugpile-view-show-task.org"))))
  59. (defun bugpile-controller-search-tasklist-handler (httpcon)
  60. "Serve a form that enables query compositon."
  61. (elnode-log-access "bugpile-controller" httpcon)
  62. (message "search-tasklist elnode-params: %s"
  63. (elnode-http-params httpcon))
  64. (elnode-send-file httpcon
  65. (iorg-controller--org-to-html
  66. (concat
  67. (iorg-projects-get-project-info
  68. "bugpile" :view)
  69. "bugpile-view-search-tasklist.org"))))
  70. (defun bugpile-controller-edit-task-handler (httpcon)
  71. "Serve a form page for editing the data of an existing task,
  72. process user edits, and present the modified task to the user."
  73. (elnode-log-access "bugpile-controller" httpcon)
  74. (message "edit-task elnode-params: %s"
  75. (elnode-http-params httpcon))
  76. (let ((view-id "3675e953-7f75-4319-a1e5-dfb09cadea1f")
  77. (obj-id "2f822a1e-4bb4-43be-bec4-b0c5caaa42a5"))
  78. (save-excursion
  79. (save-restriction
  80. (org-id-goto obj-id)
  81. (org-check-for-org-mode)
  82. (widen)
  83. (unless
  84. (member "iorg" (org-get-tags))
  85. (org-set-tags-to
  86. (cons "iorg" (org-get-tags))))
  87. (org-copy-subtree)
  88. (org-id-goto view-id)
  89. (org-check-for-org-mode)
  90. (widen)
  91. (show-all)
  92. (iorg-util-goto-last-entry)
  93. (if (member "anchor" (org-get-tags))
  94. (progn
  95. (goto-char
  96. (org-entry-end-position))
  97. (newline)
  98. (yank)
  99. (save-buffer))
  100. (delete-region
  101. (org-entry-beginning-position)
  102. (org-entry-end-position))
  103. (yank)
  104. (save-buffer)))))
  105. (elnode-send-file httpcon
  106. (iorg-controller--org-to-html
  107. (concat
  108. (iorg-projects-get-project-info
  109. "bugpile" :view)
  110. "bugpile-view-edit-task.org"))))
  111. (defun bugpile-controller-save-edits-handler (httpcon)
  112. "Save the modified object data."
  113. (elnode-log-access "bugpile-controller" httpcon)
  114. (message "save-edits elnode-params: %s, %s, %s"
  115. (elnode-http-params httpcon)
  116. (elnode-http-pathinfo httpcon)
  117. (elnode-http-query httpcon))
  118. (let ((view-id "e704e837-62f8-485d-8532-9ca0b6a04ad0")
  119. (obj-id "2f822a1e-4bb4-43be-bec4-b0c5caaa42a5")
  120. (prop (elnode-http-param httpcon 'simple-prop))
  121. (tag (elnode-http-param httpcon 'simple-tag))
  122. (section (elnode-http-param httpcon 'simple-section)))
  123. (message "prop: %s \ntag: %s \nsection: %s" prop tag section)
  124. (save-excursion
  125. (save-restriction
  126. ;; goto object file
  127. (org-id-goto obj-id)
  128. (org-check-for-org-mode)
  129. (widen)
  130. (show-all)
  131. ;; set property
  132. (org-entry-put (point)
  133. "object-foo" (cdr prop))
  134. ;; set tags
  135. (org-set-tags-to (cdr tag))
  136. ;; set content ??
  137. (save-buffer)
  138. ;; update dblock in view file
  139. (org-dblock-write:bugpile-view-show-task
  140. obj-id))))
  141. (elnode-send-file httpcon
  142. (iorg-controller--org-to-html
  143. (concat
  144. (iorg-projects-get-project-info
  145. "bugpile" :view)
  146. "bugpile-view-show-task.org"))))
  147. (defun bugpile-controller-take-action-on-selected-tasks-handler (httpcon)
  148. "Perform the action chosen by the user on all selected tasks."
  149. (elnode-log-access "bugpile-controller" httpcon)
  150. (message "take-action elnode-params: %s"
  151. (elnode-http-params httpcon))
  152. (elnode-send-file httpcon
  153. (iorg-controller--org-to-html
  154. (concat
  155. (iorg-projects-get-project-info
  156. "bugpile" :view)
  157. "bugpile-view-take-action-on-selected-tasks.org"))))
  158. (provide 'bugpile-controller)