Skip to content

Commit

Permalink
Basic exporting completed
Browse files Browse the repository at this point in the history
  • Loading branch information
dmrd committed Oct 11, 2016
1 parent f0f1802 commit ec58140
Show file tree
Hide file tree
Showing 5 changed files with 2,300 additions and 42 deletions.
2 changes: 1 addition & 1 deletion OrgView.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function side_menu(field, state) {

function createTestDoc() {
return Parser.parse(
'* DONE [#A] 1. I did this :project:\nSCHEDULED: <2016-06-05 Sun>\n:LOGBOOK:\nCLOCK: [2016-06-03 Fri 18:00]--[2016-06-03 Fri 19:30] => 1:30\n- I did MORE of it\nCLOCK: [2016-06-02 Thu 18:00]--[2016-06-02 Thu 19:00] => 1:00\n- I did part of it!\n:END:\n** 1.1 Look at all\n** 1.2 Of these headlines\n*** 1.2.1 Wow such hierarchy\n**** TODO 1.2.1.1 much test\n* 2. Work :work:\n** TODO [#A] 2.1 Do this or you lose your job!\nSCHEDULED: <2016-06-04 Sat> DEADLINE: <2016-06-06 Mon>\n*** 2.1.1 You should probably\n** TODO 2.2 so many things to do\n** TODO 2.3 and so little time\nSCHEDULED: <2016-06-06 Mon>\n** TODO 2.4 to do them all\n** DONE 2.5 Except this one. You did this one.\n** DONE 2.6 important tasks\nCLOSED: [2016-06-03 Fri 14:59]\n* 3. Home :home:\n** TODO 3.1 Remember garbage day?\nSCHEDULED: <2016-06-16 Thu +1w>\n:PROPERTIES:\n:LAST_REPEAT: [2016-06-03 Fri 21:32]\n:END:\n:LOGBOOK:\n- State \"DONE\" from \"TODO\" [2016-06-03 Fri 21:32]\n:END:\n** TODO 3.2 You should go to that thing\nSCHEDULED: <2016-06-13 Mon 20:00>\n*** DONE 3.2.1 Wow go buy some gifts or something \nCLOSED: [2016-06-11 Sat 21:33] DEADLINE: <2016-06-12 Sun>\n* 4. hobbies\n** 4.1 hobby #1\n*** TODO 4.1.1 Things and stuff hobby #1\n** 4.2 hobby #2\n*** TODO 4.2.1 Things and stuff hobby #2\n** 4.3 hobby #3\n*** TODO 4.3.1 Things and stuff hobby #3\n** 4.4 hobby #4\n*** TODO 4.4.1 Things and stuff hobby #4\n**** TODO this one has lots of nesting\n***** TODO and many children\n***** TODO to make the tree traversal complex\n***** TODO Although not all tasks are TODO here\n***** DONE Like this one. This one is done'
'* DONE [#A] 1. I did this :project:\nSCHEDULED: <2016-06-05 Sun>\n:LOGBOOK:\nCLOCK: [2016-06-03 Fri 18:00]--[2016-06-03 Fri 19:30] => 1:30\n- I did MORE of it\nCLOCK: [2016-06-02 Thu 18:00]--[2016-06-02 Thu 19:00] => 1:00\n- I did part of it!\n:END:\n** 1.1 Look at all\n** 1.2 Of these headlines\n*** 1.2.1 Wow such hierarchy\n**** TODO 1.2.1.1 much test\n* 2. Work :work:\n** TODO [#A] 2.1 Do this or you lose your job!\nSCHEDULED: <2016-06-04 Sat> DEADLINE: <2016-06-06 Mon>\n*** 2.1.1 You should probably\n** TODO 2.2 so many things to do\n** TODO 2.3 and so little time\nSCHEDULED: <2016-06-06 Mon>\n** TODO 2.4 to do them all\n** DONE 2.5 Except this one. You did this one.\n** DONE 2.6 important tasks\nCLOSED: [2016-06-03 Fri 14:59]\n* 3. Home :home:\n** TODO 3.1 Remember garbage day?\nSCHEDULED: <2016-06-16 Thu +1w>\n:PROPERTIES:\n:LAST_REPEAT: [2016-06-03 Fri 21:32]\n:END:\n:LOGBOOK:\n- State \"DONE\" from \"TODO\" [2016-06-03 Fri 21:32]\n:END:\n** TODO 3.2 You should go to that thing\nSCHEDULED: <2016-06-13 Mon 20:00>\n*** DONE 3.2.1 Wow go buy some gifts or something \nDEADLINE: <2016-06-12 Sun> CLOSED: [2016-06-11 Sat 21:33]\n* 4. hobbies\n** 4.1 hobby #1\n*** TODO 4.1.1 Things and stuff hobby #1\n** 4.2 hobby #2\n*** TODO 4.2.1 Things and stuff hobby #2\n** 4.3 hobby #3\n*** TODO 4.3.1 Things and stuff hobby #3\n** 4.4 hobby #4\n*** TODO 4.4.1 Things and stuff hobby #4\n**** TODO this one has lots of nesting\n***** TODO and many children\n***** TODO to make the tree traversal complex\n***** TODO Although not all tasks are TODO here\n***** DONE Like this one. This one is done'
);
}

Expand Down
160 changes: 135 additions & 25 deletions org/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function tsFromDate(date) {
day: date.getDate(),
hour: date.getHours(),
minute: date.getMinutes()
});
});
}

