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
Assigning a Rule to notes in a certain container (Read 953 times)
J Fallows
Full Member
*
Offline



Posts: 418

Assigning a Rule to notes in a certain container
May 16th, 2016, 9:35am
 
Here's the scenario:
  • I have a container that we'll call "Travel Projects";
  • The immediate-child contents of this container are specific projects. "Trip to China June 2016", "Trip to Mars 2020" and so on;
  • Each one of those specific projects is itself a container with a number of child items;
  • By a rule I've set up for the file as a whole, any item that has children will be based on the *Projects prototype, and any of them with no children uses the *Tasks prototype. This is based on the David Allen-GTD concept that anything involving several steps should be considered a project. The rule I use, discussed previously in this space, is based on a $ChildCount test — if yes, then apply *Projects, if no then *Tasks;

Now here is the challenge. The *Tasks prototype includes a user attribute $ProjectName. It's a set-type attribute, and for notes in this specific container I would like it to replicate the name of the parent container. For reasons I needn't go into, in some other containers I want  $ProjectName to be something different.

I understand the rule that will get the result I want: $ProjectName=$Name(parent). The question I have is about the best way to confine this rule to items within this container.
 - Would it be best to have an agent for the whole file, which included a test for this container? Eg the query descendedFrom("Travel Projects")&$Prototype="*Tasks", and then action $ProjectName=$Name(parent)  ?
- Or is there some way to have an on-assign action for items inside this container, given them (but not items in other containers) a Rule setting their $ProjectName in the desired way? And if so, would the Action be something like $Rule="if($Prototype='*Tasks'){$ProjectName=$Name(parent)}" ?
- Or something else?

Asking partly to tweak this part of the file, partly to understand larger TB-operation principles. Thanks!

Update: edited to correct name(parent) to $Name(parent). The latter is the way I actually have it in my code.
Back to top
 
« Last Edit: May 16th, 2016, 12:21pm by J Fallows »  
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Assigning a Rule to notes in a certain container
Reply #1 - May 16th, 2016, 1:50pm
 
First, do you really want to assign the rule? A simpler solution might be to have the parent have an attribute $SuggentedProjectName, which might default to be the same as $Name but could be changed for some containers.  

Note that an OnAdd action is a suggestion which you can override, while doing the equivalent action in a task is a constraint; if you try to override it. The agent will override you!
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Assigning a Rule to notes in a certain container
Reply #2 - May 16th, 2016, 1:54pm
 
My parsing of this:
  • Main container for all this is "Travel Projects"
  • All children of the above are assigned the "*Projects" prototype, presumably by the parent's $OnAdd.
  • Children of  "*Projects" prototype-based notes use the "*Tasks" prototype, which I presume is set by the "*Projects" prototype $OnAdd.
  • Grandchildren of "Travel Projects" are thus tasks.
  • Task notes need to have $ProjectName set to the $Name of their parent project, but only is descended from "Travel Projects".
Based on that assumption, I'd give the "*Projects" prototype this $OnAdd:

$Prototype = "*Tasks";
if($Name(grandparent)=="Travel Projects"){
  $ProjectName=$Name(parent);
}


(Tested in v6.5.0)

Does that help?  The 'grandparent' designator is not much seen but is useful to avoid trying to use awkward constructs like $Name(parent(parent)).

Edge case: if you move tasks, you may need to manually triage the $ProjectName values.
Back to top
 
« Last Edit: May 16th, 2016, 1:55pm by Mark Anderson »  

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



Posts: 418

Re: Assigning a Rule to notes in a certain container
Reply #3 - May 16th, 2016, 4:30pm
 
Mark B, Mark A -- thanks very much to you both. I see how to deal with the specific issue, and your advice is also very useful in larger knowledge of the program.

A follow-up on this:
Quote:
if($Name(grandparent)=="Travel Projects")... Does that help?  The 'grandparent' designator is not much seen but is useful to avoid trying to use awkward constructs like $Name(parent(parent)).


As a matter of elegance and/or efficiency in programming, is there a difference between the $Name(grandparent)=="Travel Projects" test, and the descendedFrom("Travel Projects") test? Is one cleaner than the other, less drag on the system, etc? Or, as is often the case in TB, are they just different routes to a common destination?

I can see how "grandparent" might be quicker, in that it's looking back a finite number of generations rather than the whole "descendedFrom" tree. But I can also see how, for that very reason, "descendedFrom" could be useful in covering further generations of sub-containers you might add. Just asking for fuller understanding of what I'm doing. Thanks!

Update  Mark A points out, "Edge case: if you move tasks, you may need to manually triage the $ProjectName values."
Yes, this has come up, and I've dealt with it by creating a stamp I can use for quick-and-easy setting of $ProjectName to the desired values.
Back to top
 
« Last Edit: May 16th, 2016, 5:05pm by J Fallows »  
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Assigning a Rule to notes in a certain container
Reply #4 - May 16th, 2016, 5:35pm
 
descendedFrom is fairly fast, because notes are seldom very deeply nested.  Also, descendedFrom(() only needs to do a pointer comparison on each ancestor (which takes almost no time at all), while Name comparison needs to do a string comparison on each note (which is also fast, but not quite as fast).

In other words, either should be very fast.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Assigning a Rule to notes in a certain container
Reply #5 - May 16th, 2016, 5:41pm
 
The $Name test only grandchildren - which is the tasks only  - and thus needs only one query term. A descendedFrom() tests children, grandchildren and so on down, plus you need the extra prototype value test as well to make the if()'s query work.

I very much doubt there's a significant performance difference in your TBX. I was just trying to keep things short given the narrow scope of the layout allowed for it. I wasn't suggesting your original solution was sub-optimal (though perhaps I should have made that latter fact plain!).

Also, if tasks can be nested, or if some children of projects aren't tasks, then you would would need to use the descendedFrom() approach to correctly find all tasks.
Back to top
 
 

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



Posts: 418

Re: Assigning a Rule to notes in a certain container
Reply #6 - May 16th, 2016, 6:18pm
 
Thanks, Marks both. I appreciate your giving the fuller context of how things happen, and why. Each of these cycles can give users a little more suppleness with the tools.
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print