Separating Google child labels from parent labels - email

I want to retrieve all labels a user has at Google and display them in a neat way, like Google themselves do:
When I fetch this hierarchy of labels with the Gmail API I get the following data:
GET https://www.googleapis.com/gmail/v1/users/me/labels?key={YOUR_API_KEY}
I use "/" as a delimiter in order to figure out the parent label of a certain child label. This worked great until I realized I could create labels with "/" in the name. Bummer.
Is there another way to do this, or should I stop my users from being able to create labels with "/" in them, and just live with the potential "bad" labels they might have created elsewhere? Thanks.

It's possible to handle this case correctly, though it requires a little extra work than just splitting on the '/'.
Suppose you have the labels:
foo
bar
baz/qux
When you fetch all the labels, you'll get back 3 entries:
"foo"
"foo/bar"
"foo/bar/baz/qux"
Note that while "foo" and "foo/bar" exist, there is no "foo/bar/baz". That label doesn't exist because 'baz/qux' is the literal label name.
Rather than simply split, try prefix matching instead. The parent label is going to be the longest label (+ trailing /) that is a prefix of the one your checking. Anything remaining after the prefix is the label name itself.

Related

Is it possible to have different styles in one element in Jaspersoft?

Let's say I need to print the full name of a person. What I originally did was to separate the first name and last name into two elements and placed them side by side since they needed different styling (this is just an example):
Lastname, Firstname
However, I found out after that I can't actually make their width dynamic because the developers made an effort not to allow it. So now I'm wondering if I can present the name with two different styles inside one element. Is this possible? How would I accomplish that? I hope you can help, thanks!
Okay so apparently you can. All you need to do is setup the markup attribute on the text field.
Refer here for more details: http://jasperreports.sourceforge.net/sample.reference/markup/

Visio ShapeSheet ShapeData: keep two rows in sync

I have two Shape Data rows for a Shape's ShapeSheet:
Shape Data Label Prompt Type Format Value Invisible
Prop.Type "Type" "" 4 "Alpha;Beta;Gamma;Delta;Epsilon;Zeta;Eta;Theta;Iota;Kappa" INDEX(4,Prop.Type.Format) False
Prop.Abbrev "Abbrev" No Formula 4 "A;B;G;D;E;Z;E;T;I;K" INDEX(4,Prop.Abbrev.Format) True
The way I intent to use this is to have the user select the Type, say Epsilon, and then have the Abbrev automatically switch to the corresponding value in the Prop.Abbrev.Format.
Note: the values used here are placeholders for the actual values for my application, which are not shown here so they don't distract from the real answer I need, how to keep the selections in sync when the first one is chosen or changed.
Thanks for any help you can give!
I don't have Visio on this machine, so I am unable to copy and paste a working solution. The approach gets a little complicated, but extremely flexible.
Save your lists in the User section, rather than Prop - this then becomes underlying data for use in properties. If you are using a master stencil then this also helps with managing the fields.
You can now store an index in your data as well - this index points to the appropriate values in your arrays. You can use Actions and side menus to set the index which, when referenced properly, means you can have the full name and/or abbreviation in the side menu and the ShapeSheet does all the work underneath.
The functions you want to look at are:
Index (e.g. INDEX(1,User.Type) will return "Beta". (0-based)
Lookup (e.g. LOOKUP("D", User.Abbrev) will return "3". (0-based)
GetAtRef
SetAtRef
SetAtRefExpr
SetF
I had a similar business problem which relied on setting a background colour based on the value of shape data. Your final solution could end up including formulas like this: =SETF(GetRef(Prop.Type),"GUARD(INDEX(LOOKUP(Prop.X,Prop.X.Format),User.Type))").
For more in-depth discussion - check out https://superuser.com/questions/1277331/fillforegnd-in-shapesheet-using-wrong-data and the extended discussion at http://visguy.com/vgforum/index.php?topic=8205.15 - the latter link also includes an example file with working shapesheets (well, working to the extent that they exposed my problem).

xpath for named LabeledStatement or BreakStatement

I want to create a PMD rule to forbid usage of labeled statements
Sadly I could not find a common XPath for such statements.
I need a XPath query which finds
//LabeledStatement for the labels itself
and for the
ContinueStatement and BreakStatement i would need a possiblity to check if a label is defined there.
From the PMD Rule builder (XPath builder) the labels are defined as:
BreakStatement:loop (loop is the defined label name and could be anything)
ContinueStatement:loop (loop is the defined label name and could be anything)
can someone give me a hint what XPath I should define?
You are on a very good track. Using the rule designer is a great way to figure this one out, specially since PMD 6.0.0 which revamped the GUI.
As you figured, //LabeledStatement will match all labels (which you don't want), and //BreakStatement and //ContinueStatement will flag all break / continues, which you only want to flag if they are followed by a tag.
Therefore, you simply need to check if those have a tag set or not. Using the designer to inspect properties of those AST nodes makes it easy to figure it out, the attribute where the label is stored is the Image, which is null when none is defined. As XPath stringifies all attributes, a null value is an empty string.
Therefore:
//LabeledStatement | //BreakStatement[#Image != ""] | //ContinueStatement[#Image != ""]
Will match:
All labels
All breaks with a label
All continues with a label

How to avoid finding ancestors with Protractor cssContainingText locator

I have a test that needs to determine if a span exists; I want to locate the span by the text it contains for scaleability. I tried to use element(by.cssContainingText('*', 'Test Text')) but it turns out that in addition to matching the span, it also matches every ancestor it has. How do I avoid this (.last will not work as there are multiple spans that contain the text and I want to locate the first one)?
Preferably, I want a locator that works exactly like buttonText except without the button restriction.
This will get the first element on the page that has the text that you provide:
element(by.xpath('//*[contains(text(), "test text")]'));
If you wanted to get all of the elements, just tack on a .all after element.

Smarty foreach:for every iteration add class

I have a foreach loop code in a tpl file like this:
[{foreach from=$oView->getArticleList() item=actionproduct name=test_articleList}]
[{include file="inc/product_alt.tpl" product=$actionproduct testid="action_"|cat:$actionproduct->oxarticles__oxid->value test_Cntr=$smarty.foreach.test_articleList.iteration}]
[{/foreach}]
the included file product_alt.tpl in the foreach loop contains a simple div container and get displayed for each product. Now i am looking for a solutions to add to every second div container a extra class.
I google a bit and found out (i think so) that I must work with even and odd. But i stucked how to apply this exactly to the foreach loop with the goal that every secod div container get an extra class.
You are looking for cycle. What you can do for instance is assign an extra $class variable in your include statement, that gets changed by the assign, like so:
{cycle values='yourClass1,youClass2' assign='class'}
That's probably where your odd/even thought comes from: the manual says
{cycle values='odd,even' assign='class'}
But those are just values. Anyeay, your variable 'class' now has alternating "yourClass1" and "yourClass2" (or odd/even) as content. If you assign this to your include, and then add something like
<div class="{$class}">
You get alternating classes. One of them is the one you want. the other can be empty..
check out the cycle manual: http://www.smarty.net/docsv2/en/language.function.cycle