function nowTs() {
Expand Down Expand Up @@ -152,14 +152,14 @@ export function numChildren(cursor) {
/***** Cursor logic *****/

/*
Return the path corresponding to cursor
Return the path corresponding to cursor
*/
export function getPath(cursor) {
return cursor._keyPath;
}

/*
Create a cursor into `doc` with `path`
Create a cursor into `doc` with `path`
*/
export function createCursor(doc, path = []) {
return Cursor.from(doc, path, () => {});
Expand All @@ -169,7 +169,7 @@ export function createCursor(doc, path = []) {
/***** Traversing tree *****/

/*
Return the root document node for a cursor
Return the root document node for a cursor
*/
export function getDoc(cursor) {
return createCursor(cursor._rootData);
Expand Down Expand Up @@ -392,15 +392,15 @@ function tsValue(str) {

// Named days
switch (str) {
case 'yesterday':
addDays(-1);
return date;
case 'today':
return date;
case 'tomorrow':
addDays(1);
return date;
default:
case 'yesterday':
addDays(-1);
return date;
case 'today':
return date;
case 'tomorrow':
addDays(1);
return date;
default:
}

// # offsets, e.g. 1y, 2w, -3d
Expand Down Expand Up @@ -455,7 +455,7 @@ function createFilter(str) {
} else if (type === 'object') {
op = {'eq': (a,b) => a == b,
'neq': (a,b) => a != b
}[operatorStr];
}[operatorStr];
}

if (op == null) {
Expand Down Expand Up @@ -550,32 +550,142 @@ export function sort(nodes, property, comparator=null) {

export function export_subtree(subtree) {
/* Constructs a string representing given subtree as an org mode file */
cur = subtree;
result = [];
let cur = subtree;
let result = [];
while (!!cur) {
headline = printHeadline(cur);
result = result.concat(headline);
let exported = '';
if (isDoc(cur)) {
exported = printDoc(cur);
}

if (isHeadline(cur)) {
exported = printHeadline(cur);
}

if (isSection(cur)) {
exported = printSection(cur);
}

result.push(exported);
cur = next(cur);
}
joined = result.join('');
return joined.trim()
return joined.trim();
}

function printDoc(headline) {
// TODO(ddohan): Print doc level metadata
return '';
}

function printSection(section) {
if (!isSection(section)) {
return '';
}
return getContent(section) + '\n'
}


function printHeadline(headline) {
if (!isHeadline(headline)) {
return [];
return ''
}
return ['*'.repeat(level(headline)), ' ', getContent(headline), '\n'];
}
let result = ['*'.repeat(level(headline))];

keyword = getKeyword(headline);
priority = getPriority(headline);
content = getContent(headline);
tags = getTags(headline);

function printTags(headline) {
if (!!keyword) {
result.push(' ');
result.push(keyword);
}

if (!!priority) {
result.push(' [#' + priority);
result.push(']');
}

if (!!content) {
result.push(' ');
result.push(getContent(headline));
}

if (!!tags) {
if (tags.size > 0) {
result.push(' :');
for (tag of tags.values()) {
result.push(tag);
result.push(':');
}
}
}

result.push('\n')

let planning = printPlanning(headline)
if (planning) {
result.push(planning)
result.push('\n')
}

result = result.join('');
return result;
}

function printContent(headline) {
function printPlanning(headline) {
scheduled = getScheduled(headline)
deadline = getDeadline(headline)
closed = getClosed(headline)
let result = []
if (!!scheduled) {
result.push(['SCHEDULED: ', printTs(scheduled)].join(''))
}
if (!!deadline) {
result.push(['DEADLINE: ', printTs(deadline)].join(''))
}
if (!!closed) {
result.push(['CLOSED: ', printTs(closed)].join(''))
}

return result.join(' ')
}

function printProps(headline) {
function printTs(ts) {
let result = []
if (ts.active) {
result.push('<')
} else {
result.push('[')
}

result.push(ts.year)
result.push('-')
result.push(ts.month)
result.push('-')
result.push(ts.day)
result.push(' ')
result.push(ts.dayname)
if (!!ts.hour) {
result.push(' ')
result.push(ts.hour)
result.push(':')
result.push(ts.minute)
}

if (ts.repeater) {
let repeater = ts.repeater
result.push(' ')
result.push(repeater.mark)
result.push(repeater.value)
result.push(repeater.unit)
}

if (ts.active) {
result.push('>')
} else {
result.push(']')
}
return result.join('')
}
Loading

0 comments on commit ec58140

Please sign in to comment.