1 ;;; ox-taskjuggler.el --- TaskJuggler Back-End for Org Export Engine
3 ;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: ox-taskjuggler.el
7 ;; Author: Christian Egli
8 ;; Nicolas Goaziou <n dot goaziou at gmail dot com>
9 ;; Maintainer: Christian Egli
10 ;; Keywords: org, taskjuggler, project planning
11 ;; Description: Converts an Org mode buffer into a TaskJuggler project plan
13 ;; This program is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
28 ;; This library implements a TaskJuggler exporter for Org mode.
29 ;; TaskJuggler uses a text format to define projects, tasks and
30 ;; resources, so it is a natural fit for Org mode. It can produce all
31 ;; sorts of reports for tasks or resources in either HTML, CSV or PDF.
32 ;; The current version of TaskJuggler requires KDE but the next
33 ;; version is implemented in Ruby and should therefore run on any
36 ;; The exporter does not export all the nodes of a document or
37 ;; strictly follow the order of the nodes in the document.
39 ;; Instead the TaskJuggler exporter looks for a tree that defines the
40 ;; tasks and a optionally tree that defines the resources for this
41 ;; project. It then creates a TaskJuggler file based on these trees
42 ;; and the attributes defined in all the nodes.
46 ;; Put this file into your load-path and the following line into your
49 ;; (add-to-list 'org-export-backends 'taskjuggler)
51 ;; or customize `org-export-backends' variable.
53 ;; The interactive functions are the following:
55 ;; M-x `org-taskjuggler-export'
56 ;; M-x `org-taskjuggler-export-and-open'
60 ;; Let's illustrate the usage with a small example. Create your tasks
61 ;; as you usually do with org-mode. Assign efforts to each task using
62 ;; properties (it's easiest to do this in the column view). You
63 ;; should end up with something similar to the example by Peter Jones
66 ;; http://www.contextualdevelopment.com/static/artifacts/articles/2008/project-planning/project-planning.org.
68 ;; Now mark the top node of your tasks with a tag named
69 ;; "taskjuggler_project" (or whatever you customized
70 ;; `org-taskjuggler-project-tag' to). You are now ready to export the
71 ;; project plan with `org-taskjuggler-export-and-open' which will
72 ;; export the project plan and open a Gantt chart in TaskJugglerUI.
76 ;; Next you can define resources and assign those to work on specific
77 ;; tasks. You can group your resources hierarchically. Tag the top
78 ;; node of the resources with "taskjuggler_resource" (or whatever you
79 ;; customized `org-taskjuggler-resource-tag' to). You can optionally
80 ;; assign an identifier (named "resource_id") to the resources (using
81 ;; the standard org properties commands) or you can let the exporter
82 ;; generate identifiers automatically (the exporter picks the first
83 ;; word of the headline as the identifier as long as it is unique, see
84 ;; the documentation of `org-taskjuggler--build-unique-id'). Using that
85 ;; identifier you can then allocate resources to tasks. This is again
86 ;; done with the "allocate" property on the tasks. Do this in column
87 ;; view or when on the task type
89 ;; C-c C-x p allocate RET <resource_id> RET
91 ;; Once the allocations are done you can again export to TaskJuggler
92 ;; and check in the Resource Allocation Graph which person is working
93 ;; on what task at what time.
95 ;; * Export of properties
97 ;; The exporter also takes TODO state information into consideration,
98 ;; i.e. if a task is marked as done it will have the corresponding
99 ;; attribute in TaskJuggler ("complete 100"). Also it will export any
100 ;; property on a task resource or resource node which is known to
101 ;; TaskJuggler, such as limits, vacation, shift, booking, efficiency,
102 ;; journalentry, rate for resources or account, start, note, duration,
103 ;; end, journalentry, milestone, reference, responsible, scheduling,
108 ;; The exporter will handle dependencies that are defined in the tasks
109 ;; either with the ORDERED attribute (see TODO dependencies in the Org
110 ;; mode manual) or with the BLOCKER attribute (see org-depend.el) or
111 ;; alternatively with a depends attribute. Both the BLOCKER and the
112 ;; depends attribute can be either "previous-sibling" or a reference
113 ;; to an identifier (named "task_id") which is defined for another
114 ;; task in the project. BLOCKER and the depends attribute can define
115 ;; multiple dependencies separated by either space or comma. You can
116 ;; also specify optional attributes on the dependency by simply
117 ;; appending it. The following examples should illustrate this:
119 ;; * Training material
121 ;; :task_id: training_material
124 ;; ** Markup Guidelines
128 ;; ** Workflow Guidelines
135 ;; :BLOCKER: training_material { gapduration 1d } some_other_task
139 ;; - Look at org-file-properties, org-global-properties and
140 ;; org-global-properties-fixed
141 ;; - What about property inheritance and org-property-inherit-p?
142 ;; - Use TYPE_TODO as an way to assign resources
146 (eval-when-compile (require 'cl
))
154 (defgroup org-export-taskjuggler nil
155 "Options specific for TaskJuggler export back-end."
156 :tag
"Org Export TaskJuggler"
159 (defcustom org-taskjuggler-extension
".tjp"
160 "Extension of TaskJuggler files."
161 :group
'org-export-taskjuggler
164 (defcustom org-taskjuggler-project-tag
"taskjuggler_project"
165 "Tag marking project's tasks.
166 This tag is used to find the tree containing all the tasks for
168 :group
'org-export-taskjuggler
171 (defcustom org-taskjuggler-resource-tag
"taskjuggler_resource"
172 "Tag marking project's resources.
173 This tag is used to find the tree containing all the resources
175 :group
'org-export-taskjuggler
178 (defcustom org-taskjuggler-report-tag
"taskjuggler_report"
179 "Tag marking project's reports.
180 This tag is used to find the tree containing all the reports for
182 :group
'org-export-taskjuggler
185 (defcustom org-taskjuggler-target-version
2.4
186 "Which version of TaskJuggler the exporter is targeting."
187 :group
'org-export-taskjuggler
190 (defcustom org-taskjuggler-default-project-version
"1.0"
191 "Default version string for the project.
192 This value can also be set with the \":VERSION:\" property
193 associated to the headline defining the project."
194 :group
'org-export-taskjuggler
197 (defcustom org-taskjuggler-default-project-duration
280
198 "Default project duration.
199 The value will be used if no start and end date have been defined
200 in the root node of the task tree, i.e. the tree that has been
201 marked with `org-taskjuggler-project-tag'"
202 :group
'org-export-taskjuggler
205 (defcustom org-taskjuggler-default-reports
206 '("taskreport \"Gantt Chart\" {
207 headline \"Project Gantt Chart\"
208 columns hierarchindex, name, start, end, effort, duration, completed, chart
209 timeformat \"%Y-%m-%d\"
213 "resourcereport \"Resource Graph\" {
214 headline \"Resource Allocation Graph\"
215 columns no, name, utilization, freeload, chart
220 "Default reports for the project."
221 :group
'org-export-taskjuggler
222 :type
'(repeat (string :tag
"Report")))
224 (defcustom org-taskjuggler-default-global-header
""
225 "Default global header for the project.
226 This goes before project declaration, and might be useful for
228 :group
'org-export-taskjuggler
229 :type
'(string :tag
"Preamble"))
231 (defcustom org-taskjuggler-default-global-properties
232 "shift s40 \"Part time shift\" {
233 workinghours wed, thu, fri off
236 "Default global properties for the project.
238 Here you typically define global properties such as shifts,
239 accounts, rates, vacation, macros and flags. Any property that
240 is allowed within the TaskJuggler file can be inserted. You
241 could for example include another TaskJuggler file.
243 The global properties are inserted after the project declaration
244 but before any resource and task declarations."
245 :group
'org-export-taskjuggler
246 :type
'(string :tag
"Preamble"))
248 (defcustom org-taskjuggler-valid-task-attributes
249 '(account start note duration endbuffer endcredit end
250 flags journalentry length limits maxend maxstart minend
251 minstart period reference responsible scheduling
252 startbuffer startcredit statusnote chargeset charge
)
253 "Valid attributes for Taskjuggler tasks.
254 If one of these appears as a property for a headline, it will be
255 exported with the corresponding task."
256 :group
'org-export-taskjuggler
)
258 (defcustom org-taskjuggler-valid-resource-attributes
259 '(limits vacation shift booking efficiency journalentry rate
261 "Valid attributes for Taskjuggler resources.
262 If one of these appears as a property for a headline, it will be
263 exported with the corresponding resource."
264 :group
'org-export-taskjuggler
)
266 (defcustom org-taskjuggler-valid-report-attributes
267 '(headline columns definitions timeformat hideresource hidetask
268 loadunit sorttasks formats period
)
269 "Valid attributes for Taskjuggler reports.
270 If one of these appears as a property for a headline, it will be
271 exported with the corresponding report."
272 :group
'org-export-taskjuggler
)
274 (defcustom org-taskjuggler-keep-project-as-task t
275 "Non-nil keeps the project headline as an umbrella task for all tasks.
276 Setting this to nil will allow maintaining completely separated
277 task buckets, while still sharing the same resources pool."
278 :group
'org-export-taskjuggler
285 (defvar org-taskjuggler-final-hook nil
286 "Hook run after a TaskJuggler files has been saved.
287 This hook is run with the name of the file as argument.")
291 ;;; Back-End Definition
293 (org-export-define-backend taskjuggler
294 ((template . org-taskjuggler-project-plan
))
296 (?J
"Export to TaskJuggler"
297 ((?j
"As TJP file" (lambda (a s v b
) (org-taskjuggler-export a s v
)))
298 (?o
"As TJP file and open"
300 (if a
(org-taskjuggler-export a s v
)
301 (org-taskjuggler-export-and-open s v
))))))
302 ;; This property will be used to store unique ids in communication
303 ;; channel. Ids will be retrieved with `org-taskjuggler-get-id'.
304 :options-alist
((:taskjuggler-unique-ids nil nil nil
)))
310 (defun org-taskjuggler-assign-task-ids (tasks info
)
311 "Assign a unique ID to each task in TASKS.
312 TASKS is a list of headlines. Return value is an alist between
313 headlines and their associated ID. IDs are hierarchical, which
314 means they only need to be unique among the task siblings."
317 (lambda (tasks local-ids
)
318 (org-element-map tasks
'headline
320 (let ((id (org-taskjuggler--build-unique-id task local-ids
)))
322 (push (cons task id
) alist
)
323 (funcall build-id
(org-element-contents task
) nil
)))
324 info nil
'headline
))))
325 (funcall build-id tasks nil
)
328 (defun org-taskjuggler-assign-resource-ids (resources info
)
329 "Assign a unique ID to each resource within RESOURCES.
330 RESOURCES is a list of headlines. Return value is an alist
331 between headlines and their associated ID."
333 (org-element-map resources
'headline
335 (let ((id (org-taskjuggler--build-unique-id resource ids
)))
344 (defun org-taskjuggler-get-project (info)
345 "Return project in parse tree.
346 INFO is a plist used as a communication channel. First headline
347 in buffer with `org-taskjuggler-project-tag' defines the project.
348 If no such task is defined, pick the first headline in buffer.
349 If there is no headline at all, return nil."
350 (or (org-element-map (plist-get info
:parse-tree
) 'headline
352 (and (member org-taskjuggler-project-tag
353 (org-export-get-tags hl info
))
356 (org-element-map tree
'headline
'identity info t
)))
358 (defun org-taskjuggler-get-id (item info
)
359 "Return id for task or resource ITEM.
360 ITEM is a headline. Return value is a string."
361 (cdr (assq item
(plist-get info
:taskjuggler-unique-ids
))))
363 (defun org-taskjuggler-get-name (item)
364 "Return name for task or resource ITEM.
365 ITEM is a headline. Return value is a string."
366 ;; Quote double quotes in name.
367 (replace-regexp-in-string
368 "\"" "\\\"" (org-element-property :raw-value item
) t t
))
370 (defun org-taskjuggler-get-start (item)
371 "Return start date for task or resource ITEM.
372 ITEM is a headline. Return value is a string or nil if ITEM
373 doesn't have any start date defined.."
374 (let ((scheduled (org-element-property :scheduled item
)))
375 (and scheduled
(org-timestamp-format scheduled
"%Y-%02m-%02d"))))
377 (defun org-taskjuggler-get-end (item)
378 "Return end date for task or resource ITEM.
379 ITEM is a headline. Return value is a string or nil if ITEM
380 doesn't have any end date defined.."
381 (let ((deadline (org-element-property :deadline item
)))
382 (and deadline
(org-timestamp-format deadline
"%Y-%02m-%02d"))))
386 ;;; Internal Functions
388 (defun org-taskjuggler--indent-string (s)
389 "Indent string S by 2 spaces.
390 Return new string. If S is the empty string, return it."
391 (if (equal "" s
) s
(replace-regexp-in-string "^ *\\S-" " \\&" s
)))
393 (defun org-taskjuggler--build-attributes (item attributes
)
394 "Return attributes string for task, resource or report ITEM.
395 ITEM is a headline. ATTRIBUTES is a list of symbols
396 representing valid attributes for ITEM."
399 (let ((value (org-element-property
400 (intern (upcase (format ":%s" attribute
)))
402 (and value
(format "%s %s\n" attribute value
))))
403 (remq nil attributes
) ""))
405 (defun org-taskjuggler--build-unique-id (item unique-ids
)
406 "Return a unique id for a given task or a resource.
407 ITEM is an `headline' type element representing the task or
408 resource. Its id is derived from its name and made unique
409 against UNIQUE-IDS. If the (downcased) first token of the
410 headline is not unique try to add more (downcased) tokens of the
411 headline or finally add more underscore characters (\"_\")."
412 (let* ((parts (org-split-string (org-element-property :raw-value item
)))
413 (id (org-taskjuggler--clean-id (downcase (pop parts
)))))
414 ;; Try to add more parts of the headline to make it unique.
415 (while (and (car parts
) (member id unique-ids
))
416 (setq id
(concat id
"_"
417 (org-taskjuggler--clean-id (downcase (pop parts
))))))
418 ;; If it's still not unique, add "_".
419 (while (member id unique-ids
)
420 (setq id
(concat id
"_")))
423 (defun org-taskjuggler--clean-id (id)
424 "Clean and return ID to make it acceptable for TaskJuggler.
426 ;; Replace non-ascii by "_".
427 (replace-regexp-in-string
429 ;; Make sure id doesn't start with a number.
430 (replace-regexp-in-string "^\\([0-9]\\)" "_\\1" id
)))
436 (defun org-taskjuggler-resolve-dependencies (task info
)
437 "Return a list of all tasks TASK depends on.
438 TASK is a headline. INFO is a plist used as a communication
441 ;; Get all dependencies specified in BLOCKER and DEPENDS task
442 ;; properties. Clean options from them.
443 (let ((deps (concat (org-element-property :BLOCKER task
)
444 (org-element-property :DEPENDS task
))))
446 (org-split-string (replace-regexp-in-string "{.*?}" "" deps
)
450 ;; Find tasks with :task_id: property matching id in DEPS-IDS.
451 ;; Add them to DEPENDS.
452 (let* ((project (org-taskjuggler-get-project info
))
453 (tasks (if org-taskjuggler-keep-project-as-task project
454 (org-element-contents project
))))
456 (org-element-map tasks
'headline
458 (let ((task-id (org-element-property :TASK_ID task
)))
459 (and task-id
(member task-id deps-ids
) task
)))
461 ;; Check BLOCKER and DEPENDS properties. If "previous-sibling"
462 ;; belongs to DEPS-ID, add it to DEPENDS.
463 (when (and (member-ignore-case "previous-sibling" deps-ids
)
464 (not (org-export-first-sibling-p task info
)))
465 (let ((prev (org-export-get-previous-element task info
)))
466 (and (not (memq prev depends
)) (push prev depends
)))))
467 ;; Check ORDERED status of parent.
468 (let ((parent (org-export-get-parent task
)))
470 (org-element-property :ORDERED parent
)
471 (not (org-export-first-sibling-p task info
)))
472 (push (org-export-get-previous-element task info
) depends
)))
473 ;; Return dependencies.
476 (defun org-taskjuggler-format-dependencies (dependencies task info
)
477 "Format DEPENDENCIES to match TaskJuggler syntax.
478 DEPENDENCIES is list of dependencies for TASK, as returned by
479 `org-taskjuggler-resolve-depedencies'. TASK is a headline.
480 INFO is a plist used as a communication channel. Return value
481 doesn't include leading \"depends\"."
482 (let ((dep-str (concat (org-element-property :BLOCKER task
)
484 (org-element-property :DEPENDS task
)))
487 ;; Return path to DEP relatively to TASK.
488 (let ((parent (org-export-get-parent dep
))
491 (let ((id (org-element-property :TASK_ID dep
)))
493 (string-match (concat id
" +\\({.*?}\\)") dep-str
)
494 (org-match-string-no-properties 1))))
496 ;; Compute number of exclamation marks.
497 (while (not (org-element-map parent
'headline
498 (lambda (task) (eq task dep
))))
500 (setq parent
(org-export-get-parent parent
)))
501 ;; Build path from DEP to PARENT.
502 (while (not (eq parent dep
))
503 (push (org-taskjuggler-get-id dep info
) path
)
504 (setq dep
(org-export-get-parent dep
)))
505 ;; Return full path. Add dependency options, if any.
506 (concat (make-string exclamations ?
!)
507 (mapconcat 'identity path
".")
508 (and option
(concat " " option
)))))))
509 ;; Return dependencies string, without the leading "depends".
510 (mapconcat (lambda (dep) (funcall get-path dep
)) dependencies
", ")))
514 ;;; Translator Functions
516 (defun org-taskjuggler-project-plan (contents info
)
517 "Build TaskJuggler project plan.
518 CONTENTS is ignored. INFO is a plist holding export options.
519 Return complete project plan as a string in TaskJuggler syntax."
520 (let* ((tree (plist-get info
:parse-tree
))
521 (project (or (org-taskjuggler-get-project info
)
522 (error "No project specified"))))
525 (org-element-normalize-string org-taskjuggler-default-global-header
)
526 ;; 2. Insert project.
527 (org-taskjuggler--build-project project info
)
528 ;; 3. Insert global properties.
529 (org-element-normalize-string org-taskjuggler-default-global-properties
)
530 ;; 4. Insert resources. Provide a default one if none is
532 (let ((main-resources
533 ;; Collect contents from various trees marked with
534 ;; `org-taskjuggler-resource-tag'. Only gather top level
537 (org-element-map tree
'headline
539 (and (member org-taskjuggler-resource-tag
540 (org-export-get-tags hl info
))
541 (org-element-map (org-element-contents hl
) 'headline
542 'identity info nil
'headline
)))
543 info nil
'headline
))))
544 ;; Assign a unique ID to each resource. Store it under
545 ;; `:taskjuggler-unique-ids' property in INFO.
547 (plist-put info
:taskjuggler-unique-ids
548 (org-taskjuggler-assign-resource-ids
549 main-resources info
)))
553 (lambda (resource) (org-taskjuggler--build-resource resource info
))
555 (format "resource %s \"%s\" {\n}\n" (user-login-name) user-full-name
))
558 ;; If `org-taskjuggler-keep-project-as-task' is
559 ;; non-nil, there is only one task. Otherwise, every
560 ;; direct children of PROJECT is a top level task.
561 (if org-taskjuggler-keep-project-as-task
(list project
)
562 (or (org-element-map (org-element-contents project
) 'headline
563 'identity info nil
'headline
)
564 (error "No task specified")))))
565 ;; Assign a unique ID to each task. Add it to
566 ;; `:taskjuggler-unique-ids' property in INFO.
568 (plist-put info
:taskjuggler-unique-ids
570 (org-taskjuggler-assign-task-ids main-tasks info
)
571 (plist-get info
:taskjuggler-unique-ids
))))
572 ;; If no resource is allocated among tasks, allocate one to
574 (unless (org-element-map main-tasks
'headline
575 (lambda (task) (org-element-property :ALLOCATE task
))
577 (org-element-put-property
578 (car main-tasks
) :ALLOCATE
579 (or (org-taskjuggler-get-id (car main-resources
) info
)
582 (lambda (task) (org-taskjuggler--build-task task info
))
584 ;; 6. Insert reports. If no report is defined, insert default
587 ;; Collect contents from various trees marked with
588 ;; `org-taskjuggler-report-tag'. Only gather top level
591 (org-element-map tree
'headline
593 (and (member org-taskjuggler-report-tag
594 (org-export-get-tags hl info
))
595 (org-element-map (org-element-contents hl
)
596 'headline
'identity info nil
'headline
)))
597 info nil
'headline
))))
600 (lambda (report) (org-taskjuggler--build-report report info
))
602 (mapconcat 'org-element-normalize-string
603 org-taskjuggler-default-reports
""))))))))
605 (defun org-taskjuggler--build-project (project info
)
606 "Return a project declaration.
607 PROJECT is a headline. INFO is a plist used as a communication
608 channel. If no start date is specified, start today. If no end
609 date is specified, end `org-taskjuggler-default-project-duration'
611 (format "project %s \"%s\" \"%s\" %s %s {\n}\n"
612 (org-taskjuggler-get-id project info
)
613 (org-taskjuggler-get-name project
)
614 ;; Version is obtained through :TASKJUGGLER_VERSION:
615 ;; property or `org-taskjuggler-default-project-version'.
616 (or (org-element-property :VERSION project
)
617 org-taskjuggler-default-project-version
)
618 (or (org-taskjuggler-get-start project
)
619 (format-time-string "%Y-%m-%d"))
620 (let ((end (org-taskjuggler-get-end project
)))
621 (or (and end
(format "- %s" end
))
622 (format "+%sd" org-taskjuggler-default-project-duration
)))))
624 (defun org-taskjuggler--build-resource (resource info
)
625 "Return a resource declaration.
627 RESOURCE is a headline. INFO is a plist used as a communication
630 All valid attributes from RESOURCE are inserted. If RESOURCE
631 defines a property \"resource_id\" it will be used as the id for
632 this resource. Otherwise it will use the ID property. If
633 neither is defined a unique id will be associated to it."
636 (format "resource %s \"%s\" {\n"
637 (org-taskjuggler--clean-id
638 (or (org-element-property :RESOURCE_ID resource
)
639 (org-element-property :ID resource
)
640 (org-taskjuggler-get-id resource info
)))
641 (org-taskjuggler-get-name resource
))
643 (org-taskjuggler--indent-string
644 (org-taskjuggler--build-attributes
645 resource org-taskjuggler-valid-resource-attributes
))
646 ;; Add inner resources.
647 (org-taskjuggler--indent-string
650 (org-element-map (org-element-contents resource
) 'headline
651 (lambda (hl) (org-taskjuggler--build-resource hl info
))
657 (defun org-taskjuggler--build-report (report)
658 "Return a report declaration.
659 REPORT is a headline. INFO is a plist used as a communication
663 (format "%s \"%s\" {\n"
664 (or (org-element-property :REPORT_KIND report
) "taskreport")
665 (org-taskjuggler-get-name report
))
667 (org-taskjuggler--indent-string
668 (org-taskjuggler--build-attributes
669 report org-taskjuggler-valid-report-attributes
))
670 ;; Add inner reports.
671 (org-taskjuggler--indent-string
674 (org-element-map (org-element-contents report
) 'headline
675 (lambda (hl) (org-taskjuggler--build-report hl info
))
681 (defun org-taskjuggler--build-task (task info
)
682 "Return a task declaration.
684 TASK is a headline. INFO is a plist used as a communication
687 All valid attributes from TASK are inserted. If TASK defines
688 a property \"task_id\" it will be used as the id for this task.
689 Otherwise it will use the ID property. If neither is defined
690 a unique id will be associated to it."
691 (let* ((allocate (org-element-property :ALLOCATE task
))
693 (if (eq (org-element-property :todo-type task
) 'done
) "100"
694 (org-element-property :COMPLETE task
)))
695 (depends (org-taskjuggler-resolve-dependencies task info
))
696 (effort (org-element-property :EFFORT task
))
698 (or (org-element-property :MILESTONE task
)
699 (and (org-element-map (org-element-contents task
) 'headline
700 'identity info t
) ; Has task any child?
702 (org-element-property :LENGTH task
)
703 (org-element-property :DURATION task
)
704 (and (org-taskjuggler-get-start task
)
705 (org-taskjuggler-get-end task
))
706 (org-element-property :PERIOD task
))))))
708 (let ((pri (org-element-property :priority task
)))
710 (max 1 (/ (* 1000 (- org-lowest-priority pri
))
711 (- org-lowest-priority org-highest-priority
)))))))
714 (format "task %s \"%s\" {\n"
715 (org-taskjuggler-get-id task info
)
716 (org-taskjuggler-get-name task
))
717 ;; Add default attributes.
719 (format " depends %s\n"
720 (org-taskjuggler-format-dependencies depends task info
)))
722 (format " purge %s\n allocate %s\n"
723 ;; Compatibility for previous TaskJuggler versions.
724 (if (>= org-export-taskjuggler-target-version
3.0) "allocate"
727 (and complete
(format " complete %s\n" comptete
))
729 (format " effort %s\n"
730 (let* ((minutes (org-duration-string-to-minutes effort
))
731 (hours (/ minutes
60.0)))
732 (format "%.1fh" hours
))))
733 (and priority
(format " priority %s\n" complete
))
734 (and milestone
" milestone\n")
735 ;; Add other valid attributes.
736 (org-taskjuggler--indent-string
737 (org-taskjuggler--build-attributes
738 task org-taskjuggler-valid-task-attributes
))
740 (org-taskjuggler--indent-string
742 (org-element-map (org-element-contents task
) 'headline
743 (lambda (hl) (org-taskjuggler--build-task hl info
))
751 ;;; Interactive Functions
754 (defun org-taskjuggler-export (&optional async subtreep visible-only
)
755 "Export current buffer to a TaskJuggler file.
757 The exporter looks for a tree with tag that matches
758 `org-taskjuggler-project-tag' and takes this as the tasks for
759 this project. The first node of this tree defines the project
760 properties such as project name and project period.
762 If there is a tree with tag that matches
763 `org-taskjuggler-resource-tag' this tree is taken as resources
764 for the project. If no resources are specified, a default
765 resource is created and allocated to the project.
767 Also the TaskJuggler project will be created with default reports
768 as defined in `org-taskjuggler-default-reports'.
770 If narrowing is active in the current buffer, only export its
773 If a region is active, export that region.
775 A non-nil optional argument ASYNC means the process should happen
776 asynchronously. The resulting file should be accessible through
777 the `org-export-stack' interface.
779 When optional argument SUBTREEP is non-nil, export the sub-tree
780 at point, extracting information from the headline properties
783 When optional argument VISIBLE-ONLY is non-nil, don't export
784 contents of hidden elements.
786 Return output file's name."
789 (org-export-output-file-name org-taskjuggler-extension subtreep
)))
791 (org-export-async-start
793 (org-export-add-to-stack f
'taskjuggler
)
794 (run-hook-with-args 'org-taskjuggler-final-hook f
))
796 (org-export-to-file 'taskjuggler
,outfile
,subtreep
,visible-only
)))
797 (org-export-to-file 'taskjuggler outfile subtreep visible-only
)
798 (run-hook-with-args 'org-taskjuggler-final-hook outfile
)
802 (defun org-taskjuggler-export-and-open (&optional subtreep visible-only
)
803 "Export current buffer to a TaskJuggler file and open it.
805 The exporter looks for a tree with tag that matches
806 `org-taskjuggler-project-tag' and takes this as the tasks for
807 this project. The first node of this tree defines the project
808 properties such as project name and project period.
810 If there is a tree with tag that matches
811 `org-taskjuggler-resource-tag' this tree is taken as resources
812 for the project. If no resources are specified, a default
813 resource is created and allocated to the project.
815 Also the TaskJuggler project will be created with default reports
816 as defined in `org-taskjuggler-default-reports'.
818 If narrowing is active in the current buffer, only export its
821 If a region is active, export that region.
823 When optional argument SUBTREEP is non-nil, export the sub-tree
824 at point, extracting information from the headline properties
827 When optional argument VISIBLE-ONLY is non-nil, don't export
828 contents of hidden elements.
830 Open file with the TaskJuggler GUI."
832 (let* ((file (org-taskjuggler-export nil subtreep visible-only
))
833 (process-name "TaskJugglerUI")
834 (command (concat process-name
" " file
)))
835 (start-process-shell-command process-name nil command
)))
838 (provide 'ox-taskjuggler
)
841 ;; sentence-end-double-space: t
844 ;;; ox-taskjuggler.el ends here