Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Due dates in Display Expression (Read 8404 times)
AsafKeller
Full Member
*
Offline



Posts: 77

Due dates in Display Expression
Jul 12th, 2008, 3:27pm
 
Is there a way to display due dates in note titles, without notes having no due dates appearing with "Never" in their title? Thanks.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Due dates in Display Expression
Reply #1 - Jul 12th, 2008, 4:19pm
 
Use an 'if' test.  Add this as the OnAdd action to a container:
if(DueDate!=never){DisplayExpression = $Name + " - " + $DueDate}

Now drag notes into the container note both with a mix of some with a DueDate set and some not to see the effect.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
jjablonski
Full Member
*
Offline



Posts: 1

Re: Due dates in Display Expression
Reply #2 - Jul 15th, 2008, 5:11pm
 
I've tried the technique that you've suggested and have copied the expression:

if(DueDate!=never){DisplayExpression = $Name + " - " + $DueDate}

into the OnAdd action to a container.

If I drag a task named Task #2 with a DueDate set to 7-15-08 into this container, here's what the displayed name of the note changes to:

Task #215 Jul 2008 0:00:00

If I open the note and look at the Display Expression it's:

Task #2 - 15 Jul 2008 0:00:00

If I change the format of the DueDate in the OnAdd expression to:

if(DueDate!=never){DisplayExpression = $Name + " - " + format($DueDate,"L")}

and drop a note into is whose Name is Task #3 and DueDate is set to 8/30/08, the note display name changes to:

Task#3Saturday

even though the Display Expression is

Task #3 - Saturday, August 30, 2008

So my question is: why is there this difference between the Display Expression and what is actually being displayed as the title of the note? I'm certain that I'm just missing something simple here--so if someone could explain this to me, I'd appreciate it. What I would like to have happen is to have the displayed name of the note match the Display Expression.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Due dates in Display Expression
Reply #3 - Jul 15th, 2008, 5:59pm
 
[original incorrect analysis deleted]

The problem stems from the way we're setting up DisplayExpression in the OnAdd action and it then being re-evaluated a second time. A hyphen created in the OnAdd action may thus get read as a minus sign in the second evaluation, etc. Read on...  


Back to top
 
« Last Edit: Jul 16th, 2008, 4:00am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Due dates in Display Expression
Reply #4 - Jul 15th, 2008, 6:29pm
 
...a bit more testing. This does work:
if(DueDate!=never){DisplayExpression = $Name + " \- " + $DueDate};

... the trick is to escape the hyphen otherwise when DisplayExpression is run in the context of the note itself it's seen as a minus and TB tries to do maths on the two parts of the DE expression.

This ought to work:
if(DueDate!=never){DisplayExpression = $Name + " \- " + format($DueDate,"L")};

... indeed, it looks OK in the dropped note's DE attribute value but on screen everything after the day is truncated. I suspect the commas in the date string are the problem.  No easy way around that except to manually compile the equivalent format string to "L". so here's the OnAdd action:

if(DueDate!=never){DisplayExpression = $Name + " \- " + format($DueDate,"W\\, MM d\\, y")};

The resulting DE is:
Task #2 \- Tuesday\, July 15\, 2008
..and on screen we see
Task #2 - Tuesday, July 15, 2008

Note the need for two backslashes in the OnAdd action.  One is stripped going through format leaving one in place for Display Expression to see.




Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Paul Walters
Ex Member




Re: Due dates in Display Expression
Reply #5 - Jul 15th, 2008, 8:16pm
 
Mark, you are correct in suspecting the commas.  If you change the date formats in OS X System Preferences to a custom format without the commas, then the DisplayName appears correctly when format($DueDate,"L") is used.   That is, correctly without the commas, in this case.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Due dates in Display Expression
Reply #6 - Jul 16th, 2008, 5:07am
 
That's a good workaround if such a system-wide change is acceptable as it may well be for many users. Thinking about this overnight, I came up we a more global solution to avoid unescaped maths operators creeping into DisplayExpression before it is run at note level, i.e. +-/*, plus the comma. T our rescue comes runCommand(). If you don't understand command line, my example should work. Command Line experts can replace my use of sed with their tool of choice.

Here's the revised OnAdd action:

DisplayExpression = $Name + " \\- " + runCommand("sed 's/,/\\\\,/g' | sed 's/+/\\\\+/g' | sed 's/-/\\\\-/g' | sed 's/\//\\\\\//g' | sed 's/*/\\\\*/g'",format($DueDate,"L"));

I've tested with the 4 pre-defined TB date formats  - "L", "l", "*" and "=" - and all work as expected. In fact none of the four use * in them but I figured I'd put it in for completeness. (What does the code do? See below).

To make this more re-useable you could put the command line code in another note parked in a utility section of your TBX. For example's sake I'll call the note "Escape format op" - that should help remind us of its purpose. Open the note and paste this as the text:

sed 's/,/\\\\,/g' | sed 's/+/\\\\+/g' | sed 's/-/\\\\-/g' | sed 's/\//\\\\\//g' | sed 's/*/\\\\*/g'

If you like you can set the text font to Courier or the like to make sure all the similar characters like 1 and l are clearly different. By using the note's text rather than a used attribute it's much easier to display the whole of a long piece of code.

Now, go back and change your original container's OnAdd action to:

DisplayExpression = $Name + " \\- " + runCommand($Text("Escape format op"),format($DueDate,"L"));

Think of your command line stored in the note as like a macro - now it's easy to use it in multiple instances anywhere in you TBX knowing it will work each time. Need to revise the code? Just like using a prototype, one change affects all users of the code.

In double-processed contexts like this one, besides maths operators and the comma I'd be careful to escape the caret(^) and $ as these mark the beginning/end of a string in regular expressions (that TB uses under the hood) and i'd also be careful about the semi-colon (used to delimited indivaidual actions).

~~~~

What does the command line used here do?  It uses the command 'sed' 5 times in succession, each time to escape a different character in our formatted date string. So, we want a comma ',' to end up as '\\,' and the argument sed 's/'/\\\\,/g' does this.  The 'g' on the end means replace globally, i.e. all commas not just the first.  Because in sed the \ is an escape character too, we must escape our escapes - we need 4 \ to output 2 \. The '|' symbol feeds the results of the first sed call to the next one that escapes plus signs, etc. with the eventual result being returned by runCommand() to the TB OnAdd action.  A more experienced command line user could probably do all these tasks in a shorter line of code but at least this lets the learner get a glimpse of what's going on.
Back to top
 
« Last Edit: Jul 16th, 2008, 5:19am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Due dates in Display Expression
Reply #7 - Jul 16th, 2008, 10:05am
 
Two suggestions:

1) Use a rule to format the date, saving the result in a string attribute. Then, the DisplayExpression is simple once again -- commas or no commas.

2) When things get complicated, it might be better to try runCommmand().
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Due dates in Display Expression
Reply #8 - Jul 16th, 2008, 6:11pm
 
The way to use method #1 in the above post is this:

Set Display Expression to: $Name + $MyString However, it is important to note you can't do that dynamically via an action. Either type in the value to the create/rename dialog or do so with a prototype and inherit from that.

With Display Expression set, the next part can be dynamic. For instance, use this OnAdd action and drop in a note of the above configuration: if($DueDate!="never") {MyString = " - " + format($DueDate,"*")}

If you want to set everything in one pass use the runCommand method previously described. One other solution - avoid joining strings and/or date formats that include troublesome characters!
Back to top
 
« Last Edit: Oct 11th, 2008, 12:35pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print